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