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