1 /* 2 * Copyright (C) 2017-2019 Alibaba Group Holding Limited 3 */ 4 5 /****************************************************************************** 6 * @file drv_rtc.h 7 * @brief header file for rtc driver 8 * @version V1.0 9 * @date 02. June 2017 10 * @model rtc 11 ******************************************************************************/ 12 13 #ifndef _CSI_RTC_H_ 14 #define _CSI_RTC_H_ 15 16 17 #include <stdint.h> 18 #include <drv/common.h> 19 #include <time.h> 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 /// definition for rtc handle. 25 typedef void *rtc_handle_t; 26 27 /****** rtc specific error codes *****/ 28 typedef enum { 29 RTC_ERROR_TIME = (DRV_ERROR_SPECIFIC + 1), ///<invalid data time 30 } rtc_error_e; 31 32 /** 33 \brief RTC Status 34 */ 35 typedef struct { 36 uint32_t active : 1; ///< rtc is running or not 37 } rtc_status_t; 38 39 /****** RTC Event *****/ 40 typedef enum { 41 RTC_EVENT_TIMER_INTRERRUPT = 0 ///< generate interrupt 42 } rtc_event_e; 43 44 typedef void (*rtc_event_cb_t)(int32_t idx, rtc_event_e event); ///< Pointer to \ref rtc_event_cb_t : RTC Event call back. 45 46 /** 47 \brief RTC Device Driver Capabilities. 48 */ 49 typedef struct { 50 uint32_t interrupt_mode : 1; ///< supports Interrupt mode 51 uint32_t wrap_mode : 1; ///< supports wrap mode 52 } rtc_capabilities_t; 53 54 /** 55 \brief Initialize RTC Interface. 1. Initializes the resources needed for the RTC interface 2.registers event callback function 56 \param[in] idx rtc index 57 \param[in] cb_event event callback function \ref rtc_event_cb_t 58 \return pointer to rtc instance 59 */ 60 rtc_handle_t csi_rtc_initialize(int32_t idx, rtc_event_cb_t cb_event); 61 62 /** 63 \brief De-initialize RTC Interface. stops operation and releases the software resources used by the interface 64 \param[in] handle rtc handle to operate. 65 \return error code 66 */ 67 int32_t csi_rtc_uninitialize(rtc_handle_t handle); 68 69 /** 70 \brief control rtc power. 71 \param[in] handle rtc handle to operate. 72 \param[in] state power state.\ref csi_power_stat_e. 73 \return error code 74 */ 75 int32_t csi_rtc_power_control(rtc_handle_t handle, csi_power_stat_e state); 76 77 /** 78 \brief Get driver capabilities. 79 \param[in] idx rtc index 80 \return \ref rtc_capabilities_t 81 */ 82 rtc_capabilities_t csi_rtc_get_capabilities(int32_t idx); 83 84 /** 85 \brief Set system date. 86 \param[in] handle rtc handle to operate. 87 \param[in] rtctime pointer to rtc time 88 \return error code 89 */ 90 int32_t csi_rtc_set_time(rtc_handle_t handle, const struct tm *rtctime); 91 92 /** 93 \brief Get system date. 94 \param[in] handle rtc handle to operate. 95 \param[out] rtctime pointer to rtc time 96 \return error code 97 */ 98 int32_t csi_rtc_get_time(rtc_handle_t handle, struct tm *rtctime); 99 100 /** 101 \brief Start RTC timer. 102 \param[in] handle rtc handle to operate. 103 \return error code 104 */ 105 int32_t csi_rtc_start(rtc_handle_t handle); 106 107 /** 108 \brief Stop RTC timer. 109 \param[in] handle rtc handle to operate. 110 \return error code 111 */ 112 int32_t csi_rtc_stop(rtc_handle_t handle); 113 114 115 /** 116 \brief Get RTC status. 117 \param[in] handle rtc handle to operate. 118 \return RTC status \ref rtc_status_t 119 */ 120 rtc_status_t csi_rtc_get_status(rtc_handle_t handle); 121 122 /** 123 \brief config RTC timer. 124 \param[in] handle rtc handle to operate. 125 \param[in] rtctime time to wake up 126 \return error code 127 */ 128 int32_t csi_rtc_set_alarm(rtc_handle_t handle, const struct tm *rtctime); 129 130 /** 131 \brief disable or enable RTC timer. 132 \param[in] handle rtc handle to operate. 133 \param[in] flag 1 - enable rtc alarm 0 - disable rtc alarm 134 \return error code 135 */ 136 int32_t csi_rtc_enable_alarm(rtc_handle_t handle, uint8_t flag); 137 138 #ifdef __cplusplus 139 } 140 #endif 141 142 #endif /* _CSI_RTC_H_ */ 143