( ESNUG 288 Item 6 ) ----------------------------------------------- [5/7/98]
Subject: ( ESNUG 286 #9) A Verilog Reader for Intel HEXfiles
> Does anybody have a verilog reader for Intel hexfiles or do you have
> any idea, where I can find such a reader?
>
> - Reichert Ulrich
> Siemens AG Munich
From: Jon Connell <jon.connell@hl.siemens.de>
John,
This isn't a Verilog solution (it's C), but you should be able to translate
this into Verilog really easily. If memory serves, the 20-bit address hack
was because our compiler only spits out 20-bit addresses.
extern char* memory;
void load(const char* file_name, int crc_check)
{
char l[257]; /* Line buffer */
unsigned address, base_address;
int length, rec_type, crc, i;
FILE* f;
f = fopen(file_name,"r");
if (!f) {
char msg[256];
fprintf(stderr, "load: no such file \"%.128s\"", file_name);
return;
}
rec_type = 0;
base_address = 0;
do {
if (l != fgets(l,256,f))
goto format_error;
if (l[0] == ':') {
crc = 0;
length = byte(l+1);
crc += length;
address = base_address + 256*byte(l+3)+byte(l+5);
crc += byte(l+3);
crc += byte(l+5);
rec_type = byte(l+7);
crc += rec_type;
/* Evaluate crc */
for (i = 0; i < length; i++) {
crc += byte(l+9+2*i);
}
crc += byte(l+9+2*i);
if (crc_check && ((crc & 0xff) != 0))
goto format_error;
if (rec_type == 0) {
/* Data record */
for (i = 0; i < length; i++) {
memory[address++] = byte(l+9+2*i);
}
} else if (rec_type == 2) {
/* base_address = 16*(256*byte(l+3)+byte(l+5)); */
/* only 20 bit address, bits 19:16 on 10th char of line */
base_address = 256*(256*hexdigit(l[9]));
} else if (rec_type == 4) {
base_address = (256*byte(l+9) + byte(l+11)) << 16;
}
}
} while (rec_type != 1);
return;
format_error:
fprintf(stderr, "load: invalid Intel Hex file");
return;
}
You might also want to take a look at this:
http://www.idt-isep.ipp.pt/isep/electro/automacao/doc/micro/intelhex.tut
- Jon Connell
Siemens
|
|