diff --git a/BaS_gcc/sources/s19reader.c b/BaS_gcc/sources/s19reader.c index 8d1e2bd..8ca6b3c 100644 --- a/BaS_gcc/sources/s19reader.c +++ b/BaS_gcc/sources/s19reader.c @@ -43,11 +43,15 @@ #define SREC_TYPE(a) (a)[0] /* type of record */ #define SREC_COUNT(a) (a)[1] /* length of valid bytes to follow */ #define SREC_ADDR16(a) (256 * (a)[2] + (a)[3]) /* 2 byte address field */ -#define SREC_ADDR32(a) (0x1000000 * a[2] + 0x10000 *\ +#define SREC_ADDR32(a) (0x1000000 * a[2] + 0x10000 * \ a[3] + 0x100 * (a)[4] + (a)[5]) /* 4 byte address field */ +#define SREC_ADDR24(a) (0x10000 * (a)[2] + 0x100 * \ + (a)[3] + (a)[4]) /* 3 byte address field */ #define SREC_DATA16(a) ((uint8_t *)&((a)[4])) /* address of first byte of data in a record */ +#define SREC_DATA24(a) ((uint8_t *)&((a)[3])) /* address of first data bite in 24 bit record */ #define SREC_DATA32(a) ((uint8_t *)&((a)[6])) /* adress of first byte of a record with 32 bit address field */ #define SREC_DATA16_SIZE(a) (SREC_COUNT((a)) - 3) /* length of the data[] array without the checksum field */ +#define SREC_DATA24_SIZE(a) (SREC_COUNT((a)) - 4) /* length of the data[] array without the checksum field */ #define SREC_DATA32_SIZE(a) (SREC_COUNT((a)) - 5) /* length of the data[] array without the checksum field */ #define SREC_CHECKSUM(a) (a)[SREC_COUNT(a) + 2 - 1] /* record's checksum (two's complement of the sum of all bytes) */ @@ -224,6 +228,16 @@ err_t read_srecords(char *filename, void **start_address, uint32_t *actual_lengt break; + case 2: /* three byte address field data record */ + if (!found_block_header || found_block_end) + { + xprintf("S3 record found before S0 or after S7: S-records corrupt?\r\n"); + ret = FAIL; + } + ret = callback((uint8_t *) SREC_ADDR24(vector), SREC_DATA24(vector), SREC_DATA24_SIZE(vector)); + data_records++; + break; + case 3: /* four byte address field data record */ if (!found_block_header || found_block_end) { @@ -246,8 +260,22 @@ err_t read_srecords(char *filename, void **start_address, uint32_t *actual_lengt } break; + case 8: /* three byte address field end record */ + if (!found_block_header || found_block_end) + { + xprintf("S8 record found before S0 or after S8: S-records corrupt?\r\n"); + } + else + { + // xprintf("S7 record (end) found after %d valid data blocks\r\n", data_records); + *start_address = (void *) SREC_ADDR24(vector); + } + break; + default: xprintf("unsupported record type (%d) found in line %d\r\n", vector[0], lineno); + xprintf("offending line: \r\n"); + xprintf("%s\r\n", line); ret = FAIL; break; }