2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_2/include/mgmt/cnm_timer.h#1 $
6 \brief Declaration of timer obj and related timer macro for setup time out
9 In this file we declare the timer object and provide several macro for
10 Protocol functional blocks to setup their own time out event.
13 /*******************************************************************************
14 * Copyright (c) 2009 MediaTek Inc.
16 * All rights reserved. Copying, compilation, modification, distribution
17 * or any other use whatsoever of this material is strictly prohibited
18 * except in accordance with a Software License Agreement with
20 ********************************************************************************
23 /*******************************************************************************
26 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
27 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
28 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
29 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
30 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
31 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
32 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
33 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
34 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
35 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
36 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
37 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
38 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
40 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
41 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
42 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
43 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
44 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
46 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
47 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
48 * OF LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
49 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
50 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
52 ********************************************************************************
56 ** $Log: cnm_timer.h $
59 * [WCXRP00001136] [All Wi-Fi][Driver] Add wake lock for pending timer
60 * Add wake lock if timer timeout value is smaller than 5 seconds
63 * [WCXRP00000577] [MT6620 Wi-Fi][Driver][FW] Create V2.0 branch for firmware and driver
64 * create V2.0 driver release based on label "MT6620_WIFI_DRIVER_V2_0_110318_1600" from main trunk
66 * 09 03 2010 kevin.huang
68 * Refine #include sequence and solve recursive/nested #include issue
72 * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
75 * [WPD00003833][MT6620 and MT5931] Driver migration
76 * cnm_timer has been migrated.
79 * [WPD00003833][MT6620 and MT5931] Driver migration
80 * add hem_mbox.c and cnm_mem.h (but disabled some feature) for further migration
83 * [WPD00003833][MT6620 and MT5931] Driver migration
84 * merge cnm_scan.h and hem_mbox.h
87 * [WPD00003833][MT6620 and MT5931] Driver migration
88 * merge wifi_var.h, precomp.h, cnm_timer.h (data type only)
90 * 06 04 2010 george.huang
91 * [BORA00000678][MT6620]WiFi LP integration
92 * [PM] Support U-APSD for STA mode
95 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
96 * Return timer token back to COS when entering wait off state
99 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
100 * Support longer timeout interval to 45 days from 65secu1rwduu`wvpghlqg|fh+fmdkb
102 * 01 06 2010 cm.chang
103 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
104 * Fix system time is 32KHz instead of 1ms
106 * Nov 23 2009 mtk01088
107 * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
108 * add the copy time function
110 * Nov 5 2009 mtk01461
111 * [BORA00000018] Integrate WIFI part into BORA for the 1st time
114 * Oct 28 2009 mtk01104
115 * [BORA00000018] Integrate WIFI part into BORA for the 1st time
123 /*******************************************************************************
124 * C O M P I L E R F L A G S
125 ********************************************************************************
128 /*******************************************************************************
129 * E X T E R N A L R E F E R E N C E S
130 ********************************************************************************
133 /*******************************************************************************
135 ********************************************************************************
138 #define MSEC_PER_SEC 1000
140 #define USEC_PER_MSEC 1000
141 #define USEC_PER_TU 1024 /* microsecond */
143 #define MSEC_PER_MIN (60 * MSEC_PER_SEC)
146 #define MGMT_MAX_TIMEOUT_INTERVAL ((UINT_32)0x7fffffff)
148 #define WAKE_LOCK_MAX_TIME 5 /* Unit: sec */
150 /* If WAKE_LOCK_MAX_TIME is too large, the whole system may always keep awake
151 * because of periodic timer of OBSS scanning
153 #if (WAKE_LOCK_MAX_TIME >= OBSS_SCAN_MIN_INTERVAL)
154 #error WAKE_LOCK_MAX_TIME is too large
157 /*******************************************************************************
159 ********************************************************************************
161 typedef VOID (*PFN_MGMT_TIMEOUT_FUNC)(P_ADAPTER_T, UINT_32);
163 typedef struct _TIMER_T {
164 LINK_ENTRY_T rLinkEntry;
165 OS_SYSTIME rExpiredSysTime;
169 PFN_MGMT_TIMEOUT_FUNC pfMgmtTimeOutFunc;
170 } TIMER_T, *P_TIMER_T;
172 /*******************************************************************************
173 * P U B L I C D A T A
174 ********************************************************************************
177 /*******************************************************************************
178 * P R I V A T E D A T A
179 ********************************************************************************
182 /*******************************************************************************
184 ********************************************************************************
186 /* Check if time "a" is before time "b" */
187 /* In 32-bit variable, 0x00000001~0x7fffffff -> positive number,
188 * 0x80000000~0xffffffff -> negative number
190 #define TIME_BEFORE_64bit(a,b) (a < b)
192 #define TIME_BEFORE(a,b) ((UINT_32)((UINT_32)(a) - (UINT_32)(b)) > 0x7fffffff)
194 /* #define TIME_BEFORE(a,b) ((INT_32)((INT_32)(b) - (INT_32)(a)) > 0)
195 * may cause UNexpect result between Free build and Check build for WinCE
198 #define TIME_AFTER(a,b) TIME_BEFORE(b,a)
200 #define SYSTIME_TO_SEC(_systime) ((_systime) / KAL_HZ)
201 #define SEC_TO_SYSTIME(_sec) ((_sec) * KAL_HZ)
204 /* The macros to convert second & millisecond */
205 #define MSEC_TO_SEC(_msec) ((_msec) / MSEC_PER_SEC)
206 #define SEC_TO_MSEC(_sec) ((UINT_32)(_sec) * MSEC_PER_SEC)
209 /* The macros to convert millisecond & microsecond */
210 #define USEC_TO_MSEC(_usec) ((_usec) / USEC_PER_MSEC)
211 #define MSEC_TO_USEC(_msec) ((UINT_32)(_msec) * USEC_PER_MSEC)
214 /* The macros to convert TU & microsecond, TU & millisecond */
215 #define TU_TO_USEC(_tu) ((_tu) * USEC_PER_TU)
216 #define TU_TO_MSEC(_tu) USEC_TO_MSEC( TU_TO_USEC(_tu) )
219 /* The macros to convert TU & & OS system time, round up by 0.5 */
220 #define TU_TO_SYSTIME(_tu) MSEC_TO_SYSTIME( TU_TO_MSEC(_tu) )
221 #define SYSTIME_TO_TU(_systime) \
222 ((SYSTIME_TO_USEC(_systime) + ((USEC_PER_TU / 2) - 1)) / USEC_PER_TU)
225 /* The macros to convert OS system time & microsecond */
226 #define SYSTIME_TO_USEC(_systime) (SYSTIME_TO_MSEC(_systime) * USEC_PER_MSEC)
229 /* The macro to get the current OS system time */
230 #define GET_CURRENT_SYSTIME(_systime_p) {*(_systime_p) = kalGetTimeTick();}
232 /* The macro to copy the system time */
233 #define COPY_SYSTIME(_destTime, _srcTime) (_destTime) = (_srcTime)
235 /* The macro to get the system time difference between t1 and t2 (t1 - t2) */
236 /* #define GET_SYSTIME_DIFFERENCE(_time1, _time2, _diffTime) \
237 (_diffTime) = (_time1) - (_time2) */
239 /* The macro to check for the expiration, if TRUE means _currentTime >= _expirationTime */
240 #define CHECK_FOR_EXPIRATION(_currentTime, _expirationTime) \
241 ( ((UINT_32)(_currentTime) - (UINT_32)(_expirationTime)) <= 0x7fffffffUL)
243 /* The macro to check for the timeout */
244 #define CHECK_FOR_TIMEOUT(_currentTime, _timeoutStartingTime, _timeout) \
245 CHECK_FOR_EXPIRATION((_currentTime), ((_timeoutStartingTime) + (_timeout)))
247 /* The macro to set the expiration time with a specified timeout *//* Watch out for round up.*/
248 #define SET_EXPIRATION_TIME(_expirationTime, _timeout) \
250 GET_CURRENT_SYSTIME(&(_expirationTime)); \
251 (_expirationTime) += (OS_SYSTIME)(_timeout); \
254 #define timerRenewTimer(adapter,tmr,interval) \
255 timerStartTimer(adapter,tmr,interval,(tmr)->function,(tmr)->data)
257 #define MGMT_INIT_TIMER(_adapter_p, _timer, _callbackFunc) \
258 timerInitTimer(_adapter_p, &(_timer), (UINT_32)(_callbackFunc))
261 /*******************************************************************************
262 * F U N C T I O N D E C L A R A T I O N S
263 ********************************************************************************
267 IN P_ADAPTER_T prAdapter
272 IN P_ADAPTER_T prAdapter
277 IN P_ADAPTER_T prAdapter,
278 IN P_TIMER_T prTimer,
279 IN PFN_MGMT_TIMEOUT_FUNC pfFunc,
285 IN P_ADAPTER_T prAdapter,
291 IN P_ADAPTER_T prAdapter,
292 IN P_TIMER_T prTimer,
293 IN UINT_32 u4TimeoutMs
297 cnmTimerDoTimeOutCheck (
298 IN P_ADAPTER_T prAdapter
301 /*******************************************************************************
303 ********************************************************************************
313 return prTimer->rLinkEntry.prNext != NULL;
316 #endif /* _CNM_TIMER_H */