diff --git a/firmware/fab-step/src/indicators.h b/firmware/fab-step/src/indicators.h index 29eff40391f43d14bc265b079cf449d4f42d9305..1668f6d9f5c8f7a0d2933ad455af08164607c02a 100644 --- a/firmware/fab-step/src/indicators.h +++ b/firmware/fab-step/src/indicators.h @@ -27,3 +27,6 @@ #define DEBUG1PIN_OFF DEBUG1PIN_PORT.OUTCLR.reg = DEBUG1PIN_BM #define DEBUG1PIN_TOGGLE DEBUG1PIN_PORT.OUTTGL.reg = DEBUG1PIN_BM #define DEBUG1PIN_SETUP DEBUG1PIN_PORT.DIRSET.reg = DEBUG1PIN_BM; DEBUG1PIN_OFF + +#define ERRLIGHT_ON +#define ERRLIGHT_OFF diff --git a/firmware/fab-step/src/osape-d21 b/firmware/fab-step/src/osape-d21 index b47769ec7b9994fb363d881929520afbf4589200..d7df297e7039d697def2a1252e34eebfa3981e1d 160000 --- a/firmware/fab-step/src/osape-d21 +++ b/firmware/fab-step/src/osape-d21 @@ -1 +1 @@ -Subproject commit b47769ec7b9994fb363d881929520afbf4589200 +Subproject commit d7df297e7039d697def2a1252e34eebfa3981e1d diff --git a/firmware/fab-step/src/syserror.cpp b/firmware/fab-step/src/syserror.cpp index cd758158858cdcbbbd1e19916dc397d69cd02b55..861f812ef6f338c5dc3937d3c7518979cf2a3c12 100644 --- a/firmware/fab-step/src/syserror.cpp +++ b/firmware/fab-step/src/syserror.cpp @@ -1,63 +1,58 @@ #include "syserror.h" +#include "indicators.h" #include "config.h" -//#include "../../drivers/indicators.h" #include "osape-d21/osape/osap/ts.h" #include "osape-d21/osape/utils/cobs.h" uint8_t errBuf[1028]; uint8_t errEncoded[1028]; -/* -boolean writeString(unsigned char* dest, uint16_t* dptr, String msg){ - uint16_t len = msg.length(); - dest[(*dptr) ++] = TS_STRING_KEY; - writeLenBytes(dest, dptr, len); - msg.getBytes(dest, len + 1); - return true; -} +volatile unsigned long errLightLastOn = 0; +volatile unsigned long errLightOnTime = 0; +volatile boolean errLightBlink = true; +volatile boolean errLightOn = false; -boolean writeLenBytes(unsigned char* dest, uint16_t* dptr, uint16_t len){ - dest[(*dptr) ++] = len; - dest[(*dptr) ++] = (len >> 8) & 255; - return true; +void sysErrLightFlash(uint8_t level){ + ERRLIGHT_ON; + errLightOn = true; + errLightLastOn = millis(); + switch(level){ + case 0: + errLightBlink = false; + break; + case 1: + errLightOnTime = 5000; + break; + case 2: + errLightOnTime = 1000; + break; + case 3: + errLightOnTime = 250; + break; + } } -*/ -#ifdef SPIPHY_IS_DROP +void sysErrLightCheck(void){ + if(errLightOn && errLightBlink){ + if(errLightLastOn + errLightOnTime < millis()){ + ERRLIGHT_OFF; + errLightOn = false; + } + } +} -//uint8_t escape[512]; -//uint8_t escapeHeader[10] = { PK_BUSF_KEY, 0, 0, 0, 0, PK_PTR, PK_PORTF_KEY, 0, 0, PK_DEST }; +#ifdef UCBUS_IS_DROP -// config-your-own-ll-escape-hatch void sysError(String msg){ - //ERRLIGHT_ON; - /* - uint32_t len = msg.length(); - errBuf[0] = PK_LLERR; // the ll-errmsg-key - errBuf[1] = len & 255; - errBuf[2] = (len >> 8) & 255; - errBuf[3] = (len >> 16) & 255; - errBuf[4] = (len >> 24) & 255; - msg.getBytes(&(errBuf[5]), len + 1); - // write header, - memcpy(escape, escapeHeader, 10); - // write segsize, checksum - uint16_t wptr = 10; - ts_writeUint16(128, escape, &wptr); - ts_writeUint16(len + 5, escape, &wptr); - memcpy(&(escape[wptr]), errBuf, len + 5); - // transmit on ucbus - // potential here to hang-up and do while(!(ucBusDrop->cts())) ... I *think* that would clear on an interrupt - ucBusDrop->transmit(escape, len + wptr + 5); - */ + // noop } #else // config-your-own-ll-escape-hatch void sysError(String msg){ - // escape this message w/ whatever low level device you have... - // could be i.e. OLED write, here is serial print + // whatever you want, + //ERRLIGHT_ON; uint32_t len = msg.length(); errBuf[0] = 0; // serport looks for acks in each msg, this is not one errBuf[1] = PK_PTR; @@ -68,10 +63,11 @@ void sysError(String msg){ errBuf[6] = (len >> 24) & 255; msg.getBytes(&(errBuf[7]), len + 1); size_t ecl = cobsEncode(errBuf, len + 7, errEncoded); + errEncoded[ecl] = 0; // direct escape //if(Serial.availableForWrite() > (int64_t)ecl){ - Serial.write(errEncoded, ecl); - Serial.flush(); + Serial.write(errEncoded, ecl + 1); + //Serial.flush(); //} else { // ERRLIGHT_ON; //} @@ -89,4 +85,5 @@ void logPacket(uint8_t* pck, uint16_t len){ errmsg += ", "; } sysError(errmsg); -} \ No newline at end of file +} + diff --git a/firmware/fab-step/src/syserror.h b/firmware/fab-step/src/syserror.h index 1b47d7a7cbfb1eeb51bffbdbaafcf126f400e6d6..13cd30ea619a4dbb982c802f1eb9f7fbe5fdbaee 100644 --- a/firmware/fab-step/src/syserror.h +++ b/firmware/fab-step/src/syserror.h @@ -7,4 +7,9 @@ void sysError(String msg); void logPacket(uint8_t* pck, uint16_t len); //void sysError(uint8_t* bytes, uint16_t len); +void sysErrLightFlash(uint8_t level); +void sysErrLightCheck(void); + +#define ERROR(level, msg) sysErrLightFlash(level); sysError(msg) + #endif