furi_hal_rtc.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /**
  2. * @file furi_hal_rtc.h
  3. * Furi Hal RTC API
  4. */
  5. #pragma once
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. typedef struct {
  12. // Time
  13. uint8_t hour; /**< Hour in 24H format: 0-23 */
  14. uint8_t minute; /**< Minute: 0-59 */
  15. uint8_t second; /**< Second: 0-59 */
  16. // Date
  17. uint8_t day; /**< Current day: 1-31 */
  18. uint8_t month; /**< Current month: 1-12 */
  19. uint16_t year; /**< Current year: 2000-2099 */
  20. uint8_t weekday; /**< Current weekday: 1-7 */
  21. } FuriHalRtcDateTime;
  22. typedef enum {
  23. FuriHalRtcFlagDebug = (1 << 0),
  24. FuriHalRtcFlagFactoryReset = (1 << 1),
  25. FuriHalRtcFlagLock = (1 << 2),
  26. FuriHalRtcFlagC2Update = (1 << 3),
  27. } FuriHalRtcFlag;
  28. typedef enum {
  29. FuriHalRtcBootModeNormal = 0, /**< Normal boot mode, default value */
  30. FuriHalRtcBootModeDfu, /**< Boot to DFU (MCU bootloader by ST) */
  31. FuriHalRtcBootModePreUpdate, /**< Boot to Update, pre update */
  32. FuriHalRtcBootModeUpdate, /**< Boot to Update, main */
  33. FuriHalRtcBootModePostUpdate, /**< Boot to Update, post update */
  34. } FuriHalRtcBootMode;
  35. typedef enum {
  36. FuriHalRtcHeapTrackModeNone = 0, /**< Disable allocation tracking */
  37. FuriHalRtcHeapTrackModeMain, /**< Enable allocation tracking for main application thread */
  38. FuriHalRtcHeapTrackModeTree, /**< Enable allocation tracking for main and children application threads */
  39. FuriHalRtcHeapTrackModeAll, /**< Enable allocation tracking for all threads */
  40. } FuriHalRtcHeapTrackMode;
  41. typedef enum {
  42. FuriHalRtcRegisterHeader, /**< RTC structure header */
  43. FuriHalRtcRegisterSystem, /**< Various system bits */
  44. FuriHalRtcRegisterVersion, /**< Pointer to Version */
  45. FuriHalRtcRegisterLfsFingerprint, /**< LFS geometry fingerprint */
  46. FuriHalRtcRegisterFaultData, /**< Pointer to last fault message */
  47. FuriHalRtcRegisterPinFails, /**< Failed pins count */
  48. /* Index of FS directory entry corresponding to FW update to be applied */
  49. FuriHalRtcRegisterUpdateFolderFSIndex,
  50. FuriHalRtcRegisterMAX, /**< Service value, do not use */
  51. } FuriHalRtcRegister;
  52. typedef enum {
  53. FuriHalRtcLocaleUnitsMetric = 0, /**< Metric measurement units */
  54. FuriHalRtcLocaleUnitsImperial = 1, /**< Imperial measurement units */
  55. } FuriHalRtcLocaleUnits;
  56. typedef enum {
  57. FuriHalRtcLocaleTimeFormat24h = 0, /**< 24-hour format */
  58. FuriHalRtcLocaleTimeFormat12h = 1, /**< 12-hour format */
  59. } FuriHalRtcLocaleTimeFormat;
  60. typedef enum {
  61. FuriHalRtcLocaleDateFormatDMY = 0, /**< Day/Month/Year */
  62. FuriHalRtcLocaleDateFormatMDY = 1, /**< Month/Day/Year */
  63. FuriHalRtcLocaleDateFormatYMD = 2, /**< Year/Month/Day */
  64. } FuriHalRtcLocaleDateFormat;
  65. /** Early initialization */
  66. void furi_hal_rtc_init_early();
  67. /** Early de-initialization */
  68. void furi_hal_rtc_deinit_early();
  69. /** Initialize RTC subsystem */
  70. void furi_hal_rtc_init();
  71. /** Get RTC register content
  72. *
  73. * @param[in] reg The register identifier
  74. *
  75. * @return content of the register
  76. */
  77. uint32_t furi_hal_rtc_get_register(FuriHalRtcRegister reg);
  78. /** Set register content
  79. *
  80. * @param[in] reg The register identifier
  81. * @param[in] value The value to store into register
  82. */
  83. void furi_hal_rtc_set_register(FuriHalRtcRegister reg, uint32_t value);
  84. /** Set Log Level value
  85. *
  86. * @param[in] level The level to store
  87. */
  88. void furi_hal_rtc_set_log_level(uint8_t level);
  89. /** Get Log Level value
  90. *
  91. * @return The Log Level value
  92. */
  93. uint8_t furi_hal_rtc_get_log_level();
  94. /** Set RTC Flag
  95. *
  96. * @param[in] flag The flag to set
  97. */
  98. void furi_hal_rtc_set_flag(FuriHalRtcFlag flag);
  99. /** Reset RTC Flag
  100. *
  101. * @param[in] flag The flag to reset
  102. */
  103. void furi_hal_rtc_reset_flag(FuriHalRtcFlag flag);
  104. /** Check if RTC Flag is set
  105. *
  106. * @param[in] flag The flag to check
  107. *
  108. * @return true if set
  109. */
  110. bool furi_hal_rtc_is_flag_set(FuriHalRtcFlag flag);
  111. /** Set RTC boot mode
  112. *
  113. * @param[in] mode The mode to set
  114. */
  115. void furi_hal_rtc_set_boot_mode(FuriHalRtcBootMode mode);
  116. /** Get RTC boot mode
  117. *
  118. * @return The RTC boot mode.
  119. */
  120. FuriHalRtcBootMode furi_hal_rtc_get_boot_mode();
  121. /** Set Heap Track mode
  122. *
  123. * @param[in] mode The mode to set
  124. */
  125. void furi_hal_rtc_set_heap_track_mode(FuriHalRtcHeapTrackMode mode);
  126. /** Get RTC Heap Track mode
  127. *
  128. * @return The RTC heap track mode.
  129. */
  130. FuriHalRtcHeapTrackMode furi_hal_rtc_get_heap_track_mode();
  131. /** Set locale units
  132. *
  133. * @param[in] mode The RTC Locale Units
  134. */
  135. void furi_hal_rtc_set_locale_units(FuriHalRtcLocaleUnits value);
  136. /** Get RTC Locale Units
  137. *
  138. * @return The RTC Locale Units.
  139. */
  140. FuriHalRtcLocaleUnits furi_hal_rtc_get_locale_units();
  141. /** Set RTC Locale Time Format
  142. *
  143. * @param[in] value The RTC Locale Time Format
  144. */
  145. void furi_hal_rtc_set_locale_timeformat(FuriHalRtcLocaleTimeFormat value);
  146. /** Get RTC Locale Time Format
  147. *
  148. * @return The RTC Locale Time Format.
  149. */
  150. FuriHalRtcLocaleTimeFormat furi_hal_rtc_get_locale_timeformat();
  151. /** Set RTC Locale Date Format
  152. *
  153. * @param[in] value The RTC Locale Date Format
  154. */
  155. void furi_hal_rtc_set_locale_dateformat(FuriHalRtcLocaleDateFormat value);
  156. /** Get RTC Locale Date Format
  157. *
  158. * @return The RTC Locale Date Format
  159. */
  160. FuriHalRtcLocaleDateFormat furi_hal_rtc_get_locale_dateformat();
  161. /** Set RTC Date Time
  162. *
  163. * @param datetime The date time to set
  164. */
  165. void furi_hal_rtc_set_datetime(FuriHalRtcDateTime* datetime);
  166. /** Get RTC Date Time
  167. *
  168. * @param datetime The datetime
  169. */
  170. void furi_hal_rtc_get_datetime(FuriHalRtcDateTime* datetime);
  171. /** Validate Date Time
  172. *
  173. * @param datetime The datetime to validate
  174. *
  175. * @return { description_of_the_return_value }
  176. */
  177. bool furi_hal_rtc_validate_datetime(FuriHalRtcDateTime* datetime);
  178. /** Set RTC Fault Data
  179. *
  180. * @param[in] value The value
  181. */
  182. void furi_hal_rtc_set_fault_data(uint32_t value);
  183. /** Get RTC Fault Data
  184. *
  185. * @return RTC Fault Data value
  186. */
  187. uint32_t furi_hal_rtc_get_fault_data();
  188. /** Set Pin Fails count
  189. *
  190. * @param[in] value The Pin Fails count
  191. */
  192. void furi_hal_rtc_set_pin_fails(uint32_t value);
  193. /** Get Pin Fails count
  194. *
  195. * @return Pin Fails Count
  196. */
  197. uint32_t furi_hal_rtc_get_pin_fails();
  198. /** Get UNIX Timestamp
  199. *
  200. * @return Unix Timestamp in seconds from UNIX epoch start
  201. */
  202. uint32_t furi_hal_rtc_get_timestamp();
  203. /** Convert DateTime to UNIX timestamp
  204. *
  205. * @param datetime The datetime
  206. *
  207. * @return UNIX Timestamp in seconds from UNIX epoch start
  208. */
  209. uint32_t furi_hal_rtc_datetime_to_timestamp(FuriHalRtcDateTime* datetime);
  210. #ifdef __cplusplus
  211. }
  212. #endif