FreeCalypso > hg > fc-usbser-tools
comparison fteeprom/fteeprom-read.c @ 0:11b8a30333b3
fteeprom: initial import from freecalypso-hwlab
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Sep 2023 18:08:22 +0000 |
parents | |
children | 1d76deae1e74 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:11b8a30333b3 |
---|---|
1 #include <sys/types.h> | |
2 #include <string.h> | |
3 #include <strings.h> | |
4 #include <stdio.h> | |
5 #include <stdlib.h> | |
6 #include <unistd.h> | |
7 #include <ftdi.h> | |
8 | |
9 char *device_selector; | |
10 unsigned eeprom_size = 64; | |
11 | |
12 process_cmdline(argc, argv) | |
13 char **argv; | |
14 { | |
15 int c; | |
16 extern int optind; | |
17 | |
18 while ((c = getopt(argc, argv, "bB")) != EOF) { | |
19 switch (c) { | |
20 case 'b': | |
21 eeprom_size = 128; | |
22 continue; | |
23 case 'B': | |
24 eeprom_size = 256; | |
25 continue; | |
26 default: | |
27 /* error msg already printed */ | |
28 exit(1); | |
29 } | |
30 } | |
31 if (argc != optind + 1) { | |
32 fprintf(stderr, "usage: %s [options] device-selector\n", | |
33 argv[0]); | |
34 exit(1); | |
35 } | |
36 device_selector = argv[optind]; | |
37 } | |
38 | |
39 main(argc, argv) | |
40 char **argv; | |
41 { | |
42 struct ftdi_context ftdi; | |
43 u_short word; | |
44 unsigned n, col; | |
45 | |
46 process_cmdline(argc, argv); | |
47 ftdi_init(&ftdi); | |
48 if (ftdi_usb_open_string(&ftdi, device_selector) < 0) { | |
49 fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str); | |
50 exit(1); | |
51 } | |
52 for (n = 0; n < eeprom_size; n++) { | |
53 if (ftdi_read_eeprom_location(&ftdi, n, &word) < 0) { | |
54 fprintf(stderr, "EEPROM read error: %s\n", | |
55 ftdi.error_str); | |
56 exit(1); | |
57 } | |
58 col = n & 7; | |
59 if (col == 0) | |
60 printf("%02X:", n * 2); | |
61 printf(" %04X", word); | |
62 if (col == 7) | |
63 putchar('\n'); | |
64 } | |
65 ftdi_usb_close(&ftdi); | |
66 exit(0); | |
67 } |