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, /**< Countdone 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_STRUCTURES Structures
95 * @{
96 */
97
98 /**
99 * @brief TIM event callback definition
100 */
101 typedef void (*app_tim_evt_handler_t)(app_tim_evt_t *p_evt);
102
103 /**@brief App tim state types. */
104 typedef enum
105 {
106 APP_TIM_INVALID = 0,
107 APP_TIM_ACTIVITY,
108 #ifdef APP_DRIVER_WAKEUP_CALL_FUN
109 APP_TIM_SLEEP,
110 #endif
111 } app_tim_state_t;
112
113 /**
114 * @brief TIM device structure definition
115 */
116 typedef struct
117 {
118 app_tim_evt_handler_t evt_handler; /**< TIM event callback. */
119 timer_handle_t handle; /**< TIMER handle Structure. */
120 app_tim_state_t tim_state; /**< App tim state types. */
121 }tim_env_t;
122
123 /**
124 * @brief TIM parameters structure definition
125 */
126 typedef struct
127 {
128 app_tim_id_t id; /**< specified TIMER module ID. */
129 timer_init_t init; /**< TIMER Base required parameters. */
130 tim_env_t tim_env; /**< TIM device structure definition. */
131 } app_tim_params_t;
132
133 /** @} */
134
135 /* Exported functions --------------------------------------------------------*/
136 /** @addtogroup APP_TIM_DRIVER_FUNCTIONS Functions
137 * @{
138 */
139 /**
140 ****************************************************************************************
141 * @brief Initialize the APP TIM DRIVER according to the specified parameters
142 * in the app_tim_params_t and app_tim_evt_handler_t.
143 *
144 * @param[in] p_params: Pointer to app_tim_params_t parameter which contains the
145 * configuration information for the specified TIM module.
146 * @param[in] evt_handler: TIM user callback function.
147 *
148 * @return Result of initialization.
149 ****************************************************************************************
150 */
151 uint16_t app_tim_init(app_tim_params_t *p_params, app_tim_evt_handler_t evt_handler);
152
153 /**
154 ****************************************************************************************
155 * @brief De-initialize the APP TIM DRIVER peripheral.
156 *
157 * @param[in] id: De-initialize for a specific ID.
158 *
159 * @return Result of De-initialization.
160 ****************************************************************************************
161 */
162 uint16_t app_tim_deinit(app_tim_id_t id);
163
164 /**
165 ****************************************************************************************
166 * @brief Starts the TIM counter in interrupt mode.
167 * @param[in] id: which TIM module want to start.
168 *
169 * @return Result of initialization.
170 *
171 ****************************************************************************************
172 */
173 uint16_t app_tim_start(app_tim_id_t id);
174
175 /**
176 ****************************************************************************************
177 * @brief Stops the TIM counter in interrupt mode.
178 * @param[in] id: which TIM module want to stop.
179 *
180 * @return Result of initialization.
181 *
182 ****************************************************************************************
183 */
184 uint16_t app_tim_stop(app_tim_id_t id);
185
186 /**
187 ****************************************************************************************
188 * @brief Return the TIM handle.
189 *
190 * @param[in] id: TIM Channel ID.
191 *
192 * @return Pointer to the specified ID's TIM handle.
193 ****************************************************************************************
194 */
195 timer_handle_t *app_tim_get_handle(app_tim_id_t id);
196
197 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
198 /**
199 ****************************************************************************************
200 * @brief Return channel0 value.
201 *
202 * @param[in] id: TIM Channel ID.
203 *
204 * @return Current value when channel0 captured.
205 ****************************************************************************************
206 */
207 uint32_t app_tim_get_channel0_val(app_tim_id_t id);
208
209 /**
210 ****************************************************************************************
211 * @brief Return channel1 value.
212 *
213 * @param[in] id: TIM Channel ID.
214 *
215 * @return Current value when channel1 captured.
216 ****************************************************************************************
217 */
218 uint32_t app_tim_get_channel1_val(app_tim_id_t id);
219
220 /**
221 ****************************************************************************************
222 * @brief Return channel2 value.
223 *
224 * @param[in] id: TIM Channel ID.
225 *
226 * @return Current value when channel2 captured.
227 ****************************************************************************************
228 */
229 uint32_t app_tim_get_channel2_val(app_tim_id_t id);
230
231 /**
232 ****************************************************************************************
233 * @brief Return channel3 value.
234 *
235 * @param[in] id: TIM Channel ID.
236 *
237 * @return Current value when channel3 captured.
238 ****************************************************************************************
239 */
240 uint32_t app_tim_get_channel3_val(app_tim_id_t id);
241 #endif
242
243 /** @} */
244
245 #endif
246
247 #ifdef __cplusplus
248 }
249 #endif
250
251 #endif
252
253 /** @} */
254 /** @} */
255 /** @} */
256
APP_TIM_INVALID
@ APP_TIM_INVALID
Definition: app_tim.h:106
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:118
app_tim_stop
uint16_t app_tim_stop(app_tim_id_t id)
Stops the TIM counter in interrupt mode.
app_tim_params_t::tim_env
tim_env_t tim_env
Definition: app_tim.h:130
app_tim_params_t::init
timer_init_t init
Definition: app_tim.h:129
app_tim_params_t::id
app_tim_id_t id
Definition: app_tim.h:128
tim_env_t::handle
timer_handle_t handle
Definition: app_tim.h:119
_timer_init
TIMER init Structure definition.
Definition: gr55xx_hal_tim.h:98
APP_TIM_ID_1
@ APP_TIM_ID_1
Definition: app_tim.h:74
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:120
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:127
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_ACTIVITY
@ APP_TIM_ACTIVITY
Definition: app_tim.h:107
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: gr55xx_hal_tim.h:113
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:101
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:117
app_tim_state_t
app_tim_state_t
App tim state types.
Definition: app_tim.h:105
APP_TIM_EVT_DONE
@ APP_TIM_EVT_DONE
Definition: app_tim.h:84