Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Kiet Lam | aa8e15a | 2014-02-11 23:30:06 -0800 | [diff] [blame^] | 2 | * Copyright (c) 2012-2013 Qualcomm Atheros, Inc. |
| 3 | * All Rights Reserved. |
| 4 | * Qualcomm Atheros Confidential and Proprietary. |
Gopichand Nakkala | 92f07d8 | 2013-01-08 21:16:34 -0800 | [diff] [blame] | 5 | */ |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 6 | /** |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 7 | Copyright (C) 2006 Airgo Networks, Incorporated |
Jeff Johnson | 8f7d7f9 | 2013-02-22 21:46:45 -0800 | [diff] [blame] | 8 | |
| 9 | This file contains function implementations for the Platform |
| 10 | Abstration Layer. |
| 11 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <halTypes.h> |
| 15 | #include <palTimer.h> |
| 16 | #include <vos_timer.h> |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 17 | #include <vos_memory.h> |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 18 | |
Madan Mohan Koyyalamudi | 218122c | 2013-07-24 17:10:40 +0530 | [diff] [blame] | 19 | #ifndef FEATURE_WLAN_PAL_TIMER_DISABLE |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 20 | typedef struct sPalTimer |
| 21 | { |
| 22 | palTimerCallback timerCallback; |
| 23 | void *pContext; |
| 24 | tHddHandle hHdd; // not really needed when mapping to vos timers |
| 25 | tANI_U32 uTimerInterval; //meaningful only is fRestart is true |
| 26 | tANI_BOOLEAN fRestart; |
| 27 | |
| 28 | vos_timer_t vosTimer; |
| 29 | |
| 30 | } tPalTimer, *tpPalTimer; |
| 31 | |
| 32 | |
| 33 | |
| 34 | v_VOID_t internalTimerCallback( v_PVOID_t userData ) |
| 35 | { |
| 36 | tPalTimer *pPalTimer = (tPalTimer *)userData; |
| 37 | |
| 38 | if ( pPalTimer ) |
| 39 | { |
| 40 | if ( pPalTimer->timerCallback ) |
| 41 | { |
| 42 | pPalTimer->timerCallback( pPalTimer->pContext ); |
| 43 | } |
| 44 | |
| 45 | if ( pPalTimer->fRestart ) |
| 46 | { |
| 47 | palTimerStart( pPalTimer->hHdd, pPalTimer, pPalTimer->uTimerInterval, eANI_BOOLEAN_TRUE ); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | #ifdef TIMER_MANAGER |
| 53 | eHalStatus palTimerAlloc_debug( tHddHandle hHdd, tPalTimerHandle *phPalTimer, |
| 54 | palTimerCallback pCallback, void *pContext, char* fileName, v_U32_t lineNum ) |
| 55 | { |
| 56 | eHalStatus halStatus = eHAL_STATUS_FAILURE; |
| 57 | tPalTimer *pPalTimer = NULL; |
| 58 | VOS_STATUS vosStatus; |
| 59 | |
| 60 | do |
| 61 | { |
| 62 | // allocate the internal timer structure. |
| 63 | pPalTimer = vos_mem_malloc( sizeof( tPalTimer ) ); |
| 64 | if ( NULL == pPalTimer ) break; |
| 65 | |
| 66 | // initialize the vos Timer that underlies the pal Timer. |
| 67 | vosStatus = vos_timer_init_debug( &pPalTimer->vosTimer, VOS_TIMER_TYPE_SW, |
| 68 | internalTimerCallback, pPalTimer, fileName, lineNum ); |
| 69 | if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) ) |
| 70 | { |
| 71 | // if fail to init the vos timer, free the memory and bail out. |
| 72 | vos_mem_free( pPalTimer ); |
| 73 | break; |
| 74 | } |
| 75 | |
| 76 | // initialize the info in the internal palTimer struct so we can |
| 77 | pPalTimer->timerCallback = pCallback; |
| 78 | pPalTimer->pContext = pContext; |
| 79 | pPalTimer->hHdd = hHdd; |
| 80 | |
| 81 | // return a 'handle' to the caller. |
| 82 | *phPalTimer = pPalTimer; |
| 83 | |
| 84 | halStatus = eHAL_STATUS_SUCCESS; |
| 85 | |
| 86 | } while( 0 ); |
| 87 | |
| 88 | return( halStatus ); |
| 89 | } |
| 90 | #else |
| 91 | eHalStatus palTimerAlloc( tHddHandle hHdd, tPalTimerHandle *phPalTimer, |
| 92 | palTimerCallback pCallback, void *pContext ) |
| 93 | { |
| 94 | eHalStatus halStatus = eHAL_STATUS_FAILURE; |
| 95 | tPalTimer *pPalTimer = NULL; |
| 96 | VOS_STATUS vosStatus; |
| 97 | |
| 98 | do |
| 99 | { |
| 100 | // allocate the internal timer structure. |
| 101 | pPalTimer = vos_mem_malloc( sizeof( tPalTimer ) ); |
| 102 | if ( NULL == pPalTimer ) break; |
| 103 | |
| 104 | // initialize the vos Timer that underlies the pal Timer. |
| 105 | vosStatus = vos_timer_init( &pPalTimer->vosTimer, VOS_TIMER_TYPE_SW, |
| 106 | internalTimerCallback, pPalTimer ); |
| 107 | if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) ) |
| 108 | { |
| 109 | // if fail to init the vos timer, free the memory and bail out. |
| 110 | vos_mem_free( pPalTimer ); |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | // initialize the info in the internal palTimer struct so we can |
| 115 | pPalTimer->timerCallback = pCallback; |
| 116 | pPalTimer->pContext = pContext; |
| 117 | pPalTimer->hHdd = hHdd; |
| 118 | |
| 119 | // return a 'handle' to the caller. |
| 120 | *phPalTimer = pPalTimer; |
| 121 | |
| 122 | halStatus = eHAL_STATUS_SUCCESS; |
| 123 | |
| 124 | } while( 0 ); |
| 125 | |
| 126 | return( halStatus ); |
| 127 | } |
| 128 | #endif |
| 129 | |
| 130 | |
| 131 | eHalStatus palTimerFree( tHddHandle hHdd, tPalTimerHandle hPalTimer ) |
| 132 | { |
| 133 | eHalStatus status = eHAL_STATUS_INVALID_PARAMETER; |
| 134 | VOS_STATUS vosStatus; |
| 135 | tPalTimer *pPalTimer = (tPalTimer *)hPalTimer; |
| 136 | |
| 137 | do |
| 138 | { |
| 139 | if ( NULL == pPalTimer ) break; |
| 140 | |
| 141 | // Destroy the vos timer... |
| 142 | vosStatus = vos_timer_destroy( &pPalTimer->vosTimer ); |
| 143 | if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) ) break; |
| 144 | |
| 145 | // Free the memory for the intrnal timer struct... |
| 146 | vos_mem_free( pPalTimer ); |
| 147 | |
| 148 | status = eHAL_STATUS_SUCCESS; |
| 149 | |
| 150 | } while( 0 ); |
| 151 | |
| 152 | return( status ); |
| 153 | } |
| 154 | |
| 155 | |
| 156 | eHalStatus palTimerStart(tHddHandle hHdd, tPalTimerHandle hPalTimer, tANI_U32 uExpireTime, tANI_BOOLEAN fRestart) |
| 157 | { |
| 158 | eHalStatus status = eHAL_STATUS_INVALID_PARAMETER; |
| 159 | VOS_STATUS vosStatus; |
| 160 | tANI_U32 expireTimeInMS = 0; |
| 161 | |
| 162 | tPalTimer *pPalTimer = (tPalTimer *)hPalTimer; |
| 163 | |
| 164 | do |
| 165 | { |
| 166 | if ( NULL == pPalTimer ) break; |
| 167 | |
| 168 | pPalTimer->fRestart = fRestart; |
| 169 | pPalTimer->uTimerInterval = uExpireTime; |
| 170 | |
| 171 | // vos Timer takes expiration time in milliseconds. palTimerStart and |
| 172 | // the uTimerIntervl in tPalTimer struct have expiration tiem in |
| 173 | // microseconds. Make and adjustment from microseconds to milliseconds |
| 174 | // before calling the vos_timer_start(). |
| 175 | expireTimeInMS = uExpireTime / 1000; |
| 176 | vosStatus = vos_timer_start( &pPalTimer->vosTimer, expireTimeInMS ); |
| 177 | if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) ) |
| 178 | { |
| 179 | status = eHAL_STATUS_FAILURE; |
| 180 | break; |
| 181 | } |
| 182 | |
| 183 | status = eHAL_STATUS_SUCCESS; |
| 184 | |
| 185 | } while( 0 ); |
| 186 | |
| 187 | return( status ); |
| 188 | } |
| 189 | |
| 190 | |
| 191 | eHalStatus palTimerStop(tHddHandle hHdd, tPalTimerHandle hPalTimer) |
| 192 | { |
| 193 | eHalStatus status = eHAL_STATUS_INVALID_PARAMETER; |
| 194 | |
| 195 | tPalTimer *pPalTimer = (tPalTimer *)hPalTimer; |
| 196 | |
| 197 | do |
| 198 | { |
| 199 | if ( NULL == pPalTimer ) break; |
| 200 | |
| 201 | vos_timer_stop( &pPalTimer->vosTimer ); |
| 202 | |
| 203 | // make sure the timer is not re-started. |
| 204 | pPalTimer->fRestart = eANI_BOOLEAN_FALSE; |
| 205 | |
| 206 | status = eHAL_STATUS_SUCCESS; |
| 207 | |
| 208 | } while( 0 ); |
| 209 | |
| 210 | return( status ); |
| 211 | } |
| 212 | |
Madan Mohan Koyyalamudi | 218122c | 2013-07-24 17:10:40 +0530 | [diff] [blame] | 213 | #endif |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 214 | |
| 215 | |
| 216 | |
| 217 | |