comparison cp2102/intel_hex_out.c @ 53:d4d3531d342a

cp2102-read-eeprom program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Sep 2023 18:49:07 +0000
parents
children 842cff427588
comparison
equal deleted inserted replaced
52:61cdcf2eb17b 53:d4d3531d342a
1 /*
2 * This module implements a function for writing out the same Intel HEX
3 * format as used by cp210x-program-1.0, the Python-language tool from 2014.
4 */
5
6 #include <sys/types.h>
7 #include <string.h>
8 #include <strings.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include "cp210x_defs.h"
12
13 void
14 intel_hex_out(eeprom, outf)
15 u_char *eeprom;
16 FILE *outf;
17 {
18 unsigned linecnt, bytecnt;
19 unsigned addr;
20 u_char *sp;
21 u_char record[21], *dp, csum;
22
23 sp = eeprom;
24 addr = EEPROM_START_ADDR;
25 for (linecnt = 0; linecnt < 64; linecnt++) {
26 dp = record;
27 *dp++ = 0x10;
28 *dp++ = addr >> 8;
29 *dp++ = addr;
30 *dp++ = 0x00;
31 for (bytecnt = 0; bytecnt < 16; bytecnt++)
32 *dp++ = *sp++;
33 csum = 0;
34 for (bytecnt = 0; bytecnt < 20; bytecnt++)
35 csum = record[bytecnt];
36 csum = 0x100 - csum;
37 record[20] = csum;
38 putc(':', outf);
39 for (bytecnt = 0; bytecnt < 21; bytecnt++)
40 fprintf(outf, "%02X", record[bytecnt]);
41 putc('\n', outf);
42 addr += 16;
43 }
44 fputs(":00000001FF\n", outf);
45 }