/* * rtc.h * * Created on: Jan 16, 2023 * Author: Sword * APIs to access the RTC. * */ #ifndef MAIN_RTC_H_ #define MAIN_RTC_H_ #include #include #define RTC_STATUS_OK 0 #define RTC_STATUS_ERROR -1 typedef struct { uint16_t Millisecond; uint8_t Second; /*!< Specify the present second to be set to RTC clockwatch. This parameter can be integer value in range from 0 to 59 */ uint8_t Minute; /*!< Specify the present minute to be set to RTC clockwatch. This parameter can be integer value in range from 0 to 59 */ uint8_t Hour; /*!< Specify the present hour to be set to RTC clockwatch. This parameter can be integer value in range from 0 to 23 */ uint8_t WeekDay; /*!< Specify the present day in the week to be set to RTC clockwatch. This parameter can be an integer value in range from 0 to 7 */ uint8_t MonthDay; /*!< Specify the present day in the month to be set to RTC clockwatch. This parameter can be an integer value in range from 1 to 31 (depends on month) */ uint8_t Month; /*!< Specify the present month to be set to RTC clockwatch. This parameter can be an integer value in range from 1 to 12 (depends on month) */ uint16_t Year; /*!< Specify the present year to be set to RTC clockwatch. This parameter can be an integer value in range from 0 to 3999 (depends on month) */ } rtc_timestamp_t; /* Initialize RTC. Must be called at each program startup to enable * access to RTC. * This will use a default time only once. Time is retained as long * as backup power and 32 kHz OSC are running. * Return true if RTC initialized from power-on-reset, false otherwise. */ int rtc_init(void); /* Get RTC time as a timestamp */ void rtc_get_timestamp(rtc_timestamp_t* ts); /* Set RTC time as a timestamp */ void rtc_set_timestamp(rtc_timestamp_t* ts); /* Set timestamp including a timezone offset in seconds. * The timezone offset may be positive or negative. It is applied * by subtraction, so a -ve offset (e.g. UTC-5) results in the * timezone offset being added to the local timestamp */ void rtc_set_timestamp_tz(rtc_timestamp_t* ts, int32_t tz_offset_sec); /* true if rtc has been set by set_timestamp or set_epoch. */ bool rtc_is_set(void); /* Get RTC time in units of epoch time (standard unix time: seconds since 1970) */ uint32_t rtc_get_epoch(void); /* Set RTC current time according to epoch. Note, epoch is UTC/GMT. Should a "local" time be * desired, subtract or add the necessary offset. E.g. MST is UTC-6 or -7 hours depending on DST. */ void rtc_set_epoch(uint32_t epoch); #endif /* MAIN_RTC_H_ */