cnm_timer.h 8.5 KB

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