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 #ifdef APP_DUAL_TIM_IO_ENABLE
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. */
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 #ifdef APP_DUAL_TIM_IO_ENABLE
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
101 
102 /**
103  * @brief DUAL_TIM state type Enumerations definition
104  */
105 typedef enum
106 {
109 #ifdef APP_DRIVER_WAKEUP_CALL_FUN
110  APP_DUAL_TIM_SLEEP,
111 #endif
113 /** @} */
114 
115 /** @addtogroup APP_DUAL_TIM_TYPEDEFS Type definitions
116  * @{
117  */
118 /**
119  * @brief APP_DUAL_TIM event callback definition
120  */
122 
123 /** @} */
124 
125 /** @addtogroup APP_DUAL_TIM_STRUCTURES Structures
126  * @{
127  */
128 #ifdef APP_DUAL_TIM_IO_ENABLE
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 #ifdef APP_DUAL_TIM_IO_MUX_ENABLE
139  uint32_t mux;
140 #endif
141 } app_dual_tim_pin_t;
142 
143 /**
144  * @brief DUAL_TIM io crtl parameters structure definition
145  */
146 typedef struct
147 {
148  app_dual_tim_pin_t pin_cfg; /**< Set the configuration of pin for DUAL_TIM io crtl. */
149  dual_timer_io_ctrl_cfg_t io_crtl_cfg; /**< DUAL_TIM io crtl required parameters. */
150 } app_dual_tim_io_crtl_params_t;
151 #endif
152 
153 /**
154  * @brief DUAL_TIM device structure definition
155  */
156 typedef struct
157 {
158  app_dual_tim_evt_handler_t evt_handler; /**< APP_DUAL_TIM event callback definition. */
159  dual_timer_handle_t handle; /**< DUAL_TIM handle definition. */
160  app_dual_tim_state_t dual_tim_state; /**< DUAL_TIM state type Enumerations definition. */
161 #ifdef APP_DUAL_TIM_IO_ENABLE
162  app_dual_tim_pin_t cha_pin_cfg; /**< DUAL_TIM CHANNELA IO configuration Structures. */
163  app_dual_tim_pin_t chb_pin_cfg; /**< DUAL_TIM CHANNELB IO configuration Structures. */
164  app_dual_tim_pin_t chc_pin_cfg; /**< DUAL_TIM CHANNELC IO configuration Structures. */
165 
166  volatile bool is_cha_enable;
167  volatile bool is_chb_enable;
168  volatile bool is_chc_enable;
169 #endif
171 
172 /**
173  * @brief DUAL_TIM parameters structure definition
174  */
175 typedef struct
176 {
177  app_dual_tim_id_t id; /**< specified DUAL TIMER module ID. */
178  dual_timer_init_t init; /**< DUAL_TIM Base required parameters. */
179  dual_tim_env_t dual_tim_env; /**< DUAL_TIM device structure definition. */
181 /** @} */
182 
183 /* Exported functions --------------------------------------------------------*/
184 /** @addtogroup APP_DUAL_TIM_DRIVER_FUNCTIONS Functions
185  * @{
186  */
187 /**
188  ****************************************************************************************
189  * @brief Initialize the APP DUAL TIM DRIVER according to the specified parameters
190  * in the app_dual_tim_params_t and app_dual_tim_evt_handler_t.
191  *
192  * @param[in] p_params: Pointer to app_dual_tim_params_t parameter which contains the
193  * configuration information for the specified DUAL TIM module.
194  * @param[in] evt_handler: DUAL TIM user callback function.
195  *
196  * @return Result of initialization.
197  ****************************************************************************************
198  */
200 
201 /**
202  ****************************************************************************************
203  * @brief De-initialize the APP DUAL TIM DRIVER peripheral.
204  *
205  * @param[in] id: De-initialize for a specific ID.
206  *
207  * @return Result of De-initialization.
208  ****************************************************************************************
209  */
211 
212 /**
213  ****************************************************************************************
214  * @brief Starts the DUAL TIM counter in interrupt mode.
215  * @param[in] id: which DUAL TIM module want to start.
216  *
217  * @return Result of execution.
218  *
219  ****************************************************************************************
220  */
222 
223 /**
224  ****************************************************************************************
225  * @brief Stops the DUAL TIM counter in interrupt mode.
226  * @param[in] id: which DUAL TIM module want to stop.
227  *
228  * @return Result of execution.
229  *
230  ****************************************************************************************
231  */
233 
234 /**
235  ****************************************************************************************
236  * @brief Set the APP DUAL TIM according to the specified parameters
237  *
238  * @param[in] p_params: Pointer to app_dual_tim_params_t parameter which contains the
239  * configuration information for the specified DUAL TIM module.
240  * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
241  *
242  * @return Result of execution.
243  ****************************************************************************************
244  */
246 
247 /**
248  ****************************************************************************************
249  * @brief Set the APP DUAL TIM background reload value
250  * The background reload value contains the value from which the counter is to decrement.
251  * This is the value used to reload the counter when Periodic mode is enabled, and the current count reaches 0.
252  * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
253  * @param[in] reload_value: Background reload value
254  *
255  * @return Result of execution.
256  ****************************************************************************************
257  */
258 uint16_t app_dual_tim_set_background_reload(app_dual_tim_id_t id, uint32_t reload_value);
259 
260 #ifdef APP_DUAL_TIM_IO_ENABLE
261 /**
262  ****************************************************************************************
263  * @brief Set the APP DUAL TIM one-time reload value
264  * The one-time reload value contains the value from which the counter is to decrement.
265  * This is the value used to reload the counter when Periodic mode is enabled, and the current count reaches 0.
266  * The difference is that writes to one-time reload value do not cause the counter to immediately restart from the new value.
267  * The one-time reload value only takes effect in the next cycle. It has higher priority than background reload.
268  * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
269  * @param[in] reload_value: One-time reload value
270  *
271  * @return Result of execution.
272  ****************************************************************************************
273  */
274 uint16_t app_dual_tim_set_onetime_reload(app_dual_tim_id_t id, uint32_t reload_value);
275 
276 /**
277  ****************************************************************************************
278  * @brief DUAL TIMER set period count value
279  * The value is valid when the value is greater than 1. This function is only available in Period/Loop mode with IO control.
280  * This function call must be after app_dual_tim_io_crtl_config.
281  * This function will force the stop action interrupt to be turned on.
282  * If the current count value of the dual timer is not the period value, it may cause the first period to be shortened.
283  * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
284  * @param[in] count_value: period count value
285  *
286  * @return Result of execution.
287  ****************************************************************************************
288  */
289 uint16_t app_dual_tim_set_period_count(app_dual_tim_id_t id, uint32_t count_value);
290 
291 /**
292  ****************************************************************************************
293  * @brief Configure the APP DUAL TIM io ctrl according to the specified parameters
294  * This function call must be after app_dual_tim_init. Reconfiguration needs to reinitialize APP DUAL TIM.
295  *
296  * @param[in] id: A specific timer ID which can be APP_DUAL_TIM_ID_0 or APP_DUAL_TIM_ID_1
297  * @param[in] io_crtl_params: Pointer to app_dual_tim_io_crtl_params_t parameter which contains the
298  * configuration information for the specified io crtl of the DUAL TIM module.
299  *
300  * @return Result of execution.
301  ****************************************************************************************
302  */
303 uint16_t app_dual_tim_io_crtl_config(app_dual_tim_id_t id, app_dual_tim_io_crtl_params_t *io_crtl_params);
304 #endif
305 
306 /**
307  ****************************************************************************************
308  * @brief Return the DUAL TIM handle.
309  *
310  * @param[in] id: DUAL TIM Channel ID.
311  *
312  * @return Pointer to the specified ID's DUAL TIM handle.
313  ****************************************************************************************
314  */
316 
317 /** @} */
318 
319 #endif
320 
321 #ifdef __cplusplus
322 }
323 #endif
324 
325 #endif
326 
327 /** @} */
328 /** @} */
329 /** @} */
330 
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:176
APP_DUAL_TIM_EVT_ERROR
@ APP_DUAL_TIM_EVT_ERROR
Definition: app_dual_tim.h:87
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:178
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:177
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:142
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: hal_dual_tim.h:164
app_io.h
Header file containing functions prototypes of GPIO app library.
_dual_timer_io_ctrl_cfg
DUAL TIMER io crtl config Structure definition.
Definition: hal_dual_tim.h:128
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: hal_dual_tim.h:113
dual_tim_env_t
DUAL_TIM device structure definition.
Definition: app_dual_tim.h:157
dual_tim_env_t::dual_tim_state
app_dual_tim_state_t dual_tim_state
Definition: app_dual_tim.h:160
dual_tim_env_t::handle
dual_timer_handle_t handle
Definition: app_dual_tim.h:159
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:158
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_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:179
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