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