annotate fteeprom/ftee-gen232r.c @ 0:11b8a30333b3

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