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 "gr55xx_hal.h"
56 #include "app_drv_error.h"
57 #include "app_rtos_cfg.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 /**
70 * @brief App rtc time disable macro definition
71 */
72
73 #define APP_RTC_ALARM_DISABLE_DATE CALENDAR_ALARM_DISABLE_DATE /**< Disable rtc date alarm */
74 #define APP_RTC_ALARM_DISABLE_TICK CALENDAR_ALARM_DISABLE_TICK /**< Disable rtc tick alarm */
75 #define APP_RTC_ALARM_DISABLE_ALL CALENDAR_ALARM_DISABLE_ALL /**< Disable rtc all alarm */
76 /** @} */
77
78 /** @addtogroup APP_RTC_ENUM Enumerations
79 * @{
80 */
81 /**
82 * @brief RTC event Enumerations definition
83 */
84 typedef enum
85 {
86 APP_RTC_EVT_DATE_ALARM, /**< Date alarm event. */
87 APP_RTC_EVT_TICK_ALARM, /**< Tick alarm event. */
88 } app_rtc_evt_type_t;
89 /** @} */
90
91 /** @addtogroup APP_RTC_STRUCTURES Structures
92 * @{
93 */
94 /**
95 * @brief App time structure definition
96 */
97 typedef calendar_time_t app_rtc_time_t;
98
99 /**
100 * @brief App alarm structure definition
101 */
102 typedef calendar_alarm_t app_rtc_alarm_t;
103
104
105 /**
106 * @brief RTC event structure definition
107 */
108 typedef struct
109 {
110 app_rtc_evt_type_t type; /**< Type of event. */
111 } app_rtc_evt_t;
112
113 /**
114 * @brief RTC event callback definition
115 */
116 typedef void (*app_rtc_evt_handler_t)(app_rtc_evt_t *p_evt);
117
118 /** @} */
119
120
121 /* Exported functions --------------------------------------------------------*/
122 /** @addtogroup APP_RTC_DRIVER_FUNCTIONS Functions
123 * @{
124 */
125 /**
126 ****************************************************************************************
127 * @brief Initialize the APP RTC DRIVER.
128 *
129 * @param[in] evt_handler: RTC user callback function.
130 *
131 * @return Result of initialization.
132 ****************************************************************************************
133 */
134 uint16_t app_rtc_init(app_rtc_evt_handler_t evt_handler);
135
136 /**
137 ****************************************************************************************
138 * @brief De-initialize the app rtc.
139 *
140 * @return Result of De-initialization.
141 ****************************************************************************************
142 */
143 uint16_t app_rtc_deinit(void);
144
145 /**
146 ****************************************************************************************
147 * @brief Initialize the rtc time.
148 *
149 * @param[in] p_time: Pointer to a app_rtc_time_t time struction.
150 *
151 * @return Result of operation.
152 ****************************************************************************************
153 */
154 uint16_t app_rtc_init_time(app_rtc_time_t *p_time);
155
156 /**
157 ****************************************************************************************
158 * @brief Get current rtc time.
159 *
160 * @note When CFG_LPCLK_INTERNAL_EN is true, This function should be called after BLE stack init,
161 * and the interval between two calls should be smaller than 23 hours to keep counting continously.
162 *
163 * @param[in] p_time: Pointer to a app_rtc_time_t time struction.
164 *
165 * @return Result of operation.
166 ****************************************************************************************
167 */
168 uint16_t app_rtc_get_time(app_rtc_time_t *p_time);
169
170 /**
171 ****************************************************************************************
172 * @brief Set a rtc date alarm.
173 *
174 * @param[in] p_alarm: After seconds will generate an date alarm interrupt.
175 *
176 * @return Result of operation.
177 ****************************************************************************************
178 */
179 uint16_t app_rtc_setup_alarm(app_rtc_alarm_t *p_alarm);
180
181 /**
182 ****************************************************************************************
183 * @brief Set a rtc tick alarm.
184 *
185 * @param[in] interval: After milliseconds will generate an tick alarm interrupt.
186 * The value of interval is greater than or equal to 10ms.
187 *
188 * @return Result of operation.
189 ****************************************************************************************
190 */
191 uint16_t app_rtc_setup_tick(uint32_t interval);
192
193 /**
194 ****************************************************************************************
195 * @brief Disable rtc alarm event.
196 *
197 * @param[in] disable_mode: Disable specified CALENDAR alarm mode.
198 * This parameter can be the following values:
199 * @arg @ref APP_RTC_ALARM_DISABLE_DATE
200 * @arg @ref APP_RTC_ALARM_DISABLE_TICK
201 * @arg @ref APP_RTC_ALARM_DISABLE_ALL
202 *
203 * @return Result of operation.
204 ****************************************************************************************
205 */
206 uint16_t app_rtc_disable_event(uint32_t disable_mode);
207
208 /** @} */
209
210 #endif
211
212 #ifdef __cplusplus
213 }
214 #endif
215
216 #endif
217
218 /** @} */
219 /** @} */
220 /** @} */
221
222
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
Type of event.
Definition: app_rtc.h:110
app_rtc_setup_tick
uint16_t app_rtc_setup_tick(uint32_t interval)
Set a rtc tick alarm.
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:97
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:116
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
Tick alarm event.
Definition: app_rtc.h:87
_calendar_alarm
CALENDAR_Alarm calendar alarm structure definition.
Definition: gr55xx_hal_calendar.h:126
gr55xx_hal.h
This file contains all the functions prototypes for the HAL module driver.
app_rtc_evt_type_t
app_rtc_evt_type_t
RTC event Enumerations definition.
Definition: app_rtc.h:85
APP_RTC_EVT_DATE_ALARM
@ APP_RTC_EVT_DATE_ALARM
Date alarm event.
Definition: app_rtc.h:86
_calendar_time
CALENDAR_Time calendar time structure definition.
Definition: gr55xx_hal_calendar.h:96
app_rtc_evt_t
RTC event structure definition.
Definition: app_rtc.h:109
app_rtos_cfg.h
Header file of app rtos config code.
app_drv_error.h
Header file of app driver error code.
app_rtc_alarm_t
calendar_alarm_t app_rtc_alarm_t
App alarm structure definition.
Definition: app_rtc.h:102
app_rtc_init
uint16_t app_rtc_init(app_rtc_evt_handler_t evt_handler)
Initialize the APP RTC DRIVER.