app_tim.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file app_tim.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of 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
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup APP_DRIVER APP DRIVER
43 * @{
44 */
45
46 /** @defgroup APP_TIMER TIMER
47 * @brief TIMER APP module driver.
48 * @{
49 */
50
51
52 #ifndef _APP_TIM_H_
53 #define _APP_TIM_H_
54
55 #include "grx_hal.h"
56 #include "app_drv_error.h"
57 #include "app_drv_config.h"
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
62 #ifdef HAL_TIMER_MODULE_ENABLED
63
64 /** @addtogroup APP_TIM_ENUM Enumerations
65 * @{
66 */
67
68 /**
69 * @brief TIM module Enumerations definition
70 */
71 typedef enum
72 {
73 APP_TIM_ID_0, /**< TIMER module 0 */
74 APP_TIM_ID_1, /**< TIMER module 1 */
75 APP_TIM_ID_MAX /**< Only for check parameter, not used as input parameters. */
76 } app_tim_id_t;
77
78 /**
79 * @brief TIM event Enumerations definition
80 */
81 typedef enum
82 {
83 APP_TIM_EVT_ERROR, /**< Error reported by TIMER peripheral. */
84 APP_TIM_EVT_DONE, /**< Count done event by TIMER peripheral. */
85 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
86 APP_TIM_EVT_CHANNEL0, /**< Channle0 event by TIMER peripheral. */
87 APP_TIM_EVT_CHANNEL1, /**< Channle1 event by TIMER peripheral. */
88 APP_TIM_EVT_CHANNEL2, /**< Channle2 event by TIMER peripheral. */
89 APP_TIM_EVT_CHANNEL3, /**< Channle3 event by TIMER peripheral. */
90 #endif
91 } app_tim_evt_t;
92 /** @} */
93
94 /** @addtogroup APP_TIM_TYPEDEFS Type definitions
95 * @{
96 */
97 /**
98 * @brief TIM event callback definition
99 */
100 typedef void (*app_tim_evt_handler_t)(app_tim_evt_t *p_evt);
101
102 /** @} */
103
104 /** @addtogroup APP_TIM_ENUM Enumerations
105 * @{
106 */
107 /**@brief App tim state types. */
108 typedef enum
109 {
110 APP_TIM_INVALID = 0,
111 APP_TIM_ACTIVITY,
112 #ifdef APP_DRIVER_WAKEUP_CALL_FUN
113 APP_TIM_SLEEP,
114 #endif
115 } app_tim_state_t;
116
117 /** @} */
118
119 /** @addtogroup APP_TIM_STRUCTURES Structures
120 * @{
121 */
122 /**
123 * @brief TIM device structure definition
124 */
125 typedef struct
126 {
127 app_tim_evt_handler_t evt_handler; /**< TIM event callback. */
128 timer_handle_t handle; /**< TIMER handle Structure. */
129 app_tim_state_t tim_state; /**< App tim state types. */
130 }tim_env_t;
131
132 /**
133 * @brief TIM parameters structure definition
134 */
135 typedef struct
136 {
137 app_tim_id_t id; /**< specified TIMER module ID. */
138 timer_init_t init; /**< TIMER Base required parameters. */
139 tim_env_t tim_env; /**< TIM device structure definition. */
140 } app_tim_params_t;
141
142 /** @} */
143
144 /* Exported functions --------------------------------------------------------*/
145 /** @addtogroup APP_TIM_DRIVER_FUNCTIONS Functions
146 * @{
147 */
148 /**
149 ****************************************************************************************
150 * @brief Initialize the APP TIM DRIVER according to the specified parameters
151 * in the app_tim_params_t and app_tim_evt_handler_t.
152 *
153 * @param[in] p_params: Pointer to app_tim_params_t parameter which contains the
154 * configuration information for the specified TIM module.
155 * @param[in] evt_handler: TIM user callback function.
156 *
157 * @return Result of initialization.
158 ****************************************************************************************
159 */
160 uint16_t app_tim_init(app_tim_params_t *p_params, app_tim_evt_handler_t evt_handler);
161
162 /**
163 ****************************************************************************************
164 * @brief De-initialize the APP TIM DRIVER peripheral.
165 *
166 * @param[in] id: De-initialize for a specific ID.
167 *
168 * @return Result of De-initialization.
169 ****************************************************************************************
170 */
171 uint16_t app_tim_deinit(app_tim_id_t id);
172
173 /**
174 ****************************************************************************************
175 * @brief Starts the TIM counter in interrupt mode.
176 * @param[in] id: which TIM module want to start.
177 *
178 * @return Result of initialization.
179 *
180 ****************************************************************************************
181 */
182 uint16_t app_tim_start(app_tim_id_t id);
183
184 /**
185 ****************************************************************************************
186 * @brief Stops the TIM counter in interrupt mode.
187 * @param[in] id: which TIM module want to stop.
188 *
189 * @return Result of initialization.
190 *
191 ****************************************************************************************
192 */
193 uint16_t app_tim_stop(app_tim_id_t id);
194
195 /**
196 ****************************************************************************************
197 * @brief Return the TIM handle.
198 *
199 * @param[in] id: TIM Channel ID.
200 *
201 * @return Pointer to the specified ID's TIM handle.
202 ****************************************************************************************
203 */
204 timer_handle_t *app_tim_get_handle(app_tim_id_t id);
205
206 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
207 /**
208 ****************************************************************************************
209 * @brief Return channel0 value.
210 *
211 * @param[in] id: TIM Channel ID.
212 *
213 * @return Current value when channel0 captured.
214 ****************************************************************************************
215 */
216 uint32_t app_tim_get_channel0_val(app_tim_id_t id);
217
218 /**
219 ****************************************************************************************
220 * @brief Return channel1 value.
221 *
222 * @param[in] id: TIM Channel ID.
223 *
224 * @return Current value when channel1 captured.
225 ****************************************************************************************
226 */
227 uint32_t app_tim_get_channel1_val(app_tim_id_t id);
228
229 /**
230 ****************************************************************************************
231 * @brief Return channel2 value.
232 *
233 * @param[in] id: TIM Channel ID.
234 *
235 * @return Current value when channel2 captured.
236 ****************************************************************************************
237 */
238 uint32_t app_tim_get_channel2_val(app_tim_id_t id);
239
240 /**
241 ****************************************************************************************
242 * @brief Return channel3 value.
243 *
244 * @param[in] id: TIM Channel ID.
245 *
246 * @return Current value when channel3 captured.
247 ****************************************************************************************
248 */
249 uint32_t app_tim_get_channel3_val(app_tim_id_t id);
250 #endif
251
252 /** @} */
253
254 #endif
255
256 #ifdef __cplusplus
257 }
258 #endif
259
260 #endif
261
262 /** @} */
263 /** @} */
264 /** @} */
265
app_tim_state_t
app_tim_state_t
App tim state types.
Definition: app_tim.h:109
app_tim_id_t
app_tim_id_t
TIM module Enumerations definition.
Definition: app_tim.h:72
APP_TIM_ID_MAX
@ APP_TIM_ID_MAX
Definition: app_tim.h:75
tim_env_t::evt_handler
app_tim_evt_handler_t evt_handler
Definition: app_tim.h:127
app_tim_stop
uint16_t app_tim_stop(app_tim_id_t id)
Stops the TIM counter in interrupt mode.
app_tim_evt_handler_t
void(* app_tim_evt_handler_t)(app_tim_evt_t *p_evt)
TIM event callback definition.
Definition: app_tim.h:100
app_tim_params_t::tim_env
tim_env_t tim_env
Definition: app_tim.h:139
app_tim_params_t::init
timer_init_t init
Definition: app_tim.h:138
app_tim_params_t::id
app_tim_id_t id
Definition: app_tim.h:137
tim_env_t::handle
timer_handle_t handle
Definition: app_tim.h:128
_timer_init
TIMER init Structure definition.
Definition: gr533x_hal_tim.h:158
APP_TIM_ID_1
@ APP_TIM_ID_1
Definition: app_tim.h:74
APP_TIM_INVALID
@ APP_TIM_INVALID
Definition: app_tim.h:110
APP_TIM_EVT_ERROR
@ APP_TIM_EVT_ERROR
Definition: app_tim.h:83
tim_env_t::tim_state
app_tim_state_t tim_state
Definition: app_tim.h:129
app_tim_evt_t
app_tim_evt_t
TIM event Enumerations definition.
Definition: app_tim.h:82
grx_hal.h
This file contains all the functions prototypes for the HAL module driver.
app_tim_params_t
TIM parameters structure definition.
Definition: app_tim.h:136
APP_TIM_ID_0
@ APP_TIM_ID_0
Definition: app_tim.h:73
app_tim_start
uint16_t app_tim_start(app_tim_id_t id)
Starts the TIM counter in interrupt mode.
app_tim_deinit
uint16_t app_tim_deinit(app_tim_id_t id)
De-initialize the APP TIM DRIVER peripheral.
app_tim_init
uint16_t app_tim_init(app_tim_params_t *p_params, app_tim_evt_handler_t evt_handler)
Initialize the APP TIM DRIVER according to the specified parameters in the app_tim_params_t and app_t...
_timer_handle
TIMER handle Structure definition.
Definition: gr533x_hal_tim.h:176
APP_TIM_ACTIVITY
@ APP_TIM_ACTIVITY
Definition: app_tim.h:111
app_tim_get_handle
timer_handle_t * app_tim_get_handle(app_tim_id_t id)
Return the TIM handle.
app_drv_error.h
Header file of app driver error code.
app_drv_config.h
Header file of app driver config code.
tim_env_t
TIM device structure definition.
Definition: app_tim.h:126
APP_TIM_EVT_DONE
@ APP_TIM_EVT_DONE
Definition: app_tim.h:84