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.

55 lines
1.4 KiB

  1. /*
  2. RTMEM MODULE
  3. Copyright (C) 2019 by Maxim Prokhorov <prokhorov dot max at outlook dot com>
  4. */
  5. #pragma once
  6. // Base address of USER RTC memory
  7. // https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map#memmory-mapped-io-registers
  8. #define RTCMEM_ADDR_BASE (0x60001200)
  9. // RTC memory is accessed using blocks of 4 bytes.
  10. // Blocks 0..63 are reserved by the SDK, 64..192 are available to the user.
  11. // Blocks 64..96 are reserved by the eboot 'struct eboot_command' (128 -> (128 / 4) -> 32):
  12. // https://github.com/esp8266/Arduino/blob/master/bootloaders/eboot/eboot_command.h
  13. #define RTCMEM_OFFSET 32u
  14. #define RTCMEM_ADDR (RTCMEM_ADDR_BASE + (RTCMEM_OFFSET * 4u))
  15. #define RTCMEM_BLOCKS 96u
  16. // Change this when modifying RtcmemData
  17. #define RTCMEM_MAGIC 0x45535075
  18. // XXX: All access must be 4-byte aligned and always at full length.
  19. //
  20. // For example, using bitfields / inner structs / etc:
  21. // ...
  22. // uint32_t a : 8;
  23. // uint32_t b : 8;
  24. // uint32_t c : 8;
  25. // uint32_t d : 8;
  26. // ...
  27. //
  28. // This would not write the expected thing:
  29. // mem->d = 4;
  30. // TODO replace with custom memory segment in ldscript?
  31. struct RtcmemData {
  32. uint32_t magic;
  33. uint32_t sys;
  34. uint32_t relay;
  35. uint32_t mqtt;
  36. uint64_t light;
  37. double energy[4];
  38. };
  39. static_assert(sizeof(RtcmemData) <= (RTCMEM_BLOCKS * 4u), "RTCMEM struct is too big");
  40. constexpr uint8_t RtcmemSize = (sizeof(RtcmemData) / 4u);
  41. auto Rtcmem = reinterpret_cast<volatile RtcmemData*>(RTCMEM_ADDR);
  42. bool rtcmemStatus();