FreeCalypso > hg > fc-usbser-tools
annotate fteeprom/ftee-gen2232c.c @ 74:d069e2a6760e
ftee-gen2232h: add ftdi-chip and eeprom settings
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 26 Sep 2023 00:23:50 +0000 |
parents | 201503e4be18 |
children | 7ff9b4857aaf |
rev | line source |
---|---|
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
1 /* |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
2 * This program constucts a configuration EEPROM image for FT2232C/D chips |
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 |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
63 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
|
64 char *arg, *filename_for_errs; |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 { |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
66 if (!strcasecmp(arg, "FT2232C")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
67 return; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
68 if (!strcasecmp(arg, "FT2232D")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
69 return; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
70 if (!strcasecmp(arg, "FT2232x")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
71 return; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
72 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
|
73 filename_for_errs, lineno); |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
74 exit(1); |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
75 } |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
76 |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
77 static void |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
78 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
|
79 char *arg, *filename_for_errs; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
80 { |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
81 if (!strcasecmp(arg, "93C46")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
82 eeprom_chip = 0x46; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
83 else if (!strcasecmp(arg, "93C56")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
84 eeprom_chip = 0x56; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
85 else if (!strcasecmp(arg, "93C66")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
86 eeprom_chip = 0x66; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
87 else { |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
88 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
|
89 filename_for_errs, lineno); |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
90 exit(1); |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
91 } |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
92 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
|
93 fprintf(stderr, |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
94 "%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
|
95 filename_for_errs, lineno); |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
96 exit(1); |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
100 static void |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 read_config_file() |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 FILE *inf; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 char linebuf[1024]; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 int lineno; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 char *cp, *np; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 |
7
b2c891299e83
ftee-gen*: look for EEPROM config file in /opt/freecalypso/ftdi
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
108 inf = open_eeprom_config_file(configfile); |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 if (!inf) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 perror(configfile); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 exit(1); |
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 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 cp = index(linebuf, '\n'); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 if (!cp) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 fprintf(stderr, |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 "%s line %d: too long or unterminated\n", |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 configfile, lineno); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 *cp = '\0'; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 for (cp = linebuf; isspace(*cp); cp++) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 ; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 if (*cp == '\0' || *cp == '#') |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 continue; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 for (np = cp; *cp && !isspace(*cp); cp++) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 ; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 if (*cp) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 *cp++ = '\0'; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 while (isspace(*cp)) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 cp++; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 if (*cp == '\0' || *cp == '#') { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 fprintf(stderr, |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 "%s line %d: \"%s\" setting without argument\n", |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 configfile, lineno, np); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 exit(1); |
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 (!strcmp(np, "vid")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 vid = strtoul(cp, 0, 16); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 else if (!strcmp(np, "pid")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 pid = strtoul(cp, 0, 16); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 else if (!strcmp(np, "manuf")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 manuf = strdup(cp); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 else if (!strcmp(np, "product")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 product = strdup(cp); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 else if (!strcmp(np, "byte00")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 byte00 = strtoul(cp, 0, 16); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 else if (!strcmp(np, "byte01")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 byte01 = strtoul(cp, 0, 16); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 else if (!strcmp(np, "byte08")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 byte08 = strtoul(cp, 0, 16); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 else if (!strcmp(np, "byte0A")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 byte0A = strtoul(cp, 0, 16); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 else if (!strcmp(np, "maxpower")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 maxpower = strtoul(cp, 0, 10); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 else if (!strcmp(np, "usbver")) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 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
|
158 else if (!strcmp(np, "ftdi-chip")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
159 ftdi_chip_setting(cp, configfile, lineno); |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
160 else if (!strcmp(np, "eeprom")) |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
161 eeprom_setting(cp, configfile, lineno); |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 else { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 fprintf(stderr, "%s line %d: unknown \"%s\" setting\n", |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 configfile, lineno, np); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 fclose(inf); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 if (!manuf) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 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
|
171 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 if (!product) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 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
|
175 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
179 static void |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
180 init_eeprom_size() |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
181 { |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
182 if (eeprom_chip == 0x46) { |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
183 eeprom_size = 64; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
184 eeprom_string_ptr = 0x0B; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
185 } else { |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
186 eeprom_size = 128; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
187 eeprom_string_ptr = 0x4B; |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
188 } |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
189 } |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
190 |
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
191 static int |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 write_string(str) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 char *str; |
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 unsigned longlen, startptr; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 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
|
198 fprintf(stderr, "error: strings are too long\n"); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 exit(1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 longlen = strlen(str) * 2 + 2; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 startptr = eeprom_string_ptr; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 eeprom[eeprom_string_ptr++] = 0x0300 | longlen; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 while (*str) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 eeprom[eeprom_string_ptr++] = *str++; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 return (longlen << 8) | 0x80 | (startptr << 1); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
209 static void |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 fill_eeprom() |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 u_char byte09; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 if (serial) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 byte0A |= 0x08; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 else |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 byte0A &= 0xF7; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 byte09 = maxpower / 2; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 eeprom[0] = (byte01 << 8) | byte00; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 eeprom[1] = vid; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 eeprom[2] = pid; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 eeprom[3] = 0x0500; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 eeprom[4] = (byte09 << 8) | byte08; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 eeprom[5] = byte0A; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 eeprom[6] = usb_version; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 eeprom[7] = write_string(manuf); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 eeprom[8] = write_string(product); |
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 eeprom[9] = write_string(serial); |
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 eeprom[9] = 0; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 eeprom[10] = eeprom_chip; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
235 static void |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 do_checksum() |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 u_short chksum = 0xAAAA; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 unsigned n; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 for (n = 0; n < eeprom_size - 1; n++) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 chksum ^= eeprom[n]; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 chksum = (chksum << 1) | (chksum >> 15); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 eeprom[n] = chksum; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 } |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 |
73
201503e4be18
ftee-gen2232c: add ftdi-chip and eeprom settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
248 static void |
0
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 emit_output() |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 unsigned n, col; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 for (n = 0; n < eeprom_size; n++) { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 col = n & 7; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 if (col == 0) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 printf("%02X:", n * 2); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 printf(" %04X", eeprom[n]); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 if (col == 7) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 putchar('\n'); |
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 } |
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 main(argc, argv) |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 char **argv; |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 { |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 process_cmdline(argc, argv); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 read_config_file(); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 init_eeprom_size(); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 fill_eeprom(); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 do_checksum(); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 emit_output(); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 exit(0); |
11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 } |