2021-12-14 22:39:59 +00:00
|
|
|
/**
|
2022-01-05 16:10:18 +00:00
|
|
|
* @file furi_hal_rtc.h
|
2021-12-14 22:39:59 +00:00
|
|
|
* Furi Hal RTC API
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
// Time
|
2022-01-05 16:10:18 +00:00
|
|
|
uint8_t hour; /**< Hour in 24H format: 0-23 */
|
2021-12-14 22:39:59 +00:00
|
|
|
uint8_t minute; /**< Minute: 0-59 */
|
|
|
|
uint8_t second; /**< Second: 0-59 */
|
|
|
|
// Date
|
2022-01-05 16:10:18 +00:00
|
|
|
uint8_t day; /**< Current day: 1-31 */
|
|
|
|
uint8_t month; /**< Current month: 1-12 */
|
|
|
|
uint16_t year; /**< Current year: 2000-2099 */
|
|
|
|
uint8_t weekday; /**< Current weekday: 1-7 */
|
2021-12-14 22:39:59 +00:00
|
|
|
} FuriHalRtcDateTime;
|
|
|
|
|
|
|
|
typedef enum {
|
2022-01-05 16:10:18 +00:00
|
|
|
FuriHalRtcFlagDebug = (1 << 0),
|
|
|
|
FuriHalRtcFlagFactoryReset = (1 << 1),
|
|
|
|
FuriHalRtcFlagLock = (1 << 2),
|
2022-04-27 15:53:48 +00:00
|
|
|
FuriHalRtcFlagC2Update = (1 << 3),
|
2021-12-14 22:39:59 +00:00
|
|
|
} FuriHalRtcFlag;
|
|
|
|
|
2021-12-24 14:33:58 +00:00
|
|
|
typedef enum {
|
2022-04-13 20:50:25 +00:00
|
|
|
FuriHalRtcBootModeNormal = 0, /**< Normal boot mode, default value */
|
|
|
|
FuriHalRtcBootModeDfu, /**< Boot to DFU (MCU bootloader by ST) */
|
|
|
|
FuriHalRtcBootModePreUpdate, /**< Boot to Update, pre update */
|
|
|
|
FuriHalRtcBootModeUpdate, /**< Boot to Update, main */
|
|
|
|
FuriHalRtcBootModePostUpdate, /**< Boot to Update, post update */
|
|
|
|
} FuriHalRtcBootMode;
|
|
|
|
|
2022-11-12 08:46:04 +00:00
|
|
|
typedef enum {
|
|
|
|
FuriHalRtcHeapTrackModeNone = 0, /**< Disable allocation tracking */
|
|
|
|
FuriHalRtcHeapTrackModeMain, /**< Enable allocation tracking for main application thread */
|
|
|
|
FuriHalRtcHeapTrackModeTree, /**< Enable allocation tracking for main and children application threads */
|
|
|
|
FuriHalRtcHeapTrackModeAll, /**< Enable allocation tracking for all threads */
|
|
|
|
} FuriHalRtcHeapTrackMode;
|
|
|
|
|
2022-04-13 20:50:25 +00:00
|
|
|
typedef enum {
|
|
|
|
FuriHalRtcRegisterHeader, /**< RTC structure header */
|
|
|
|
FuriHalRtcRegisterSystem, /**< Various system bits */
|
|
|
|
FuriHalRtcRegisterVersion, /**< Pointer to Version */
|
|
|
|
FuriHalRtcRegisterLfsFingerprint, /**< LFS geometry fingerprint */
|
|
|
|
FuriHalRtcRegisterFaultData, /**< Pointer to last fault message */
|
|
|
|
FuriHalRtcRegisterPinFails, /**< Failed pins count */
|
|
|
|
/* Index of FS directory entry corresponding to FW update to be applied */
|
|
|
|
FuriHalRtcRegisterUpdateFolderFSIndex,
|
|
|
|
|
|
|
|
FuriHalRtcRegisterMAX, /**< Service value, do not use */
|
2021-12-24 14:33:58 +00:00
|
|
|
} FuriHalRtcRegister;
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
typedef enum {
|
|
|
|
FuriHalRtcLocaleUnitsMetric = 0, /**< Metric measurement units */
|
|
|
|
FuriHalRtcLocaleUnitsImperial = 1, /**< Imperial measurement units */
|
|
|
|
} FuriHalRtcLocaleUnits;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
FuriHalRtcLocaleTimeFormat24h = 0, /**< 24-hour format */
|
|
|
|
FuriHalRtcLocaleTimeFormat12h = 1, /**< 12-hour format */
|
|
|
|
} FuriHalRtcLocaleTimeFormat;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
FuriHalRtcLocaleDateFormatDMY = 0, /**< Day/Month/Year */
|
|
|
|
FuriHalRtcLocaleDateFormatMDY = 1, /**< Month/Day/Year */
|
|
|
|
FuriHalRtcLocaleDateFormatYMD = 2, /**< Year/Month/Day */
|
|
|
|
} FuriHalRtcLocaleDateFormat;
|
|
|
|
|
2022-04-13 20:50:25 +00:00
|
|
|
/** Early initialization */
|
|
|
|
void furi_hal_rtc_init_early();
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Early de-initialization */
|
2022-04-13 20:50:25 +00:00
|
|
|
void furi_hal_rtc_deinit_early();
|
|
|
|
|
2021-12-14 22:39:59 +00:00
|
|
|
/** Initialize RTC subsystem */
|
|
|
|
void furi_hal_rtc_init();
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Get RTC register content
|
|
|
|
*
|
|
|
|
* @param[in] reg The register identifier
|
|
|
|
*
|
|
|
|
* @return content of the register
|
|
|
|
*/
|
2021-12-24 14:33:58 +00:00
|
|
|
uint32_t furi_hal_rtc_get_register(FuriHalRtcRegister reg);
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Set register content
|
|
|
|
*
|
|
|
|
* @param[in] reg The register identifier
|
|
|
|
* @param[in] value The value to store into register
|
|
|
|
*/
|
2021-12-24 14:33:58 +00:00
|
|
|
void furi_hal_rtc_set_register(FuriHalRtcRegister reg, uint32_t value);
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Set Log Level value
|
|
|
|
*
|
|
|
|
* @param[in] level The level to store
|
|
|
|
*/
|
2021-12-14 22:39:59 +00:00
|
|
|
void furi_hal_rtc_set_log_level(uint8_t level);
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Get Log Level value
|
|
|
|
*
|
|
|
|
* @return The Log Level value
|
|
|
|
*/
|
2021-12-14 22:39:59 +00:00
|
|
|
uint8_t furi_hal_rtc_get_log_level();
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Set RTC Flag
|
|
|
|
*
|
|
|
|
* @param[in] flag The flag to set
|
|
|
|
*/
|
2021-12-14 22:39:59 +00:00
|
|
|
void furi_hal_rtc_set_flag(FuriHalRtcFlag flag);
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Reset RTC Flag
|
|
|
|
*
|
|
|
|
* @param[in] flag The flag to reset
|
|
|
|
*/
|
2021-12-14 22:39:59 +00:00
|
|
|
void furi_hal_rtc_reset_flag(FuriHalRtcFlag flag);
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Check if RTC Flag is set
|
|
|
|
*
|
|
|
|
* @param[in] flag The flag to check
|
|
|
|
*
|
|
|
|
* @return true if set
|
|
|
|
*/
|
2021-12-14 22:39:59 +00:00
|
|
|
bool furi_hal_rtc_is_flag_set(FuriHalRtcFlag flag);
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Set RTC boot mode
|
|
|
|
*
|
|
|
|
* @param[in] mode The mode to set
|
|
|
|
*/
|
2022-04-13 20:50:25 +00:00
|
|
|
void furi_hal_rtc_set_boot_mode(FuriHalRtcBootMode mode);
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Get RTC boot mode
|
|
|
|
*
|
|
|
|
* @return The RTC boot mode.
|
|
|
|
*/
|
2022-04-13 20:50:25 +00:00
|
|
|
FuriHalRtcBootMode furi_hal_rtc_get_boot_mode();
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Set Heap Track mode
|
|
|
|
*
|
|
|
|
* @param[in] mode The mode to set
|
|
|
|
*/
|
2022-11-12 08:46:04 +00:00
|
|
|
void furi_hal_rtc_set_heap_track_mode(FuriHalRtcHeapTrackMode mode);
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Get RTC Heap Track mode
|
|
|
|
*
|
|
|
|
* @return The RTC heap track mode.
|
|
|
|
*/
|
2022-11-12 08:46:04 +00:00
|
|
|
FuriHalRtcHeapTrackMode furi_hal_rtc_get_heap_track_mode();
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Set locale units
|
|
|
|
*
|
|
|
|
* @param[in] mode The RTC Locale Units
|
|
|
|
*/
|
|
|
|
void furi_hal_rtc_set_locale_units(FuriHalRtcLocaleUnits value);
|
|
|
|
|
|
|
|
/** Get RTC Locale Units
|
|
|
|
*
|
|
|
|
* @return The RTC Locale Units.
|
|
|
|
*/
|
|
|
|
FuriHalRtcLocaleUnits furi_hal_rtc_get_locale_units();
|
|
|
|
|
|
|
|
/** Set RTC Locale Time Format
|
|
|
|
*
|
|
|
|
* @param[in] value The RTC Locale Time Format
|
|
|
|
*/
|
|
|
|
void furi_hal_rtc_set_locale_timeformat(FuriHalRtcLocaleTimeFormat value);
|
|
|
|
|
|
|
|
/** Get RTC Locale Time Format
|
|
|
|
*
|
|
|
|
* @return The RTC Locale Time Format.
|
|
|
|
*/
|
|
|
|
FuriHalRtcLocaleTimeFormat furi_hal_rtc_get_locale_timeformat();
|
|
|
|
|
|
|
|
/** Set RTC Locale Date Format
|
|
|
|
*
|
|
|
|
* @param[in] value The RTC Locale Date Format
|
|
|
|
*/
|
|
|
|
void furi_hal_rtc_set_locale_dateformat(FuriHalRtcLocaleDateFormat value);
|
|
|
|
|
|
|
|
/** Get RTC Locale Date Format
|
|
|
|
*
|
|
|
|
* @return The RTC Locale Date Format
|
|
|
|
*/
|
|
|
|
FuriHalRtcLocaleDateFormat furi_hal_rtc_get_locale_dateformat();
|
|
|
|
|
|
|
|
/** Set RTC Date Time
|
|
|
|
*
|
|
|
|
* @param datetime The date time to set
|
|
|
|
*/
|
2021-12-14 22:39:59 +00:00
|
|
|
void furi_hal_rtc_set_datetime(FuriHalRtcDateTime* datetime);
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Get RTC Date Time
|
|
|
|
*
|
|
|
|
* @param datetime The datetime
|
|
|
|
*/
|
2021-12-14 22:39:59 +00:00
|
|
|
void furi_hal_rtc_get_datetime(FuriHalRtcDateTime* datetime);
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Validate Date Time
|
|
|
|
*
|
|
|
|
* @param datetime The datetime to validate
|
|
|
|
*
|
|
|
|
* @return { description_of_the_return_value }
|
|
|
|
*/
|
2021-12-17 13:24:37 +00:00
|
|
|
bool furi_hal_rtc_validate_datetime(FuriHalRtcDateTime* datetime);
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Set RTC Fault Data
|
|
|
|
*
|
|
|
|
* @param[in] value The value
|
|
|
|
*/
|
2021-12-31 17:32:49 +00:00
|
|
|
void furi_hal_rtc_set_fault_data(uint32_t value);
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Get RTC Fault Data
|
|
|
|
*
|
|
|
|
* @return RTC Fault Data value
|
|
|
|
*/
|
2021-12-31 17:32:49 +00:00
|
|
|
uint32_t furi_hal_rtc_get_fault_data();
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Set Pin Fails count
|
|
|
|
*
|
|
|
|
* @param[in] value The Pin Fails count
|
|
|
|
*/
|
2022-02-10 18:17:41 +00:00
|
|
|
void furi_hal_rtc_set_pin_fails(uint32_t value);
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Get Pin Fails count
|
|
|
|
*
|
|
|
|
* @return Pin Fails Count
|
|
|
|
*/
|
2022-02-10 18:17:41 +00:00
|
|
|
uint32_t furi_hal_rtc_get_pin_fails();
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Get UNIX Timestamp
|
|
|
|
*
|
|
|
|
* @return Unix Timestamp in seconds from UNIX epoch start
|
|
|
|
*/
|
2022-11-04 05:26:04 +00:00
|
|
|
uint32_t furi_hal_rtc_get_timestamp();
|
|
|
|
|
2022-12-19 09:38:20 +00:00
|
|
|
/** Convert DateTime to UNIX timestamp
|
|
|
|
*
|
|
|
|
* @param datetime The datetime
|
|
|
|
*
|
|
|
|
* @return UNIX Timestamp in seconds from UNIX epoch start
|
|
|
|
*/
|
2022-05-19 19:53:33 +00:00
|
|
|
uint32_t furi_hal_rtc_datetime_to_timestamp(FuriHalRtcDateTime* datetime);
|
|
|
|
|
2021-12-14 22:39:59 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|