FreeCalypso > hg > fc-usbser-tools
annotate cp2102/write_eeprom.c @ 97:8d35346f1d46
cp2102 tools: accept "default" as device-selector
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 28 Sep 2023 03:26:11 +0000 |
parents | c6d04771bf6a |
children |
rev | line source |
---|---|
53
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
96
c6d04771bf6a
cp2102-write-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
2 * This module implements the elementary function for writing the EEPROM |
c6d04771bf6a
cp2102-write-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
3 * on a CP2102 device. |
53
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 |
96
c6d04771bf6a
cp2102-write-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
16 write_eeprom(usbh) |
53
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 |
96
c6d04771bf6a
cp2102-write-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
21 rc = usb_control_msg(usbh, DEVICE_OUT_REQTYPE, CP210x_CONFIG, |
53
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 REG_EEPROM, 0, (char *) eeprom, SIZE_EEPROM, |
96
c6d04771bf6a
cp2102-write-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
23 USB_WRITE_TIMEOUT); |
53
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, |
96
c6d04771bf6a
cp2102-write-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
26 "EEPROM write error: usb_control_msg() returned %d\n", |
53
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 } |