Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2014-2015 The Linux Foundation. All rights reserved. |
| 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. |
| 20 | */ |
| 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 | |
| 28 | #if !defined(__CDF_MC_TIMER_H) |
| 29 | #define __CDF_MC_TIMER_H |
| 30 | |
| 31 | /** |
| 32 | * DOC: cdf_mc_timer |
| 33 | * |
| 34 | * Connectivity driver framework timer APIs serialized to MC thread |
| 35 | */ |
| 36 | |
| 37 | /* Include Files */ |
| 38 | #include <cdf_types.h> |
| 39 | #include <cdf_status.h> |
| 40 | #include <cdf_lock.h> |
| 41 | #include <i_cdf_mc_timer.h> |
| 42 | |
| 43 | #ifdef TIMER_MANAGER |
| 44 | #include <cdf_list.h> |
| 45 | #endif |
| 46 | |
| 47 | /* Preprocessor definitions and constants */ |
| 48 | #define CDF_TIMER_STATE_COOKIE (0x12) |
| 49 | #define CDF_MC_TIMER_TO_MS_UNIT (1000) |
| 50 | #define CDF_MC_TIMER_TO_SEC_UNIT (1000000) |
| 51 | |
| 52 | /* Type declarations */ |
| 53 | /* cdf Timer callback function prototype (well, actually a prototype for |
| 54 | a pointer to this callback function) */ |
| 55 | typedef void (*cdf_mc_timer_callback_t)(void *userData); |
| 56 | |
| 57 | typedef enum { |
| 58 | CDF_TIMER_STATE_UNUSED = CDF_TIMER_STATE_COOKIE, |
| 59 | CDF_TIMER_STATE_STOPPED, |
| 60 | CDF_TIMER_STATE_STARTING, |
| 61 | CDF_TIMER_STATE_RUNNING, |
| 62 | } CDF_TIMER_STATE; |
| 63 | |
| 64 | #ifdef TIMER_MANAGER |
| 65 | struct cdf_mc_timer_s; |
| 66 | typedef struct cdf_mc_timer_node_s { |
| 67 | cdf_list_node_t pNode; |
| 68 | char *fileName; |
| 69 | unsigned int lineNum; |
| 70 | struct cdf_mc_timer_s *cdf_timer; |
| 71 | } cdf_mc_timer_node_t; |
| 72 | #endif |
| 73 | |
| 74 | typedef struct cdf_mc_timer_s { |
| 75 | #ifdef TIMER_MANAGER |
| 76 | cdf_mc_timer_node_t *ptimerNode; |
| 77 | #endif |
| 78 | |
| 79 | cdf_mc_timer_platform_t platformInfo; |
| 80 | cdf_mc_timer_callback_t callback; |
| 81 | void *userData; |
| 82 | cdf_mutex_t lock; |
| 83 | CDF_TIMER_TYPE type; |
| 84 | CDF_TIMER_STATE state; |
| 85 | } cdf_mc_timer_t; |
| 86 | |
| 87 | /* Function declarations and documenation */ |
| 88 | #ifdef TIMER_MANAGER |
| 89 | void cdf_mc_timer_manager_init(void); |
| 90 | void cdf_mc_timer_exit(void); |
| 91 | #else |
| 92 | /** |
| 93 | * cdf_mc_timer_manager_init() - initialize CDF debug timer manager |
| 94 | * |
| 95 | * This API initializes CDF timer debug functionality. |
| 96 | * |
| 97 | * Return: none |
| 98 | */ |
| 99 | static inline void cdf_mc_timer_manager_init(void) |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * cdf_mc_timer_exit() - exit CDF timer debug functionality |
| 105 | * |
| 106 | * This API exists CDF timer debug functionality |
| 107 | * |
| 108 | * Return: none |
| 109 | */ |
| 110 | static inline void cdf_mc_timer_exit(void) |
| 111 | { |
| 112 | } |
| 113 | #endif |
| 114 | /** |
| 115 | * cdf_mc_timer_get_current_state() - get the current state of the timer |
| 116 | * @pTimer: Pointer to timer object |
| 117 | * |
| 118 | * Return: |
| 119 | * CDF_TIMER_STATE - cdf timer state |
| 120 | */ |
| 121 | |
| 122 | CDF_TIMER_STATE cdf_mc_timer_get_current_state(cdf_mc_timer_t *pTimer); |
| 123 | |
| 124 | /** |
| 125 | * cdf_mc_timer_init() - initialize a CDF timer |
| 126 | * @pTimer: Pointer to timer object |
| 127 | * @timerType: Type of timer |
| 128 | * @callback: Callback to be called after timer expiry |
| 129 | * @serData: User data which will be passed to callback function |
| 130 | * |
| 131 | * This API initializes a CDF Timer object. |
| 132 | * |
| 133 | * cdf_mc_timer_init() initializes a CDF Timer object. A timer must be |
| 134 | * initialized by calling cdf_mc_timer_initialize() before it may be used in |
| 135 | * any other timer functions. |
| 136 | * |
| 137 | * Attempting to initialize timer that is already initialized results in |
| 138 | * a failure. A destroyed timer object can be re-initialized with a call to |
| 139 | * cdf_mc_timer_init(). The results of otherwise referencing the object |
| 140 | * after it has been destroyed are undefined. |
| 141 | * |
| 142 | * Calls to CDF timer functions to manipulate the timer such |
| 143 | * as cdf_mc_timer_set() will fail if the timer is not initialized or has |
| 144 | * been destroyed. Therefore, don't use the timer after it has been |
| 145 | * destroyed until it has been re-initialized. |
| 146 | * |
| 147 | * All callback will be executed within the CDS main thread unless it is |
| 148 | * initialized from the Tx thread flow, in which case it will be executed |
| 149 | * within the tx thread flow. |
| 150 | * |
| 151 | * Return: |
| 152 | * CDF_STATUS_SUCCESS - Timer is initialized successfully |
| 153 | * CDF failure status - Timer initialization failed |
| 154 | */ |
| 155 | #ifdef TIMER_MANAGER |
| 156 | #define cdf_mc_timer_init(timer, timerType, callback, userdata) \ |
| 157 | cdf_mc_timer_init_debug(timer, timerType, callback, userdata, \ |
| 158 | __FILE__, __LINE__) |
| 159 | |
| 160 | CDF_STATUS cdf_mc_timer_init_debug(cdf_mc_timer_t *timer, |
| 161 | CDF_TIMER_TYPE timerType, |
| 162 | cdf_mc_timer_callback_t callback, |
| 163 | void *userData, char *fileName, |
| 164 | uint32_t lineNum); |
| 165 | #else |
| 166 | CDF_STATUS cdf_mc_timer_init(cdf_mc_timer_t *timer, CDF_TIMER_TYPE timerType, |
| 167 | cdf_mc_timer_callback_t callback, |
| 168 | void *userData); |
| 169 | #endif |
| 170 | |
| 171 | /** |
| 172 | * cdf_mc_timer_destroy() - destroy CDF timer |
| 173 | * @timer: Pointer to timer object |
| 174 | * |
| 175 | * cdf_mc_timer_destroy() function shall destroy the timer object. |
| 176 | * After a successful return from \a cdf_mc_timer_destroy() the timer |
| 177 | * object becomes, in effect, uninitialized. |
| 178 | * |
| 179 | * A destroyed timer object can be re-initialized by calling |
| 180 | * cdf_mc_timer_init(). The results of otherwise referencing the object |
| 181 | * after it has been destroyed are undefined. |
| 182 | * |
| 183 | * Calls to CDF timer functions to manipulate the timer, such |
| 184 | * as cdf_mc_timer_set() will fail if the lock is destroyed. Therefore, |
| 185 | * don't use the timer after it has been destroyed until it has |
| 186 | * been re-initialized. |
| 187 | * |
| 188 | * Return: |
| 189 | * CDF_STATUS_SUCCESS - Timer is initialized successfully |
| 190 | * CDF failure status - Timer initialization failed |
| 191 | */ |
| 192 | CDF_STATUS cdf_mc_timer_destroy(cdf_mc_timer_t *timer); |
| 193 | |
| 194 | /** |
| 195 | * cdf_mc_timer_start() - start a CDF Timer object |
| 196 | * @timer: Pointer to timer object |
| 197 | * @expirationTime: Time to expire |
| 198 | * |
| 199 | * cdf_mc_timer_start() function starts a timer to expire after the |
| 200 | * specified interval, thus running the timer callback function when |
| 201 | * the interval expires. |
| 202 | * |
| 203 | * A timer only runs once (a one-shot timer). To re-start the |
| 204 | * timer, cdf_mc_timer_start() has to be called after the timer runs |
| 205 | * or has been cancelled. |
| 206 | * |
| 207 | * Return: |
| 208 | * CDF_STATUS_SUCCESS - Timer is initialized successfully |
| 209 | * CDF failure status - Timer initialization failed |
| 210 | */ |
| 211 | CDF_STATUS cdf_mc_timer_start(cdf_mc_timer_t *timer, uint32_t expirationTime); |
| 212 | |
| 213 | /** |
| 214 | * cdf_mc_timer_stop() - stop a CDF Timer |
| 215 | * @timer: Pointer to timer object |
| 216 | * cdf_mc_timer_stop() function stops a timer that has been started but |
| 217 | * has not expired, essentially cancelling the 'start' request. |
| 218 | * |
| 219 | * After a timer is stopped, it goes back to the state it was in after it |
| 220 | * was created and can be started again via a call to cdf_mc_timer_start(). |
| 221 | * |
| 222 | * Return: |
| 223 | * CDF_STATUS_SUCCESS - Timer is initialized successfully |
| 224 | * CDF failure status - Timer initialization failed |
| 225 | */ |
| 226 | CDF_STATUS cdf_mc_timer_stop(cdf_mc_timer_t *timer); |
| 227 | |
| 228 | /** |
| 229 | * cdf_mc_timer_get_system_ticks() - get the system time in 10ms ticks |
| 230 | |
| 231 | * cdf_mc_timer_get_system_ticks() function returns the current number |
| 232 | * of timer ticks in 10msec intervals. This function is suitable timestamping |
| 233 | * and calculating time intervals by calculating the difference between two |
| 234 | * timestamps. |
| 235 | * |
| 236 | * Return: |
| 237 | * The current system tick count (in 10msec intervals). This |
| 238 | * function cannot fail. |
| 239 | */ |
| 240 | v_TIME_t cdf_mc_timer_get_system_ticks(void); |
| 241 | |
| 242 | /** |
| 243 | * cdf_mc_timer_get_system_time() - Get the system time in milliseconds |
| 244 | * |
| 245 | * cdf_mc_timer_get_system_time() function returns the number of milliseconds |
| 246 | * that have elapsed since the system was started |
| 247 | * |
| 248 | * Return: |
| 249 | * The current system time in milliseconds |
| 250 | */ |
| 251 | v_TIME_t cdf_mc_timer_get_system_time(void); |
| 252 | |
| 253 | #endif /* #if !defined __CDF_MC_TIMER_H */ |