annotate fteeprom/ftee-gen2232h.c @ 78:d46ea7a3fa0c

eeproms: add ftdi-chip and eeprom settings as appropriate
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 26 Sep 2023 01:37:33 +0000
parents 66cbbd7d85cf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
74
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
1 /*
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
2 * This program constructs a configuration EEPROM image for an FT2232H chip
d069e2a6760e ftee-gen2232h: 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.
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
4 */
d069e2a6760e ftee-gen2232h: 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_char group0, group1, group2, group3;
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];
74
d069e2a6760e ftee-gen2232h: 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
74
d069e2a6760e ftee-gen2232h: 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
74
d069e2a6760e ftee-gen2232h: 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':
74
d069e2a6760e ftee-gen2232h: 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':
74
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
42 eeprom_chip = eeprom_chip_cmdline = 0x66;
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
43 continue;
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
44 case 's':
d069e2a6760e ftee-gen2232h: 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
74
d069e2a6760e ftee-gen2232h: 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: 74
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: 74
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: 74
diff changeset
65 {
66cbbd7d85cf ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
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: 74
diff changeset
67
66cbbd7d85cf ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
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: 74
diff changeset
69 ;
66cbbd7d85cf ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
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: 74
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: 74
diff changeset
72 }
66cbbd7d85cf ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
73
66cbbd7d85cf ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
74 static void
74
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
75 ftdi_chip_setting(arg, filename_for_errs, lineno)
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
76 char *arg, *filename_for_errs;
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
77 {
77
66cbbd7d85cf ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
78 take_one_arg(arg);
74
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
79 if (!strcasecmp(arg, "FT2232H"))
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
80 return;
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
81 if (!strcasecmp(arg, "FT2232x"))
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
82 return;
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
83 fprintf(stderr, "%s line %d: config is for wrong FTDI chip\n",
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
84 filename_for_errs, lineno);
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
85 exit(1);
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
86 }
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
87
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
88 static void
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
89 eeprom_setting(arg, filename_for_errs, lineno)
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
90 char *arg, *filename_for_errs;
0
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 {
77
66cbbd7d85cf ftee-gen*: allow trailing ws and comments after ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
92 take_one_arg(arg);
74
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
93 if (!strcasecmp(arg, "93C46"))
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
94 eeprom_chip = 0x46;
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
95 else if (!strcasecmp(arg, "93C56"))
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
96 eeprom_chip = 0x56;
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
97 else if (!strcasecmp(arg, "93C66"))
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
98 eeprom_chip = 0x66;
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
99 else {
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
100 fprintf(stderr, "%s line %d: invalid eeprom setting\n",
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
101 filename_for_errs, lineno);
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
102 exit(1);
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
103 }
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
104 if (eeprom_chip_cmdline && eeprom_chip_cmdline != eeprom_chip) {
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
105 fprintf(stderr,
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
106 "%s line %d: eeprom setting disagrees with command line option\n",
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
107 filename_for_errs, lineno);
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
108 exit(1);
0
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
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
74
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
112 static void
0
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 read_config_file()
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 FILE *inf;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 char linebuf[1024];
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 int lineno;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 char *cp, *np;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119
7
b2c891299e83 ftee-gen*: look for EEPROM config file in /opt/freecalypso/ftdi
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
120 inf = open_eeprom_config_file(configfile);
0
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 if (!inf) {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 perror(configfile);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 exit(1);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 }
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 cp = index(linebuf, '\n');
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 if (!cp) {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 fprintf(stderr,
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 "%s line %d: too long or unterminated\n",
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 configfile, lineno);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 exit(1);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 }
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 *cp = '\0';
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 for (cp = linebuf; isspace(*cp); cp++)
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 ;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 if (*cp == '\0' || *cp == '#')
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 continue;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 for (np = cp; *cp && !isspace(*cp); cp++)
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 ;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 if (*cp)
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 *cp++ = '\0';
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 while (isspace(*cp))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 cp++;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 if (*cp == '\0' || *cp == '#') {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 fprintf(stderr,
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 "%s line %d: \"%s\" setting without argument\n",
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 configfile, lineno, np);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 exit(1);
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 if (!strcmp(np, "vid"))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 vid = strtoul(cp, 0, 16);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 else if (!strcmp(np, "pid"))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 pid = strtoul(cp, 0, 16);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 else if (!strcmp(np, "manuf"))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 manuf = strdup(cp);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 else if (!strcmp(np, "product"))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 product = strdup(cp);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 else if (!strcmp(np, "byte00"))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 byte00 = strtoul(cp, 0, 16);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 else if (!strcmp(np, "byte01"))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 byte01 = strtoul(cp, 0, 16);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 else if (!strcmp(np, "byte08"))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 byte08 = strtoul(cp, 0, 16);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 else if (!strcmp(np, "byte0A"))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 byte0A = strtoul(cp, 0, 16);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 else if (!strcmp(np, "maxpower"))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 maxpower = strtoul(cp, 0, 10);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 else if (!strcmp(np, "group0"))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 group0 = strtoul(cp, 0, 16);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 else if (!strcmp(np, "group1"))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 group1 = strtoul(cp, 0, 16);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 else if (!strcmp(np, "group2"))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 group2 = strtoul(cp, 0, 16);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 else if (!strcmp(np, "group3"))
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 group3 = strtoul(cp, 0, 16);
74
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
176 else if (!strcmp(np, "ftdi-chip"))
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
177 ftdi_chip_setting(cp, configfile, lineno);
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
178 else if (!strcmp(np, "eeprom"))
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
179 eeprom_setting(cp, configfile, lineno);
0
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 else {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 fprintf(stderr, "%s line %d: unknown \"%s\" setting\n",
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 configfile, lineno, np);
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 }
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 fclose(inf);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 if (!manuf) {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 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
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 if (!product) {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 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
193 exit(1);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 }
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 }
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196
74
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
197 static void
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
198 init_eeprom_size()
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
199 {
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
200 if (eeprom_chip == 0x46) {
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
201 eeprom_size = 64;
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
202 eeprom_string_ptr = 0x0D;
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
203 } else {
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
204 eeprom_size = 128;
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
205 eeprom_string_ptr = 0x4D;
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
206 }
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
207 }
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
208
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
209 static int
0
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 write_string(str)
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 char *str;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 unsigned longlen, startptr;
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 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
216 fprintf(stderr, "error: strings are too long\n");
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 exit(1);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 }
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 longlen = strlen(str) * 2 + 2;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 startptr = eeprom_string_ptr;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 eeprom[eeprom_string_ptr++] = 0x0300 | longlen;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 while (*str)
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 eeprom[eeprom_string_ptr++] = *str++;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 return (longlen << 8) | 0x80 | (startptr << 1);
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
74
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
227 static void
0
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 fill_eeprom()
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 u_char byte09;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 if (serial)
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 byte0A |= 0x08;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 else
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 byte0A &= 0xF7;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 byte09 = maxpower / 2;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 eeprom[0] = (byte01 << 8) | byte00;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 eeprom[1] = vid;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 eeprom[2] = pid;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 eeprom[3] = 0x0700;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 eeprom[4] = (byte09 << 8) | byte08;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 eeprom[5] = byte0A;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 eeprom[6] = (group3 << 12) | (group2 << 8) | (group1 << 4) | group0;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 eeprom[7] = write_string(manuf);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 eeprom[8] = write_string(product);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 if (serial)
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 eeprom[9] = write_string(serial);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 else
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 eeprom[9] = 0;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 eeprom[12] = eeprom_chip;
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
74
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
253 static void
0
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 do_checksum()
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 u_short chksum = 0xAAAA;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 unsigned n;
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 for (n = 0; n < eeprom_size - 1; n++) {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 chksum ^= eeprom[n];
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 chksum = (chksum << 1) | (chksum >> 15);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 }
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 eeprom[n] = chksum;
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
74
d069e2a6760e ftee-gen2232h: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
266 static void
0
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 emit_output()
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 unsigned n, col;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 for (n = 0; n < eeprom_size; n++) {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 col = n & 7;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 if (col == 0)
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 printf("%02X:", n * 2);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 printf(" %04X", eeprom[n]);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 if (col == 7)
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 putchar('\n');
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 }
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
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 main(argc, argv)
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 char **argv;
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 {
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 process_cmdline(argc, argv);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 read_config_file();
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 init_eeprom_size();
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 fill_eeprom();
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 do_checksum();
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 emit_output();
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 exit(0);
11b8a30333b3 fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 }