FreeCalypso > hg > fc-usbser-tools
annotate fteeprom/ftee-gen2232c.c @ 77:66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 26 Sep 2023 01:17:32 +0000 |
parents | 7ff9b4857aaf |
children |
rev | line source |
---|---|
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
1 /* |
75
7ff9b4857aaf
fteeprom/ftee-gen2232c.c: typo in header comment
Mychaela Falconia <falcon@freecalypso.org>
parents:
73
diff
changeset
|
2 * This program constructs a configuration EEPROM image for FT2232C/D chips |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
3 * based on a configuration source file giving various settings. |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
4 */ |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
5 |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <ctype.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdio.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <unistd.h> |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
7
b2c891299e83
ftee-gen*: look for EEPROM config file in /opt/freecalypso/ftdi
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
14 extern FILE *open_eeprom_config_file(); |
b2c891299e83
ftee-gen*: look for EEPROM config file in /opt/freecalypso/ftdi
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
15 |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char *configfile, *serial; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 u_short vid = 0x0403, pid = 0x6010; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char *manuf, *product; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 u_char byte00 = 0x08, byte01 = 0x08; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 u_char byte08 = 0x80, byte0A = 0x00; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 unsigned maxpower = 100; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 u_short usb_version = 0x0200; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 u_short eeprom[128]; |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
26 u_char eeprom_chip = 0x46, eeprom_chip_cmdline; |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 unsigned eeprom_size, eeprom_string_ptr; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
29 static void |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 process_cmdline(argc, argv) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 char **argv; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 int c; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 extern int optind; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
36 while ((c = getopt(argc, argv, "bBs")) != EOF) { |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 switch (c) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 case 'b': |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
39 eeprom_chip = eeprom_chip_cmdline = 0x56; |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 continue; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 case 'B': |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
42 eeprom_chip = eeprom_chip_cmdline = 0x66; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
43 continue; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
44 case 's': |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
45 eeprom_chip = eeprom_chip_cmdline = 0x46; |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 continue; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 default: |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 /* error msg already printed */ |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (argc < optind + 1 || argc > optind + 2) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 fprintf(stderr, |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 "usage: %s [options] config-file [serial-num]\n", |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 argv[0]); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 configfile = argv[optind]; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 serial = argv[optind+1]; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
62 static void |
77
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
63 take_one_arg(arg) |
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
64 char *arg; |
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
65 { |
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
66 char *cp; |
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
67 |
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
68 for (cp = arg; *cp && !isspace(*cp); cp++) |
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
69 ; |
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
70 if (*cp) |
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
71 *cp = '\0'; |
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
72 } |
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
73 |
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
74 static void |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
75 ftdi_chip_setting(arg, filename_for_errs, lineno) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
76 char *arg, *filename_for_errs; |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 { |
77
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
78 take_one_arg(arg); |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
79 if (!strcasecmp(arg, "FT2232C")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
80 return; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
81 if (!strcasecmp(arg, "FT2232D")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
82 return; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
83 if (!strcasecmp(arg, "FT2232x")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
84 return; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
85 fprintf(stderr, "%s line %d: config is for wrong FTDI chip\n", |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
86 filename_for_errs, lineno); |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
87 exit(1); |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
88 } |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
89 |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
90 static void |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
91 eeprom_setting(arg, filename_for_errs, lineno) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
92 char *arg, *filename_for_errs; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
93 { |
77
66cbbd7d85cf
ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
94 take_one_arg(arg); |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
95 if (!strcasecmp(arg, "93C46")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
96 eeprom_chip = 0x46; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
97 else if (!strcasecmp(arg, "93C56")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
98 eeprom_chip = 0x56; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
99 else if (!strcasecmp(arg, "93C66")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
100 eeprom_chip = 0x66; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
101 else { |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
102 fprintf(stderr, "%s line %d: invalid eeprom setting\n", |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
103 filename_for_errs, lineno); |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
104 exit(1); |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
105 } |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
106 if (eeprom_chip_cmdline && eeprom_chip_cmdline != eeprom_chip) { |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
107 fprintf(stderr, |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
108 "%s line %d: eeprom setting disagrees with command line option\n", |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
109 filename_for_errs, lineno); |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
110 exit(1); |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
114 static void |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 read_config_file() |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 FILE *inf; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 char linebuf[1024]; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 int lineno; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 char *cp, *np; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 |
7
b2c891299e83
ftee-gen*: look for EEPROM config file in /opt/freecalypso/ftdi
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
122 inf = open_eeprom_config_file(configfile); |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 if (!inf) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 perror(configfile); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 cp = index(linebuf, '\n'); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 if (!cp) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 fprintf(stderr, |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 "%s line %d: too long or unterminated\n", |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 configfile, lineno); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 *cp = '\0'; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 for (cp = linebuf; isspace(*cp); cp++) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 ; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 if (*cp == '\0' || *cp == '#') |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 continue; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 for (np = cp; *cp && !isspace(*cp); cp++) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 ; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 if (*cp) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 *cp++ = '\0'; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 while (isspace(*cp)) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 cp++; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 if (*cp == '\0' || *cp == '#') { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 fprintf(stderr, |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 "%s line %d: \"%s\" setting without argument\n", |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 configfile, lineno, np); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 if (!strcmp(np, "vid")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 vid = strtoul(cp, 0, 16); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 else if (!strcmp(np, "pid")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 pid = strtoul(cp, 0, 16); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 else if (!strcmp(np, "manuf")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 manuf = strdup(cp); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 else if (!strcmp(np, "product")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 product = strdup(cp); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 else if (!strcmp(np, "byte00")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 byte00 = strtoul(cp, 0, 16); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 else if (!strcmp(np, "byte01")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 byte01 = strtoul(cp, 0, 16); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 else if (!strcmp(np, "byte08")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 byte08 = strtoul(cp, 0, 16); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 else if (!strcmp(np, "byte0A")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 byte0A = strtoul(cp, 0, 16); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 else if (!strcmp(np, "maxpower")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 maxpower = strtoul(cp, 0, 10); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 else if (!strcmp(np, "usbver")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 usb_version = strtoul(cp, 0, 16); |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
172 else if (!strcmp(np, "ftdi-chip")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
173 ftdi_chip_setting(cp, configfile, lineno); |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
174 else if (!strcmp(np, "eeprom")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
175 eeprom_setting(cp, configfile, lineno); |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 else { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 fprintf(stderr, "%s line %d: unknown \"%s\" setting\n", |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 configfile, lineno, np); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 fclose(inf); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 if (!manuf) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 fprintf(stderr, "error: manuf not set in %s\n", configfile); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 if (!product) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 fprintf(stderr, "error: product not set in %s\n", configfile); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
193 static void |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
194 init_eeprom_size() |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
195 { |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
196 if (eeprom_chip == 0x46) { |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
197 eeprom_size = 64; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
198 eeprom_string_ptr = 0x0B; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
199 } else { |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
200 eeprom_size = 128; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
201 eeprom_string_ptr = 0x4B; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
202 } |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
203 } |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
204 |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
205 static int |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 write_string(str) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 char *str; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 unsigned longlen, startptr; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 if (eeprom_size - 1 - eeprom_string_ptr < strlen(str) + 1) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 fprintf(stderr, "error: strings are too long\n"); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 longlen = strlen(str) * 2 + 2; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 startptr = eeprom_string_ptr; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 eeprom[eeprom_string_ptr++] = 0x0300 | longlen; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 while (*str) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 eeprom[eeprom_string_ptr++] = *str++; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 return (longlen << 8) | 0x80 | (startptr << 1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
223 static void |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 fill_eeprom() |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 u_char byte09; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 if (serial) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 byte0A |= 0x08; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 else |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 byte0A &= 0xF7; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 byte09 = maxpower / 2; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 eeprom[0] = (byte01 << 8) | byte00; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 eeprom[1] = vid; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 eeprom[2] = pid; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 eeprom[3] = 0x0500; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 eeprom[4] = (byte09 << 8) | byte08; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 eeprom[5] = byte0A; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 eeprom[6] = usb_version; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 eeprom[7] = write_string(manuf); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 eeprom[8] = write_string(product); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 if (serial) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 eeprom[9] = write_string(serial); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 else |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 eeprom[9] = 0; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 eeprom[10] = eeprom_chip; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
249 static void |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 do_checksum() |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 u_short chksum = 0xAAAA; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 unsigned n; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 for (n = 0; n < eeprom_size - 1; n++) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 chksum ^= eeprom[n]; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 chksum = (chksum << 1) | (chksum >> 15); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 eeprom[n] = chksum; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
262 static void |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 emit_output() |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 unsigned n, col; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 for (n = 0; n < eeprom_size; n++) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 col = n & 7; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 if (col == 0) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 printf("%02X:", n * 2); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 printf(" %04X", eeprom[n]); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 if (col == 7) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 putchar('\n'); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 main(argc, argv) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 char **argv; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 process_cmdline(argc, argv); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 read_config_file(); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 init_eeprom_size(); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 fill_eeprom(); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 do_checksum(); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 emit_output(); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 exit(0); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 } |