From ca008db4258598f14f6ec1891a4ab20c262ca924 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Fri, 5 Sep 2025 18:41:12 -0400 Subject: usb: preemptive bug fix --- fw/usb.c | 23 +++++++++++++++-------- sw/usbcom/usbcom.c | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/fw/usb.c b/fw/usb.c index bdf3b64..7f283e1 100644 --- a/fw/usb.c +++ b/fw/usb.c @@ -72,8 +72,10 @@ idleState(void) { static State state; uint8_t opcode; + state.next = idleState; + readLen = getsUSBUSART(readBuf, sizeof(readBuf)); - if (readLen >= 2u) { + if (readLen >= 2u) { // ... opcode = readBuf[0u]; // skip @@ -84,11 +86,8 @@ idleState(void) { case 'e': state.next = echoState; break; case 'w': state.next = writeEepromState; break; case 'r': state.next = readEepromState; break; - default: state.next = idleState; break; // invalid command + default: break; // invalid command } - } else { - // Invalid command. Must start with - state.next = idleState; } return &state; @@ -97,9 +96,11 @@ idleState(void) { // Handle "e" echo command. static State * echoState(void) { - static State state = {echoState}; + static State state; uint8_t i; + state.next = echoState; + if (readLen == 0u) { readLen = getsUSBUSART(readBuf, sizeof(readBuf)); } @@ -125,16 +126,22 @@ echoState(void) { // Handle "w" write eeprom command. static State * writeEepromState(void) { - static State state = {idleState}; + static State state; + // TODO + + state.next = idleState; return &state; } // Handle "r" read eeprom command. static State * readEepromState(void) { - static State state = {idleState}; + static State state; + // TODO + + state.next = idleState; return &state; } diff --git a/sw/usbcom/usbcom.c b/sw/usbcom/usbcom.c index a51bd6f..a374875 100644 --- a/sw/usbcom/usbcom.c +++ b/sw/usbcom/usbcom.c @@ -6,7 +6,7 @@ #include -#define TIMEOUT_MS 1000 +#define TIMEOUT_MS 5000 #define BUF_SIZE 512 -- cgit v1.2.3