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 DAUL 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_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_STRUCTURES Structures
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 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
124 /**
125 * @brief DUAL_TIM IO configuration Structures
126 */
127 typedef struct
128 {
129 app_io_type_t type; /**< Specifies the type of Dual Timer IO.
130 This parameter can be any value of @ref app_io_type_t. */
131 uint32_t pin; /**< Specifies the IO pins to be configured.
132 This parameter can be any value of @ref GR5xxx_pins. */
133 } app_dual_tim_pin_t;
134
135 /**
136 * @brief DUAL_TIM io crtl parameters structure definition
137 */
138 typedef struct
139 {
140 app_dual_tim_pin_t pin_cfg; /**< Set the configuration of pin for DUAL_TIM io crtl. */
141 dual_timer_io_ctrl_cfg_t io_crtl_cfg; /**< DUAL_TIM io crtl required parameters. */
142 } app_dual_tim_io_crtl_params_t;
143 #endif
144
145 /**
146 * @brief DUAL_TIM device structure definition
147 */
148 typedef struct
149 {
150 app_dual_tim_evt_handler_t evt_handler; /**< APP_DUAL_TIM event callback definition. */
151 dual_timer_handle_t handle; /**< DUAL_TIM handle definition. */
152 app_dual_tim_state_t dual_tim_state; /**< DUAL_TIM state type Enumerations definition. */
153 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
154 app_dual_tim_pin_t cha_pin_cfg; /**< DUAL_TIM CHANNELA IO configuration Structures. */
155 app_dual_tim_pin_t chb_pin_cfg; /**< DUAL_TIM CHANNELB IO configuration Structures. */
156 app_dual_tim_pin_t chc_pin_cfg; /**< DUAL_TIM CHANNELC IO configuration Structures. */
157
158 volatile bool is_cha_enable;
159 volatile bool is_chb_enable;
160 volatile bool is_chc_enable;
161 #endif
162 }dual_tim_env_t;
163
164 /**
165 * @brief DUAL_TIM parameters structure definition
166 */
167 typedef struct
168 {
169 app_dual_tim_id_t id; /**< specified DUAL TIMER module ID. */
170 dual_timer_init_t init; /**< DUAL_TIM Base required parameters. */
171 dual_tim_env_t dual_tim_env; /**< DUAL_TIM device structure definition. */
172 } app_dual_tim_params_t;
173 /** @} */
174
175 /* Exported functions --------------------------------------------------------*/
176 /** @addtogroup APP_DUAL_TIM_DRIVER_FUNCTIONS Functions
177 * @{
178 */
179 /**
180 ****************************************************************************************
181 * @brief Initialize the APP DUAL TIM DRIVER according to the specified parameters
182 * in the app_dual_tim_params_t and app_dual_tim_evt_handler_t.
183 *
184 * @param[in] p_params: Pointer to app_dual_tim_params_t parameter which contains the
185 * configuration information for the specified DUAL TIM module.
186 * @param[in] evt_handler: DUAL TIM user callback function.
187 *
188 * @return Result of initialization.
189 ****************************************************************************************
190 */
191 uint16_t app_dual_tim_init(app_dual_tim_params_t *p_params, app_dual_tim_evt_handler_t evt_handler);
192
193 /**
194 ****************************************************************************************
195 * @brief De-initialize the APP DUAL TIM DRIVER peripheral.
196 *
197 * @param[in] id: De-initialize for a specific ID.
198 *
199 * @return Result of De-initialization.
200 ****************************************************************************************
201 */
202 uint16_t app_dual_tim_deinit(app_dual_tim_id_t id);
203
204 /**
205 ****************************************************************************************
206 * @brief Starts the DUAL TIM counter in interrupt mode.
207 * @param[in] id: which DUAL TIM module want to start.
208 *
209 * @return Result of execution.
210 *
211 ****************************************************************************************
212 */
213 uint16_t app_dual_tim_start(app_dual_tim_id_t id);
214
215 /**
216 ****************************************************************************************
217 * @brief Stops the DUAL TIM counter in interrupt mode.
218 * @param[in] id: which DUAL TIM module want to stop.
219 *
220 * @return Result of execution.
221 *
222 ****************************************************************************************
223 */
224 uint16_t app_dual_tim_stop(app_dual_tim_id_t id);
225
226 /**
227 ****************************************************************************************
228 * @brief Set the APP DUAL TIM according to the specified parameters
229 *
230 * @param[in] p_params: Pointer to app_dual_tim_params_t parameter which contains the
231 * configuration information for the specified DUAL TIM module.
232 * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
233 *
234 * @return Result of execution.
235 ****************************************************************************************
236 */
237 uint16_t app_dual_tim_set_params(app_dual_tim_params_t *p_params, app_dual_tim_id_t id);
238
239 /**
240 ****************************************************************************************
241 * @brief Set the APP DUAL TIM background reload value
242 * The background reload value contains the value from which the counter is to decrement.
243 * This is the value used to reload the counter when Periodic mode is enabled, and the current count reaches 0.
244 * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
245 * @param[in] reload_value: Background reload value
246 *
247 * @return Result of execution.
248 ****************************************************************************************
249 */
250 uint16_t app_dual_tim_set_background_reload(app_dual_tim_id_t id, uint32_t reload_value);
251
252 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
253 /**
254 ****************************************************************************************
255 * @brief Set the APP DUAL TIM one-time reload value
256 * The one-time reload value contains the value from which the counter is to decrement.
257 * This is the value used to reload the counter when Periodic mode is enabled, and the current count reaches 0.
258 * The difference is that writes to one-time reload value do not cause the counter to immediately restart from the new value.
259 * The one-time reload value only takes effect in the next cycle. It has higher priority than background reload.
260 * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
261 * @param[in] reload_value: One-time reload value
262 *
263 * @return Result of execution.
264 ****************************************************************************************
265 */
266 uint16_t app_dual_tim_set_onetime_reload(app_dual_tim_id_t id, uint32_t reload_value);
267
268 /**
269 ****************************************************************************************
270 * @brief DUAL TIMER set period count value
271 * The value is valid when the value is greater than 1. This fucntion is only avaliable in Period/Loop mode with IO control.
272 * This function call must be after app_dual_tim_io_crtl_config.
273 * This function will force the stop action interrupt to be turned on.
274 * If the current count value of the dual timer is not the period value, it may cause the first period to be shortened.
275 * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
276 * @param[in] count_value: period count value
277 *
278 * @return Result of execution.
279 ****************************************************************************************
280 */
281 uint16_t app_dual_tim_set_period_count(app_dual_tim_id_t id, uint32_t count_value);
282
283 /**
284 ****************************************************************************************
285 * @brief Configure the APP DUAL TIM io ctrl according to the specified parameters
286 * This function call must be after app_dual_tim_init. Reconfiguration needs to reinitialize APP DUAL TIM.
287 *
288 * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
289 * @param[in] io_crtl_params: Pointer to app_dual_tim_io_crtl_params_t parameter which contains the
290 * configuration information for the specified io crtl of the DUAL TIM module.
291 *
292 * @return Result of execution.
293 ****************************************************************************************
294 */
295 uint16_t app_dual_tim_io_crtl_config(app_dual_tim_id_t id, app_dual_tim_io_crtl_params_t *io_crtl_params);
296 #endif
297
298 /**
299 ****************************************************************************************
300 * @brief Return the DUAL TIM handle.
301 *
302 * @param[in] id: DUAL TIM Channel ID.
303 *
304 * @return Pointer to the specified ID's DUAL TIM handle.
305 ****************************************************************************************
306 */
307 dual_timer_handle_t *app_dual_tim_get_handle(app_dual_tim_id_t id);
308
309 /** @} */
310
311 #endif
312
313 #ifdef __cplusplus
314 }
315 #endif
316
317 #endif
318
319 /** @} */
320 /** @} */
321 /** @} */
322
APP_DUAL_TIM_EVT_ERROR
@ APP_DUAL_TIM_EVT_ERROR
Error reported by DUAL TIMER peripheral.
Definition: app_dual_tim.h:87
app_dual_tim_params_t
DUAL_TIM parameters structure definition.
Definition: app_dual_tim.h:168
app_dual_tim_evt_t
app_dual_tim_evt_t
DUAL_TIM event Enumerations definition.
Definition: app_dual_tim.h:86
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
DUAL_TIM Base required parameters.
Definition: app_dual_tim.h:170
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
specified DUAL TIMER module ID.
Definition: app_dual_tim.h:169
app_io_type_t
app_io_type_t
GPIO type Enumerations definition.
Definition: app_io.h:145
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_ACTIVITY
@ APP_DUAL_TIM_ACTIVITY
Definition: app_dual_tim.h:108
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
_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.
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_ID_1
@ APP_DUAL_TIM_ID_1
DUAL TIMER module 1.
Definition: app_dual_tim.h:78
APP_DUAL_TIM_ID_0
@ APP_DUAL_TIM_ID_0
DUAL TIMER module 0.
Definition: app_dual_tim.h:77
grx_hal.h
This file contains all the functions prototypes for the HAL module driver.
APP_DUAL_TIM_INVALID
@ APP_DUAL_TIM_INVALID
Definition: app_dual_tim.h:107
_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:149
dual_tim_env_t::dual_tim_state
app_dual_tim_state_t dual_tim_state
DUAL_TIM state type Enumerations definition.
Definition: app_dual_tim.h:152
APP_DUAL_TIM_ID_MAX
@ APP_DUAL_TIM_ID_MAX
Only for check parameter, not used as input parameters.
Definition: app_dual_tim.h:79
dual_tim_env_t::handle
dual_timer_handle_t handle
DUAL_TIM handle definition.
Definition: app_dual_tim.h:151
APP_DUAL_TIM_EVT_DONE
@ APP_DUAL_TIM_EVT_DONE
Interrupt done by DUAL TIMER peripheral.
Definition: app_dual_tim.h:88
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
APP_DUAL_TIM event callback definition.
Definition: app_dual_tim.h:150
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_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_params_t::dual_tim_env
dual_tim_env_t dual_tim_env
DUAL_TIM device structure definition.
Definition: app_dual_tim.h:171
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...