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 /**
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_OVERFLOW, /**< Overflow event. */
90 /** @} */
91 
92 /** @addtogroup APP_RTC_STRUCTURES Structures
93  * @{
94  */
95 /**
96  * @brief App time structure definition
97  */
99 
100 /**
101  * @brief App alarm structure definition
102  */
104 
105 
106 /**
107  * @brief RTC event structure definition
108  */
109 typedef struct
110 {
111  app_rtc_evt_type_t type; /**< Type of event. */
112 } app_rtc_evt_t;
113 
114 /**
115  * @brief RTC event callback definition
116  */
117 typedef void (*app_rtc_evt_handler_t)(app_rtc_evt_t *p_evt);
118 
119 /** @} */
120 
121 
122 /* Exported functions --------------------------------------------------------*/
123 /** @addtogroup APP_RTC_DRIVER_FUNCTIONS Functions
124  * @{
125  */
126 /**
127  ****************************************************************************************
128  * @brief Initialize the APP RTC DRIVER.
129  *
130  * @param[in] evt_handler: RTC user callback function.
131  *
132  * @return Result of initialization.
133  ****************************************************************************************
134  */
135 uint16_t app_rtc_init(app_rtc_evt_handler_t evt_handler);
136 
137 /**
138  ****************************************************************************************
139  * @brief De-initialize the app rtc.
140  *
141  * @return Result of De-initialization.
142  ****************************************************************************************
143  */
144 uint16_t app_rtc_deinit(void);
145 
146 /**
147  ****************************************************************************************
148  * @brief Initialize the rtc time.
149  *
150  * @param[in] p_time: Pointer to a app_rtc_time_t time struction.
151  *
152  * @return Result of operation.
153  ****************************************************************************************
154  */
156 
157 /**
158  ****************************************************************************************
159  * @brief Get current rtc time.
160  *
161  * @param[in] p_time: Pointer to a app_rtc_time_t time struction.
162  *
163  * @return Result of operation.
164  ****************************************************************************************
165  */
167 
168 /**
169  ****************************************************************************************
170  * @brief Set a rtc date alarm.
171  *
172  * @param[in] p_alarm: After seconds will generate an date alarm interrupt.
173  *
174  * @return Result of operation.
175  ****************************************************************************************
176  */
178 
179 /**
180  ****************************************************************************************
181  * @brief Set a rtc tick alarm.
182  *
183  * @param[in] interval: After milliseconds will generate an tick alarm interrupt.
184  * The value of interval is greater than or equal to 10ms.
185  *
186  * @return Result of operation.
187  ****************************************************************************************
188  */
189 uint16_t app_rtc_setup_tick(uint32_t interval);
190 
191 /**
192  ****************************************************************************************
193  * @brief Disable rtc alarm event.
194  *
195  * @param[in] disable_mode: Disable specified CALENDAR alarm mode.
196  * This parameter can be the following values:
197  * @arg @ref APP_RTC_ALARM_DISABLE_DATE
198  * @arg @ref APP_RTC_ALARM_DISABLE_TICK
199  * @arg @ref APP_RTC_ALARM_DISABLE_ALL
200  *
201  * @return Result of operation.
202  ****************************************************************************************
203  */
204 uint16_t app_rtc_disable_event(uint32_t disable_mode);
205 
206 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5526X) || (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5525X) || (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
207 /**
208  ****************************************************************************************
209  * @brief Synchronous RTC low speed clock.
210  *
211  * @param[in] SlowClockFreq: Number of slow clocks
212  *
213  * @return None.
214  ****************************************************************************************
215  */
216 void app_rtc_time_sync(uint16_t SlowClockFreq);
217 #endif
218 /** @} */
219 
220 #endif
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif
227 
228 /** @} */
229 /** @} */
230 /** @} */
231 
232 
APP_RTC_EVT_OVERFLOW
@ APP_RTC_EVT_OVERFLOW
Definition: app_rtc.h:88
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:111
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:98
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:117
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:87
_calendar_alarm
CALENDAR_Alarm calendar alarm structure definition.
Definition: gr55xx_hal_calendar.h:127
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
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:110
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:103
app_rtc_init
uint16_t app_rtc_init(app_rtc_evt_handler_t evt_handler)
Initialize the APP RTC DRIVER.