blob: e9a76c18e0f15744023ab734f1e7cbf3f7508ddd [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala92f07d82013-01-08 21:16:34 -08002 * Copyright (c) 2012-2013, 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/*
Jeff Johnson32d95a32012-09-10 13:15:23 -070022 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070023 *
24 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
25 *
26 *
27 * Permission to use, copy, modify, and/or distribute this software for
28 * any purpose with or without fee is hereby granted, provided that the
29 * above copyright notice and this permission notice appear in all
30 * copies.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
33 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
35 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
36 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
37 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
38 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39 * PERFORMANCE OF THIS SOFTWARE.
40 */
41
42/**
43
44 \file palTimer.c
45
46 \brief Implemenation of the Platform Abstracion Layer timer functions
47
48 $Id$
49
50
51 Copyright (C) 2006 Airgo Networks, Incorporated
52
53 This file contains function implementations for the Platform Abstration Layer.
54
55 */
56
57#include <halTypes.h>
58#include <palTimer.h>
59#include <vos_timer.h>
60#ifdef FEATURE_WLAN_INTEGRATED_SOC
61#include <vos_memory.h>
62#endif
63
64typedef struct sPalTimer
65{
66 palTimerCallback timerCallback;
67 void *pContext;
68 tHddHandle hHdd; // not really needed when mapping to vos timers
69 tANI_U32 uTimerInterval; //meaningful only is fRestart is true
70 tANI_BOOLEAN fRestart;
71
72 vos_timer_t vosTimer;
73
74} tPalTimer, *tpPalTimer;
75
76
77
78v_VOID_t internalTimerCallback( v_PVOID_t userData )
79{
80 tPalTimer *pPalTimer = (tPalTimer *)userData;
81
82 if ( pPalTimer )
83 {
84 if ( pPalTimer->timerCallback )
85 {
86 pPalTimer->timerCallback( pPalTimer->pContext );
87 }
88
89 if ( pPalTimer->fRestart )
90 {
91 palTimerStart( pPalTimer->hHdd, pPalTimer, pPalTimer->uTimerInterval, eANI_BOOLEAN_TRUE );
92 }
93 }
94}
95
96#ifdef TIMER_MANAGER
97eHalStatus palTimerAlloc_debug( tHddHandle hHdd, tPalTimerHandle *phPalTimer,
98 palTimerCallback pCallback, void *pContext, char* fileName, v_U32_t lineNum )
99{
100 eHalStatus halStatus = eHAL_STATUS_FAILURE;
101 tPalTimer *pPalTimer = NULL;
102 VOS_STATUS vosStatus;
103
104 do
105 {
106 // allocate the internal timer structure.
107 pPalTimer = vos_mem_malloc( sizeof( tPalTimer ) );
108 if ( NULL == pPalTimer ) break;
109
110 // initialize the vos Timer that underlies the pal Timer.
111 vosStatus = vos_timer_init_debug( &pPalTimer->vosTimer, VOS_TIMER_TYPE_SW,
112 internalTimerCallback, pPalTimer, fileName, lineNum );
113 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
114 {
115 // if fail to init the vos timer, free the memory and bail out.
116 vos_mem_free( pPalTimer );
117 break;
118 }
119
120 // initialize the info in the internal palTimer struct so we can
121 pPalTimer->timerCallback = pCallback;
122 pPalTimer->pContext = pContext;
123 pPalTimer->hHdd = hHdd;
124
125 // return a 'handle' to the caller.
126 *phPalTimer = pPalTimer;
127
128 halStatus = eHAL_STATUS_SUCCESS;
129
130 } while( 0 );
131
132 return( halStatus );
133}
134#else
135eHalStatus palTimerAlloc( tHddHandle hHdd, tPalTimerHandle *phPalTimer,
136 palTimerCallback pCallback, void *pContext )
137{
138 eHalStatus halStatus = eHAL_STATUS_FAILURE;
139 tPalTimer *pPalTimer = NULL;
140 VOS_STATUS vosStatus;
141
142 do
143 {
144 // allocate the internal timer structure.
145 pPalTimer = vos_mem_malloc( sizeof( tPalTimer ) );
146 if ( NULL == pPalTimer ) break;
147
148 // initialize the vos Timer that underlies the pal Timer.
149 vosStatus = vos_timer_init( &pPalTimer->vosTimer, VOS_TIMER_TYPE_SW,
150 internalTimerCallback, pPalTimer );
151 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
152 {
153 // if fail to init the vos timer, free the memory and bail out.
154 vos_mem_free( pPalTimer );
155 break;
156 }
157
158 // initialize the info in the internal palTimer struct so we can
159 pPalTimer->timerCallback = pCallback;
160 pPalTimer->pContext = pContext;
161 pPalTimer->hHdd = hHdd;
162
163 // return a 'handle' to the caller.
164 *phPalTimer = pPalTimer;
165
166 halStatus = eHAL_STATUS_SUCCESS;
167
168 } while( 0 );
169
170 return( halStatus );
171}
172#endif
173
174
175eHalStatus palTimerFree( tHddHandle hHdd, tPalTimerHandle hPalTimer )
176{
177 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
178 VOS_STATUS vosStatus;
179 tPalTimer *pPalTimer = (tPalTimer *)hPalTimer;
180
181 do
182 {
183 if ( NULL == pPalTimer ) break;
184
185 // Destroy the vos timer...
186 vosStatus = vos_timer_destroy( &pPalTimer->vosTimer );
187 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) ) break;
188
189 // Free the memory for the intrnal timer struct...
190 vos_mem_free( pPalTimer );
191
192 status = eHAL_STATUS_SUCCESS;
193
194 } while( 0 );
195
196 return( status );
197}
198
199
200eHalStatus palTimerStart(tHddHandle hHdd, tPalTimerHandle hPalTimer, tANI_U32 uExpireTime, tANI_BOOLEAN fRestart)
201{
202 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
203 VOS_STATUS vosStatus;
204 tANI_U32 expireTimeInMS = 0;
205
206 tPalTimer *pPalTimer = (tPalTimer *)hPalTimer;
207
208 do
209 {
210 if ( NULL == pPalTimer ) break;
211
212 pPalTimer->fRestart = fRestart;
213 pPalTimer->uTimerInterval = uExpireTime;
214
215 // vos Timer takes expiration time in milliseconds. palTimerStart and
216 // the uTimerIntervl in tPalTimer struct have expiration tiem in
217 // microseconds. Make and adjustment from microseconds to milliseconds
218 // before calling the vos_timer_start().
219 expireTimeInMS = uExpireTime / 1000;
220 vosStatus = vos_timer_start( &pPalTimer->vosTimer, expireTimeInMS );
221 if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
222 {
223 status = eHAL_STATUS_FAILURE;
224 break;
225 }
226
227 status = eHAL_STATUS_SUCCESS;
228
229 } while( 0 );
230
231 return( status );
232}
233
234
235eHalStatus palTimerStop(tHddHandle hHdd, tPalTimerHandle hPalTimer)
236{
237 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
238
239 tPalTimer *pPalTimer = (tPalTimer *)hPalTimer;
240
241 do
242 {
243 if ( NULL == pPalTimer ) break;
244
245 vos_timer_stop( &pPalTimer->vosTimer );
246
247 // make sure the timer is not re-started.
248 pPalTimer->fRestart = eANI_BOOLEAN_FALSE;
249
250 status = eHAL_STATUS_SUCCESS;
251
252 } while( 0 );
253
254 return( status );
255}
256
257
258
259
260
261