comparison fteeprom/ftee-gen232r.c @ 76:957fb6e08577

ftee-gen232r: add ftdi-chip setting
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 26 Sep 2023 00:38:58 +0000
parents b2c891299e83
children 66cbbd7d85cf
comparison
equal deleted inserted replaced
75:7ff9b4857aaf 76:957fb6e08577
1 /*
2 * This program constructs a configuration EEPROM image for an FT232R chip
3 * based on a configuration source file giving various settings.
4 */
5
1 #include <sys/types.h> 6 #include <sys/types.h>
2 #include <ctype.h> 7 #include <ctype.h>
3 #include <string.h> 8 #include <string.h>
4 #include <strings.h> 9 #include <strings.h>
5 #include <stdio.h> 10 #include <stdio.h>
16 u_char cbusconf[5] = {3, 2, 0, 1, 5}; 21 u_char cbusconf[5] = {3, 2, 0, 1, 5};
17 22
18 u_short eeprom[64]; 23 u_short eeprom[64];
19 unsigned eeprom_string_ptr = 0x0C; 24 unsigned eeprom_string_ptr = 0x0C;
20 25
26 static void
27 ftdi_chip_setting(arg, filename_for_errs, lineno)
28 char *arg, *filename_for_errs;
29 {
30 if (!strcasecmp(arg, "FT232R"))
31 return;
32 fprintf(stderr, "%s line %d: config is for wrong FTDI chip\n",
33 filename_for_errs, lineno);
34 exit(1);
35 }
36
37 static void
21 read_config_file(filename) 38 read_config_file(filename)
22 char *filename; 39 char *filename;
23 { 40 {
24 FILE *inf; 41 FILE *inf;
25 char linebuf[1024]; 42 char linebuf[1024];
86 cbusconf[2] = strtoul(cp, 0, 16); 103 cbusconf[2] = strtoul(cp, 0, 16);
87 else if (!strcmp(np, "cbus3")) 104 else if (!strcmp(np, "cbus3"))
88 cbusconf[3] = strtoul(cp, 0, 16); 105 cbusconf[3] = strtoul(cp, 0, 16);
89 else if (!strcmp(np, "cbus4")) 106 else if (!strcmp(np, "cbus4"))
90 cbusconf[4] = strtoul(cp, 0, 16); 107 cbusconf[4] = strtoul(cp, 0, 16);
108 else if (!strcmp(np, "ftdi-chip"))
109 ftdi_chip_setting(cp, filename, lineno);
91 else { 110 else {
92 fprintf(stderr, "%s line %d: unknown \"%s\" setting\n", 111 fprintf(stderr, "%s line %d: unknown \"%s\" setting\n",
93 filename, lineno, np); 112 filename, lineno, np);
94 exit(1); 113 exit(1);
95 } 114 }
103 fprintf(stderr, "error: product not set in %s\n", filename); 122 fprintf(stderr, "error: product not set in %s\n", filename);
104 exit(1); 123 exit(1);
105 } 124 }
106 } 125 }
107 126
127 static int
108 write_string(str) 128 write_string(str)
109 char *str; 129 char *str;
110 { 130 {
111 unsigned longlen, startptr; 131 unsigned longlen, startptr;
112 132
120 while (*str) 140 while (*str)
121 eeprom[eeprom_string_ptr++] = *str++; 141 eeprom[eeprom_string_ptr++] = *str++;
122 return (longlen << 8) | 0x80 | (startptr << 1); 142 return (longlen << 8) | 0x80 | (startptr << 1);
123 } 143 }
124 144
145 static void
125 fill_eeprom(serial) 146 fill_eeprom(serial)
126 char *serial; 147 char *serial;
127 { 148 {
128 u_char byte09; 149 u_char byte09;
129 150
148 eeprom[10] = (cbusconf[3] << 12) | (cbusconf[2] << 8) | 169 eeprom[10] = (cbusconf[3] << 12) | (cbusconf[2] << 8) |
149 (cbusconf[1] << 4) | cbusconf[0]; 170 (cbusconf[1] << 4) | cbusconf[0];
150 eeprom[11] = cbusconf[4]; 171 eeprom[11] = cbusconf[4];
151 } 172 }
152 173
174 static void
153 do_checksum() 175 do_checksum()
154 { 176 {
155 u_short chksum = 0xAAAA; 177 u_short chksum = 0xAAAA;
156 unsigned n; 178 unsigned n;
157 179
160 chksum = (chksum << 1) | (chksum >> 15); 182 chksum = (chksum << 1) | (chksum >> 15);
161 } 183 }
162 eeprom[63] = chksum; 184 eeprom[63] = chksum;
163 } 185 }
164 186
187 static void
165 emit_output() 188 emit_output()
166 { 189 {
167 unsigned n, col; 190 unsigned n, col;
168 191
169 for (n = 0; n < 64; n++) { 192 for (n = 0; n < 64; n++) {