diff --git a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/main.cpp b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/main.cpp index 80e9dea8..2fd52ea1 100644 --- a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/main.cpp +++ b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/main.cpp @@ -53,6 +53,7 @@ uint64_t __attribute__((section(".fwmagic"))) magic = FW_MAGIC; #define TAG_MODE_CHANSEARCH 0 #define TAG_MODE_ASSOCIATED 1 +#define TAG_MODE_DEEPSLEEP 0x10 __attribute__((section(".aon"))) uint8_t currentTagMode = TAG_MODE_CHANSEARCH; __attribute__((section(".aon"))) volatile struct zigbeeCalibDataStruct zigbeeCalibData; @@ -444,6 +445,11 @@ void TagChanSearch() { } } +void tagDeepSleep() { + printf("MAIN: long sleepy\n"); + sleep_with_with_wakeup(1800 * 1000UL); +} + int main(void) { (*(volatile unsigned int *)0x20124000) = 0x100004; // On WARM RESET: Goto this address. -> entry (*(volatile unsigned int *)0xE000ED08) = 0x20100000; // Vector table in RAM and offset 0x4000 @@ -538,6 +544,9 @@ int main(void) { case TAG_MODE_CHANSEARCH: TagChanSearch(); break; + case TAG_MODE_DEEPSLEEP: + tagDeepSleep(); + break; } } return 0; @@ -592,3 +601,34 @@ void applyUpdate(uint32_t size) { while (1) ; } + +void executeCommand(uint8_t cmd) { + printf("executing command %d \n", cmd); + delay(20); + switch (cmd) { + case CMD_DO_REBOOT: + NVIC_SystemReset(); + break; + case CMD_DO_RESET_SETTINGS: + break; + case CMD_DO_SCAN: + currentChannel = showChannelSelect(); + break; + case CMD_ERASE_EEPROM_IMAGES: + eraseImageBlocks(); + break; + case CMD_GET_BATTERY_VOLTAGE: + doVoltageReading(); + // ensure + longDataReqCounter = LONG_DATAREQ_INTERVAL + 1; + sleep_with_with_wakeup(2 * 1000UL); + break; + case CMD_DO_DEEPSLEEP: + showLongTermSleep(); + currentTagMode = TAG_MODE_DEEPSLEEP; + break; + default: + printf("Unimplemented command 0x%02X\n", cmd); + break; + } +} \ No newline at end of file diff --git a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/main.h b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/main.h index 842a788c..695a0dff 100755 --- a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/main.h +++ b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/main.h @@ -31,3 +31,4 @@ #define RADIO_FIRST_CHANNEL (11) //2.4-GHz channels start at 11 void applyUpdate(uint32_t len); +void executeCommand(uint8_t cmd); \ No newline at end of file diff --git a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/mz100/timer.c b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/mz100/timer.c index 5aa617cf..f3b55f8a 100644 --- a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/mz100/timer.c +++ b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/mz100/timer.c @@ -68,3 +68,6 @@ uint32_t timerMs(){ return (uint32_t)(diff/TIMER_TICKS_PER_MSEC); } +uint32_t millis(){ + return (uint32_t)(timerGet() / TIMER_TICKS_PER_MSEC); +} \ No newline at end of file diff --git a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/mz100/timer.h b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/mz100/timer.h index 5a57a303..7c0786d9 100644 --- a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/mz100/timer.h +++ b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/mz100/timer.h @@ -11,6 +11,8 @@ uint64_t timerGet(void); void timerStop(void); uint32_t timerMs(void); +uint32_t millis(); + void timerDelay(uint64_t cycles); diff --git a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/oepl-protocol.cpp b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/oepl-protocol.cpp index 0d63cdd2..a90e8c55 100644 --- a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/oepl-protocol.cpp +++ b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/oepl-protocol.cpp @@ -31,17 +31,12 @@ extern "C" { #define FW88MZ100 #define HAL_PacketRX commsRxUnenc -#define millis() timerGet() -#define HAL_TIMER_TICK (TIMER_TICKS_PER_MSEC) void inline HAL_msDelay(uint32_t t) { timerDelay(t * TIMER_TICKS_PER_MSEC); } -void executeCommand(uint8_t c) { -} - void loadSettingsFromBuffer(uint8_t *buffer) { } diff --git a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/powermgt.cpp b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/powermgt.cpp index 0deb7aac..d8f0342c 100644 --- a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/powermgt.cpp +++ b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/powermgt.cpp @@ -18,6 +18,7 @@ extern "C" { #include "screen.h" #include "mz100/util.h" #include "zigbee.h" +#include "mz100/timer.h" } __attribute__((section(".aonshadow"))) uint16_t dataReqAttemptArr[POWER_SAVING_SMOOTHING] = {0}; // Holds the amount of attempts required per data_req/check-in @@ -120,9 +121,7 @@ void powerDown(const uint8_t parts) { } void doSleep(const uint32_t t) { - printf("Sleeping for: %d ms\r\n", t); - // sleepForMs(t); - delay(t); + timerDelay(t*TIMER_TICKS_PER_MSEC); } uint32_t getNextScanSleep(const bool increment) { diff --git a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/powermgt.h b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/powermgt.h index 67d54364..2165b5c0 100755 --- a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/powermgt.h +++ b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/powermgt.h @@ -27,13 +27,13 @@ // power saving algorithm #define INTERVAL_BASE 40 // interval (in seconds) (when 1 packet is sent/received) for target current (7.2µA) #define INTERVAL_AT_MAX_ATTEMPTS 300 // interval (in seconds) (at max attempts) for target average current -#define DATA_REQ_RX_WINDOW_SIZE 5UL // How many milliseconds we should wait for a packet during the data_request. +#define DATA_REQ_RX_WINDOW_SIZE 4UL // How many milliseconds we should wait for a packet during the data_request. // If the AP holds a long list of data for tags, it may need a little more time to lookup the mac address #define DATA_REQ_MAX_ATTEMPTS 3 // How many attempts (at most) we should do to get something back from the AP #define POWER_SAVING_SMOOTHING 8 // How many samples we should use to smooth the data request interval #define MINIMUM_INTERVAL 45 // IMPORTANT: Minimum interval for check-in; this determines overal battery life! #define MAXIMUM_PING_ATTEMPTS 3 // How many attempts to discover an AP the tag should do -#define PING_REPLY_WINDOW 5UL +#define PING_REPLY_WINDOW 10UL #define LONG_DATAREQ_INTERVAL 300 // How often (in seconds, approximately) the tag should do a long datareq (including temperature) #define VOLTAGE_CHECK_INTERVAL 288 // How often the tag should do a battery voltage check (multiplied by LONG_DATAREQ_INTERVAL) diff --git a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/settings.h b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/settings.h index cbe9c76e..1e973814 100755 --- a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/settings.h +++ b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/settings.h @@ -3,8 +3,8 @@ #include -#define FW_VERSION 0x0027 // version number (max 2.5.5 :) ) -#define FW_VERSION_SUFFIX "-zlib" // suffix, like -RC1 or whatever. +#define FW_VERSION 0x0028 // version number (max 2.5.5 :) ) +#define FW_VERSION_SUFFIX "-cmds" // suffix, like -RC1 or whatever. // #define DEBUGBLOCKS // uncomment to enable extra debug information on the block transfers // #define PRINT_LUT // uncomment if you want the tag to print the LUT for the current temperature bracket diff --git a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/userinterface.cpp b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/userinterface.cpp index 56971edd..86926b2f 100644 --- a/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/userinterface.cpp +++ b/ARM_Tag_FW/88MZ100_OpenEpaperLink_7.4/userinterface.cpp @@ -83,15 +83,12 @@ void showSplashScreen() { fr.epdPrintf(10, 350, 0, rotation::ROTATE_0, "Tag MAC: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", mSelfMac[7], mSelfMac[6], mSelfMac[5], mSelfMac[4], mSelfMac[3], mSelfMac[2], mSelfMac[1], mSelfMac[0]); addQR(80, 160, 3, 3, "https://openepaperlink.eu/tag/0/%02X/%02X%02X%02X%02X%02X%02X%02X%02X/", tag.OEPLtype, mSelfMac[7], mSelfMac[6], mSelfMac[5], mSelfMac[4], mSelfMac[3], mSelfMac[2], mSelfMac[1], mSelfMac[0]); fr.setFont((char *)"font/FreeSans9pt7b"); - fr.epdPrintf(622, 290, 0, rotation::ROTATE_270, "v%04X%s", FW_VERSION, FW_VERSION_SUFFIX); + fr.epdPrintf(622, 280, 0, rotation::ROTATE_270, "v%04X%s", FW_VERSION, FW_VERSION_SUFFIX); selectLUT(1); draw(); epdEnterSleep(); } -#define FW_VERSION 0x0027 // version number (max 2.5.5 :) ) -#define FW_VERSION_SUFFIX "-zlib" // suffix, like -RC1 or whatever. - void showApplyUpdate() { epdSetup(); fs->init(); @@ -120,7 +117,7 @@ void showAPFound() { fr.epdPrintf(10, 315, 0, rotation::ROTATE_0, "Battery: %d.%dV", batteryVoltage / 1000, batteryVoltage % 1000); fr.epdPrintf(10, 350, 0, rotation::ROTATE_0, "Tag MAC: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", mSelfMac[7], mSelfMac[6], mSelfMac[5], mSelfMac[4], mSelfMac[3], mSelfMac[2], mSelfMac[1], mSelfMac[0]); fr.setFont((char *)"font/FreeSans9pt7b"); - fr.epdPrintf(622, 290, 0, rotation::ROTATE_270, "v%04X%s", FW_VERSION, FW_VERSION_SUFFIX); + fr.epdPrintf(622, 280, 0, rotation::ROTATE_270, "v%04X%s", FW_VERSION, FW_VERSION_SUFFIX); addOverlay(); if (lowBatteryShown) { @@ -154,16 +151,12 @@ void showNoAP() { } void showLongTermSleep() { - // selectLUT(EPD_LUT_NO_REPEATS); - // clearScreen(); - - // epdPrintBegin(2, SCREEN_HEIGHT - 16, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); - // epdpr("zZ"); - // epdPrintEnd(); - - addOverlay(); - // drawWithSleep(); + epdSetup(); + selectLUT(0); + draw(); + epdEnterSleep(); } + void showNoEEPROM() { // selectLUT(EPD_LUT_NO_REPEATS); // clearScreen(); diff --git a/ARM_Tag_FW/common/drawing.cpp b/ARM_Tag_FW/common/drawing.cpp index 989e9657..b25d831f 100644 --- a/ARM_Tag_FW/common/drawing.cpp +++ b/ARM_Tag_FW/common/drawing.cpp @@ -63,7 +63,7 @@ void addBufferedImage(uint16_t x, uint16_t y, bool color, enum rotation ro, cons di->type = drawItem::drawType::DRAW_MASK; else di->type = drawItem::drawType::DRAW_BUFFERED_1BPP; - + di->checkBounds(); di->addToList(); } @@ -85,6 +85,7 @@ void addFlashImage(uint16_t x, uint16_t y, bool color, enum rotation ro, const u di->color = color; di->cleanUp = false; di->type = drawItem::drawType::DRAW_BUFFERED_1BPP; + di->checkBounds(); di->addToList(); } #ifdef ENABLE_OEPLFS @@ -119,6 +120,7 @@ void addFSImage(uint16_t x, uint16_t y, uint8_t color, enum rotation ro, char *n } else { di->type = drawItem::drawType::DRAW_OEPLFS_1BPP; } + di->checkBounds(); di->addToList(); } @@ -153,6 +155,7 @@ void addCompressedFSImage(uint16_t x, uint16_t y, enum rotation ro, char *name) di->color = imgheader.bpp; if (di->color == 1) di->color = 0; di->cleanUp = true; + di->checkBounds(); di->addToList(); } #endif @@ -207,6 +210,8 @@ void addQR(uint16_t x, uint16_t y, uint8_t version, uint8_t scale, const char *c di->ypos = y; di->color = 0; di->type = drawItem::drawType::DRAW_BUFFERED_1BPP; + + di->checkBounds(); di->addToList(); } @@ -227,8 +232,12 @@ void drawImageAtAddressWrap(uint32_t addr, uint8_t lut) { di->addItem((uint8_t *)addr, epd->effectiveXRes, epd->effectiveYRes); di->type = drawItem::drawType::DRAW_EEPROM_1BPP; di->direction = false; - if (di->mirrorH) di->mirrorV = !di->mirrorV; + if (di->mirrorH) { + di->mirrorH = 0; + di->mirrorV = !di->mirrorV; + } di->cleanUp = false; + di->checkBounds(); di->addToList(); } break; case DATATYPE_IMG_RAW_2BPP: { @@ -240,8 +249,12 @@ void drawImageAtAddressWrap(uint32_t addr, uint8_t lut) { di->addItem((uint8_t *)addr, epd->effectiveXRes, epd->effectiveYRes); di->type = drawItem::drawType::DRAW_EEPROM_2BPP; di->direction = false; - if (di->mirrorH) di->mirrorV = !di->mirrorV; + if (di->mirrorH) { + di->mirrorH = 0; + di->mirrorV = !di->mirrorV; + } di->cleanUp = false; + di->checkBounds(); di->addToList(); } break; case DATATYPE_IMG_ZLIB: { @@ -271,10 +284,14 @@ void drawImageAtAddressWrap(uint32_t addr, uint8_t lut) { di->xpos = 0; di->ypos = 0; di->direction = false; - if (di->mirrorH) di->mirrorV = !di->mirrorV; + if (di->mirrorH) { + di->mirrorH = 0; + di->mirrorV = !di->mirrorV; + } if (imgheader.bpp == 1) di->color = 0; if (imgheader.bpp == 2) di->color = 2; di->cleanUp = true; + di->checkBounds(); di->addToList(); } break; } @@ -297,7 +314,7 @@ void drawRoundedRectangle(uint16_t xpos, uint16_t ypos, uint16_t width, uint16_t return; } uint8_t frameBufferZerosize = width; - if((width % 8) != 0){ + if ((width % 8) != 0) { frameBufferZerosize++; } ((uint16_t *)framebuffer)[0] = frameBufferZerosize; @@ -455,9 +472,9 @@ void drawItem::getXLine(uint8_t *line, uint16_t y, uint8_t c) { } } if (mirrorH) { - copyWithByteShift(line, &buffer[((height - (y - ypos)) * widthBytes)], widthBytes, xpos / 8); + copyWithByteShift(line, &buffer[((height - (y - ypos)) * widthBytes)], drawnWidthBytes, xpos / 8); } else { - copyWithByteShift(line, &buffer[((y - ypos) * widthBytes)], widthBytes, xpos / 8); + copyWithByteShift(line, &buffer[((y - ypos) * widthBytes)], drawnWidthBytes, xpos / 8); } } break; @@ -478,7 +495,7 @@ void drawItem::getXLine(uint8_t *line, uint16_t y, uint8_t c) { if (mirrorV) { reverseBytes(dbuffer, widthBytes); } - copyWithByteShift(line, dbuffer, widthBytes, xpos / 8); + copyWithByteShift(line, dbuffer, drawnWidthBytes, xpos / 8); free(dbuffer); } break; @@ -498,20 +515,36 @@ void drawItem::getXLine(uint8_t *line, uint16_t y, uint8_t c) { if (mirrorV) { reverseBytes(dbuffer, widthBytes); } - copyWithByteShift(line, dbuffer, widthBytes, xpos / 8); + copyWithByteShift(line, dbuffer, drawnWidthBytes, xpos / 8); free(dbuffer); } break; case DRAW_EEPROM_1BPP: if (c != color) return; - if (epd->drawDirectionRight) + if (mirrorH) y = epd->effectiveYRes - 1 - y; - HAL_flashRead((uint32_t)buffer + sizeof(struct EepromImageHeader) + (y * (epd->effectiveXRes / 8)), line, (epd->effectiveXRes / 8)); + if (mirrorV) { + uint8_t *dbuffer = (uint8_t *)malloc(widthBytes); + HAL_flashRead((uint32_t)buffer + sizeof(struct EepromImageHeader) + (y * (epd->effectiveXRes / 8)), dbuffer, (epd->effectiveXRes / 8)); + reverseBytes(dbuffer, widthBytes); + memcpy(line, dbuffer, widthBytes); + free(dbuffer); + } else { + HAL_flashRead((uint32_t)buffer + sizeof(struct EepromImageHeader) + (y * (epd->effectiveXRes / 8)), line, (epd->effectiveXRes / 8)); + } break; case DRAW_EEPROM_2BPP: - if (epd->drawDirectionRight) + if (mirrorH) y = epd->effectiveYRes - 1 - y; - HAL_flashRead((uint32_t)(buffer + sizeof(struct EepromImageHeader) + ((y + (c * epd->effectiveYRes)) * (epd->effectiveXRes / 8))), line, (epd->effectiveXRes / 8)); + if (mirrorV) { + uint8_t *dbuffer = (uint8_t *)malloc(widthBytes); + HAL_flashRead((uint32_t)(buffer + sizeof(struct EepromImageHeader) + ((y + (c * epd->effectiveYRes)) * (epd->effectiveXRes / 8))), dbuffer, (epd->effectiveXRes / 8)); + reverseBytes(dbuffer, widthBytes); + memcpy(line, dbuffer, widthBytes); + free(dbuffer); + } else { + HAL_flashRead((uint32_t)(buffer + sizeof(struct EepromImageHeader) + ((y + (c * epd->effectiveYRes)) * (epd->effectiveXRes / 8))), line, (epd->effectiveXRes / 8)); + } break; default: printf("DRAW: Not supported mode!\n"); @@ -641,6 +674,16 @@ bool drawItem::addToList() { return false; } +void drawItem::checkBounds() { + drawnWidthBytes = widthBytes; + + // if(!direction){ // draw X lines + uint8_t availBytesWidth = epd->effectiveXRes / 8; + availBytesWidth -= (xpos / 8); + if (widthBytes < availBytesWidth) availBytesWidth = widthBytes; + drawnWidthBytes = availBytesWidth; +} + drawItem::~drawItem() { if (cleanUp) { switch (this->type) { @@ -935,5 +978,6 @@ void fontrender::epdPrintf(uint16_t x, uint16_t y, bool color, enum rotation ro, di->xpos = x; di->color = color; di->type = drawItem::drawType::DRAW_FONT; + di->checkBounds(); di->addToList(); } diff --git a/ARM_Tag_FW/common/drawing.h b/ARM_Tag_FW/common/drawing.h index 7fcb1d33..5681a8f8 100644 --- a/ARM_Tag_FW/common/drawing.h +++ b/ARM_Tag_FW/common/drawing.h @@ -72,6 +72,8 @@ class drawItem { static void renderDrawLine(uint8_t *line, uint16_t number, uint8_t c); static void flushDrawItems(); + void checkBounds(); + // these are also used for rotated screens static void reverseBytes(uint8_t *src, uint8_t src_len); static uint8_t bitReverse(uint8_t byte); @@ -113,6 +115,7 @@ class drawItem { void getXLine(uint8_t *line, uint16_t yPos, uint8_t color); void getYLine(uint8_t *line, uint16_t xPos, uint8_t color); uint8_t widthBytes = 0; + uint8_t drawnWidthBytes = 0; uint8_t *buffer = nullptr; }; diff --git a/ARM_Tag_FW/common/oepl-protocol.cpp b/ARM_Tag_FW/common/oepl-protocol.cpp index e0df6630..bcc580b0 100644 --- a/ARM_Tag_FW/common/oepl-protocol.cpp +++ b/ARM_Tag_FW/common/oepl-protocol.cpp @@ -23,8 +23,6 @@ volatile uint8_t PERSISTENTVAR currentChannel = 0; static uint8_t inBuffer[128] = {0}; static uint8_t outBuffer[128] = {0}; -extern void executeCommand(uint8_t cmd); // this is defined in main.c - // tools static uint8_t getPacketType(const void *buffer) { const struct MacFcs *fcs = (MacFcs *)buffer; @@ -112,7 +110,7 @@ uint8_t detectAP(const uint8_t channel) { radioRxEnable(true); for (uint8_t c = 1; c <= MAXIMUM_PING_ATTEMPTS; c++) { sendPing(); - t = millis() + (HAL_TIMER_TICK * (PING_REPLY_WINDOW)); + t = millis() + PING_REPLY_WINDOW; while (millis() < t) { int8_t ret = HAL_PacketRX(inBuffer); if (ret > 1) { @@ -126,7 +124,7 @@ uint8_t detectAP(const uint8_t channel) { } } } - HAL_msDelay(1); + HAL_msDelay(10); } } return 0; @@ -179,7 +177,7 @@ struct AvailDataInfo *getAvailDataInfo() { uint32_t t; for (uint8_t c = 0; c < DATA_REQ_MAX_ATTEMPTS; c++) { sendAvailDataReq(); - t = millis() + (HAL_TIMER_TICK * (DATA_REQ_RX_WINDOW_SIZE)); + t = millis() + DATA_REQ_RX_WINDOW_SIZE; while (millis() < t) { int8_t ret = HAL_PacketRX(inBuffer); if (ret > 1) { @@ -203,8 +201,7 @@ struct AvailDataInfo *getShortAvailDataInfo() { uint32_t t; for (uint8_t c = 0; c < DATA_REQ_MAX_ATTEMPTS; c++) { sendShortAvailDataReq(); - // sendAvailDataReq(); - t = millis() + (HAL_TIMER_TICK * (DATA_REQ_RX_WINDOW_SIZE)); + t = millis() + DATA_REQ_RX_WINDOW_SIZE; while (millis() < t) { int8_t ret = HAL_PacketRX(inBuffer); if (ret > 1) { @@ -251,7 +248,7 @@ static bool blockRxLoop(const uint32_t timeout, uint8_t *blockbuffer) { uint32_t t; bool success = false; radioRxEnable(true); - t = millis() + (HAL_TIMER_TICK * (timeout + 20)); + t = millis() + (timeout + 20); bool blockComplete = false; @@ -316,16 +313,17 @@ static struct blockRequestAck *performBlockRequest() { uint32_t t; radioRxEnable(true); radioRxFlush(); - for (uint8_t c = 0; c < 30; c++) { + for (uint8_t c = 0; c < 10; c++) { sendBlockRequest(); - t = millis() + (HAL_TIMER_TICK * ((7UL + c / 10))); + t = millis() + 6UL; do { int8_t ret = HAL_PacketRX(inBuffer); if (ret > 1) { switch (getPacketType(inBuffer)) { case PKT_BLOCK_REQUEST_ACK: - if (checkCRC((inBuffer + sizeof(struct MacFrameNormal) + 1), sizeof(struct blockRequestAck))) + if (checkCRC((inBuffer + sizeof(struct MacFrameNormal) + 1), sizeof(struct blockRequestAck))) { return (struct blockRequestAck *)(inBuffer + sizeof(struct MacFrameNormal) + 1); + } break; case PKT_BLOCK_PART: return continueToRX(); @@ -370,7 +368,7 @@ static void sendXferComplete() { for (uint8_t c = 0; c < 16; c++) { sendXferCompletePacket(); uint32_t start = millis(); - while ((millis() - start) < (HAL_TIMER_TICK * (6UL))) { + while ((millis() - start) < (6UL)) { int8_t ret = HAL_PacketRX(inBuffer); if (ret > 1) { if (getPacketType(inBuffer) == PKT_XFER_COMPLETE_ACK) { @@ -591,7 +589,7 @@ static uint8_t *getDataBlock(const uint16_t blockSize) { } #ifdef FWNRF - doSleep(ack->pleaseWaitMs + 40); + doSleep(ack->pleaseWaitMs); powerUp(INIT_UART | INIT_RADIO); radioRxEnable(true); #endif @@ -656,8 +654,8 @@ static uint8_t *getDataBlock(const uint16_t blockSize) { } static uint32_t downloadFWUpdate(const struct AvailDataInfo *avail) { - uint16_t dataRequestSize = 0; - uint32_t curXferSize = 0; + static uint32_t PERSISTENTVAR curXferSize = 0; + // check if we already started the transfer of this information & haven't completed it if (!memcmp((const void *)&avail->dataVer, (const void *)&xferDataInfo.dataVer, 8) && xferDataInfo.dataSize) { // looks like we did. We'll carry on where we left off. @@ -672,6 +670,7 @@ static uint32_t downloadFWUpdate(const struct AvailDataInfo *avail) { } while (xferDataInfo.dataSize) { + uint16_t dataRequestSize = 0; wdt10s(); if (xferDataInfo.dataSize > BLOCK_DATA_SIZE) { // more than one block remaining @@ -709,8 +708,8 @@ static uint32_t downloadFWUpdate(const struct AvailDataInfo *avail) { } static bool downloadImageDataToEEPROM(const struct AvailDataInfo *avail) { - uint16_t dataRequestSize = 0; - uint32_t curXferSize = 0; + static uint32_t PERSISTENTVAR curXferSize = 0; + powerUp(INIT_EEPROM); // check if we already started the transfer of this information & haven't completed it if (!memcmp((const void *)&avail->dataVer, (const void *)&xferDataInfo.dataVer, 8) && xferDataInfo.dataSize) { @@ -772,6 +771,7 @@ static bool downloadImageDataToEEPROM(const struct AvailDataInfo *avail) { } while (xferDataInfo.dataSize) { + uint16_t dataRequestSize = 0; wdt10s(); if (xferDataInfo.dataSize > BLOCK_DATA_SIZE) { // more than one block remaining diff --git a/binaries/Tag/SOL_M2_75_full_0028.bin b/binaries/Tag/SOL_M2_75_full_0028.bin new file mode 100644 index 00000000..80007f66 Binary files /dev/null and b/binaries/Tag/SOL_M2_75_full_0028.bin differ diff --git a/binaries/Tag/SOL_M2_75_ota_0028.bin b/binaries/Tag/SOL_M2_75_ota_0028.bin new file mode 100644 index 00000000..ad5f853e Binary files /dev/null and b/binaries/Tag/SOL_M2_75_ota_0028.bin differ