timers.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. /*
  2. * FreeRTOS Kernel V10.5.1
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. *
  8. */
  9. #ifndef TIMERS_H
  10. #define TIMERS_H
  11. #ifndef INC_FREERTOS_H
  12. #error "include FreeRTOS.h must appear in source files before include timers.h"
  13. #endif
  14. /*lint -save -e537 This headers are only multiply included if the application code
  15. * happens to also be including task.h. */
  16. #include "task.h"
  17. /*lint -restore */
  18. /*-----------------------------------------------------------
  19. * MACROS AND DEFINITIONS
  20. *----------------------------------------------------------*/
  21. /* IDs for commands that can be sent/received on the timer queue. These are to
  22. * be used solely through the macros that make up the public software timer API,
  23. * as defined below. The commands that are sent from interrupts must use the
  24. * highest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task
  25. * or interrupt version of the queue send function should be used. */
  26. #define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 )
  27. #define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 )
  28. #define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 )
  29. #define tmrCOMMAND_START ( ( BaseType_t ) 1 )
  30. #define tmrCOMMAND_RESET ( ( BaseType_t ) 2 )
  31. #define tmrCOMMAND_STOP ( ( BaseType_t ) 3 )
  32. #define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 )
  33. #define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 )
  34. #define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 )
  35. #define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 )
  36. #define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 )
  37. #define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 )
  38. #define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 )
  39. /**
  40. * Type by which software timers are referenced. For example, a call to
  41. * xTimerCreate() returns an TimerHandle_t variable that can then be used to
  42. * reference the subject timer in calls to other software timer API functions
  43. * (for example, xTimerStart(), xTimerReset(), etc.).
  44. */
  45. struct tmrTimerControl; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
  46. typedef struct tmrTimerControl * TimerHandle_t;
  47. /*
  48. * Defines the prototype to which timer callback functions must conform.
  49. */
  50. typedef void (*TimerCallbackFunction_t)(TimerHandle_t xTimer);
  51. /*
  52. * Defines the prototype to which functions used with the
  53. * xTimerPendFunctionCallFromISR() function must conform.
  54. */
  55. typedef void (* PendedFunction_t)(void *, uint32_t );
  56. /**
  57. * TimerHandle_t xTimerCreate( const char * const pcTimerName,
  58. * TickType_t xTimerPeriodInTicks,
  59. * BaseType_t xAutoReload,
  60. * void * pvTimerID,
  61. * TimerCallbackFunction_t pxCallbackFunction );
  62. *
  63. * Creates a new software timer instance, and returns a handle by which the
  64. * created software timer can be referenced.
  65. *
  66. * Internally, within the FreeRTOS implementation, software timers use a block
  67. * of memory, in which the timer data structure is stored. If a software timer
  68. * is created using xTimerCreate() then the required memory is automatically
  69. * dynamically allocated inside the xTimerCreate() function. (see
  70. * https://www.FreeRTOS.org/a00111.html). If a software timer is created using
  71. * xTimerCreateStatic() then the application writer must provide the memory that
  72. * will get used by the software timer. xTimerCreateStatic() therefore allows a
  73. * software timer to be created without using any dynamic memory allocation.
  74. *
  75. * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  76. * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  77. * xTimerChangePeriodFromISR() API functions can all be used to transition a
  78. * timer into the active state.
  79. *
  80. * @param pcTimerName A text name that is assigned to the timer. This is done
  81. * purely to assist debugging. The kernel itself only ever references a timer
  82. * by its handle, and never by its name.
  83. *
  84. * @param xTimerPeriodInTicks The timer period. The time is defined in tick
  85. * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
  86. * has been specified in milliseconds. For example, if the timer must expire
  87. * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
  88. * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
  89. * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
  90. * equal to 1000. Time timer period must be greater than 0.
  91. *
  92. * @param xAutoReload If xAutoReload is set to pdTRUE then the timer will
  93. * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
  94. * If xAutoReload is set to pdFALSE then the timer will be a one-shot timer and
  95. * enter the dormant state after it expires.
  96. *
  97. * @param pvTimerID An identifier that is assigned to the timer being created.
  98. * Typically this would be used in the timer callback function to identify which
  99. * timer expired when the same callback function is assigned to more than one
  100. * timer.
  101. *
  102. * @param pxCallbackFunction The function to call when the timer expires.
  103. * Callback functions must have the prototype defined by TimerCallbackFunction_t,
  104. * which is "void vCallbackFunction( TimerHandle_t xTimer );".
  105. *
  106. * @return If the timer is successfully created then a handle to the newly
  107. * created timer is returned. If the timer cannot be created because there is
  108. * insufficient FreeRTOS heap remaining to allocate the timer
  109. * structures then NULL is returned.
  110. *
  111. */
  112. TimerHandle_t xTimerCreate(const char * const pcTimerName,
  113. const TickType_t xTimerPeriodInTicks,
  114. const BaseType_t xAutoReload,
  115. void * const pvTimerID,
  116. TimerCallbackFunction_t pxCallbackFunction) PRIVILEGED_FUNCTION;
  117. /**
  118. * void *pvTimerGetTimerID( TimerHandle_t xTimer );
  119. *
  120. * Returns the ID assigned to the timer.
  121. *
  122. * IDs are assigned to timers using the pvTimerID parameter of the call to
  123. * xTimerCreated() that was used to create the timer, and by calling the
  124. * vTimerSetTimerID() API function.
  125. *
  126. * If the same callback function is assigned to multiple timers then the timer
  127. * ID can be used as time specific (timer local) storage.
  128. *
  129. * @param xTimer The timer being queried.
  130. *
  131. * @return The ID assigned to the timer being queried.
  132. *
  133. * Example usage:
  134. *
  135. * See the xTimerCreate() API function example usage scenario.
  136. */
  137. void * pvTimerGetTimerID(const TimerHandle_t xTimer) PRIVILEGED_FUNCTION;
  138. /**
  139. * void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID );
  140. *
  141. * Sets the ID assigned to the timer.
  142. *
  143. * IDs are assigned to timers using the pvTimerID parameter of the call to
  144. * xTimerCreated() that was used to create the timer.
  145. *
  146. * If the same callback function is assigned to multiple timers then the timer
  147. * ID can be used as time specific (timer local) storage.
  148. *
  149. * @param xTimer The timer being updated.
  150. *
  151. * @param pvNewID The ID to assign to the timer.
  152. *
  153. * Example usage:
  154. *
  155. * See the xTimerCreate() API function example usage scenario.
  156. */
  157. void vTimerSetTimerID(TimerHandle_t xTimer, void * pvNewID) PRIVILEGED_FUNCTION;
  158. /**
  159. * BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer );
  160. *
  161. * Queries a timer to see if it is active or dormant.
  162. *
  163. * A timer will be dormant if:
  164. * 1) It has been created but not started, or
  165. * 2) It is an expired one-shot timer that has not been restarted.
  166. *
  167. * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  168. * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  169. * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the
  170. * active state.
  171. *
  172. * @param xTimer The timer being queried.
  173. *
  174. * @return pdFALSE will be returned if the timer is dormant. A value other than
  175. * pdFALSE will be returned if the timer is active.
  176. *
  177. */
  178. BaseType_t xTimerIsTimerActive(TimerHandle_t xTimer) PRIVILEGED_FUNCTION;
  179. /**
  180. * TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
  181. *
  182. * Simply returns the handle of the timer service/daemon task. It it not valid
  183. * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started.
  184. */
  185. TaskHandle_t xTimerGetTimerDaemonTaskHandle(void) PRIVILEGED_FUNCTION;
  186. /**
  187. * BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xTicksToWait );
  188. *
  189. * Timer functionality is provided by a timer service/daemon task. Many of the
  190. * public FreeRTOS timer API functions send commands to the timer service task
  191. * through a queue called the timer command queue. The timer command queue is
  192. * private to the kernel itself and is not directly accessible to application
  193. * code. The length of the timer command queue is set by the
  194. * configTIMER_QUEUE_LENGTH configuration constant.
  195. *
  196. * xTimerStart() starts a timer that was previously created using the
  197. * xTimerCreate() API function. If the timer had already been started and was
  198. * already in the active state, then xTimerStart() has equivalent functionality
  199. * to the xTimerReset() API function.
  200. *
  201. * Starting a timer ensures the timer is in the active state. If the timer
  202. * is not stopped, deleted, or reset in the mean time, the callback function
  203. * associated with the timer will get called 'n' ticks after xTimerStart() was
  204. * called, where 'n' is the timers defined period.
  205. *
  206. * It is valid to call xTimerStart() before the scheduler has been started, but
  207. * when this is done the timer will not actually start until the scheduler is
  208. * started, and the timers expiry time will be relative to when the scheduler is
  209. * started, not relative to when xTimerStart() was called.
  210. *
  211. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart()
  212. * to be available.
  213. *
  214. * @param xTimer The handle of the timer being started/restarted.
  215. *
  216. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  217. * be held in the Blocked state to wait for the start command to be successfully
  218. * sent to the timer command queue, should the queue already be full when
  219. * xTimerStart() was called. xTicksToWait is ignored if xTimerStart() is called
  220. * before the scheduler is started.
  221. *
  222. * @return pdFAIL will be returned if the start command could not be sent to
  223. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  224. * be returned if the command was successfully sent to the timer command queue.
  225. * When the command is actually processed will depend on the priority of the
  226. * timer service/daemon task relative to other tasks in the system, although the
  227. * timers expiry time is relative to when xTimerStart() is actually called. The
  228. * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  229. * configuration constant.
  230. */
  231. #define xTimerStart(xTimer, xTicksToWait) \
  232. xTimerGenericCommand((xTimer), tmrCOMMAND_START, (xTaskGetTickCount()), NULL, (xTicksToWait))
  233. /**
  234. * BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xTicksToWait );
  235. *
  236. * Timer functionality is provided by a timer service/daemon task. Many of the
  237. * public FreeRTOS timer API functions send commands to the timer service task
  238. * through a queue called the timer command queue. The timer command queue is
  239. * private to the kernel itself and is not directly accessible to application
  240. * code. The length of the timer command queue is set by the
  241. * configTIMER_QUEUE_LENGTH configuration constant.
  242. *
  243. * xTimerStop() stops a timer that was previously started using either of the
  244. * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(),
  245. * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions.
  246. *
  247. * Stopping a timer ensures the timer is not in the active state.
  248. *
  249. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop()
  250. * to be available.
  251. *
  252. * @param xTimer The handle of the timer being stopped.
  253. *
  254. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  255. * be held in the Blocked state to wait for the stop command to be successfully
  256. * sent to the timer command queue, should the queue already be full when
  257. * xTimerStop() was called. xTicksToWait is ignored if xTimerStop() is called
  258. * before the scheduler is started.
  259. *
  260. * @return pdFAIL will be returned if the stop command could not be sent to
  261. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  262. * be returned if the command was successfully sent to the timer command queue.
  263. * When the command is actually processed will depend on the priority of the
  264. * timer service/daemon task relative to other tasks in the system. The timer
  265. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  266. * configuration constant.
  267. */
  268. #define xTimerStop(xTimer, xTicksToWait) \
  269. xTimerGenericCommand((xTimer), tmrCOMMAND_STOP, 0U, NULL, (xTicksToWait))
  270. /**
  271. * BaseType_t xTimerChangePeriod( TimerHandle_t xTimer,
  272. * TickType_t xNewPeriod,
  273. * TickType_t xTicksToWait );
  274. *
  275. * Timer functionality is provided by a timer service/daemon task. Many of the
  276. * public FreeRTOS timer API functions send commands to the timer service task
  277. * through a queue called the timer command queue. The timer command queue is
  278. * private to the kernel itself and is not directly accessible to application
  279. * code. The length of the timer command queue is set by the
  280. * configTIMER_QUEUE_LENGTH configuration constant.
  281. *
  282. * xTimerChangePeriod() changes the period of a timer that was previously
  283. * created using the xTimerCreate() API function.
  284. *
  285. * xTimerChangePeriod() can be called to change the period of an active or
  286. * dormant state timer.
  287. *
  288. * The configUSE_TIMERS configuration constant must be set to 1 for
  289. * xTimerChangePeriod() to be available.
  290. *
  291. * @param xTimer The handle of the timer that is having its period changed.
  292. *
  293. * @param xNewPeriod The new period for xTimer. Timer periods are specified in
  294. * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
  295. * that has been specified in milliseconds. For example, if the timer must
  296. * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
  297. * if the timer must expire after 500ms, then xNewPeriod can be set to
  298. * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
  299. * or equal to 1000.
  300. *
  301. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  302. * be held in the Blocked state to wait for the change period command to be
  303. * successfully sent to the timer command queue, should the queue already be
  304. * full when xTimerChangePeriod() was called. xTicksToWait is ignored if
  305. * xTimerChangePeriod() is called before the scheduler is started.
  306. *
  307. * @return pdFAIL will be returned if the change period command could not be
  308. * sent to the timer command queue even after xTicksToWait ticks had passed.
  309. * pdPASS will be returned if the command was successfully sent to the timer
  310. * command queue. When the command is actually processed will depend on the
  311. * priority of the timer service/daemon task relative to other tasks in the
  312. * system. The timer service/daemon task priority is set by the
  313. * configTIMER_TASK_PRIORITY configuration constant.
  314. *
  315. */
  316. #define xTimerChangePeriod(xTimer, xNewPeriod, xTicksToWait) \
  317. xTimerGenericCommand((xTimer), tmrCOMMAND_CHANGE_PERIOD, (xNewPeriod), NULL, (xTicksToWait))
  318. /**
  319. * BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait );
  320. *
  321. * Timer functionality is provided by a timer service/daemon task. Many of the
  322. * public FreeRTOS timer API functions send commands to the timer service task
  323. * through a queue called the timer command queue. The timer command queue is
  324. * private to the kernel itself and is not directly accessible to application
  325. * code. The length of the timer command queue is set by the
  326. * configTIMER_QUEUE_LENGTH configuration constant.
  327. *
  328. * xTimerDelete() deletes a timer that was previously created using the
  329. * xTimerCreate() API function.
  330. *
  331. * The configUSE_TIMERS configuration constant must be set to 1 for
  332. * xTimerDelete() to be available.
  333. *
  334. * @param xTimer The handle of the timer being deleted.
  335. *
  336. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  337. * be held in the Blocked state to wait for the delete command to be
  338. * successfully sent to the timer command queue, should the queue already be
  339. * full when xTimerDelete() was called. xTicksToWait is ignored if xTimerDelete()
  340. * is called before the scheduler is started.
  341. *
  342. * @return pdFAIL will be returned if the delete command could not be sent to
  343. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  344. * be returned if the command was successfully sent to the timer command queue.
  345. * When the command is actually processed will depend on the priority of the
  346. * timer service/daemon task relative to other tasks in the system. The timer
  347. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  348. * configuration constant.
  349. *
  350. * Example usage:
  351. *
  352. * See the xTimerChangePeriod() API function example usage scenario.
  353. */
  354. #define xTimerDelete(xTimer, xTicksToWait) \
  355. xTimerGenericCommand((xTimer), tmrCOMMAND_DELETE, 0U, NULL, (xTicksToWait))
  356. /**
  357. * BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait );
  358. *
  359. * Timer functionality is provided by a timer service/daemon task. Many of the
  360. * public FreeRTOS timer API functions send commands to the timer service task
  361. * through a queue called the timer command queue. The timer command queue is
  362. * private to the kernel itself and is not directly accessible to application
  363. * code. The length of the timer command queue is set by the
  364. * configTIMER_QUEUE_LENGTH configuration constant.
  365. *
  366. * xTimerReset() re-starts a timer that was previously created using the
  367. * xTimerCreate() API function. If the timer had already been started and was
  368. * already in the active state, then xTimerReset() will cause the timer to
  369. * re-evaluate its expiry time so that it is relative to when xTimerReset() was
  370. * called. If the timer was in the dormant state then xTimerReset() has
  371. * equivalent functionality to the xTimerStart() API function.
  372. *
  373. * Resetting a timer ensures the timer is in the active state. If the timer
  374. * is not stopped, deleted, or reset in the mean time, the callback function
  375. * associated with the timer will get called 'n' ticks after xTimerReset() was
  376. * called, where 'n' is the timers defined period.
  377. *
  378. * It is valid to call xTimerReset() before the scheduler has been started, but
  379. * when this is done the timer will not actually start until the scheduler is
  380. * started, and the timers expiry time will be relative to when the scheduler is
  381. * started, not relative to when xTimerReset() was called.
  382. *
  383. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset()
  384. * to be available.
  385. *
  386. * @param xTimer The handle of the timer being reset/started/restarted.
  387. *
  388. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  389. * be held in the Blocked state to wait for the reset command to be successfully
  390. * sent to the timer command queue, should the queue already be full when
  391. * xTimerReset() was called. xTicksToWait is ignored if xTimerReset() is called
  392. * before the scheduler is started.
  393. *
  394. * @return pdFAIL will be returned if the reset command could not be sent to
  395. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  396. * be returned if the command was successfully sent to the timer command queue.
  397. * When the command is actually processed will depend on the priority of the
  398. * timer service/daemon task relative to other tasks in the system, although the
  399. * timers expiry time is relative to when xTimerStart() is actually called. The
  400. * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  401. * configuration constant.
  402. *
  403. */
  404. #define xTimerReset(xTimer, xTicksToWait) \
  405. xTimerGenericCommand((xTimer), tmrCOMMAND_RESET, (xTaskGetTickCount()), NULL, (xTicksToWait))
  406. /**
  407. * BaseType_t xTimerStartFromISR( TimerHandle_t xTimer,
  408. * BaseType_t *pxHigherPriorityTaskWoken );
  409. *
  410. * A version of xTimerStart() that can be called from an interrupt service
  411. * routine.
  412. *
  413. * @param xTimer The handle of the timer being started/restarted.
  414. *
  415. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  416. * of its time in the Blocked state, waiting for messages to arrive on the timer
  417. * command queue. Calling xTimerStartFromISR() writes a message to the timer
  418. * command queue, so has the potential to transition the timer service/daemon
  419. * task out of the Blocked state. If calling xTimerStartFromISR() causes the
  420. * timer service/daemon task to leave the Blocked state, and the timer service/
  421. * daemon task has a priority equal to or greater than the currently executing
  422. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  423. * get set to pdTRUE internally within the xTimerStartFromISR() function. If
  424. * xTimerStartFromISR() sets this value to pdTRUE then a context switch should
  425. * be performed before the interrupt exits.
  426. *
  427. * @return pdFAIL will be returned if the start command could not be sent to
  428. * the timer command queue. pdPASS will be returned if the command was
  429. * successfully sent to the timer command queue. When the command is actually
  430. * processed will depend on the priority of the timer service/daemon task
  431. * relative to other tasks in the system, although the timers expiry time is
  432. * relative to when xTimerStartFromISR() is actually called. The timer
  433. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  434. * configuration constant.
  435. *
  436. */
  437. #define xTimerStartFromISR(xTimer, pxHigherPriorityTaskWoken) \
  438. xTimerGenericCommand((xTimer), tmrCOMMAND_START_FROM_ISR, (xTaskGetTickCountFromISR()), (pxHigherPriorityTaskWoken), 0U)
  439. /**
  440. * BaseType_t xTimerStopFromISR( TimerHandle_t xTimer,
  441. * BaseType_t *pxHigherPriorityTaskWoken );
  442. *
  443. * A version of xTimerStop() that can be called from an interrupt service
  444. * routine.
  445. *
  446. * @param xTimer The handle of the timer being stopped.
  447. *
  448. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  449. * of its time in the Blocked state, waiting for messages to arrive on the timer
  450. * command queue. Calling xTimerStopFromISR() writes a message to the timer
  451. * command queue, so has the potential to transition the timer service/daemon
  452. * task out of the Blocked state. If calling xTimerStopFromISR() causes the
  453. * timer service/daemon task to leave the Blocked state, and the timer service/
  454. * daemon task has a priority equal to or greater than the currently executing
  455. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  456. * get set to pdTRUE internally within the xTimerStopFromISR() function. If
  457. * xTimerStopFromISR() sets this value to pdTRUE then a context switch should
  458. * be performed before the interrupt exits.
  459. *
  460. * @return pdFAIL will be returned if the stop command could not be sent to
  461. * the timer command queue. pdPASS will be returned if the command was
  462. * successfully sent to the timer command queue. When the command is actually
  463. * processed will depend on the priority of the timer service/daemon task
  464. * relative to other tasks in the system. The timer service/daemon task
  465. * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  466. *
  467. */
  468. #define xTimerStopFromISR(xTimer, pxHigherPriorityTaskWoken) \
  469. xTimerGenericCommand((xTimer), tmrCOMMAND_STOP_FROM_ISR, 0, (pxHigherPriorityTaskWoken), 0U)
  470. /**
  471. * BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer,
  472. * TickType_t xNewPeriod,
  473. * BaseType_t *pxHigherPriorityTaskWoken );
  474. *
  475. * A version of xTimerChangePeriod() that can be called from an interrupt
  476. * service routine.
  477. *
  478. * @param xTimer The handle of the timer that is having its period changed.
  479. *
  480. * @param xNewPeriod The new period for xTimer. Timer periods are specified in
  481. * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
  482. * that has been specified in milliseconds. For example, if the timer must
  483. * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
  484. * if the timer must expire after 500ms, then xNewPeriod can be set to
  485. * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
  486. * or equal to 1000.
  487. *
  488. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  489. * of its time in the Blocked state, waiting for messages to arrive on the timer
  490. * command queue. Calling xTimerChangePeriodFromISR() writes a message to the
  491. * timer command queue, so has the potential to transition the timer service/
  492. * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR()
  493. * causes the timer service/daemon task to leave the Blocked state, and the
  494. * timer service/daemon task has a priority equal to or greater than the
  495. * currently executing task (the task that was interrupted), then
  496. * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the
  497. * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets
  498. * this value to pdTRUE then a context switch should be performed before the
  499. * interrupt exits.
  500. *
  501. * @return pdFAIL will be returned if the command to change the timers period
  502. * could not be sent to the timer command queue. pdPASS will be returned if the
  503. * command was successfully sent to the timer command queue. When the command
  504. * is actually processed will depend on the priority of the timer service/daemon
  505. * task relative to other tasks in the system. The timer service/daemon task
  506. * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  507. *
  508. */
  509. #define xTimerChangePeriodFromISR(xTimer, xNewPeriod, pxHigherPriorityTaskWoken) \
  510. xTimerGenericCommand((xTimer), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, (xNewPeriod), (pxHigherPriorityTaskWoken), 0U)
  511. /**
  512. * BaseType_t xTimerResetFromISR( TimerHandle_t xTimer,
  513. * BaseType_t *pxHigherPriorityTaskWoken );
  514. *
  515. * A version of xTimerReset() that can be called from an interrupt service
  516. * routine.
  517. *
  518. * @param xTimer The handle of the timer that is to be started, reset, or
  519. * restarted.
  520. *
  521. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  522. * of its time in the Blocked state, waiting for messages to arrive on the timer
  523. * command queue. Calling xTimerResetFromISR() writes a message to the timer
  524. * command queue, so has the potential to transition the timer service/daemon
  525. * task out of the Blocked state. If calling xTimerResetFromISR() causes the
  526. * timer service/daemon task to leave the Blocked state, and the timer service/
  527. * daemon task has a priority equal to or greater than the currently executing
  528. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  529. * get set to pdTRUE internally within the xTimerResetFromISR() function. If
  530. * xTimerResetFromISR() sets this value to pdTRUE then a context switch should
  531. * be performed before the interrupt exits.
  532. *
  533. * @return pdFAIL will be returned if the reset command could not be sent to
  534. * the timer command queue. pdPASS will be returned if the command was
  535. * successfully sent to the timer command queue. When the command is actually
  536. * processed will depend on the priority of the timer service/daemon task
  537. * relative to other tasks in the system, although the timers expiry time is
  538. * relative to when xTimerResetFromISR() is actually called. The timer service/daemon
  539. * task priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  540. *
  541. */
  542. #define xTimerResetFromISR(xTimer, pxHigherPriorityTaskWoken) \
  543. xTimerGenericCommand((xTimer), tmrCOMMAND_RESET_FROM_ISR, (xTaskGetTickCountFromISR()), (pxHigherPriorityTaskWoken), 0U)
  544. /**
  545. * BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
  546. * void *pvParameter1,
  547. * uint32_t ulParameter2,
  548. * BaseType_t *pxHigherPriorityTaskWoken );
  549. *
  550. *
  551. * Used from application interrupt service routines to defer the execution of a
  552. * function to the RTOS daemon task (the timer service task, hence this function
  553. * is implemented in timers.c and is prefixed with 'Timer').
  554. *
  555. * Ideally an interrupt service routine (ISR) is kept as short as possible, but
  556. * sometimes an ISR either has a lot of processing to do, or needs to perform
  557. * processing that is not deterministic. In these cases
  558. * xTimerPendFunctionCallFromISR() can be used to defer processing of a function
  559. * to the RTOS daemon task.
  560. *
  561. * A mechanism is provided that allows the interrupt to return directly to the
  562. * task that will subsequently execute the pended callback function. This
  563. * allows the callback function to execute contiguously in time with the
  564. * interrupt - just as if the callback had executed in the interrupt itself.
  565. *
  566. * @param xFunctionToPend The function to execute from the timer service/
  567. * daemon task. The function must conform to the PendedFunction_t
  568. * prototype.
  569. *
  570. * @param pvParameter1 The value of the callback function's first parameter.
  571. * The parameter has a void * type to allow it to be used to pass any type.
  572. * For example, unsigned longs can be cast to a void *, or the void * can be
  573. * used to point to a structure.
  574. *
  575. * @param ulParameter2 The value of the callback function's second parameter.
  576. *
  577. * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
  578. * will result in a message being sent to the timer daemon task. If the
  579. * priority of the timer daemon task (which is set using
  580. * configTIMER_TASK_PRIORITY in FreeRTOSConfig.h) is higher than the priority of
  581. * the currently running task (the task the interrupt interrupted) then
  582. * *pxHigherPriorityTaskWoken will be set to pdTRUE within
  583. * xTimerPendFunctionCallFromISR(), indicating that a context switch should be
  584. * requested before the interrupt exits. For that reason
  585. * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
  586. * example code below.
  587. *
  588. * @return pdPASS is returned if the message was successfully sent to the
  589. * timer daemon task, otherwise pdFALSE is returned.
  590. *
  591. */
  592. BaseType_t xTimerPendFunctionCallFromISR(PendedFunction_t xFunctionToPend,
  593. void * pvParameter1,
  594. uint32_t ulParameter2,
  595. BaseType_t * pxHigherPriorityTaskWoken) PRIVILEGED_FUNCTION;
  596. /**
  597. * BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
  598. * void *pvParameter1,
  599. * uint32_t ulParameter2,
  600. * TickType_t xTicksToWait );
  601. *
  602. *
  603. * Used to defer the execution of a function to the RTOS daemon task (the timer
  604. * service task, hence this function is implemented in timers.c and is prefixed
  605. * with 'Timer').
  606. *
  607. * @param xFunctionToPend The function to execute from the timer service/
  608. * daemon task. The function must conform to the PendedFunction_t
  609. * prototype.
  610. *
  611. * @param pvParameter1 The value of the callback function's first parameter.
  612. * The parameter has a void * type to allow it to be used to pass any type.
  613. * For example, unsigned longs can be cast to a void *, or the void * can be
  614. * used to point to a structure.
  615. *
  616. * @param ulParameter2 The value of the callback function's second parameter.
  617. *
  618. * @param xTicksToWait Calling this function will result in a message being
  619. * sent to the timer daemon task on a queue. xTicksToWait is the amount of
  620. * time the calling task should remain in the Blocked state (so not using any
  621. * processing time) for space to become available on the timer queue if the
  622. * queue is found to be full.
  623. *
  624. * @return pdPASS is returned if the message was successfully sent to the
  625. * timer daemon task, otherwise pdFALSE is returned.
  626. *
  627. */
  628. BaseType_t xTimerPendFunctionCall(PendedFunction_t xFunctionToPend,
  629. void * pvParameter1,
  630. uint32_t ulParameter2,
  631. TickType_t xTicksToWait) PRIVILEGED_FUNCTION;
  632. /**
  633. * const char * const pcTimerGetName( TimerHandle_t xTimer );
  634. *
  635. * Returns the name that was assigned to a timer when the timer was created.
  636. *
  637. * @param xTimer The handle of the timer being queried.
  638. *
  639. * @return The name assigned to the timer specified by the xTimer parameter.
  640. */
  641. const char * pcTimerGetName(TimerHandle_t xTimer) PRIVILEGED_FUNCTION;
  642. /**
  643. * void vTimerSetReloadMode( TimerHandle_t xTimer, const BaseType_t xAutoReload );
  644. *
  645. * Updates a timer to be either an auto-reload timer, in which case the timer
  646. * automatically resets itself each time it expires, or a one-shot timer, in
  647. * which case the timer will only expire once unless it is manually restarted.
  648. *
  649. * @param xTimer The handle of the timer being updated.
  650. *
  651. * @param xAutoReload If xAutoReload is set to pdTRUE then the timer will
  652. * expire repeatedly with a frequency set by the timer's period (see the
  653. * xTimerPeriodInTicks parameter of the xTimerCreate() API function). If
  654. * xAutoReload is set to pdFALSE then the timer will be a one-shot timer and
  655. * enter the dormant state after it expires.
  656. */
  657. void vTimerSetReloadMode(TimerHandle_t xTimer,
  658. const BaseType_t xAutoReload) PRIVILEGED_FUNCTION;
  659. /**
  660. * BaseType_t xTimerGetReloadMode( TimerHandle_t xTimer );
  661. *
  662. * Queries a timer to determine if it is an auto-reload timer, in which case the timer
  663. * automatically resets itself each time it expires, or a one-shot timer, in
  664. * which case the timer will only expire once unless it is manually restarted.
  665. *
  666. * @param xTimer The handle of the timer being queried.
  667. *
  668. * @return If the timer is an auto-reload timer then pdTRUE is returned, otherwise
  669. * pdFALSE is returned.
  670. */
  671. BaseType_t xTimerGetReloadMode(TimerHandle_t xTimer) PRIVILEGED_FUNCTION;
  672. /**
  673. * UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer );
  674. *
  675. * Queries a timer to determine if it is an auto-reload timer, in which case the timer
  676. * automatically resets itself each time it expires, or a one-shot timer, in
  677. * which case the timer will only expire once unless it is manually restarted.
  678. *
  679. * @param xTimer The handle of the timer being queried.
  680. *
  681. * @return If the timer is an auto-reload timer then pdTRUE is returned, otherwise
  682. * pdFALSE is returned.
  683. */
  684. UBaseType_t uxTimerGetReloadMode(TimerHandle_t xTimer) PRIVILEGED_FUNCTION;
  685. /**
  686. * TickType_t xTimerGetPeriod( TimerHandle_t xTimer );
  687. *
  688. * Returns the period of a timer.
  689. *
  690. * @param xTimer The handle of the timer being queried.
  691. *
  692. * @return The period of the timer in ticks.
  693. */
  694. TickType_t xTimerGetPeriod(TimerHandle_t xTimer) PRIVILEGED_FUNCTION;
  695. /**
  696. * TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer );
  697. *
  698. * Returns the time in ticks at which the timer will expire. If this is less
  699. * than the current tick count then the expiry time has overflowed from the
  700. * current time.
  701. *
  702. * @param xTimer The handle of the timer being queried.
  703. *
  704. * @return If the timer is running then the time in ticks at which the timer
  705. * will next expire is returned. If the timer is not running then the return
  706. * value is undefined.
  707. */
  708. TickType_t xTimerGetExpiryTime(TimerHandle_t xTimer) PRIVILEGED_FUNCTION;
  709. /*
  710. * Functions beyond this part are not part of the public API and are intended
  711. * for use by the kernel only.
  712. */
  713. BaseType_t xTimerCreateTimerTask(void) PRIVILEGED_FUNCTION;
  714. BaseType_t xTimerGenericCommand(TimerHandle_t xTimer,
  715. const BaseType_t xCommandID,
  716. const TickType_t xOptionalValue,
  717. BaseType_t * const pxHigherPriorityTaskWoken,
  718. const TickType_t xTicksToWait) PRIVILEGED_FUNCTION;
  719. #if (configUSE_TRACE_FACILITY == 1)
  720. void vTimerSetTimerNumber(TimerHandle_t xTimer,
  721. UBaseType_t uxTimerNumber) PRIVILEGED_FUNCTION;
  722. UBaseType_t uxTimerGetTimerNumber(TimerHandle_t xTimer) PRIVILEGED_FUNCTION;
  723. #endif
  724. #endif /* TIMERS_H */