blob: 3b2107d2af2ca3ac6640309b6cd0a2f55a982924 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +05302 * Copyright (c) 2012-2013, 2017-2018 The Linux Foundation. All rights reserved.
Kiet Lam1ed83fc2014-02-19 01:15:45 -08003 *
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 Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam1ed83fc2014-02-19 01:15:45 -080021
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 Johnson295189b2012-06-20 16:38:30 -070028/**=========================================================================
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 Johnson295189b2012-06-20 16:38:30 -070036
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 Sirasanagandla5b21a9c2018-01-08 17:05:11 +053043#include "vos_api.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070044
Leo Changbbf86b72013-06-19 16:13:00 -070045#include <linux/delay.h>
Arif Hussain6c8947a2013-11-27 13:57:14 -080046#if defined(ANI_OS_TYPE_ANDROID)
47#include <asm/arch_timer.h>
48#endif
Leo Changbbf86b72013-06-19 16:13:00 -070049
Jeff Johnson295189b2012-06-20 16:38:30 -070050/*---------------------------------------------------------------------------
51 \brief wpalTimerCback - VOS timer callback function
52
53 \param pUserdata - A cookie to data passed back in the callback function
54---------------------------------------------------------------------------*/
55static 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 Johnsonc7c54b12013-11-17 11:49:03 -080065 WPAL_TRACE( eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_WARN,
Jeff Johnsonc63b4a22017-09-19 08:30:14 -070066 " %s pTimer(%pK) callback after deleted",
Jeff Johnsonc7c54b12013-11-17 11:49:03 -080067 __func__, pTimer );
Jeff Johnson295189b2012-06-20 16:38:30 -070068 }
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---------------------------------------------------------------------------*/
80wpt_status wpalTimerInit(wpt_timer * pTimer, wpal_timer_callback callback, void *pUserData)
81{
82 /* Sanity Checks */
83 if( pTimer == NULL || callback == NULL )
84 {
Jeff Johnsonc7c54b12013-11-17 11:49:03 -080085 WPAL_TRACE( eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR,
Jeff Johnsonc63b4a22017-09-19 08:30:14 -070086 " %s Wrong param pTimer(%pK) callback(%pK)",
Jeff Johnsonc7c54b12013-11-17 11:49:03 -080087 __func__, pTimer, callback );
Jeff Johnson295189b2012-06-20 16:38:30 -070088 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---------------------------------------------------------------------------*/
110wpt_status wpalTimerDelete(wpt_timer *pTimer)
111{
112 wpt_status status;
113
114 /* Sanity Checks */
115 if( pTimer == NULL )
116 {
Jeff Johnsonc7c54b12013-11-17 11:49:03 -0800117 WPAL_TRACE( eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR,
Jeff Johnsonc63b4a22017-09-19 08:30:14 -0700118 " %s Wrong param pTimer(%pK)",
Jeff Johnsonc7c54b12013-11-17 11:49:03 -0800119 __func__, pTimer );
Jeff Johnson295189b2012-06-20 16:38:30 -0700120 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---------------------------------------------------------------------------*/
144wpt_status wpalTimerStart(wpt_timer * pTimer, wpt_uint32 timeout)
145{
146 /* Sanity Checks */
147 if( pTimer == NULL )
148 {
Jeff Johnsonc7c54b12013-11-17 11:49:03 -0800149 WPAL_TRACE( eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR,
Jeff Johnsonc63b4a22017-09-19 08:30:14 -0700150 " %s Wrong param pTimer(%pK)",
Jeff Johnsonc7c54b12013-11-17 11:49:03 -0800151 __func__, pTimer );
Jeff Johnson295189b2012-06-20 16:38:30 -0700152 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---------------------------------------------------------------------------*/
168wpt_status wpalTimerStop(wpt_timer * pTimer)
169{
170 /* Sanity Checks */
171 if( pTimer == NULL )
172 {
Jeff Johnsonc7c54b12013-11-17 11:49:03 -0800173 WPAL_TRACE( eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR,
Jeff Johnsonc63b4a22017-09-19 08:30:14 -0700174 " %s Wrong param pTimer(%pK)",
Jeff Johnsonc7c54b12013-11-17 11:49:03 -0800175 __func__, pTimer );
Jeff Johnson295189b2012-06-20 16:38:30 -0700176 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 Nakkalaa5e3ede2012-12-21 15:28:36 -0800182 \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 Nakkala3c5b0632012-12-23 08:30:59 -0800189WPAL_TIMER_STATE wpalTimerGetCurStatus(wpt_timer * pTimer)
Gopichand Nakkalaa5e3ede2012-12-21 15:28:36 -0800190{
191 /* Sanity Checks */
192 if( pTimer == NULL )
193 {
Jeff Johnsonc7c54b12013-11-17 11:49:03 -0800194 WPAL_TRACE( eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR,
Jeff Johnsonc63b4a22017-09-19 08:30:14 -0700195 " %s Wrong param pTimer(%pK)",
Jeff Johnsonc7c54b12013-11-17 11:49:03 -0800196 __func__, pTimer );
Gopichand Nakkalaa5e3ede2012-12-21 15:28:36 -0800197 return eWLAN_PAL_STATUS_E_INVAL;
198 }
199 return vos_timer_getCurrentState( &pTimer->timer.timerObj );
Gopichand Nakkala3c5b0632012-12-23 08:30:59 -0800200}/*wpalTimerGetCurStatus*/
201
202/*---------------------------------------------------------------------------
203 \brief wpalGetSystemTime - Get the system time in milliseconds
204
205 \return
206 current time in milliseconds
207---------------------------------------------------------------------------*/
208wpt_uint32 wpalGetSystemTime(void)
209{
210 return vos_timer_get_system_time();
211}/*wpalGetSystemTime*/
Gopichand Nakkalaa5e3ede2012-12-21 15:28:36 -0800212
213/*---------------------------------------------------------------------------
Arif Hussain6c8947a2013-11-27 13:57:14 -0800214 \brief wpalGetArchCounterTime - Get time from physical counter
215
216 \return
217 MPM counter value
218---------------------------------------------------------------------------*/
219#if defined(ANI_OS_TYPE_ANDROID)
220wpt_uint64 wpalGetArchCounterTime(void)
221{
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +0530222 return __vos_get_log_timestamp();
Arif Hussain6c8947a2013-11-27 13:57:14 -0800223}/*wpalGetArchCounterTime*/
224#else
225wpt_uint64 wpalGetArchCounterTime(void)
226{
227 return 0;
228}/*wpalGetArchCounterTime*/
229#endif
230
231/*---------------------------------------------------------------------------
Jeff Johnson295189b2012-06-20 16:38:30 -0700232 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---------------------------------------------------------------------------*/
238wpt_status wpalSleep(wpt_uint32 timeout)
239{
240 vos_sleep( timeout );
241 return eWLAN_PAL_STATUS_SUCCESS;
242}
Leo Changbbf86b72013-06-19 16:13:00 -0700243
244/*---------------------------------------------------------------------------
Leo Changf8940fd2013-07-12 14:00:25 -0700245 wpalBusyWait - Thread busy wait with specified usec
Leo Changbbf86b72013-06-19 16:13:00 -0700246 Param:
Leo Changf8940fd2013-07-12 14:00:25 -0700247 usecDelay - amount of time to wait. In unit of micro-seconds.
Leo Changbbf86b72013-06-19 16:13:00 -0700248 Return:
Leo Changf8940fd2013-07-12 14:00:25 -0700249 NONE
Leo Changbbf86b72013-06-19 16:13:00 -0700250---------------------------------------------------------------------------*/
Leo Changf8940fd2013-07-12 14:00:25 -0700251void wpalBusyWait(wpt_uint32 usecDelay)
Leo Changbbf86b72013-06-19 16:13:00 -0700252{
Leo Changf8940fd2013-07-12 14:00:25 -0700253 vos_busy_wait(usecDelay);
254 return;
Leo Changbbf86b72013-06-19 16:13:00 -0700255}