app_rtc.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file app_rtc.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of RTC app library.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup APP_DRIVER APP DRIVER
43 * @{
44 */
45
46 /** @defgroup APP_RTC RTC
47 * @brief RTC APP module driver.
48 * @{
49 */
50
51
52 #ifndef _APP_RTC_H_
53 #define _APP_RTC_H_
54
55 #include "grx_hal.h"
56 #include "app_drv_error.h"
57 #include "app_drv_config.h"
58
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62
63 #ifdef HAL_CALENDAR_MODULE_ENABLED
64
65 /** @addtogroup APP_RTC_DEFINE Defines
66 * @{
67 */
68
69 /** @defgroup App rtc time disable macro definition
70 * @{
71 */
72 #define APP_RTC_ALARM_DISABLE_DATE CALENDAR_ALARM_DISABLE_DATE /**< Disable rtc date alarm */
73 #define APP_RTC_ALARM_DISABLE_TICK CALENDAR_ALARM_DISABLE_TICK /**< Disable rtc tick alarm */
74 #define APP_RTC_ALARM_DISABLE_ALL CALENDAR_ALARM_DISABLE_ALL /**< Disable rtc all alarm */
75 /** @} */
76
77 /** @} */
78
79 /** @addtogroup APP_RTC_ENUM Enumerations
80 * @{
81 */
82 /**
83 * @brief RTC event Enumerations definition
84 */
85 typedef enum
86 {
87 APP_RTC_EVT_DATE_ALARM, /**< Date alarm event. */
88 APP_RTC_EVT_TICK_ALARM, /**< Tick alarm event. */
89 APP_RTC_EVT_OVERFLOW, /**< Overflow event. */
90 } app_rtc_evt_type_t;
91 /** @} */
92
93 /** @addtogroup APP_RTC_STRUCTURES Structures
94 * @{
95 */
96 /**
97 * @brief App time structure definition
98 */
99 typedef calendar_time_t app_rtc_time_t;
100
101 /**
102 * @brief App alarm structure definition
103 */
104 typedef calendar_alarm_t app_rtc_alarm_t;
105
106
107 /**
108 * @brief RTC event structure definition
109 */
110 typedef struct
111 {
112 app_rtc_evt_type_t type; /**< Type of event. */
113 } app_rtc_evt_t;
114
115 /** @} */
116
117 /** @addtogroup APP_RTC_TYPEDEFS Type definitions
118 * @{
119 */
120 /**
121 * @brief RTC event callback definition
122 */
123 typedef void (*app_rtc_evt_handler_t)(app_rtc_evt_t *p_evt);
124
125 /** @} */
126
127
128 /* Exported functions --------------------------------------------------------*/
129 /** @addtogroup APP_RTC_DRIVER_FUNCTIONS Functions
130 * @{
131 */
132 /**
133 ****************************************************************************************
134 * @brief Initialize the APP RTC DRIVER.
135 *
136 * @param[in] evt_handler: RTC user callback function.
137 *
138 * @return Result of initialization.
139 ****************************************************************************************
140 */
141 uint16_t app_rtc_init(app_rtc_evt_handler_t evt_handler);
142
143 /**
144 ****************************************************************************************
145 * @brief De-initialize the app rtc.
146 *
147 * @return Result of De-initialization.
148 ****************************************************************************************
149 */
150 uint16_t app_rtc_deinit(void);
151
152 /**
153 ****************************************************************************************
154 * @brief Initialize the rtc time.
155 *
156 * @param[in] p_time: Pointer to a app_rtc_time_t time struct.
157 *
158 * @return Result of operation.
159 ****************************************************************************************
160 */
161 uint16_t app_rtc_init_time(app_rtc_time_t *p_time);
162
163 /**
164 ****************************************************************************************
165 * @brief Get current rtc time.
166 *
167 * @param[in] p_time: Pointer to a app_rtc_time_t time struct.
168 *
169 * @return Result of operation.
170 ****************************************************************************************
171 */
172 uint16_t app_rtc_get_time(app_rtc_time_t *p_time);
173
174 /**
175 ****************************************************************************************
176 * @brief Set a rtc date alarm.
177 *
178 * @param[in] p_alarm: After seconds will generate an date alarm interrupt.
179 *
180 * @return Result of operation.
181 ****************************************************************************************
182 */
183 uint16_t app_rtc_setup_alarm(app_rtc_alarm_t *p_alarm);
184
185 /**
186 ****************************************************************************************
187 * @brief Set a rtc tick alarm.
188 *
189 * @param[in] interval: After milliseconds will generate an tick alarm interrupt.
190 * The value of interval is greater than or equal to 10ms.
191 *
192 * @return Result of operation.
193 ****************************************************************************************
194 */
195 uint16_t app_rtc_setup_tick(uint32_t interval);
196
197 /**
198 ****************************************************************************************
199 * @brief Disable rtc alarm event.
200 *
201 * @param[in] disable_mode: Disable specified CALENDAR alarm mode.
202 * This parameter can be the following values:
203 * @arg @ref APP_RTC_ALARM_DISABLE_DATE
204 * @arg @ref APP_RTC_ALARM_DISABLE_TICK
205 * @arg @ref APP_RTC_ALARM_DISABLE_ALL
206 *
207 * @return Result of operation.
208 ****************************************************************************************
209 */
210 uint16_t app_rtc_disable_event(uint32_t disable_mode);
211
212 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5526X) || (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5525X) || (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
213 /**
214 ****************************************************************************************
215 * @brief Synchronous RTC low speed clock.
216 *
217 * @param[in] SlowClockFreq: Number of slow clocks
218 *
219 * @return None.
220 ****************************************************************************************
221 */
222 void app_rtc_time_sync(float SlowClockFreq);
223 #endif
224 /** @} */
225
226 #endif
227
228 #ifdef __cplusplus
229 }
230 #endif
231
232 #endif
233
234 /** @} */
235 /** @} */
236 /** @} */
237
238
APP_RTC_EVT_OVERFLOW
@ APP_RTC_EVT_OVERFLOW
Definition: app_rtc.h:89
app_rtc_disable_event
uint16_t app_rtc_disable_event(uint32_t disable_mode)
Disable rtc alarm event.
app_rtc_evt_t::type
app_rtc_evt_type_t type
Definition: app_rtc.h:112
app_rtc_setup_tick
uint16_t app_rtc_setup_tick(uint32_t interval)
Set a rtc tick alarm.
app_rtc_evt_handler_t
void(* app_rtc_evt_handler_t)(app_rtc_evt_t *p_evt)
RTC event callback definition.
Definition: app_rtc.h:123
app_rtc_deinit
uint16_t app_rtc_deinit(void)
De-initialize the app rtc.
app_rtc_init_time
uint16_t app_rtc_init_time(app_rtc_time_t *p_time)
Initialize the rtc time.
app_rtc_get_time
uint16_t app_rtc_get_time(app_rtc_time_t *p_time)
Get current rtc time.
app_rtc_time_t
calendar_time_t app_rtc_time_t
App time structure definition.
Definition: app_rtc.h:99
grx_hal.h
This file contains all the functions prototypes for the HAL module driver.
app_rtc_setup_alarm
uint16_t app_rtc_setup_alarm(app_rtc_alarm_t *p_alarm)
Set a rtc date alarm.
APP_RTC_EVT_TICK_ALARM
@ APP_RTC_EVT_TICK_ALARM
Definition: app_rtc.h:88
_calendar_alarm
CALENDAR_Alarm calendar alarm structure definition.
Definition: gr55xx_hal_calendar.h:106
app_rtc_evt_type_t
app_rtc_evt_type_t
RTC event Enumerations definition.
Definition: app_rtc.h:86
APP_RTC_EVT_DATE_ALARM
@ APP_RTC_EVT_DATE_ALARM
Definition: app_rtc.h:87
_calendar_time
CALENDAR_Time calendar time structure definition.
Definition: gr55xx_hal_calendar.h:76
app_rtc_evt_t
RTC event structure definition.
Definition: app_rtc.h:111
app_drv_error.h
Header file of app driver error code.
app_drv_config.h
Header file of app driver config code.
app_rtc_alarm_t
calendar_alarm_t app_rtc_alarm_t
App alarm structure definition.
Definition: app_rtc.h:104
app_rtc_init
uint16_t app_rtc_init(app_rtc_evt_handler_t evt_handler)
Initialize the APP RTC DRIVER.