2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/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.
16 ** $Log: cnm_timer.h $
19 * [WCXRP00001136] [All Wi-Fi][Driver] Add wake lock for pending timer
20 * Add wake lock if timer timeout value is smaller than 5 seconds
22 * 09 03 2010 kevin.huang
24 * Refine #include sequence and solve recursive/nested #include issue
28 * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
31 * [WPD00003833][MT6620 and MT5931] Driver migration
32 * cnm_timer has been migrated.
35 * [WPD00003833][MT6620 and MT5931] Driver migration
36 * add hem_mbox.c and cnm_mem.h (but disabled some feature) for further migration
39 * [WPD00003833][MT6620 and MT5931] Driver migration
40 * merge cnm_scan.h and hem_mbox.h
43 * [WPD00003833][MT6620 and MT5931] Driver migration
44 * merge wifi_var.h, precomp.h, cnm_timer.h (data type only)
46 * 06 04 2010 george.huang
47 * [BORA00000678][MT6620]WiFi LP integration
48 * [PM] Support U-APSD for STA mode
51 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
52 * Return timer token back to COS when entering wait off state
55 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
56 * Support longer timeout interval to 45 days from 65secu1rwduu`wvpghlqg|fh+fmdkb
59 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
60 * Fix system time is 32KHz instead of 1ms
62 * Nov 23 2009 mtk01088
63 * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
64 * add the copy time function
67 * [BORA00000018] Integrate WIFI part into BORA for the 1st time
70 * Oct 28 2009 mtk01104
71 * [BORA00000018] Integrate WIFI part into BORA for the 1st time
79 /*******************************************************************************
80 * C O M P I L E R F L A G S
81 ********************************************************************************
84 /*******************************************************************************
85 * E X T E R N A L R E F E R E N C E S
86 ********************************************************************************
89 /*******************************************************************************
91 ********************************************************************************
94 #define MSEC_PER_SEC 1000
96 #define USEC_PER_MSEC 1000
97 #define USEC_PER_TU 1024 /* microsecond */
99 #define MSEC_PER_MIN (60 * MSEC_PER_SEC)
102 #define MGMT_MAX_TIMEOUT_INTERVAL ((UINT_32)0x7fffffff)
104 #define WAKE_LOCK_MAX_TIME 5 /* Unit: sec */
106 /* If WAKE_LOCK_MAX_TIME is too large, the whole system may always keep awake
107 * because of periodic timer of OBSS scanning
109 #if (WAKE_LOCK_MAX_TIME >= OBSS_SCAN_MIN_INTERVAL)
110 #error WAKE_LOCK_MAX_TIME is too large
113 /*******************************************************************************
115 ********************************************************************************
117 typedef VOID (*PFN_MGMT_TIMEOUT_FUNC)(P_ADAPTER_T, UINT_32);
119 typedef struct _TIMER_T {
120 LINK_ENTRY_T rLinkEntry;
121 OS_SYSTIME rExpiredSysTime;
125 PFN_MGMT_TIMEOUT_FUNC pfMgmtTimeOutFunc;
126 } TIMER_T, *P_TIMER_T;
128 /*******************************************************************************
129 * P U B L I C D A T A
130 ********************************************************************************
133 /*******************************************************************************
134 * P R I V A T E D A T A
135 ********************************************************************************
138 /*******************************************************************************
140 ********************************************************************************
142 /* Check if time "a" is before time "b" */
143 /* In 32-bit variable, 0x00000001~0x7fffffff -> positive number,
144 * 0x80000000~0xffffffff -> negative number
146 #define TIME_BEFORE_64bit(a,b) (a < b)
148 #define TIME_BEFORE(a,b) ((UINT_32)((UINT_32)(a) - (UINT_32)(b)) > 0x7fffffff)
150 /* #define TIME_BEFORE(a,b) ((INT_32)((INT_32)(b) - (INT_32)(a)) > 0)
151 * may cause UNexpect result between Free build and Check build for WinCE
154 #define TIME_AFTER(a,b) TIME_BEFORE(b,a)
156 #define SYSTIME_TO_SEC(_systime) ((_systime) / KAL_HZ)
157 #define SEC_TO_SYSTIME(_sec) ((_sec) * KAL_HZ)
160 /* The macros to convert second & millisecond */
161 #define MSEC_TO_SEC(_msec) ((_msec) / MSEC_PER_SEC)
162 #define SEC_TO_MSEC(_sec) ((UINT_32)(_sec) * MSEC_PER_SEC)
165 /* The macros to convert millisecond & microsecond */
166 #define USEC_TO_MSEC(_usec) ((_usec) / USEC_PER_MSEC)
167 #define MSEC_TO_USEC(_msec) ((UINT_32)(_msec) * USEC_PER_MSEC)
170 /* The macros to convert TU & microsecond, TU & millisecond */
171 #define TU_TO_USEC(_tu) ((_tu) * USEC_PER_TU)
172 #define TU_TO_MSEC(_tu) USEC_TO_MSEC( TU_TO_USEC(_tu) )
175 /* The macros to convert TU & & OS system time, round up by 0.5 */
176 #define TU_TO_SYSTIME(_tu) MSEC_TO_SYSTIME( TU_TO_MSEC(_tu) )
177 #define SYSTIME_TO_TU(_systime) \
178 ((SYSTIME_TO_USEC(_systime) + ((USEC_PER_TU / 2) - 1)) / USEC_PER_TU)
181 /* The macros to convert OS system time & microsecond */
182 #define SYSTIME_TO_USEC(_systime) (SYSTIME_TO_MSEC(_systime) * USEC_PER_MSEC)
185 /* The macro to get the current OS system time */
186 #define GET_CURRENT_SYSTIME(_systime_p) {*(_systime_p) = kalGetTimeTick();}
188 /* The macro to copy the system time */
189 #define COPY_SYSTIME(_destTime, _srcTime) (_destTime) = (_srcTime)
191 /* The macro to get the system time difference between t1 and t2 (t1 - t2) */
192 /* #define GET_SYSTIME_DIFFERENCE(_time1, _time2, _diffTime) \
193 (_diffTime) = (_time1) - (_time2) */
195 /* The macro to check for the expiration, if TRUE means _currentTime >= _expirationTime */
196 #define CHECK_FOR_EXPIRATION(_currentTime, _expirationTime) \
197 ( ((UINT_32)(_currentTime) - (UINT_32)(_expirationTime)) <= 0x7fffffffUL)
199 /* The macro to check for the timeout */
200 #define CHECK_FOR_TIMEOUT(_currentTime, _timeoutStartingTime, _timeout) \
201 CHECK_FOR_EXPIRATION((_currentTime), ((_timeoutStartingTime) + (_timeout)))
203 /* The macro to set the expiration time with a specified timeout *//* Watch out for round up.*/
204 #define SET_EXPIRATION_TIME(_expirationTime, _timeout) \
206 GET_CURRENT_SYSTIME(&(_expirationTime)); \
207 (_expirationTime) += (OS_SYSTIME)(_timeout); \
210 #define timerRenewTimer(adapter,tmr,interval) \
211 timerStartTimer(adapter,tmr,interval,(tmr)->function,(tmr)->data)
213 #define MGMT_INIT_TIMER(_adapter_p, _timer, _callbackFunc) \
214 timerInitTimer(_adapter_p, &(_timer), (UINT_32)(_callbackFunc))
217 /*******************************************************************************
218 * F U N C T I O N D E C L A R A T I O N S
219 ********************************************************************************
223 IN P_ADAPTER_T prAdapter
228 IN P_ADAPTER_T prAdapter
233 IN P_ADAPTER_T prAdapter,
234 IN P_TIMER_T prTimer,
235 IN PFN_MGMT_TIMEOUT_FUNC pfFunc,
241 IN P_ADAPTER_T prAdapter,
247 IN P_ADAPTER_T prAdapter,
248 IN P_TIMER_T prTimer,
249 IN UINT_32 u4TimeoutMs
253 cnmTimerDoTimeOutCheck (
254 IN P_ADAPTER_T prAdapter
257 /*******************************************************************************
259 ********************************************************************************
269 return prTimer->rLinkEntry.prNext != NULL;
272 #endif /* _CNM_TIMER_H */