Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of RTCMEM storage #1420

Merged
merged 13 commits into from
May 8, 2019
Merged

Conversation

mcspr
Copy link
Collaborator

@mcspr mcspr commented Dec 11, 2018

Part of #1265

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 via std::bitset

Missing:
energy counter (EEPROM_ENERGY_COUNT) - should it be saved like this?
mqtt json id counter (EEPROM_MESSAGE_ID) - can write here every send, no need for delay like for eeprom.

Note:
This also can directly use rtcmem as an array (example from esp-open-rtos)

typedef volatile uint32_t rtcmem_array_t[96];
#define RTCMEM_USER (*(rtcmem_array_t *)(RTCMEM_ADDR))
...
RTCMEM_USER[...SOME_INDEX_DEFINE...] = 1; // indexes defined like for eeprom
RTCMEM_USER[97] = 2; // compiler will yell because of rtcmem_array_t definition

And idk if consistency check is required at all, and just checking magic value would suffice
+ tracking resetInfo->reason for REASON_DEFAULT_RST / REASON_SOFT_RESTART

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
@xoseperez
Copy link
Owner

We are not checking for consistency in the flash atm.
I would add energy count too and light colors also (same update frequency than relays).

@mcspr
Copy link
Collaborator Author

mcspr commented Dec 15, 2018

for energy counter the goal here is to protect readings in between save intervals from disappearing?

lights are straightforward enough, save 5 channels + brightness + mireds state. even fits inside 64 bit. only unlike relay it always saves - should it have an option like relayBoot to optionally do it?

Remove crc check and commit requirement
Add light state save and restore
Add sensor energy total save and restore
@mcspr
Copy link
Collaborator Author

mcspr commented Dec 16, 2018

Removed crc, added mqtt counter, added general methods for energy total and lights handling.
Last thing - check when it is appropriate to save / read them.
edit: and another - use module prefix instead of _rtcmem... for methods?

For lights: LIGHT_SAVE_ENABLED should be a setting and somehow wired into this?
For sensor: one can also save uptime() in rtc and reference that in energy ts code, since now it becomes 2 states - uptime under power with occasional reboots and complete shutdown with eeprom saves.

Copy link
Owner

@xoseperez xoseperez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I would merge it after 1.13.4 so we have time to test it.

code/espurna/light.ino Show resolved Hide resolved
@mcspr mcspr added this to the 1.13.5 milestone Feb 23, 2019
@xoseperez xoseperez modified the milestones: 1.13.5, 1.13.6 Feb 26, 2019
@mcspr
Copy link
Collaborator Author

mcspr commented Apr 17, 2019

Light issue resolved via static check of array size.

To reiterate - breaking changes are:
mqtt counter (no longer persisted between power-offs)
emon sensor total persists between reboots

I wonder if ntp time can be saved too.

@mcspr mcspr merged commit 820d8c4 into xoseperez:dev May 8, 2019
@mcspr mcspr deleted the rtcmem-storage branch May 8, 2019 21:21
@mcspr
Copy link
Collaborator Author

mcspr commented May 8, 2019

No obvious things stand up. Merging in the interest of moving milestone forward.
edit: ... perhaps "4 byte blocks" should be named word (or simply 32 bit) access. something to signify that we cannot read less than that. also, alignment...

Exception system might need some tweaking though:

  • maybe lock the boards in safe mode until reboot. don't reset system stability counter to 0 on the 5th time, and force manual intervention (terminal command / web switch / power cycle)
  • allow to store "small" crash log, instead of the full one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants