Skip to content

Commit 771fc76

Browse files
committed
Added utility function for reading data bytes out of a ihx record.
1 parent 7de6f54 commit 771fc76

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/intel_hex.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ uint8_t ihx_check_line(char line[]) {
6363
if (byte_count > IHX_MAX_LEN)
6464
return IHX_RECORD_TOO_LONG;
6565

66-
checksum = hex8(&line[9 + 2*byte_count]);
66+
checksum = ihx_data_byte(line, byte_count);
6767

6868
if (record_type > 1)
6969
return IHX_BAD_RECORD_TYPE;
@@ -87,6 +87,10 @@ uint8_t ihx_record_type(char line[]) {
8787
return hex8(&line[7]);
8888
}
8989

90+
uint8_t ihx_data_byte(char line[], uint8_t n) {
91+
return hex8(&line[9 + n*2]);
92+
}
93+
9094
void ihx_readline(char line[]) {
9195
char c;
9296
uint8_t len;
@@ -117,7 +121,7 @@ void ihx_write(char line[]) {
117121
case IHX_RECORD_DATA:
118122
buff[0] = 0xFF; // Padding in case the flash start address is not even.
119123
for (i=0; i<byte_count; i++)
120-
buff[i+1] = hex8(&line[9 + i*2]);
124+
buff[i+1] = ihx_data_byte(line, i);
121125
buff[byte_count+1] = 0xFF; // If there are not an even no. of bytes, pad with 0xFF to preserve flash.
122126

123127
if (address & 1) {

src/intel_hex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ uint8_t ihx_check_line(char line[]);
4242
void ihx_readline(char line[]);
4343
void ihx_write(char line[]);
4444
uint8_t ihx_record_type(char line[]);
45+
uint8_t ihx_data_byte(char line[], uint8_t n);
4546

4647
#endif // _INTEL_HEX_H_

0 commit comments

Comments
 (0)