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