]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/T-HEAD_CB2201_CDK/csi/csi_driver/include/drv_rtc.h
Introduce a port for T-HEAD CK802. A simple demo for T-HEAD CB2201 is also included.
[freertos] / FreeRTOS / Demo / T-HEAD_CB2201_CDK / csi / csi_driver / include / drv_rtc.h
1 /*
2  * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /******************************************************************************
17  * @file     drv_rtc.h
18  * @brief    header file for rtc driver
19  * @version  V1.0
20  * @date     02. June 2017
21  ******************************************************************************/
22
23 #ifndef _CSI_RTC_H_
24 #define _CSI_RTC_H_
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #include <stdint.h>
31 #include <drv_common.h>
32 #include <time.h>
33
34 /// definition for rtc handle.
35 typedef void *rtc_handle_t;
36
37 /****** rtc specific error codes *****/
38 typedef enum {
39     EDRV_RTC_TIME  = (EDRV_SPECIFIC + 1),      ///< timer data not supported
40 } drv_rtc_error_e;
41
42 /**
43 \brief RTC Status
44 */
45 typedef struct {
46     uint32_t active          : 1;        ///< rtc is running or not
47 } rtc_status_t;
48
49 /****** RTC Event *****/
50 typedef enum {
51     RTC_EVENT_TIMER_INTRERRUPT  = 0   ///< generate interrupt
52 } rtc_event_e;
53
54 typedef void (*rtc_event_cb_t)(rtc_event_e event);  ///< Pointer to \ref rtc_event_cb_t : RTC Event call back.
55
56 /**
57 \brief RTC Device Driver Capabilities.
58 */
59 typedef struct {
60     uint32_t interrupt_mode          : 1;      ///< supports Interrupt mode
61     uint32_t wrap_mode               : 1;      ///< supports wrap mode
62 } rtc_capabilities_t;
63
64 /**
65   \brief       get rtc instance count.
66   \return      rtc instance count
67 */
68 int32_t csi_rtc_get_instance_count(void);
69
70 /**
71   \brief       Initialize RTC Interface. 1. Initializes the resources needed for the RTC interface 2.registers event callback function
72   \param[in]   idx  must not exceed return value of csi_rtc_get_instance_count()
73   \param[in]   cb_event  Pointer to \ref rtc_event_cb_t
74   \return      pointer to rtc instance
75 */
76 rtc_handle_t csi_rtc_initialize(int32_t idx, rtc_event_cb_t cb_event);
77
78 /**
79   \brief       De-initialize RTC Interface. stops operation and releases the software resources used by the interface
80   \param[in]   handle rtc handle to operate.
81   \return      error code
82 */
83 int32_t csi_rtc_uninitialize(rtc_handle_t handle);
84
85 /**
86   \brief       Get driver capabilities.
87   \param[in]   handle rtc handle to operate.
88   \return      \ref rtc_capabilities_t
89 */
90 rtc_capabilities_t csi_rtc_get_capabilities(rtc_handle_t handle);
91
92 /**
93   \brief       Set RTC timer.
94   \param[in]   handle rtc handle to operate.
95   \param[in]   rtctime pointer to rtc time
96   \return      error code
97 */
98 int32_t csi_rtc_set_time(rtc_handle_t handle, const struct tm *rtctime);
99
100 /**
101   \brief       Get RTC timer.
102   \param[in]   handle rtc handle to operate.
103   \param[in]   rtctime  pointer to rtc time
104   \return      error code
105 */
106 int32_t csi_rtc_get_time(rtc_handle_t handle, struct tm *rtctime);
107
108
109
110 /**
111   \brief       Start RTC timer.
112   \param[in]   handle rtc handle to operate.
113   \return      error code
114 */
115 int32_t csi_rtc_start(rtc_handle_t handle);
116
117 /**
118   \brief       Stop RTC timer.
119   \param[in]   handle rtc handle to operate.
120   \return      error code
121 */
122 int32_t csi_rtc_stop(rtc_handle_t handle);
123
124 /**
125   \brief       config rtc mode.
126   \param[in]   handle rtc handle to operate.
127   \return      error code
128 */
129 //int32_t drv_rtc_config (rtc_handle_t handle/*,rtc_mode_e mode*/);
130
131 /**
132   \brief       Get RTC status.
133   \param[in]   handle rtc handle to operate.
134   \return      RTC status \ref rtc_status_t
135 */
136 rtc_status_t csi_rtc_get_status(rtc_handle_t handle);
137
138 /**
139   \brief       config RTC timer.
140   \param[in]   handle rtc handle to operate.
141   \param[in]   rtctime time to wake up
142   \return      error code
143 */
144 int32_t csi_rtc_timer_config(rtc_handle_t handle, const struct tm *rtctime);
145
146 /**
147   \brief       disable or enable RTC timer.
148   \param[in]   handle rtc handle to operate.
149   \param[in]   en set 1 enable for rtc timer
150   \return      error code
151 */
152 int32_t csi_rtc_timer_enable(rtc_handle_t handle, uint8_t en);
153
154
155
156
157 #ifdef __cplusplus
158 }
159 #endif
160
161 #endif /* _CSI_RTC_H_ */