From 14b796b41010abaa4f3aa17bc478dfb1631421a0 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Mon, 24 Jun 2019 00:15:44 +0300 Subject: [PATCH] Rtcmem update (#1770) * Custom erase method instead of memset * Print whole available user rtc memory --- code/espurna/rtcmem.ino | 56 +++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/code/espurna/rtcmem.ino b/code/espurna/rtcmem.ino index df86b74a..634693bf 100644 --- a/code/espurna/rtcmem.ino +++ b/code/espurna/rtcmem.ino @@ -1,7 +1,22 @@ +/* + +RTMEM MODULE + +*/ + bool _rtcmem_status = false; +void _rtcmemErase() { + auto ptr = reinterpret_cast(RTCMEM_ADDR); + const auto end = ptr + RTCMEM_BLOCKS; + DEBUG_MSG_P(PSTR("[RTCMEM] Erasing start=%p end=%p\n"), ptr, end); + do { + *ptr = 0; + } while (++ptr != end); +} + void _rtcmemInit() { - memset((uint32_t*)RTCMEM_ADDR, 0, sizeof(uint32_t) * RTCMEM_BLOCKS); + _rtcmemErase(); Rtcmem->magic = RTCMEM_MAGIC; } @@ -31,17 +46,38 @@ void _rtcmemInitCommands() { _rtcmemInit(); }); - terminalRegisterCommand(F("RTCMEM.TEST"), [](Embedis* e) { - }); - terminalRegisterCommand(F("RTCMEM.DUMP"), [](Embedis* e) { - DEBUG_MSG_P(PSTR("[RTCMEM] status:%u blocks:%u addr:0x%p\n"), - _rtcmemStatus(), RtcmemSize, Rtcmem); - for (uint8_t block=0; block(RTCMEM_ADDR)[block]); - } + DEBUG_MSG_P(PSTR("[RTCMEM] boot_status=%u status=%u blocks_used=%u\n"), + _rtcmem_status, _rtcmemStatus(), RtcmemSize); + + String line; + line.reserve(96); + char buffer[16] = {0}; + + auto addr = reinterpret_cast(RTCMEM_ADDR); + + uint8_t block = 1; + uint8_t offset = 0; + uint8_t start = 0; + + do { + + offset = block - 1; + + snprintf(buffer, sizeof(buffer), "%08x ", *(addr + offset)); + line += buffer; + + if ((block % 8) == 0) { + DEBUG_MSG_P(PSTR("%02u %p: %s\n"), start, addr+start, line.c_str()); + start = block; + line = ""; + } + + ++block; + + } while (block<(RTCMEM_BLOCKS+1)); + }); }