1 /** 2 * @file rtc.h 3 * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited 4 */ 5 6 #ifndef HAL_RTC_H 7 #define HAL_RTC_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /** @addtogroup hal_rtc RTC 14 * rtc hal API. 15 * 16 * @{ 17 */ 18 19 #include <stdint.h> 20 21 /* Decode format list */ 22 #define HAL_RTC_FORMAT_DEC 1 23 #define HAL_RTC_FORMAT_BCD 2 24 25 typedef struct { 26 uint8_t format; /**< time formart DEC or BCD */ 27 } rtc_config_t; 28 29 typedef struct { 30 uint8_t port; /**< rtc port */ 31 rtc_config_t config; /**< rtc config */ 32 void *priv; /**< priv data */ 33 } rtc_dev_t; 34 35 /* 36 * RTC time 37 */ 38 typedef struct { 39 uint8_t sec; /**< DEC format:value range from 0 to 59, BCD format:value range from 0x00 to 0x59 */ 40 uint8_t min; /**< DEC format:value range from 0 to 59, BCD format:value range from 0x00 to 0x59 */ 41 uint8_t hr; /**< DEC format:value range from 0 to 23, BCD format:value range from 0x00 to 0x23 */ 42 uint8_t weekday; /**< DEC format:value range from 1 to 7, BCD format:value range from 0x01 to 0x07 */ 43 uint8_t date; /**< DEC format:value range from 1 to 31, BCD format:value range from 0x01 to 0x31 */ 44 uint8_t month; /**< DEC format:value range from 1 to 12, BCD format:value range from 0x01 to 0x12 */ 45 uint16_t year; /**< DEC format:value range from 0 to 9999, BCD format:value range from 0x0000 to 0x9999 */ 46 } rtc_time_t; 47 48 /** 49 * This function will initialize the on board CPU real time clock 50 * 51 * 52 * @param[in] rtc rtc device 53 * 54 * @return 0 : on success, otherwise is error 55 */ 56 int32_t hal_rtc_init(rtc_dev_t *rtc); 57 58 /** 59 * This function will return the value of time read from the on board CPU real time clock. 60 * 61 * @param[in] rtc rtc device 62 * @param[out] time pointer to a time structure 63 * 64 * @return 0 : on success, otherwise is error 65 */ 66 int32_t hal_rtc_get_time(rtc_dev_t *rtc, rtc_time_t *time); 67 68 /** 69 * This function will set MCU RTC time to a new value. 70 * 71 * @param[in] rtc rtc device 72 * @param[in] time pointer to a time structure 73 * 74 * @return 0 : on success, otherwise is error 75 */ 76 int32_t hal_rtc_set_time(rtc_dev_t *rtc, const rtc_time_t *time); 77 78 /** 79 * De-initialises an RTC interface, Turns off an RTC hardware interface 80 * 81 * @param[in] RTC the interface which should be de-initialised 82 * 83 * @return 0 : on success, otherwise is error 84 */ 85 int32_t hal_rtc_finalize(rtc_dev_t *rtc); 86 87 /** @} */ 88 89 #ifdef __cplusplus 90 } 91 #endif 92 93 #endif /* HAL_RTC_H */ 94 95