FreeCalypso > hg > fc-usbser-tools
annotate cp2102/read_eeprom.c @ 104:866eae65dbea
LICENSE: same as other FreeCalypso tools
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 29 Sep 2023 18:20:04 +0000 |
parents | d4d3531d342a |
children |
rev | line source |
---|---|
53
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the elementary function for reading the EEPROM |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * content out of a CP2102 device. |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <unistd.h> |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <usb.h> |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "cp210x_defs.h" |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern u_char eeprom[SIZE_EEPROM]; |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 void |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 read_eeprom(usbh) |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 usb_dev_handle *usbh; |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int rc; |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 rc = usb_control_msg(usbh, DEVICE_IN_REQTYPE, CP210x_CONFIG, |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 REG_EEPROM, 0, (char *) eeprom, SIZE_EEPROM, |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 USB_READ_TIMEOUT); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (rc != SIZE_EEPROM) { |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 fprintf(stderr, |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 "EEPROM read error: usb_control_msg() returned %d\n", |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 rc); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 exit(1); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |