FreeCalypso > hg > fc-usbser-tools
annotate duart28/eeprom_wr.c @ 32:bb1d0956b0a8
fteeprom-read: we can do it without kicking off ftdi_sio driver
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 09 Sep 2023 19:56:11 +0000 |
parents | 530ec3792de8 |
children |
rev | line source |
---|---|
29
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
31
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
2 * This module implements the final step of modifying the EEPROM |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
3 * for the desired configuration. |
29
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <usb.h> |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "../libftmini/eeprom_func.h" |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
31
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
14 extern u_short eeprom[64]; |
29
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 static void |
31
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
17 recompute_checksum() |
29
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 u_short chksum = 0xAAAA; |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 unsigned n; |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
31
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
22 for (n = 0; n < 63; n++) { |
29
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 chksum ^= eeprom[n]; |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 chksum = (chksum << 1) | (chksum >> 15); |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
31
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
26 eeprom[63] = chksum; |
29
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 } |
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
31
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
29 void |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
30 update_eeprom(usbh, newconf) |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
31 usb_dev_handle *usbh; |
29
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 { |
31
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
33 switch (newconf) { |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
34 case 'C': |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
35 eeprom[2] = 0x7152; |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
36 break; |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
37 case 'S': |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
38 eeprom[2] = 0x6010; |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
39 break; |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
40 default: |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
41 fprintf(stderr, "BUG: wrong argument to update_eeprom()\n"); |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
42 abort(); |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
43 } |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
44 eeprom[31] = newconf; |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
45 recompute_checksum(); |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
46 ftmini_write_eeprom_loc(usbh, 2, eeprom[2]); |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
47 ftmini_write_eeprom_loc(usbh, 31, eeprom[31]); |
530ec3792de8
fc-duart28-conf: implement set command
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
48 ftmini_write_eeprom_loc(usbh, 63, eeprom[63]); |
29
a7393d00996a
fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |