FreeCalypso > hg > freecalypso-hwlab
annotate ee2232/ee2232-gen.c @ 84:1d7d8615d628
pcsc-test: some experiments to get pcsc-lite working
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 23 Jan 2021 17:21:08 +0000 |
parents | 252e3d37b9e5 |
children |
rev | line source |
---|---|
0
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <ctype.h> |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <string.h> |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <strings.h> |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdlib.h> |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 u_short vid = 0x0403, pid = 0x6010; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 char *manuf, *product; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 u_char byte00 = 0x08, byte01 = 0x08; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 u_char byte08 = 0x80, byte0A = 0x00; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 unsigned maxpower = 100; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 u_short usb_version = 0x0200; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 u_short eeprom[64]; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 unsigned eeprom_string_ptr = 0x0B; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 read_config_file(filename) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char *filename; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 FILE *inf; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 char linebuf[1024]; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 int lineno; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 char *cp, *np; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 inf = fopen(filename, "r"); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (!inf) { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 perror(filename); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 exit(1); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 cp = index(linebuf, '\n'); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (!cp) { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 fprintf(stderr, |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 "%s line %d: too long or unterminated\n", |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 filename, lineno); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 exit(1); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 *cp = '\0'; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 for (cp = linebuf; isspace(*cp); cp++) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 ; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (*cp == '\0' || *cp == '#') |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 continue; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 for (np = cp; *cp && !isspace(*cp); cp++) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 ; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (*cp) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 *cp++ = '\0'; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 while (isspace(*cp)) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 cp++; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (*cp == '\0' || *cp == '#') { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 fprintf(stderr, |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 "%s line %d: \"%s\" setting without argument\n", |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 filename, lineno, np); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 exit(1); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (!strcmp(np, "vid")) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 vid = strtoul(cp, 0, 16); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 else if (!strcmp(np, "pid")) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 pid = strtoul(cp, 0, 16); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 else if (!strcmp(np, "manuf")) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 manuf = strdup(cp); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 else if (!strcmp(np, "product")) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 product = strdup(cp); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 else if (!strcmp(np, "byte00")) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 byte00 = strtoul(cp, 0, 16); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 else if (!strcmp(np, "byte01")) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 byte01 = strtoul(cp, 0, 16); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 else if (!strcmp(np, "byte08")) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 byte08 = strtoul(cp, 0, 16); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 else if (!strcmp(np, "byte0A")) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 byte0A = strtoul(cp, 0, 16); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 else if (!strcmp(np, "maxpower")) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 maxpower = strtoul(cp, 0, 10); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 else if (!strcmp(np, "usbver")) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 usb_version = strtoul(cp, 0, 16); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 else { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 fprintf(stderr, "%s line %d: unknown \"%s\" setting\n", |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 filename, lineno, np); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 exit(1); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 fclose(inf); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 if (!manuf) { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 fprintf(stderr, "error: manuf not set in %s\n", filename); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 exit(1); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 if (!product) { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 fprintf(stderr, "error: product not set in %s\n", filename); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 exit(1); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 write_string(str) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 char *str; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 unsigned longlen, startptr; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 longlen = strlen(str) * 2 + 2; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 startptr = eeprom_string_ptr; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 eeprom[eeprom_string_ptr++] = 0x0300 | longlen; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 while (*str) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 eeprom[eeprom_string_ptr++] = *str++; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 return (longlen << 8) | 0x80 | (startptr << 1); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 fill_eeprom(serial) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 char *serial; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 u_char byte09; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 if (serial) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 byte0A |= 0x08; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 else |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 byte0A &= 0xF7; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 byte09 = maxpower / 2; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 eeprom[0] = (byte01 << 8) | byte00; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 eeprom[1] = vid; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 eeprom[2] = pid; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 eeprom[3] = 0x0500; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 eeprom[4] = (byte09 << 8) | byte08; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 eeprom[5] = byte0A; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 eeprom[6] = usb_version; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 eeprom[7] = write_string(manuf); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 eeprom[8] = write_string(product); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 if (serial) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 eeprom[9] = write_string(serial); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 else |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 eeprom[9] = 0; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 eeprom[10] = 0x46; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 do_checksum() |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 { |
2
252e3d37b9e5
ee2232-gen works after checksum bugfix
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
134 u_short chksum = 0xAAAA; |
0
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 unsigned n; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 for (n = 0; n < 63; n++) { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 chksum ^= eeprom[n]; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 chksum = (chksum << 1) | (chksum >> 15); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 eeprom[63] = chksum; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 emit_output() |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 unsigned n, col; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 for (n = 0; n < 64; n++) { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 col = n & 7; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 if (col == 0) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 printf("%02X:", n * 2); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 printf(" %04X", eeprom[n]); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 if (col == 7) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 putchar('\n'); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 main(argc, argv) |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 char **argv; |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 if (argc < 2 || argc > 3) { |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 fprintf(stderr, "usage: %s config-file [serial-num]\n", |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 argv[0]); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 exit(1); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 } |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 read_config_file(argv[1]); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 fill_eeprom(argv[2]); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 do_checksum(); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 emit_output(); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 exit(0); |
be4cbc0efb7e
ee2232-gen program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 } |