FreeCalypso > hg > freecalypso-hwlab
annotate fteeprom/ftee-gen2232c.c @ 176:fb2f6497ba53 default tip
doc/Linux-DTR-RTS-flaw: point to new location of this article
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 11 Dec 2023 19:37:20 +0000 |
parents | ea0b5aed9a9c |
children |
rev | line source |
---|---|
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <ctype.h> |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <string.h> |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <strings.h> |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdlib.h> |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
7 #include <unistd.h> |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
8 |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
9 char *configfile, *serial; |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 u_short vid = 0x0403, pid = 0x6010; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 char *manuf, *product; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 u_char byte00 = 0x08, byte01 = 0x08; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 u_char byte08 = 0x80, byte0A = 0x00; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 unsigned maxpower = 100; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 u_short usb_version = 0x0200; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
18 u_short eeprom[128]; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
19 u_char eeprom_chip = 0x46; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
20 unsigned eeprom_size, eeprom_string_ptr; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
21 |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
22 process_cmdline(argc, argv) |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
23 char **argv; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
24 { |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
25 int c; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
26 extern int optind; |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
28 while ((c = getopt(argc, argv, "bB")) != EOF) { |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
29 switch (c) { |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
30 case 'b': |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
31 eeprom_chip = 0x56; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
32 continue; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
33 case 'B': |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
34 eeprom_chip = 0x66; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
35 continue; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
36 default: |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
37 /* error msg already printed */ |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
38 exit(1); |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
39 } |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
40 } |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
41 if (argc < optind + 1 || argc > optind + 2) { |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
42 fprintf(stderr, |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
43 "usage: %s [options] config-file [serial-num]\n", |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
44 argv[0]); |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
45 exit(1); |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
46 } |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
47 configfile = argv[optind]; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
48 serial = argv[optind+1]; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
49 } |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
50 |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
51 init_eeprom_size() |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
52 { |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
53 if (eeprom_chip == 0x46) { |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
54 eeprom_size = 64; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
55 eeprom_string_ptr = 0x0B; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
56 } else { |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
57 eeprom_size = 128; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
58 eeprom_string_ptr = 0x4B; |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
59 } |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
60 } |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
61 |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
62 read_config_file() |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 { |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 FILE *inf; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 char linebuf[1024]; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 int lineno; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 char *cp, *np; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
69 inf = fopen(configfile, "r"); |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (!inf) { |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
71 perror(configfile); |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 exit(1); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 cp = index(linebuf, '\n'); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 if (!cp) { |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 fprintf(stderr, |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 "%s line %d: too long or unterminated\n", |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
79 configfile, lineno); |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 exit(1); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 *cp = '\0'; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 for (cp = linebuf; isspace(*cp); cp++) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 ; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 if (*cp == '\0' || *cp == '#') |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 continue; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 for (np = cp; *cp && !isspace(*cp); cp++) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 ; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 if (*cp) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 *cp++ = '\0'; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 while (isspace(*cp)) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 cp++; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 if (*cp == '\0' || *cp == '#') { |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 fprintf(stderr, |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 "%s line %d: \"%s\" setting without argument\n", |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
96 configfile, lineno, np); |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 exit(1); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 if (!strcmp(np, "vid")) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 vid = strtoul(cp, 0, 16); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 else if (!strcmp(np, "pid")) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 pid = strtoul(cp, 0, 16); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 else if (!strcmp(np, "manuf")) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 manuf = strdup(cp); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 else if (!strcmp(np, "product")) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 product = strdup(cp); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 else if (!strcmp(np, "byte00")) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 byte00 = strtoul(cp, 0, 16); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 else if (!strcmp(np, "byte01")) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 byte01 = strtoul(cp, 0, 16); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 else if (!strcmp(np, "byte08")) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 byte08 = strtoul(cp, 0, 16); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 else if (!strcmp(np, "byte0A")) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 byte0A = strtoul(cp, 0, 16); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 else if (!strcmp(np, "maxpower")) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 maxpower = strtoul(cp, 0, 10); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 else if (!strcmp(np, "usbver")) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 usb_version = strtoul(cp, 0, 16); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 else { |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 fprintf(stderr, "%s line %d: unknown \"%s\" setting\n", |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
121 configfile, lineno, np); |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 exit(1); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 } |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 } |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 fclose(inf); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 if (!manuf) { |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
127 fprintf(stderr, "error: manuf not set in %s\n", configfile); |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 exit(1); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 } |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 if (!product) { |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
131 fprintf(stderr, "error: product not set in %s\n", configfile); |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 exit(1); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 } |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 } |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 write_string(str) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 char *str; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 { |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 unsigned longlen, startptr; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
141 if (eeprom_size - 1 - eeprom_string_ptr < strlen(str) + 1) { |
34
ae48b7d69744
ftee-gen2232c: added guard against strings overflowing EEPROM space
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
142 fprintf(stderr, "error: strings are too long\n"); |
ae48b7d69744
ftee-gen2232c: added guard against strings overflowing EEPROM space
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
143 exit(1); |
ae48b7d69744
ftee-gen2232c: added guard against strings overflowing EEPROM space
Mychaela Falconia <falcon@freecalypso.org>
parents:
31
diff
changeset
|
144 } |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 longlen = strlen(str) * 2 + 2; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 startptr = eeprom_string_ptr; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 eeprom[eeprom_string_ptr++] = 0x0300 | longlen; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 while (*str) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 eeprom[eeprom_string_ptr++] = *str++; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 return (longlen << 8) | 0x80 | (startptr << 1); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 } |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
153 fill_eeprom() |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 { |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 u_char byte09; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 if (serial) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 byte0A |= 0x08; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 else |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 byte0A &= 0xF7; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 byte09 = maxpower / 2; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 eeprom[0] = (byte01 << 8) | byte00; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 eeprom[1] = vid; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 eeprom[2] = pid; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 eeprom[3] = 0x0500; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 eeprom[4] = (byte09 << 8) | byte08; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 eeprom[5] = byte0A; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 eeprom[6] = usb_version; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 eeprom[7] = write_string(manuf); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 eeprom[8] = write_string(product); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 if (serial) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 eeprom[9] = write_string(serial); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 else |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 eeprom[9] = 0; |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
175 eeprom[10] = eeprom_chip; |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 } |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 do_checksum() |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 { |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 u_short chksum = 0xAAAA; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 unsigned n; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
183 for (n = 0; n < eeprom_size - 1; n++) { |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 chksum ^= eeprom[n]; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 chksum = (chksum << 1) | (chksum >> 15); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 } |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
187 eeprom[n] = chksum; |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 } |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 emit_output() |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 { |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 unsigned n, col; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
194 for (n = 0; n < eeprom_size; n++) { |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 col = n & 7; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 if (col == 0) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 printf("%02X:", n * 2); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 printf(" %04X", eeprom[n]); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 if (col == 7) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 putchar('\n'); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 } |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 } |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 main(argc, argv) |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 char **argv; |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 { |
43
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
207 process_cmdline(argc, argv); |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
208 read_config_file(); |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
209 init_eeprom_size(); |
ea0b5aed9a9c
ftee-gen2232c reworked to support larger EEPROMs
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
210 fill_eeprom(); |
31
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 do_checksum(); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 emit_output(); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 exit(0); |
16b625911e19
fteeprom: generalization of previous ee2232 tools
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 } |