# HG changeset patch # User Mychaela Falconia # Date 1694288458 0 # Node ID 530ec3792de805b71f820fc043af913e8f71e37e # Parent 8de3891460db0ce6dd25a77c0930fffd2498da20 fc-duart28-conf: implement set command diff -r 8de3891460db -r 530ec3792de8 duart28/Makefile --- a/duart28/Makefile Sat Sep 09 19:39:15 2023 +0000 +++ b/duart28/Makefile Sat Sep 09 19:40:58 2023 +0000 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 PROG= fc-duart28-conf -OBJS= eeprom_rd.o find_usb.o main.o +OBJS= eeprom_rd.o eeprom_wr.o find_usb.o main.o LIBS= ../libftmini/libftmini.a ../libuwrap/libuwrap.a INSTALL_PREFIX= /opt/freecalypso diff -r 8de3891460db -r 530ec3792de8 duart28/eeprom_wr.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/duart28/eeprom_wr.c Sat Sep 09 19:40:58 2023 +0000 @@ -0,0 +1,49 @@ +/* + * This module implements the final step of modifying the EEPROM + * for the desired configuration. + */ + +#include +#include +#include +#include +#include +#include +#include "../libftmini/eeprom_func.h" + +extern u_short eeprom[64]; + +static void +recompute_checksum() +{ + u_short chksum = 0xAAAA; + unsigned n; + + for (n = 0; n < 63; n++) { + chksum ^= eeprom[n]; + chksum = (chksum << 1) | (chksum >> 15); + } + eeprom[63] = chksum; +} + +void +update_eeprom(usbh, newconf) + usb_dev_handle *usbh; +{ + switch (newconf) { + case 'C': + eeprom[2] = 0x7152; + break; + case 'S': + eeprom[2] = 0x6010; + break; + default: + fprintf(stderr, "BUG: wrong argument to update_eeprom()\n"); + abort(); + } + eeprom[31] = newconf; + recompute_checksum(); + ftmini_write_eeprom_loc(usbh, 2, eeprom[2]); + ftmini_write_eeprom_loc(usbh, 31, eeprom[31]); + ftmini_write_eeprom_loc(usbh, 63, eeprom[63]); +} diff -r 8de3891460db -r 530ec3792de8 duart28/main.c --- a/duart28/main.c Sat Sep 09 19:39:15 2023 +0000 +++ b/duart28/main.c Sat Sep 09 19:40:58 2023 +0000 @@ -41,8 +41,28 @@ oper_program(newconf) { - fprintf(stderr, "error: set command not yet implemented\n"); - exit(1); + struct usb_device *dev; + usb_dev_handle *usbh; + int prev; + + dev = find_duart28_usbdev(); + if (!dev) { + fprintf(stderr, "error: no DUART28 adapter found\n"); + exit(1); + } + usbh = usbwrap_open_dev(dev, 1); + read_eeprom(usbh); + prev = analyze_eeprom(); + if (prev == newconf) { + printf("EEPROM is already in the right state, nothing to do\n"); + usbwrap_close_dev(usbh); + return 0; + } + printf("Reprogramming to DUART28%c configuration\n", newconf); + update_eeprom(usbh, newconf); + usbwrap_close_dev(usbh); + printf("EEPROM changed, replug the USB device to take effect\n"); + return 0; } main(argc, argv)