app_dual_tim.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file app_dual_tim.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of DUAL TIM 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 /** @addtogroup PERIPHERAL Peripheral Driver
38 * @{
39 */
40
41 /** @addtogroup APP_DRIVER APP DRIVER
42 * @{
43 */
44
45 /** @defgroup APP_DUAL_TIMER DUAL TIMER
46 * @brief DUAL TIMER APP module driver.
47 * @{
48 */
49
50
51 #ifndef _APP_DUAL_TIM_H_
52 #define _APP_DUAL_TIM_H_
53
54 #include "grx_hal.h"
55 #include "app_drv_error.h"
56 #include "app_drv_config.h"
57
58 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
59 #include "app_io.h"
60 #endif
61
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65
66 #ifdef HAL_DUAL_TIMER_MODULE_ENABLED
67
68 /** @addtogroup APP_DUAL_TIM_ENUM Enumerations
69 * @{
70 */
71
72 /**
73 * @brief APP_DUAL_TIM module Enumerations definition
74 */
75 typedef enum
76 {
77 APP_DUAL_TIM_ID_0, /**< DUAL TIMER module 0 */
78 APP_DUAL_TIM_ID_1, /**< DUAL TIMER module 1 */
79 APP_DUAL_TIM_ID_MAX /**< Only for check parameter, not used as input parameters. */
80 } app_dual_tim_id_t;
81
82 /**
83 * @brief DUAL_TIM event Enumerations definition
84 */
85 typedef enum
86 {
87 APP_DUAL_TIM_EVT_ERROR, /**< Error reported by DUAL TIMER peripheral. */
88 APP_DUAL_TIM_EVT_DONE, /**< Interrupt done by DUAL TIMER peripheral. */
89 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
90 APP_DUAL_TIM_EVT_ACT_START, /**< Interrupt action start by DUAL TIMER peripheral. */
91 APP_DUAL_TIM_EVT_IOA_ACT_C1, /**< Interrupt ioa action count 1 by DUAL TIMER peripheral. */
92 APP_DUAL_TIM_EVT_IOA_ACT_C2, /**< Interrupt ioa action count 2 by DUAL TIMER peripheral. */
93 APP_DUAL_TIM_EVT_ACT_PERIOD, /**< Interrupt action period by DUAL TIMER peripheral. */
94 APP_DUAL_TIM_EVT_ACT_STOP, /**< Interrupt action stop by DUAL TIMER peripheral. */
95 APP_DUAL_TIM_EVT_IOB_ACT_C1, /**< Interrupt iob action count 1 by DUAL TIMER peripheral. */
96 APP_DUAL_TIM_EVT_IOB_ACT_C2, /**< Interrupt iob action count 2 by DUAL TIMER peripheral. */
97 APP_DUAL_TIM_EVT_IOC_ACT_C1, /**< Interrupt ioc action count 1 by DUAL TIMER peripheral. */
98 APP_DUAL_TIM_EVT_IOC_ACT_C2 /**< Interrupt ioc action count 2 by DUAL TIMER peripheral. */
99 #endif
100 } app_dual_tim_evt_t;
101
102 /**
103 * @brief DUAL_TIM state type Enumerations definition
104 */
105 typedef enum
106 {
107 APP_DUAL_TIM_INVALID = 0,
108 APP_DUAL_TIM_ACTIVITY,
109 #ifdef APP_DRIVER_WAKEUP_CALL_FUN
110 APP_DUAL_TIM_SLEEP,
111 #endif
112 } app_dual_tim_state_t;
113 /** @} */
114
115 /** @addtogroup APP_DUAL_TIM_TYPEDEFS Type definitions
116 * @{
117 */
118 /**
119 * @brief APP_DUAL_TIM event callback definition
120 */
121 typedef void (*app_dual_tim_evt_handler_t)(app_dual_tim_evt_t *p_evt);
122
123 /** @} */
124
125 /** @addtogroup APP_DUAL_TIM_STRUCTURES Structures
126 * @{
127 */
128 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
129 /**
130 * @brief DUAL_TIM IO configuration Structures
131 */
132 typedef struct
133 {
134 app_io_type_t type; /**< Specifies the type of Dual Timer IO.
135 This parameter can be any value of @ref app_io_type_t. */
136 uint32_t pin; /**< Specifies the IO pins to be configured.
137 This parameter can be any value of @ref GR5xxx_pins. */
138 } app_dual_tim_pin_t;
139
140 /**
141 * @brief DUAL_TIM io crtl parameters structure definition
142 */
143 typedef struct
144 {
145 app_dual_tim_pin_t pin_cfg; /**< Set the configuration of pin for DUAL_TIM io crtl. */
146 dual_timer_io_ctrl_cfg_t io_crtl_cfg; /**< DUAL_TIM io crtl required parameters. */
147 } app_dual_tim_io_crtl_params_t;
148 #endif
149
150 /**
151 * @brief DUAL_TIM device structure definition
152 */
153 typedef struct
154 {
155 app_dual_tim_evt_handler_t evt_handler; /**< APP_DUAL_TIM event callback definition. */
156 dual_timer_handle_t handle; /**< DUAL_TIM handle definition. */
157 app_dual_tim_state_t dual_tim_state; /**< DUAL_TIM state type Enumerations definition. */
158 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
159 app_dual_tim_pin_t cha_pin_cfg; /**< DUAL_TIM CHANNELA IO configuration Structures. */
160 app_dual_tim_pin_t chb_pin_cfg; /**< DUAL_TIM CHANNELB IO configuration Structures. */
161 app_dual_tim_pin_t chc_pin_cfg; /**< DUAL_TIM CHANNELC IO configuration Structures. */
162
163 volatile bool is_cha_enable;
164 volatile bool is_chb_enable;
165 volatile bool is_chc_enable;
166 #endif
167 }dual_tim_env_t;
168
169 /**
170 * @brief DUAL_TIM parameters structure definition
171 */
172 typedef struct
173 {
174 app_dual_tim_id_t id; /**< specified DUAL TIMER module ID. */
175 dual_timer_init_t init; /**< DUAL_TIM Base required parameters. */
176 dual_tim_env_t dual_tim_env; /**< DUAL_TIM device structure definition. */
177 } app_dual_tim_params_t;
178 /** @} */
179
180 /* Exported functions --------------------------------------------------------*/
181 /** @addtogroup APP_DUAL_TIM_DRIVER_FUNCTIONS Functions
182 * @{
183 */
184 /**
185 ****************************************************************************************
186 * @brief Initialize the APP DUAL TIM DRIVER according to the specified parameters
187 * in the app_dual_tim_params_t and app_dual_tim_evt_handler_t.
188 *
189 * @param[in] p_params: Pointer to app_dual_tim_params_t parameter which contains the
190 * configuration information for the specified DUAL TIM module.
191 * @param[in] evt_handler: DUAL TIM user callback function.
192 *
193 * @return Result of initialization.
194 ****************************************************************************************
195 */
196 uint16_t app_dual_tim_init(app_dual_tim_params_t *p_params, app_dual_tim_evt_handler_t evt_handler);
197
198 /**
199 ****************************************************************************************
200 * @brief De-initialize the APP DUAL TIM DRIVER peripheral.
201 *
202 * @param[in] id: De-initialize for a specific ID.
203 *
204 * @return Result of De-initialization.
205 ****************************************************************************************
206 */
207 uint16_t app_dual_tim_deinit(app_dual_tim_id_t id);
208
209 /**
210 ****************************************************************************************
211 * @brief Starts the DUAL TIM counter in interrupt mode.
212 * @param[in] id: which DUAL TIM module want to start.
213 *
214 * @return Result of execution.
215 *
216 ****************************************************************************************
217 */
218 uint16_t app_dual_tim_start(app_dual_tim_id_t id);
219
220 /**
221 ****************************************************************************************
222 * @brief Stops the DUAL TIM counter in interrupt mode.
223 * @param[in] id: which DUAL TIM module want to stop.
224 *
225 * @return Result of execution.
226 *
227 ****************************************************************************************
228 */
229 uint16_t app_dual_tim_stop(app_dual_tim_id_t id);
230
231 /**
232 ****************************************************************************************
233 * @brief Set the APP DUAL TIM according to the specified parameters
234 *
235 * @param[in] p_params: Pointer to app_dual_tim_params_t parameter which contains the
236 * configuration information for the specified DUAL TIM module.
237 * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
238 *
239 * @return Result of execution.
240 ****************************************************************************************
241 */
242 uint16_t app_dual_tim_set_params(app_dual_tim_params_t *p_params, app_dual_tim_id_t id);
243
244 /**
245 ****************************************************************************************
246 * @brief Set the APP DUAL TIM background reload value
247 * The background reload value contains the value from which the counter is to decrement.
248 * This is the value used to reload the counter when Periodic mode is enabled, and the current count reaches 0.
249 * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
250 * @param[in] reload_value: Background reload value
251 *
252 * @return Result of execution.
253 ****************************************************************************************
254 */
255 uint16_t app_dual_tim_set_background_reload(app_dual_tim_id_t id, uint32_t reload_value);
256
257 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
258 /**
259 ****************************************************************************************
260 * @brief Set the APP DUAL TIM one-time reload value
261 * The one-time reload value contains the value from which the counter is to decrement.
262 * This is the value used to reload the counter when Periodic mode is enabled, and the current count reaches 0.
263 * The difference is that writes to one-time reload value do not cause the counter to immediately restart from the new value.
264 * The one-time reload value only takes effect in the next cycle. It has higher priority than background reload.
265 * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
266 * @param[in] reload_value: One-time reload value
267 *
268 * @return Result of execution.
269 ****************************************************************************************
270 */
271 uint16_t app_dual_tim_set_onetime_reload(app_dual_tim_id_t id, uint32_t reload_value);
272
273 /**
274 ****************************************************************************************
275 * @brief DUAL TIMER set period count value
276 * The value is valid when the value is greater than 1. This function is only available in Period/Loop mode with IO control.
277 * This function call must be after app_dual_tim_io_crtl_config.
278 * This function will force the stop action interrupt to be turned on.
279 * If the current count value of the dual timer is not the period value, it may cause the first period to be shortened.
280 * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
281 * @param[in] count_value: period count value
282 *
283 * @return Result of execution.
284 ****************************************************************************************
285 */
286 uint16_t app_dual_tim_set_period_count(app_dual_tim_id_t id, uint32_t count_value);
287
288 /**
289 ****************************************************************************************
290 * @brief Configure the APP DUAL TIM io ctrl according to the specified parameters
291 * This function call must be after app_dual_tim_init. Reconfiguration needs to reinitialize APP DUAL TIM.
292 *
293 * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
294 * @param[in] io_crtl_params: Pointer to app_dual_tim_io_crtl_params_t parameter which contains the
295 * configuration information for the specified io crtl of the DUAL TIM module.
296 *
297 * @return Result of execution.
298 ****************************************************************************************
299 */
300 uint16_t app_dual_tim_io_crtl_config(app_dual_tim_id_t id, app_dual_tim_io_crtl_params_t *io_crtl_params);
301 #endif
302
303 /**
304 ****************************************************************************************
305 * @brief Return the DUAL TIM handle.
306 *
307 * @param[in] id: DUAL TIM Channel ID.
308 *
309 * @return Pointer to the specified ID's DUAL TIM handle.
310 ****************************************************************************************
311 */
312 dual_timer_handle_t *app_dual_tim_get_handle(app_dual_tim_id_t id);
313
314 /**
315 ****************************************************************************************
316 * @brief Set the APP DUAL TIM background reload value and current reload value
317 * The background reload value contains the value from which the counter is to decrement.
318 * This is the value used to reload the counter when Periodic mode is enabled, and the current count reaches 0.
319 * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
320 * @param[in] reload_value: current reload value
321 * @param[in] bg_reload_value: Background reload value
322 *
323 * @return Result of execution.
324 ****************************************************************************************
325 */
326 uint16_t app_dual_tim_set_reload_value_bg_reload_value(app_dual_tim_id_t id, uint32_t reload_value,uint32_t bg_reload_value);
327
328 /**
329 ****************************************************************************************
330 * @brief Return the DUAL TIM counter.
331 *
332 * @param[in] id: DUAL TIM Channel ID.
333 *
334 * @return DUAL TIM Counter.
335 ****************************************************************************************
336 */
337 uint32_t app_dual_tim_get_counter_value(app_dual_tim_id_t id);
338 /** @} */
339
340 #endif
341
342 #ifdef __cplusplus
343 }
344 #endif
345
346 #endif
347
348 /** @} */
349 /** @} */
350 /** @} */
351
APP_DUAL_TIM_ID_0
@ APP_DUAL_TIM_ID_0
Definition: app_dual_tim.h:77
app_dual_tim_params_t
DUAL_TIM parameters structure definition.
Definition: app_dual_tim.h:173
APP_DUAL_TIM_EVT_ERROR
@ APP_DUAL_TIM_EVT_ERROR
Definition: app_dual_tim.h:87
app_dual_tim_get_counter_value
uint32_t app_dual_tim_get_counter_value(app_dual_tim_id_t id)
Return the DUAL TIM counter.
app_dual_tim_set_params
uint16_t app_dual_tim_set_params(app_dual_tim_params_t *p_params, app_dual_tim_id_t id)
Set the APP DUAL TIM according to the specified parameters.
app_dual_tim_params_t::init
dual_timer_init_t init
Definition: app_dual_tim.h:175
app_dual_tim_get_handle
dual_timer_handle_t * app_dual_tim_get_handle(app_dual_tim_id_t id)
Return the DUAL TIM handle.
app_dual_tim_params_t::id
app_dual_tim_id_t id
Definition: app_dual_tim.h:174
app_dual_tim_evt_handler_t
void(* app_dual_tim_evt_handler_t)(app_dual_tim_evt_t *p_evt)
APP_DUAL_TIM event callback definition.
Definition: app_dual_tim.h:121
app_io_type_t
app_io_type_t
GPIO type Enumerations definition.
Definition: app_io.h:147
app_dual_tim_set_background_reload
uint16_t app_dual_tim_set_background_reload(app_dual_tim_id_t id, uint32_t reload_value)
Set the APP DUAL TIM background reload value The background reload value contains the value from whic...
APP_DUAL_TIM_ID_1
@ APP_DUAL_TIM_ID_1
Definition: app_dual_tim.h:78
APP_DUAL_TIM_INVALID
@ APP_DUAL_TIM_INVALID
Definition: app_dual_tim.h:107
_dual_timer_handle
DUAL_TIMER handle Structure definition.
Definition: gr55xx_hal_dual_tim.h:119
app_io.h
Header file containing functions prototypes of GPIO app library.
grx_hal.h
This file contains all the functions prototypes for the HAL module driver.
APP_DUAL_TIM_EVT_DONE
@ APP_DUAL_TIM_EVT_DONE
Definition: app_dual_tim.h:88
_dual_timer_init
DUAL TIMER init Structure definition.
Definition: gr55xx_hal_dual_tim.h:98
dual_tim_env_t
DUAL_TIM device structure definition.
Definition: app_dual_tim.h:154
dual_tim_env_t::dual_tim_state
app_dual_tim_state_t dual_tim_state
Definition: app_dual_tim.h:157
dual_tim_env_t::handle
dual_timer_handle_t handle
Definition: app_dual_tim.h:156
app_dual_tim_stop
uint16_t app_dual_tim_stop(app_dual_tim_id_t id)
Stops the DUAL TIM counter in interrupt mode.
app_dual_tim_start
uint16_t app_dual_tim_start(app_dual_tim_id_t id)
Starts the DUAL TIM counter in interrupt mode.
dual_tim_env_t::evt_handler
app_dual_tim_evt_handler_t evt_handler
Definition: app_dual_tim.h:155
app_dual_tim_deinit
uint16_t app_dual_tim_deinit(app_dual_tim_id_t id)
De-initialize the APP DUAL TIM DRIVER peripheral.
APP_DUAL_TIM_ID_MAX
@ APP_DUAL_TIM_ID_MAX
Definition: app_dual_tim.h:79
app_dual_tim_state_t
app_dual_tim_state_t
DUAL_TIM state type Enumerations definition.
Definition: app_dual_tim.h:106
app_drv_error.h
Header file of app driver error code.
app_drv_config.h
Header file of app driver config code.
app_dual_tim_set_reload_value_bg_reload_value
uint16_t app_dual_tim_set_reload_value_bg_reload_value(app_dual_tim_id_t id, uint32_t reload_value, uint32_t bg_reload_value)
Set the APP DUAL TIM background reload value and current reload value The background reload value con...
APP_DUAL_TIM_ACTIVITY
@ APP_DUAL_TIM_ACTIVITY
Definition: app_dual_tim.h:108
app_dual_tim_params_t::dual_tim_env
dual_tim_env_t dual_tim_env
Definition: app_dual_tim.h:176
app_dual_tim_init
uint16_t app_dual_tim_init(app_dual_tim_params_t *p_params, app_dual_tim_evt_handler_t evt_handler)
Initialize the APP DUAL TIM DRIVER according to the specified parameters in the app_dual_tim_params_t...
app_dual_tim_id_t
app_dual_tim_id_t
APP_DUAL_TIM module Enumerations definition.
Definition: app_dual_tim.h:76
app_dual_tim_evt_t
app_dual_tim_evt_t
DUAL_TIM event Enumerations definition.
Definition: app_dual_tim.h:86