IxTimerCtrl.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /**
  2. * @file IxTimerCtrl.h
  3. * @brief
  4. * This is the header file for the Timer Control component.
  5. *
  6. * The timer callback control component provides a mechanism by which different
  7. * client components can start a timer and have a supplied callback function
  8. * invoked when the timer expires.
  9. * The callbacks are all dispatched from one thread inside this component.
  10. * Any component that needs to be called periodically should use this facility
  11. * rather than create its own task with a sleep loop.
  12. *
  13. * @par
  14. *
  15. * @par
  16. * IXP400 SW Release version 2.0
  17. *
  18. * -- Copyright Notice --
  19. *
  20. * @par
  21. * Copyright 2001-2005, Intel Corporation.
  22. * All rights reserved.
  23. *
  24. * @par
  25. * Redistribution and use in source and binary forms, with or without
  26. * modification, are permitted provided that the following conditions
  27. * are met:
  28. * 1. Redistributions of source code must retain the above copyright
  29. * notice, this list of conditions and the following disclaimer.
  30. * 2. Redistributions in binary form must reproduce the above copyright
  31. * notice, this list of conditions and the following disclaimer in the
  32. * documentation and/or other materials provided with the distribution.
  33. * 3. Neither the name of the Intel Corporation nor the names of its contributors
  34. * may be used to endorse or promote products derived from this software
  35. * without specific prior written permission.
  36. *
  37. * @par
  38. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  39. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  40. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  41. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  42. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  43. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  44. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  45. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  46. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  47. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  48. * SUCH DAMAGE.
  49. *
  50. * @par
  51. * -- End of Copyright Notice --
  52. */
  53. /**
  54. * @defgroup IxTimerCtrl IXP400 Timer Control (IxTimerCtrl) API
  55. *
  56. * @brief The public API for the IXP400 Timer Control Component.
  57. *
  58. * @{
  59. */
  60. #ifndef IxTimerCtrl_H
  61. #define IxTimerCtrl_H
  62. #include "IxTypes.h"
  63. /* #include "Ossl.h" */
  64. /*
  65. * #defines and macros used in this file.
  66. */
  67. /**
  68. * @ingroup IxTimerCtrl
  69. *
  70. * @def IX_TIMERCTRL_NO_FREE_TIMERS
  71. *
  72. * @brief Timer schedule return code.
  73. *
  74. * Indicates that the request to start a timer failed because
  75. * all available timer resources are used.
  76. */
  77. #define IX_TIMERCTRL_NO_FREE_TIMERS 2
  78. /**
  79. * @ingroup IxTimerCtrl
  80. *
  81. * @def IX_TIMERCTRL_PARAM_ERROR
  82. *
  83. * @brief Timer schedule return code.
  84. *
  85. * Indicates that the request to start a timer failed because
  86. * the client has supplied invalid parameters.
  87. */
  88. #define IX_TIMERCTRL_PARAM_ERROR 3
  89. /*
  90. * Typedefs whose scope is limited to this file.
  91. */
  92. /**
  93. * @ingroup IxTimerCtrl
  94. *
  95. * @brief A typedef for a pointer to a timer callback function.
  96. * @para void * - This parameter is supplied by the client when the
  97. * timer is started and passed back to the client in the callback.
  98. * @note in general timer callback functions should not block or
  99. * take longer than 100ms. This constraint is required to ensure that
  100. * higher priority callbacks are not held up.
  101. * All callbacks are called from the same thread.
  102. * This thread is a shared resource.
  103. * The parameter passed is provided when the timer is scheduled.
  104. */
  105. typedef void (*IxTimerCtrlTimerCallback)(void *userParam);
  106. /**
  107. * @ingroup IxTimerCtrl
  108. *
  109. * @brief List used to identify the users of timers.
  110. * @note The order in this list indicates priority. Components appearing
  111. * higher in the list will be given priority over components lower in the
  112. * list. When adding components, please insert at an appropriate position
  113. * for priority ( i.e values should be less than IxTimerCtrlMaxPurpose ) .
  114. */
  115. typedef enum
  116. {
  117. IxTimerCtrlAdslPurpose,
  118. /* Insert new purposes above this line only
  119. */
  120. IxTimerCtrlMaxPurpose
  121. }
  122. IxTimerCtrlPurpose;
  123. /*
  124. * Function definition
  125. */
  126. /**
  127. * @ingroup IxTimerCtrl
  128. *
  129. * @fn ixTimerCtrlSchedule(IxTimerCtrlTimerCallback func,
  130. void *userParam,
  131. IxTimerCtrlPurpose purpose,
  132. UINT32 relativeTime,
  133. unsigned *timerId )
  134. *
  135. * @brief Schedules a callback function to be called after a period of "time".
  136. * The callback function should not block or run for more than 100ms.
  137. * This function
  138. *
  139. * @param func @ref IxTimerCtrlTimerCallback [in] - the callback function to be called.
  140. * @param userParam void [in] - a parameter to send to the callback function, can be NULL.
  141. * @param purpose @ref IxTimerCtrlPurpose [in] - the purpose of the callback, internally this component will
  142. * decide the priority of callbacks with different purpose.
  143. * @param relativeTime UINT32 [in] - time relative to now in milliseconds after which the callback
  144. * will be called. The time must be greater than the duration of one OS tick.
  145. * @param *timerId unsigned [out] - An id for the callback scheduled.
  146. * This id can be used to cancel the callback.
  147. * @return
  148. * @li IX_SUCCESS - The timer was started successfully.
  149. * @li IX_TIMERCTRL_NO_FREE_TIMERS - The timer was not started because the maximum number
  150. * of running timers has been exceeded.
  151. * @li IX_TIMERCTRL_PARAM_ERROR - The timer was not started because the client has supplied
  152. * a NULL callback func, or the requested timeout is less than one OS tick.
  153. * @note This function is re-entrant. The function accesses a list of running timers
  154. * and may suspend the calling thread if this list is being accesed by another thread.
  155. */
  156. PUBLIC IX_STATUS
  157. ixTimerCtrlSchedule(IxTimerCtrlTimerCallback func,
  158. void *userParam,
  159. IxTimerCtrlPurpose purpose,
  160. UINT32 relativeTime,
  161. unsigned *timerId );
  162. /**
  163. * @ingroup IxTimerCtrl
  164. *
  165. * @fn ixTimerCtrlScheduleRepeating(IxTimerCtrlTimerCallback func,
  166. void *param,
  167. IxTimerCtrlPurpose purpose,
  168. UINT32 interval,
  169. unsigned *timerId )
  170. *
  171. * @brief Schedules a callback function to be called after a period of "time".
  172. * The callback function should not block or run for more than 100ms.
  173. *
  174. * @param func @ref IxTimerCtrlTimerCallback [in] - the callback function to be called.
  175. * @param userParam void [in] - a parameter to send to the callback function, can be NULL.
  176. * @param purpose @ref IxTimerCtrlPurpose [in] - the purpose of the callback, internally this component will
  177. * decide the priority of callbacks with different purpose.
  178. * @param interval UINT32 [in] - the interval in milliseconds between calls to func.
  179. * @param timerId unsigned [out] - An id for the callback scheduled.
  180. * This id can be used to cancel the callback.
  181. * @return
  182. * @li IX_SUCCESS - The timer was started successfully.
  183. * @li IX_TIMERCTRL_NO_FREE_TIMERS - The timer was not started because the maximum number
  184. * of running timers has been exceeded.
  185. * @li IX_TIMERCTRL_PARAM_ERROR - The timer was not started because the client has supplied
  186. * a NULL callback func, or the requested timeout is less than one OS tick.
  187. * @note This function is re-entrant. The function accesses a list of running timers
  188. * and may suspend the calling thread if this list is being accesed by another thread.
  189. */
  190. PUBLIC IX_STATUS
  191. ixTimerCtrlScheduleRepeating(IxTimerCtrlTimerCallback func,
  192. void *param,
  193. IxTimerCtrlPurpose purpose,
  194. UINT32 interval,
  195. unsigned *timerId );
  196. /**
  197. * @ingroup IxTimerCtrl
  198. *
  199. * @fn ixTimerCtrlCancel (unsigned id)
  200. *
  201. * @brief Cancels a scheduled callback.
  202. *
  203. * @param id unsigned [in] - the id of the callback to be cancelled.
  204. * @return
  205. * @li IX_SUCCESS - The timer was successfully stopped.
  206. * @li IX_FAIL - The id parameter did not corrrespond to any running timer..
  207. * @note This function is re-entrant. The function accesses a list of running timers
  208. * and may suspend the calling thread if this list is being accesed by another thread.
  209. */
  210. PUBLIC IX_STATUS
  211. ixTimerCtrlCancel (unsigned id);
  212. /**
  213. * @ingroup IxTimerCtrl
  214. *
  215. * @fn ixTimerCtrlInit(void)
  216. *
  217. * @brief Initialise the Timer Control Component.
  218. * @return
  219. * @li IX_SUCCESS - The timer control component initialized successfully.
  220. * @li IX_FAIL - The timer control component initialization failed,
  221. * or the component was already initialized.
  222. * @note This must be done before any other API function is called.
  223. * This function should be called once only and is not re-entrant.
  224. */
  225. PUBLIC IX_STATUS
  226. ixTimerCtrlInit(void);
  227. /**
  228. * @ingroup IxTimerCtrl
  229. *
  230. * @fn ixTimerCtrlShow( void )
  231. *
  232. * @brief Display the status of the Timer Control Component.
  233. * @return void
  234. * @note Displays a list of running timers.
  235. * This function is not re-entrant. This function does not suspend the calling thread.
  236. */
  237. PUBLIC void
  238. ixTimerCtrlShow( void );
  239. #endif /* IXTIMERCTRL_H */