• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  * Description: Provides Timer driver api \n
16  *
17  * History: \n
18  * 2022-11-07, Create file. \n
19  */
20 #ifndef TIMER_H
21 #define TIMER_H
22 
23 #include <stdint.h>
24 #include "errcode.h"
25 #include "hal_drv_timer.h"
26 
27 #ifdef __cplusplus
28 #if __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31 #endif /* __cplusplus */
32 
33 /**
34  * @defgroup drivers_driver_timer Timer
35  * @ingroup  drivers_driver
36  * @{
37  */
38 
39 /**
40  * @if Eng
41  * @brief  Handle of Timer.
42  * @else
43  * @brief  定时器句柄。
44  * @endif
45  */
46 typedef void *timer_handle_t;
47 
48 /**
49  * @if Eng
50  * @brief  Timer callback function.
51  * @else
52  * @brief  定时器回调函数。
53  * @endif
54  */
55 typedef void (*timer_callback_t)(uintptr_t data);
56 
57 /**
58  * @if Eng
59  * @brief  Initialize the Timer.
60  * @retval ERRCODE_SUCC   Success.
61  * @retval Other          Failure. For details, see @ref errcode_t.
62  * @else
63  * @brief  初始化定时器。
64  * @retval ERRCODE_SUCC   成功。
65  * @retval Other          失败,参考 @ref errcode_t 。
66  * @endif
67  */
68 errcode_t uapi_timer_init(void);
69 
70 /**
71  * @if Eng
72  * @brief  Adapt the Timer.
73  * @param  [in] index Index of the hardware Timer.
74  * @param  [in] int_id Interrupt ID of the hardware Timer.
75  * @param  [in] int_priority Hardware Timer interrupt priority.
76  * @retval ERRCODE_SUCC   Success.
77  * @retval Other          Failure. For details, see @ref errcode_t.
78  * @else
79  * @brief  适配定时器。
80  * @param  [in] index 硬件定时器索引。
81  * @param  [in] int_id 硬件定时器中断ID。
82  * @param  [in] int_priority 硬件定时器中断优先级。
83  * @retval ERRCODE_SUCC   成功。
84  * @retval Other          失败,参考 @ref errcode_t 。
85  * @endif
86  */
87 errcode_t uapi_timer_adapter(timer_index_t index, uint32_t int_id, uint16_t int_priority);
88 
89 /**
90  * @if Eng
91  * @brief  Deinitialize the Timer.
92  * @retval ERRCODE_SUCC   Success.
93  * @retval Other          Failure. For details, see @ref errcode_t.
94  * @else
95  * @brief  去初始化定时器。
96  * @retval ERRCODE_SUCC   成功。
97  * @retval Other          失败,参考 @ref errcode_t 。
98  * @endif
99  */
100 errcode_t uapi_timer_deinit(void);
101 
102 /**
103  * @if Eng
104  * @brief  Create a Timer.
105  * @param  [in] index Index of the hardware Timer.
106  * @param  [out] timer Timer handle that returned.
107  * @retval ERRCODE_SUCC   Success.
108  * @retval Other          Failure. For details, see @ref errcode_t.
109  * @else
110  * @brief  创建定时器。
111  * @param  [in] index 硬件定时器索引。
112  * @param  [out] timer 定时器处理返回值。
113  * @retval ERRCODE_SUCC   成功。
114  * @retval Other          失败,参考 @ref errcode_t 。
115  * @endif
116  */
117 errcode_t uapi_timer_create(timer_index_t index, timer_handle_t *timer);
118 
119 /**
120  * @if Eng
121  * @brief  Delete a Timer.
122  * @param  [in]  timer Timer handle which created by @ref uapi_timer_create.
123  * @retval ERRCODE_SUCC   Success.
124  * @retval Other          Failure. For details, see @ref errcode_t.
125  * @else
126  * @brief  删除定时器。
127  * @param  [in]  timer 被 @ref uapi_timer_create 创建的定时器。
128  * @retval ERRCODE_SUCC   成功。
129  * @retval Other          失败,参考 @ref errcode_t 。
130  * @endif
131  */
132 errcode_t uapi_timer_delete(timer_handle_t timer);
133 
134 /**
135  * @if Eng
136  * @brief  Access the maximum settable delay time of the Timer(us).
137  * @retval uint32_t  delay time(us).
138  * @else
139  * @brief  用户可以获取到timer最大可以设置的延时时间(us)。
140  * @retval uint32_t  延时时间(us)。
141  * @endif
142  */
143 uint32_t uapi_timer_get_max_us(void);
144 
145 /**
146  * @if Eng
147  * @brief  Start a Timer.
148  * @param  [in]  timer Timer handle which created by @ref uapi_timer_create.
149  * @param  [in]  time_us Timer expiration time. see @ref uapi_timer_get_max_us obtains the maximum time.
150  * @param  [in]  callback The callback function of the Timer.
151  * @param  [in]  data Input parameter of the Timer callback function.
152  * @retval ERRCODE_SUCC   Success.
153  * @retval Other          Failure. For details, see @ref errcode_t.
154  * @else
155  * @brief  启动指定的定时器。
156  * @param  [in]  timer 被 @ref uapi_timer_create 创建的定时器。
157  * @param  [in]  time_us 定时器超时时间。参考 @ref uapi_timer_get_max_us 函数获取最大时间。
158  * @param  [in]  callback 定时器回调函数。
159  * @param  [in]  data 定时器参数,用于传递给定时器回调函数。
160  * @retval ERRCODE_SUCC   成功。
161  * @retval Other          失败,参考 @ref errcode_t 。
162  * @endif
163  */
164 errcode_t uapi_timer_start(timer_handle_t timer, uint32_t time_us, timer_callback_t callback, uintptr_t data);
165 
166 /**
167  * @if Eng
168  * @brief  Stop a Timer, the callback passed in by the user will not be called.
169  * @param  [in]  timer Timer handle which created by @ref uapi_timer_create.
170  * @retval ERRCODE_SUCC   Success.
171  * @retval Other          Failure. For details, see @ref errcode_t.
172  * @else
173  * @brief  停止指定的定时器, 不会调用用户传入的callback.
174  * @param  [in]  timer 被 @ref uapi_timer_create 创建的定时器。
175  * @retval ERRCODE_SUCC   成功。
176  * @retval Other          失败,参考 @ref errcode_t 。
177  * @endif
178  */
179 errcode_t uapi_timer_stop(timer_handle_t timer);
180 
181 /**
182  * @if Eng
183  * @brief  Get current time of the low layer Timer.
184  * @param  [in]  index Index of the low layer Timer.
185  * @param  [out] current_time_us Current time (us) of the low layer Timer.
186  * @retval ERRCODE_SUCC   Success.
187  * @retval Other          Failure. For details, see @ref errcode_t.
188  * @else
189  * @brief  获取指定底层Timer定时器的当前时间。
190  * @param  [in]  index 底层Timer定时器索引。
191  * @param  [out] current_time_us 底层Timer定时器当前时间us值。
192  * @retval ERRCODE_SUCC   成功。
193  * @retval Other          失败,参考 @ref errcode_t 。
194  * @endif
195  */
196 errcode_t uapi_timer_get_current_time_us(timer_index_t index, uint32_t *current_time_us);
197 
198 #if defined(CONFIG_TIMER_SUPPORT_LPM)
199 /**
200  * @if Eng
201  * @brief  Suspend the Timer.
202  * @param  [in]  arg Argument for suspend.
203  * @retval ERRCODE_SUCC Success.
204  * @retval Other        Failure. For details, see @ref errcode_t.
205  * @else
206  * @brief  挂起Timer。
207  * @param  [in]  arg 挂起所需要的参数。
208  * @retval ERRCODE_SUCC 成功。
209  * @retval Other        失败,参考 @ref errcode_t 。
210  * @endif
211  */
212 errcode_t uapi_timer_suspend(uintptr_t val);
213 
214 /**
215  * @if Eng
216  * @brief  Resume the Timer.
217  * @param  [in]  arg Argument for resume.
218  * @retval ERRCODE_SUCC Success.
219  * @retval Other        Failure. For details, see @ref errcode_t.
220  * @else
221  * @brief  恢复Timer。
222  * @param  [in]  arg 恢复所需要的参数。
223  * @retval ERRCODE_SUCC 成功。
224  * @retval Other        失败,参考 @ref errcode_t 。
225  * @endif
226  */
227 errcode_t uapi_timer_resume(uintptr_t val);
228 #endif
229 
230 /**
231  * @}
232  */
233 
234 #ifdef __cplusplus
235 #if __cplusplus
236 }
237 #endif /* __cplusplus */
238 #endif /* __cplusplus */
239 
240 #endif