cnm_timer.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/include/mgmt/cnm_timer.h#1
  3. */
  4. /*! \file cnm_timer.h
  5. \brief Declaration of timer obj and related timer macro for setup time out
  6. event.
  7. In this file we declare the timer object and provide several macro for
  8. Protocol functional blocks to setup their own time out event.
  9. */
  10. /*
  11. ** Log: cnm_timer.h
  12. **
  13. ** 05 24 2013 cm.chang
  14. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  15. ** Refine macro of SYSTIME_TO_USEC()
  16. **
  17. ** 09 17 2012 cm.chang
  18. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  19. ** Duplicate source from MT6620 v2.3 driver branch
  20. ** (Davinci label: MT6620_WIFI_Driver_V2_3_120913_1942_As_MT6630_Base)
  21. *
  22. * 12 13 2011 cm.chang
  23. * [WCXRP00001136] [All Wi-Fi][Driver] Add wake lock for pending timer
  24. * Add wake lock if timer timeout value is smaller than 5 seconds
  25. *
  26. * 09 03 2010 kevin.huang
  27. * NULL
  28. * Refine #include sequence and solve recursive/nested #include issue
  29. *
  30. * 07 08 2010 cp.wu
  31. *
  32. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  33. *
  34. * 06 08 2010 cp.wu
  35. * [WPD00003833][MT6620 and MT5931] Driver migration
  36. * cnm_timer has been migrated.
  37. *
  38. * 06 08 2010 cp.wu
  39. * [WPD00003833][MT6620 and MT5931] Driver migration
  40. * add hem_mbox.c and cnm_mem.h (but disabled some feature) for further migration
  41. *
  42. * 06 07 2010 cp.wu
  43. * [WPD00003833][MT6620 and MT5931] Driver migration
  44. * merge cnm_scan.h and hem_mbox.h
  45. *
  46. * 06 07 2010 cp.wu
  47. * [WPD00003833][MT6620 and MT5931] Driver migration
  48. * merge wifi_var.h, precomp.h, cnm_timer.h (data type only)
  49. *
  50. * 06 04 2010 george.huang
  51. * [BORA00000678][MT6620]WiFi LP integration
  52. * [PM] Support U-APSD for STA mode
  53. *
  54. * 04 24 2010 cm.chang
  55. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  56. * Return timer token back to COS when entering wait off state
  57. *
  58. * 01 08 2010 cm.chang
  59. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  60. * Support longer timeout interval to 45 days from 65secu1rwduu`wvpghlqg|fh+fmdkb
  61. *
  62. * 01 06 2010 cm.chang
  63. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  64. * Fix system time is 32KHz instead of 1ms
  65. *
  66. * Nov 23 2009 mtk01088
  67. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  68. * add the copy time function
  69. *
  70. * Nov 5 2009 mtk01461
  71. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  72. * Fix LINT warnning
  73. *
  74. * Oct 28 2009 mtk01104
  75. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  76. *
  77. **
  78. */
  79. #ifndef _CNM_TIMER_H
  80. #define _CNM_TIMER_H
  81. /*******************************************************************************
  82. * C O M P I L E R F L A G S
  83. ********************************************************************************
  84. */
  85. /*******************************************************************************
  86. * E X T E R N A L R E F E R E N C E S
  87. ********************************************************************************
  88. */
  89. /*******************************************************************************
  90. * C O N S T A N T S
  91. ********************************************************************************
  92. */
  93. #undef MSEC_PER_SEC
  94. #define MSEC_PER_SEC 1000
  95. #undef USEC_PER_MSEC
  96. #define USEC_PER_MSEC 1000
  97. #undef USEC_PER_SEC
  98. #define USEC_PER_SEC 1000000
  99. #define USEC_PER_TU 1024 /* microsecond */
  100. #define MSEC_PER_MIN (60 * MSEC_PER_SEC)
  101. #define MGMT_MAX_TIMEOUT_INTERVAL ((UINT_32)0x7fffffff)
  102. #define WAKE_LOCK_MAX_TIME 5 /* Unit: sec */
  103. #define OBSS_SCAN_MIN_INTERVAL 10 /* In unit of sec */
  104. /* If WAKE_LOCK_MAX_TIME is too large, the whole system may always keep awake
  105. * because of periodic timer of OBSS scanning
  106. */
  107. #if (WAKE_LOCK_MAX_TIME >= OBSS_SCAN_MIN_INTERVAL)
  108. #error WAKE_LOCK_MAX_TIME is too large
  109. #endif
  110. /*******************************************************************************
  111. * D A T A T Y P E S
  112. ********************************************************************************
  113. */
  114. typedef VOID(*PFN_MGMT_TIMEOUT_FUNC) (P_ADAPTER_T, ULONG);
  115. typedef struct _TIMER_T {
  116. LINK_ENTRY_T rLinkEntry;
  117. OS_SYSTIME rExpiredSysTime;
  118. UINT_16 u2Minutes;
  119. UINT_16 u2Reserved;
  120. ULONG ulDataPtr;
  121. PFN_MGMT_TIMEOUT_FUNC pfMgmtTimeOutFunc;
  122. } TIMER_T, *P_TIMER_T;
  123. /*******************************************************************************
  124. * P U B L I C D A T A
  125. ********************************************************************************
  126. */
  127. /*******************************************************************************
  128. * P R I V A T E D A T A
  129. ********************************************************************************
  130. */
  131. /*******************************************************************************
  132. * M A C R O S
  133. ********************************************************************************
  134. */
  135. /* Check if time "a" is before time "b" */
  136. /* In 32-bit variable, 0x00000001~0x7fffffff -> positive number,
  137. * 0x80000000~0xffffffff -> negative number
  138. */
  139. #define TIME_BEFORE_64bit(a, b) (a < b)
  140. #define TIME_BEFORE(a, b) ((UINT_32)((UINT_32)(a) - (UINT_32)(b)) > 0x7fffffff)
  141. /* #define TIME_BEFORE(a,b) ((INT_32)((INT_32)(b) - (INT_32)(a)) > 0)
  142. * may cause UNexpect result between Free build and Check build for WinCE
  143. */
  144. #define TIME_AFTER(a, b) TIME_BEFORE(b, a)
  145. #define SYSTIME_TO_SEC(_systime) ((_systime) / KAL_HZ)
  146. #define SEC_TO_SYSTIME(_sec) ((_sec) * KAL_HZ)
  147. /* The macros to convert second & millisecond */
  148. #define MSEC_TO_SEC(_msec) ((_msec) / MSEC_PER_SEC)
  149. #define SEC_TO_MSEC(_sec) ((UINT_32)(_sec) * MSEC_PER_SEC)
  150. /* The macros to convert millisecond & microsecond */
  151. #define USEC_TO_MSEC(_usec) ((_usec) / USEC_PER_MSEC)
  152. #define MSEC_TO_USEC(_msec) ((UINT_32)(_msec) * USEC_PER_MSEC)
  153. /* The macros to convert TU & microsecond, TU & millisecond */
  154. #define TU_TO_USEC(_tu) ((_tu) * USEC_PER_TU)
  155. #define TU_TO_MSEC(_tu) USEC_TO_MSEC(TU_TO_USEC(_tu))
  156. /* The macros to convert TU & & OS system time, round up by 0.5 */
  157. #define TU_TO_SYSTIME(_tu) MSEC_TO_SYSTIME(TU_TO_MSEC(_tu))
  158. #define SYSTIME_TO_TU(_systime) \
  159. ((SYSTIME_TO_USEC(_systime) + ((USEC_PER_TU / 2) - 1)) / USEC_PER_TU)
  160. /* The macros to convert OS system time & microsecond */
  161. #define SYSTIME_TO_USEC(_systime) (((_systime) * USEC_PER_SEC) / KAL_HZ)
  162. /* The macro to get the current OS system time */
  163. #define GET_CURRENT_SYSTIME(_systime_p) {*(_systime_p) = kalGetTimeTick(); }
  164. /* The macro to copy the system time */
  165. #define COPY_SYSTIME(_destTime, _srcTime) {(_destTime) = (_srcTime); }
  166. /* The macro to get the system time difference between t1 and t2 (t1 - t2) */
  167. /* #define GET_SYSTIME_DIFFERENCE(_time1, _time2, _diffTime) \
  168. (_diffTime) = (_time1) - (_time2) */
  169. /* The macro to check for the expiration, if TRUE means _currentTime >= _expirationTime */
  170. #define CHECK_FOR_EXPIRATION(_currentTime, _expirationTime) \
  171. (((UINT_32)(_currentTime) - (UINT_32)(_expirationTime)) <= 0x7fffffffUL)
  172. /* The macro to check for the timeout */
  173. #define CHECK_FOR_TIMEOUT(_currentTime, _timeoutStartingTime, _timeout) \
  174. CHECK_FOR_EXPIRATION((_currentTime), ((_timeoutStartingTime) + (_timeout)))
  175. /* The macro to set the expiration time with a specified timeout *//* Watch out for round up. */
  176. #define SET_EXPIRATION_TIME(_expirationTime, _timeout) \
  177. { \
  178. GET_CURRENT_SYSTIME(&(_expirationTime)); \
  179. (_expirationTime) += (OS_SYSTIME)(_timeout); \
  180. }
  181. #define timerRenewTimer(adapter, tmr, interval) \
  182. timerStartTimer(adapter, tmr, interval, (tmr)->function, (tmr)->data)
  183. #define MGMT_INIT_TIMER(_adapter_p, _timer, _callbackFunc) \
  184. timerInitTimer(_adapter_p, &(_timer), (UINT_32)(_callbackFunc))
  185. /*******************************************************************************
  186. * F U N C T I O N D E C L A R A T I O N S
  187. ********************************************************************************
  188. */
  189. VOID cnmTimerInitialize(IN P_ADAPTER_T prAdapter);
  190. VOID cnmTimerDestroy(IN P_ADAPTER_T prAdapter);
  191. VOID
  192. cnmTimerInitTimer(IN P_ADAPTER_T prAdapter, IN P_TIMER_T prTimer, IN PFN_MGMT_TIMEOUT_FUNC pfFunc, IN ULONG ulDataPtr);
  193. VOID cnmTimerStopTimer(IN P_ADAPTER_T prAdapter, IN P_TIMER_T prTimer);
  194. VOID cnmTimerStartTimer(IN P_ADAPTER_T prAdapter, IN P_TIMER_T prTimer, IN UINT_32 u4TimeoutMs);
  195. VOID cnmTimerDoTimeOutCheck(IN P_ADAPTER_T prAdapter);
  196. /*******************************************************************************
  197. * F U N C T I O N S
  198. ********************************************************************************
  199. */
  200. static __KAL_INLINE__ INT_32 timerPendingTimer(IN P_TIMER_T prTimer)
  201. {
  202. ASSERT(prTimer);
  203. return prTimer->rLinkEntry.prNext != NULL;
  204. }
  205. #endif /* _CNM_TIMER_H */