annotate cp2102/intel_hex_out.c @ 102:4f72e09fb698

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