Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Abhishek Singh | 3e50077 | 2017-07-17 10:13:43 +0530 | [diff] [blame] | 2 | * Copyright (c) 2012-2017 The Linux Foundation. All rights reserved. |
Kiet Lam | 1ed83fc | 2014-02-19 01:15:45 -0800 | [diff] [blame] | 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
Gopichand Nakkala | 92f07d8 | 2013-01-08 21:16:34 -0800 | [diff] [blame] | 20 | */ |
Kiet Lam | 1ed83fc | 2014-02-19 01:15:45 -0800 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 28 | #if !defined( __VOS_TIMER_H ) |
| 29 | #define __VOS_TIMER_H |
| 30 | |
| 31 | /**========================================================================= |
| 32 | |
| 33 | \file vos_timer.h |
| 34 | |
| 35 | \brief virtual Operating System Servies (vOS) |
| 36 | |
| 37 | Definitions for vOSS Timer services |
| 38 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 39 | |
| 40 | ========================================================================*/ |
| 41 | |
| 42 | /* $Header$ */ |
| 43 | |
| 44 | /*-------------------------------------------------------------------------- |
| 45 | Include Files |
| 46 | ------------------------------------------------------------------------*/ |
| 47 | #include <vos_types.h> |
| 48 | #include <vos_status.h> |
| 49 | #include <vos_lock.h> |
| 50 | #include <i_vos_timer.h> |
| 51 | |
| 52 | #ifdef TIMER_MANAGER |
| 53 | #include "wlan_hdd_dp_utils.h" |
| 54 | #endif |
| 55 | |
| 56 | /*-------------------------------------------------------------------------- |
| 57 | Preprocessor definitions and constants |
| 58 | ------------------------------------------------------------------------*/ |
| 59 | #define VOS_TIMER_STATE_COOKIE 0x12 |
| 60 | |
| 61 | /*-------------------------------------------------------------------------- |
| 62 | Type declarations |
| 63 | ------------------------------------------------------------------------*/ |
| 64 | /// vos Timer callback function prototype (well, actually a prototype for |
| 65 | /// a pointer to this callback function) |
| 66 | typedef v_VOID_t ( *vos_timer_callback_t )( v_PVOID_t userData ); |
| 67 | |
| 68 | typedef enum |
| 69 | { |
| 70 | /// pure software timer. No guarantee the apps processor will |
| 71 | /// awaken when these timers expire. |
| 72 | VOS_TIMER_TYPE_SW, |
| 73 | |
| 74 | /// These timers can awaken the Apps processor from power collapse |
| 75 | /// when these timers expire. |
| 76 | /// \todo I really dont like this name :-) |
| 77 | VOS_TIMER_TYPE_WAKE_APPS |
| 78 | |
| 79 | } VOS_TIMER_TYPE; |
| 80 | |
| 81 | typedef enum |
| 82 | { |
| 83 | VOS_TIMER_STATE_UNUSED = VOS_TIMER_STATE_COOKIE, |
| 84 | VOS_TIMER_STATE_STOPPED, |
| 85 | VOS_TIMER_STATE_STARTING, |
| 86 | VOS_TIMER_STATE_RUNNING, |
| 87 | } VOS_TIMER_STATE; |
| 88 | |
| 89 | #ifdef TIMER_MANAGER |
| 90 | struct vos_timer_s; |
| 91 | typedef struct timer_node_s |
| 92 | { |
| 93 | hdd_list_node_t pNode; |
| 94 | char* fileName; |
| 95 | unsigned int lineNum; |
| 96 | struct vos_timer_s *vosTimer; |
| 97 | }timer_node_t; |
| 98 | #endif |
| 99 | |
| 100 | typedef struct vos_timer_s |
| 101 | { |
| 102 | #ifdef TIMER_MANAGER |
| 103 | timer_node_t *ptimerNode; |
| 104 | #endif |
| 105 | |
| 106 | vos_timer_platform_t platformInfo; |
| 107 | vos_timer_callback_t callback; |
| 108 | v_PVOID_t userData; |
| 109 | vos_lock_t lock; |
| 110 | VOS_TIMER_TYPE type; |
| 111 | VOS_TIMER_STATE state; |
| 112 | } vos_timer_t; |
| 113 | |
| 114 | /*------------------------------------------------------------------------- |
| 115 | Function declarations and documenation |
| 116 | ------------------------------------------------------------------------*/ |
| 117 | #ifdef TIMER_MANAGER |
| 118 | void vos_timer_manager_init(void); |
| 119 | void vos_timer_exit(void); |
| 120 | #endif |
| 121 | |
| 122 | /*--------------------------------------------------------------------------- |
| 123 | |
| 124 | \brief vos_timer_getCurrentState() - Get the current state of the timer |
| 125 | |
| 126 | \param pTimer - the timer object |
| 127 | |
| 128 | \return timer state |
| 129 | |
| 130 | \sa |
| 131 | |
| 132 | ---------------------------------------------------------------------------*/ |
| 133 | VOS_TIMER_STATE vos_timer_getCurrentState( vos_timer_t *pTimer ); |
| 134 | |
| 135 | /*-------------------------------------------------------------------------- |
| 136 | |
| 137 | \brief vos_timer_init() - Initialize a vOSS timer. |
| 138 | |
| 139 | This API initializes a vOS Timer object. |
| 140 | |
| 141 | The \a vos_timer_init() initializes a vOS Timer object. A timer must be |
| 142 | initialized by calling vos_timer_initialize() before it may be used in |
| 143 | any other timer functions. |
| 144 | |
| 145 | Attempting to initialize timer that is already initialized results in |
| 146 | a failure. A destroyed timer object can be re-initialized with a call to |
| 147 | \a vos_timer_init(). The results of otherwise referencing the object |
| 148 | after it has been destroyed are undefined. |
| 149 | |
| 150 | Calls to vOSS timer functions to manipulate the timer such |
| 151 | as vos_timer_set() will fail if the timer is not initialized or has |
| 152 | been destroyed. Therefore, don't use the timer after it has been |
| 153 | destroyed until it has been re-initialized. |
| 154 | |
| 155 | All callback will be executed within the VOS main thread unless it is |
| 156 | initialized from the Tx thread flow, in which case it will be executed |
| 157 | within the tx thread flow. |
| 158 | |
| 159 | \param timer - pointer to the opaque timer object to initialize |
| 160 | |
| 161 | \param timerType - specifies the type of timer. We have two different |
| 162 | timer types. |
| 163 | <ol> |
| 164 | <li> VOS_TIMER_TYPE_SW - Pure software timer. The Apps processor |
| 165 | may not be awoken when this timer expires. |
| 166 | <li> VOS_TIMER_TYPE_WAKE_APPS - The Apps processor will be awoken |
| 167 | from power collapse when this type of timer expires. |
| 168 | </ol> |
| 169 | |
| 170 | \param callback - the callback function to be called when the timer |
| 171 | expires. |
| 172 | |
| 173 | \param userData - a user data (or context) that is returned to the |
| 174 | callback function as a parameter when the timer expires. |
| 175 | |
| 176 | \return VOS_STATUS_SUCCESS - timer was successfully initialized and |
| 177 | is ready to be used. |
| 178 | |
| 179 | VOS_STATUS_E_RESOURCES - System resources (other than memory) |
| 180 | are unavailable to initialize the timer |
| 181 | |
| 182 | VOS_STATUS_E_NOMEM - insufficient memory exists to initialize |
| 183 | the timer |
| 184 | |
| 185 | VOS_STATUS_E_BUSY - The implementation has detected an attempt |
| 186 | to initialize the object referenced by timer, a previously |
| 187 | initialized but not yet destroyed timer. |
| 188 | |
| 189 | VOS_STATUS_E_FAULT - timer is an invalid pointer. |
| 190 | \sa |
| 191 | |
| 192 | ---------------------------------------------------------------------------*/ |
| 193 | #ifdef TIMER_MANAGER |
| 194 | #define vos_timer_init(timer, timerType, callback, userdata) \ |
Abhishek Singh | 92d0a06 | 2016-02-26 14:47:41 +0530 | [diff] [blame] | 195 | vos_timer_init_debug(timer, timerType, callback, userdata, \ |
| 196 | __FILE__, __LINE__) |
| 197 | |
| 198 | VOS_STATUS vos_timer_init_debug( vos_timer_t *timer, VOS_TIMER_TYPE timerType, |
| 199 | vos_timer_callback_t callback, v_PVOID_t userData, |
| 200 | char* fileName, v_U32_t lineNum ); |
| 201 | |
| 202 | #define vos_timer_init_deferrable(timer, timerType, callback, userdata) \ |
| 203 | vos_timer_init_deferrable_debug(timer, timerType, \ |
| 204 | callback, userdata, __FILE__, __LINE__) |
| 205 | |
| 206 | VOS_STATUS vos_timer_init_deferrable_debug( vos_timer_t *timer, |
| 207 | VOS_TIMER_TYPE timerType, |
| 208 | vos_timer_callback_t callback, v_PVOID_t userData, |
| 209 | char* fileName, v_U32_t lineNum ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 210 | #else |
Abhishek Singh | 92d0a06 | 2016-02-26 14:47:41 +0530 | [diff] [blame] | 211 | VOS_STATUS vos_timer_init( vos_timer_t *timer, VOS_TIMER_TYPE timerType, |
| 212 | vos_timer_callback_t callback, v_PVOID_t userData ); |
| 213 | VOS_STATUS vos_timer_init_deferrable( vos_timer_t *timer, |
| 214 | VOS_TIMER_TYPE timerType, |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 215 | vos_timer_callback_t callback, v_PVOID_t userData ); |
| 216 | #endif |
| 217 | |
| 218 | /*--------------------------------------------------------------------------- |
| 219 | |
| 220 | \brief vos_timer_destroy() - Destroy a vOSS Timer object |
| 221 | |
| 222 | The \a vos_timer_destroy() function shall destroy the timer object. |
| 223 | After a successful return from \a vos_timer_destroy() the timer |
| 224 | object becomes, in effect, uninitialized. |
| 225 | |
| 226 | A destroyed timer object can be re-initialized by calling |
| 227 | vos_timer_init(). The results of otherwise referencing the object |
| 228 | after it has been destroyed are undefined. |
| 229 | |
| 230 | Calls to vOSS timer functions to manipulate the timer, such |
| 231 | as vos_timer_set() will fail if the lock is destroyed. Therefore, |
| 232 | don't use the timer after it has been destroyed until it has |
| 233 | been re-initialized. |
| 234 | |
| 235 | \param timer - the timer object to be destroyed. |
| 236 | |
| 237 | \return VOS_STATUS_SUCCESS - timer was successfully destroyed. |
| 238 | |
| 239 | VOS_STATUS_E_BUSY - The implementation has detected an attempt |
| 240 | to destroy the object referenced by timer while it is still |
| 241 | still referenced. The timer must be stopped before it can be |
| 242 | destroyed. |
| 243 | |
| 244 | VOS_STATUS_E_INVAL - The value specified by timer is invalid. |
| 245 | |
| 246 | VOS_STATUS_E_FAULT - timer is an invalid pointer. |
| 247 | \sa |
| 248 | |
| 249 | ---------------------------------------------------------------------------*/ |
| 250 | VOS_STATUS vos_timer_destroy( vos_timer_t *timer ); |
| 251 | |
| 252 | |
| 253 | /*-------------------------------------------------------------------------- |
| 254 | |
| 255 | \brief vos_timer_start() - Start a vOSS Timer object |
| 256 | |
| 257 | The \a vos_timer_start() function starts a timer to expire after the |
| 258 | specified interval, thus running the timer callback function when |
| 259 | the interval expires. |
| 260 | |
| 261 | A timer only runs once (a one-shot timer). To re-start the |
| 262 | timer, vos_timer_start() has to be called after the timer runs |
| 263 | or has been cancelled. |
| 264 | |
| 265 | \param timer - the timer object to be started |
| 266 | |
| 267 | \param expirationTime - expiration time for the timer (in milliseconds) |
| 268 | The expiration time cannot be less than 10 ms. |
| 269 | |
| 270 | \return VOS_STATUS_SUCCESS - timer was successfully started. |
| 271 | |
| 272 | VOS_STATUS_E_ALREADY - The implementation has detected an attempt |
| 273 | to start a timer while it is already started. The timer must |
| 274 | be stopped or expire before it can be started again. |
| 275 | |
| 276 | VOS_STATUS_E_INVAL - The value specified by timer is invalid. |
| 277 | |
| 278 | VOS_STATUS_E_FAULT - timer is an invalid pointer. |
| 279 | \sa |
| 280 | |
| 281 | -------------------------------------------------------------------------*/ |
| 282 | VOS_STATUS vos_timer_start( vos_timer_t *timer, v_U32_t expirationTime ); |
| 283 | |
| 284 | |
| 285 | /*-------------------------------------------------------------------------- |
| 286 | |
| 287 | \brief vos_timer_stop() - Stop a vOSS Timer |
| 288 | |
| 289 | The \a vos_timer_stop() function stops a timer that has been started but |
| 290 | has not expired, essentially cancelling the 'start' request. |
| 291 | |
| 292 | After a timer is stopped, it goes back to the state it was in after it |
| 293 | was created and can be started again via a call to vos_timer_start(). |
| 294 | |
| 295 | \param timer - the timer object to be stopped |
| 296 | |
| 297 | \return VOS_STATUS_SUCCESS - timer was successfully stopped. |
| 298 | |
| 299 | VOS_STATUS_E_EMPTY - The implementation has detected an attempt |
| 300 | to stop a timer that has not been started or has already |
| 301 | expired. |
| 302 | |
| 303 | VOS_STATUS_E_INVAL - The value specified by timer is invalid. |
| 304 | |
| 305 | VOS_STATUS_E_FAULT - timer is an invalid pointer. |
| 306 | \sa |
| 307 | |
| 308 | ------------------------------------------------------------------------*/ |
| 309 | VOS_STATUS vos_timer_stop( vos_timer_t *timer ); |
| 310 | |
| 311 | |
| 312 | /*-------------------------------------------------------------------------- |
| 313 | |
| 314 | \brief vos_timer_get_system_ticks() - Get the system time in 10ms ticks |
| 315 | |
| 316 | The \a vos_timer_get_system_ticks() function returns the current number |
| 317 | of timer ticks in 10msec intervals. This function is suitable timestamping |
| 318 | and calculating time intervals by calculating the difference between two |
| 319 | timestamps. |
| 320 | |
| 321 | \returns - The current system tick count (in 10msec intervals). This |
| 322 | function cannot fail. |
| 323 | |
| 324 | \sa |
| 325 | |
| 326 | ------------------------------------------------------------------------*/ |
| 327 | v_TIME_t vos_timer_get_system_ticks( v_VOID_t ); |
| 328 | |
Abhishek Singh | 3e50077 | 2017-07-17 10:13:43 +0530 | [diff] [blame] | 329 | /** |
| 330 | * vos_system_time_after() - Check if a is later than b |
| 331 | * @a: Time stamp value a |
| 332 | * @b: Time stamp value b |
| 333 | * |
| 334 | * Return: |
| 335 | * true if a is after b else false |
| 336 | */ |
| 337 | static inline bool vos_system_time_after(v_TIME_t a, v_TIME_t b) |
| 338 | { |
| 339 | return (long)(b) - (long)(a) < 0; |
| 340 | } |
| 341 | |
| 342 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 343 | |
| 344 | /*-------------------------------------------------------------------------- |
| 345 | |
| 346 | \brief vos_timer_get_system_time() - Get the system time in milliseconds |
| 347 | |
| 348 | The \a vos_timer_get_system_time() function returns the number of milliseconds |
| 349 | that have elapsed since the system was started |
| 350 | |
| 351 | \returns - The current system time in milliseconds. |
| 352 | |
| 353 | \sa |
| 354 | |
| 355 | ------------------------------------------------------------------------*/ |
| 356 | v_TIME_t vos_timer_get_system_time( v_VOID_t ); |
| 357 | |
Ganesh Kondabattini | cbfdc39 | 2015-09-11 19:12:59 +0530 | [diff] [blame] | 358 | v_BOOL_t vos_timer_is_initialized(vos_timer_t *timer); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 359 | |
Mahesh A Saptasagar | a67b86d | 2016-04-26 21:20:41 +0530 | [diff] [blame] | 360 | void vos_process_wd_timer(void); |
| 361 | void vos_wdthread_init_timer_work(void *callbackptr); |
| 362 | void vos_wdthread_flush_timer_work(void); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 363 | #endif // #if !defined __VOSS_TIMER_H |