Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Rajeev Kumar Sirasanagandla | 5b21a9c | 2018-01-08 17:05:11 +0530 | [diff] [blame] | 2 | * Copyright (c) 2012-2013, 2017-2018 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 | /**========================================================================= |
| 29 | |
| 30 | \file wlan_qct_pal_timer.c |
| 31 | |
| 32 | \brief Implementation trace/logging APIs PAL exports. wpt = (Wlan Pal Type) wpal = (Wlan PAL) |
| 33 | |
| 34 | Definitions for platform Windows. |
| 35 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 36 | |
| 37 | ========================================================================*/ |
| 38 | |
| 39 | #include "wlan_qct_pal_timer.h" |
| 40 | #include "wlan_qct_pal_trace.h" |
| 41 | #include "wlan_qct_os_status.h" |
| 42 | #include "vos_threads.h" |
Rajeev Kumar Sirasanagandla | 5b21a9c | 2018-01-08 17:05:11 +0530 | [diff] [blame] | 43 | #include "vos_api.h" |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 44 | |
Leo Chang | bbf86b7 | 2013-06-19 16:13:00 -0700 | [diff] [blame] | 45 | #include <linux/delay.h> |
Arif Hussain | 6c8947a | 2013-11-27 13:57:14 -0800 | [diff] [blame] | 46 | #if defined(ANI_OS_TYPE_ANDROID) |
| 47 | #include <asm/arch_timer.h> |
| 48 | #endif |
Leo Chang | bbf86b7 | 2013-06-19 16:13:00 -0700 | [diff] [blame] | 49 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 50 | /*--------------------------------------------------------------------------- |
| 51 | \brief wpalTimerCback - VOS timer callback function |
| 52 | |
| 53 | \param pUserdata - A cookie to data passed back in the callback function |
| 54 | ---------------------------------------------------------------------------*/ |
| 55 | static void wpalTimerCback( void * userData ) |
| 56 | { |
| 57 | wpt_timer *pTimer = (wpt_timer *)userData; |
| 58 | |
| 59 | if(NULL != pTimer->callback) |
| 60 | { |
| 61 | pTimer->callback(pTimer->pUserData); |
| 62 | } |
| 63 | else |
| 64 | { |
Jeff Johnson | c7c54b1 | 2013-11-17 11:49:03 -0800 | [diff] [blame] | 65 | WPAL_TRACE( eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_WARN, |
Jeff Johnson | c63b4a2 | 2017-09-19 08:30:14 -0700 | [diff] [blame] | 66 | " %s pTimer(%pK) callback after deleted", |
Jeff Johnson | c7c54b1 | 2013-11-17 11:49:03 -0800 | [diff] [blame] | 67 | __func__, pTimer ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 68 | } |
| 69 | }/*wpalTimerCback*/ |
| 70 | |
| 71 | /*--------------------------------------------------------------------------- |
| 72 | \brief wpalTimerInit - initialize a wpt_timer object |
| 73 | |
| 74 | \param pTimer - a pointer to caller allocated wpt_timer object |
| 75 | \param callback - A callback function |
| 76 | \param pUserData - A cookie to data passed back in the callback function |
| 77 | |
| 78 | \return wpt_status eWLAN_PAL_STATUS_SUCCESS - success. Fail otherwise. |
| 79 | ---------------------------------------------------------------------------*/ |
| 80 | wpt_status wpalTimerInit(wpt_timer * pTimer, wpal_timer_callback callback, void *pUserData) |
| 81 | { |
| 82 | /* Sanity Checks */ |
| 83 | if( pTimer == NULL || callback == NULL ) |
| 84 | { |
Jeff Johnson | c7c54b1 | 2013-11-17 11:49:03 -0800 | [diff] [blame] | 85 | WPAL_TRACE( eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR, |
Jeff Johnson | c63b4a2 | 2017-09-19 08:30:14 -0700 | [diff] [blame] | 86 | " %s Wrong param pTimer(%pK) callback(%pK)", |
Jeff Johnson | c7c54b1 | 2013-11-17 11:49:03 -0800 | [diff] [blame] | 87 | __func__, pTimer, callback ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 88 | return eWLAN_PAL_STATUS_E_INVAL; |
| 89 | } |
| 90 | |
| 91 | if ( vos_timer_init( &pTimer->timer.timerObj, VOS_TIMER_TYPE_SW, |
| 92 | wpalTimerCback, (void*)pTimer ) == VOS_STATUS_SUCCESS ) |
| 93 | { |
| 94 | pTimer->callback = callback; |
| 95 | pTimer->pUserData = pUserData; |
| 96 | return eWLAN_PAL_STATUS_SUCCESS; |
| 97 | } |
| 98 | |
| 99 | return eWLAN_PAL_STATUS_E_FAILURE; |
| 100 | }/*wpalTimerInit*/ |
| 101 | |
| 102 | |
| 103 | /*--------------------------------------------------------------------------- |
| 104 | \brief wpalTimerDelete - invalidate a wpt_timer object |
| 105 | |
| 106 | \param pTimer a pointer to caller allocated wpt_timer object |
| 107 | |
| 108 | \return eWLAN_PAL_STATUS_SUCCESS ?? success. Fail otherwise. |
| 109 | ---------------------------------------------------------------------------*/ |
| 110 | wpt_status wpalTimerDelete(wpt_timer *pTimer) |
| 111 | { |
| 112 | wpt_status status; |
| 113 | |
| 114 | /* Sanity Checks */ |
| 115 | if( pTimer == NULL ) |
| 116 | { |
Jeff Johnson | c7c54b1 | 2013-11-17 11:49:03 -0800 | [diff] [blame] | 117 | WPAL_TRACE( eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR, |
Jeff Johnson | c63b4a2 | 2017-09-19 08:30:14 -0700 | [diff] [blame] | 118 | " %s Wrong param pTimer(%pK)", |
Jeff Johnson | c7c54b1 | 2013-11-17 11:49:03 -0800 | [diff] [blame] | 119 | __func__, pTimer ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 120 | return eWLAN_PAL_STATUS_E_INVAL; |
| 121 | } |
| 122 | |
| 123 | status = WPAL_VOS_TO_WPAL_STATUS( vos_timer_destroy(&pTimer->timer.timerObj)); |
| 124 | |
| 125 | if( status == eWLAN_PAL_STATUS_SUCCESS ) |
| 126 | { |
| 127 | pTimer->callback = NULL; |
| 128 | pTimer->pUserData = NULL; |
| 129 | } |
| 130 | |
| 131 | return status; |
| 132 | }/*wpalTimerDelete*/ |
| 133 | |
| 134 | |
| 135 | /*--------------------------------------------------------------------------- |
| 136 | wpalTimerStart - start a wpt_timer object with a timeout value |
| 137 | |
| 138 | \param pTimer - a pointer to caller allocated wpt_timer object |
| 139 | \param timeout - timeout value of the timer. In unit of milli-seconds |
| 140 | |
| 141 | \return |
| 142 | eWLAN_PAL_STATUS_SUCCESS - success. Fail otherwise. |
| 143 | ---------------------------------------------------------------------------*/ |
| 144 | wpt_status wpalTimerStart(wpt_timer * pTimer, wpt_uint32 timeout) |
| 145 | { |
| 146 | /* Sanity Checks */ |
| 147 | if( pTimer == NULL ) |
| 148 | { |
Jeff Johnson | c7c54b1 | 2013-11-17 11:49:03 -0800 | [diff] [blame] | 149 | WPAL_TRACE( eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR, |
Jeff Johnson | c63b4a2 | 2017-09-19 08:30:14 -0700 | [diff] [blame] | 150 | " %s Wrong param pTimer(%pK)", |
Jeff Johnson | c7c54b1 | 2013-11-17 11:49:03 -0800 | [diff] [blame] | 151 | __func__, pTimer ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 152 | return eWLAN_PAL_STATUS_E_INVAL; |
| 153 | } |
| 154 | return ( WPAL_VOS_TO_WPAL_STATUS( vos_timer_start( &pTimer->timer.timerObj, |
| 155 | timeout ) ) ); |
| 156 | }/*wpalTimerStart*/ |
| 157 | |
| 158 | |
| 159 | /*--------------------------------------------------------------------------- |
| 160 | \brief wpalTimerStop - stop a wpt_timer object. Stop doesn't guarantee the |
| 161 | timer handler is not called if it is already timeout. |
| 162 | |
| 163 | \param pTimer - a pointer to caller allocated wpt_timer object |
| 164 | |
| 165 | \return |
| 166 | eWLAN_PAL_STATUS_SUCCESS - success. Fail otherwise. |
| 167 | ---------------------------------------------------------------------------*/ |
| 168 | wpt_status wpalTimerStop(wpt_timer * pTimer) |
| 169 | { |
| 170 | /* Sanity Checks */ |
| 171 | if( pTimer == NULL ) |
| 172 | { |
Jeff Johnson | c7c54b1 | 2013-11-17 11:49:03 -0800 | [diff] [blame] | 173 | WPAL_TRACE( eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR, |
Jeff Johnson | c63b4a2 | 2017-09-19 08:30:14 -0700 | [diff] [blame] | 174 | " %s Wrong param pTimer(%pK)", |
Jeff Johnson | c7c54b1 | 2013-11-17 11:49:03 -0800 | [diff] [blame] | 175 | __func__, pTimer ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 176 | return eWLAN_PAL_STATUS_E_INVAL; |
| 177 | } |
| 178 | return (WPAL_VOS_TO_WPAL_STATUS( vos_timer_stop( &pTimer->timer.timerObj ))); |
| 179 | }/*wpalTimerStop*/ |
| 180 | |
| 181 | /*--------------------------------------------------------------------------- |
Gopichand Nakkala | a5e3ede | 2012-12-21 15:28:36 -0800 | [diff] [blame] | 182 | \brief wpalTimerGetCurStatus - Get the current status of timer |
| 183 | |
| 184 | \param pTimer - a pointer to caller allocated wpt_timer object |
| 185 | |
| 186 | \return |
| 187 | VOS_TIMER_STATE |
| 188 | ---------------------------------------------------------------------------*/ |
Gopichand Nakkala | 3c5b063 | 2012-12-23 08:30:59 -0800 | [diff] [blame] | 189 | WPAL_TIMER_STATE wpalTimerGetCurStatus(wpt_timer * pTimer) |
Gopichand Nakkala | a5e3ede | 2012-12-21 15:28:36 -0800 | [diff] [blame] | 190 | { |
| 191 | /* Sanity Checks */ |
| 192 | if( pTimer == NULL ) |
| 193 | { |
Jeff Johnson | c7c54b1 | 2013-11-17 11:49:03 -0800 | [diff] [blame] | 194 | WPAL_TRACE( eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR, |
Jeff Johnson | c63b4a2 | 2017-09-19 08:30:14 -0700 | [diff] [blame] | 195 | " %s Wrong param pTimer(%pK)", |
Jeff Johnson | c7c54b1 | 2013-11-17 11:49:03 -0800 | [diff] [blame] | 196 | __func__, pTimer ); |
Gopichand Nakkala | a5e3ede | 2012-12-21 15:28:36 -0800 | [diff] [blame] | 197 | return eWLAN_PAL_STATUS_E_INVAL; |
| 198 | } |
| 199 | return vos_timer_getCurrentState( &pTimer->timer.timerObj ); |
Gopichand Nakkala | 3c5b063 | 2012-12-23 08:30:59 -0800 | [diff] [blame] | 200 | }/*wpalTimerGetCurStatus*/ |
| 201 | |
| 202 | /*--------------------------------------------------------------------------- |
| 203 | \brief wpalGetSystemTime - Get the system time in milliseconds |
| 204 | |
| 205 | \return |
| 206 | current time in milliseconds |
| 207 | ---------------------------------------------------------------------------*/ |
| 208 | wpt_uint32 wpalGetSystemTime(void) |
| 209 | { |
| 210 | return vos_timer_get_system_time(); |
| 211 | }/*wpalGetSystemTime*/ |
Gopichand Nakkala | a5e3ede | 2012-12-21 15:28:36 -0800 | [diff] [blame] | 212 | |
| 213 | /*--------------------------------------------------------------------------- |
Arif Hussain | 6c8947a | 2013-11-27 13:57:14 -0800 | [diff] [blame] | 214 | \brief wpalGetArchCounterTime - Get time from physical counter |
| 215 | |
| 216 | \return |
| 217 | MPM counter value |
| 218 | ---------------------------------------------------------------------------*/ |
| 219 | #if defined(ANI_OS_TYPE_ANDROID) |
| 220 | wpt_uint64 wpalGetArchCounterTime(void) |
| 221 | { |
Rajeev Kumar Sirasanagandla | 5b21a9c | 2018-01-08 17:05:11 +0530 | [diff] [blame] | 222 | return __vos_get_log_timestamp(); |
Arif Hussain | 6c8947a | 2013-11-27 13:57:14 -0800 | [diff] [blame] | 223 | }/*wpalGetArchCounterTime*/ |
| 224 | #else |
| 225 | wpt_uint64 wpalGetArchCounterTime(void) |
| 226 | { |
| 227 | return 0; |
| 228 | }/*wpalGetArchCounterTime*/ |
| 229 | #endif |
| 230 | |
| 231 | /*--------------------------------------------------------------------------- |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 232 | wpalSleep - sleep for a specified interval |
| 233 | Param: |
| 234 | timeout - amount of time to sleep. In unit of milli-seconds. |
| 235 | Return: |
| 236 | eWLAN_PAL_STATUS_SUCCESS - success. Fail otherwise. |
| 237 | ---------------------------------------------------------------------------*/ |
| 238 | wpt_status wpalSleep(wpt_uint32 timeout) |
| 239 | { |
| 240 | vos_sleep( timeout ); |
| 241 | return eWLAN_PAL_STATUS_SUCCESS; |
| 242 | } |
Leo Chang | bbf86b7 | 2013-06-19 16:13:00 -0700 | [diff] [blame] | 243 | |
| 244 | /*--------------------------------------------------------------------------- |
Leo Chang | f8940fd | 2013-07-12 14:00:25 -0700 | [diff] [blame] | 245 | wpalBusyWait - Thread busy wait with specified usec |
Leo Chang | bbf86b7 | 2013-06-19 16:13:00 -0700 | [diff] [blame] | 246 | Param: |
Leo Chang | f8940fd | 2013-07-12 14:00:25 -0700 | [diff] [blame] | 247 | usecDelay - amount of time to wait. In unit of micro-seconds. |
Leo Chang | bbf86b7 | 2013-06-19 16:13:00 -0700 | [diff] [blame] | 248 | Return: |
Leo Chang | f8940fd | 2013-07-12 14:00:25 -0700 | [diff] [blame] | 249 | NONE |
Leo Chang | bbf86b7 | 2013-06-19 16:13:00 -0700 | [diff] [blame] | 250 | ---------------------------------------------------------------------------*/ |
Leo Chang | f8940fd | 2013-07-12 14:00:25 -0700 | [diff] [blame] | 251 | void wpalBusyWait(wpt_uint32 usecDelay) |
Leo Chang | bbf86b7 | 2013-06-19 16:13:00 -0700 | [diff] [blame] | 252 | { |
Leo Chang | f8940fd | 2013-07-12 14:00:25 -0700 | [diff] [blame] | 253 | vos_busy_wait(usecDelay); |
| 254 | return; |
Leo Chang | bbf86b7 | 2013-06-19 16:13:00 -0700 | [diff] [blame] | 255 | } |