Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3 KiB

  1. #pragma once
  2. // Base address of USER RTC memory
  3. // https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map#memmory-mapped-io-registers
  4. #define RTCMEM_ADDR_BASE (0x60001200)
  5. // RTC memory is accessed using blocks of 4 bytes.
  6. // Blocks 0..63 are reserved by the SDK, 64..192 are available to the user.
  7. // Blocks 64..96 are reserved by the eboot 'struct eboot_command' (128 -> (128 / 4) -> 32):
  8. // https://github.com/esp8266/Arduino/blob/master/bootloaders/eboot/eboot_command.h
  9. #define RTCMEM_OFFSET 32u
  10. #define RTCMEM_ADDR (RTCMEM_ADDR_BASE + (RTCMEM_OFFSET * 4u))
  11. #define RTCMEM_BLOCKS 96u
  12. // Change this when modifying RtcmemData
  13. #define RTCMEM_MAGIC 0x45535075
  14. // XXX When using bitfields / inner structs / etc:
  15. // ...
  16. // uint32_t a : 8;
  17. // uint32_t b : 8;
  18. // uint32_t c : 8;
  19. // uint32_t d : 8;
  20. // ...
  21. // mem->d = 4;
  22. // At the same time writes 4 to the a, b and c
  23. // TODO replace with custom memory segment in ldscript
  24. struct RtcmemData {
  25. uint32_t magic;
  26. uint32_t sys;
  27. uint32_t relay;
  28. uint32_t mqtt;
  29. uint64_t light;
  30. double energy[4];
  31. };
  32. static_assert(sizeof(RtcmemData) <= (RTCMEM_BLOCKS * 4u), "RTCMEM struct is too big");
  33. constexpr uint8_t RtcmemSize = (sizeof(RtcmemData) / 4u);
  34. auto Rtcmem = reinterpret_cast<volatile RtcmemData*>(RTCMEM_ADDR);
  35. bool rtcmemStatus();