-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of RTCMEM storage (#1420)
- store system crash counter and reset reason in rtcmem instead of eeprom - store relay state mask in rtc in addition to the eeprom - store relay state in eeprom only when boot mode requires it - simplify relay state mask calculation / reading using std::bitset - light state save and restore - energy total save and restore
- Loading branch information
Showing
13 changed files
with
365 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
|
||
// Base address of USER RTC memory | ||
// https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map#memmory-mapped-io-registers | ||
#define RTCMEM_ADDR_BASE (0x60001200) | ||
|
||
// RTC memory is accessed using blocks of 4 bytes. | ||
// Blocks 0..63 are reserved by the SDK, 64..192 are available to the user. | ||
// Blocks 64..96 are reserved by the eboot 'struct eboot_command' (128 -> (128 / 4) -> 32): | ||
// https://github.com/esp8266/Arduino/blob/master/bootloaders/eboot/eboot_command.h | ||
#define RTCMEM_OFFSET 32u | ||
#define RTCMEM_ADDR (RTCMEM_ADDR_BASE + (RTCMEM_OFFSET * 4u)) | ||
|
||
#define RTCMEM_BLOCKS 96u | ||
|
||
// Change this when modifying RtcmemData | ||
#define RTCMEM_MAGIC 0x45535075 | ||
|
||
// XXX When using bitfields / inner structs / etc: | ||
// ... | ||
// uint32_t a : 8; | ||
// uint32_t b : 8; | ||
// uint32_t c : 8; | ||
// uint32_t d : 8; | ||
// ... | ||
// mem->d = 4; | ||
// At the same time writes 4 to the a, b and c | ||
|
||
// TODO replace with custom memory segment in ldscript | ||
struct RtcmemData { | ||
uint32_t magic; | ||
uint32_t sys; | ||
uint32_t relay; | ||
uint32_t mqtt; | ||
uint64_t light; | ||
double energy; | ||
}; | ||
|
||
static_assert(sizeof(RtcmemData) <= (RTCMEM_BLOCKS * 4u), "RTCMEM struct is too big"); | ||
constexpr uint8_t RtcmemSize = (sizeof(RtcmemData) / 4u); | ||
|
||
auto Rtcmem = reinterpret_cast<volatile RtcmemData*>(RTCMEM_ADDR); | ||
|
||
bool rtcmemStatus(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,9 @@ void setup() { | |
debugSetup(); | ||
#endif | ||
|
||
// Init RTCMEM | ||
rtcmemSetup(); | ||
|
||
// Init EEPROM | ||
eepromSetup(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.