fr_timers.h 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  1. /*
  2. FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.
  3. All rights reserved
  4. VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
  5. This file is part of the FreeRTOS distribution.
  6. FreeRTOS is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License (version 2) as published by the
  8. Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
  9. ***************************************************************************
  10. >>! NOTE: The modification to the GPL is included to allow you to !<<
  11. >>! distribute a combined work that includes FreeRTOS without being !<<
  12. >>! obliged to provide the source code for proprietary components !<<
  13. >>! outside of the FreeRTOS kernel. !<<
  14. ***************************************************************************
  15. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
  16. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  17. FOR A PARTICULAR PURPOSE. Full license text is available on the following
  18. link: http://www.freertos.org/a00114.html
  19. ***************************************************************************
  20. * *
  21. * FreeRTOS provides completely free yet professionally developed, *
  22. * robust, strictly quality controlled, supported, and cross *
  23. * platform software that is more than just the market leader, it *
  24. * is the industry's de facto standard. *
  25. * *
  26. * Help yourself get started quickly while simultaneously helping *
  27. * to support the FreeRTOS project by purchasing a FreeRTOS *
  28. * tutorial book, reference manual, or both: *
  29. * http://www.FreeRTOS.org/Documentation *
  30. * *
  31. ***************************************************************************
  32. http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
  33. the FAQ page "My application does not run, what could be wrong?". Have you
  34. defined configASSERT()?
  35. http://www.FreeRTOS.org/support - In return for receiving this top quality
  36. embedded software for free we request you assist our global community by
  37. participating in the support forum.
  38. http://www.FreeRTOS.org/training - Investing in training allows your team to
  39. be as productive as possible as early as possible. Now you can receive
  40. FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
  41. Ltd, and the world's leading authority on the world's leading RTOS.
  42. http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
  43. including FreeRTOS+Trace - an indispensable productivity tool, a DOS
  44. compatible FAT file system, and our tiny thread aware UDP/IP stack.
  45. http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
  46. Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
  47. http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
  48. Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
  49. licenses offer ticketed support, indemnification and commercial middleware.
  50. http://www.SafeRTOS.com - High Integrity Systems also provide a safety
  51. engineered and independently SIL3 certified version for use in safety and
  52. mission critical applications that require provable dependability.
  53. 1 tab == 4 spaces!
  54. */
  55. #ifndef TIMERS_H
  56. #define TIMERS_H
  57. #ifndef INC_FREERTOS_H
  58. #error "include FreeRTOS.h must appear in source files before include timers.h"
  59. #endif
  60. /*lint -e537 This headers are only multiply included if the application code
  61. happens to also be including task.h. */
  62. #include "task.h"
  63. /*lint +e537 */
  64. #ifdef __cplusplus
  65. extern "C" {
  66. #endif
  67. /*-----------------------------------------------------------
  68. * MACROS AND DEFINITIONS
  69. *----------------------------------------------------------*/
  70. /* IDs for commands that can be sent/received on the timer queue. These are to
  71. be used solely through the macros that make up the public software timer API,
  72. as defined below. The commands that are sent from interrupts must use the
  73. highest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task
  74. or interrupt version of the queue send function should be used. */
  75. #define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 )
  76. #define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 )
  77. #define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 )
  78. #define tmrCOMMAND_START ( ( BaseType_t ) 1 )
  79. #define tmrCOMMAND_RESET ( ( BaseType_t ) 2 )
  80. #define tmrCOMMAND_STOP ( ( BaseType_t ) 3 )
  81. #define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 )
  82. #define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 )
  83. #define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 )
  84. #define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 )
  85. #define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 )
  86. #define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 )
  87. #define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 )
  88. /**
  89. * Type by which software timers are referenced. For example, a call to
  90. * xTimerCreate() returns an TimerHandle_t variable that can then be used to
  91. * reference the subject timer in calls to other software timer API functions
  92. * (for example, xTimerStart(), xTimerReset(), etc.).
  93. */
  94. typedef void * TimerHandle_t;
  95. /*
  96. * Defines the prototype to which timer callback functions must conform.
  97. */
  98. typedef void (*TimerCallbackFunction_t)( TimerHandle_t xTimer );
  99. /*
  100. * Defines the prototype to which functions used with the
  101. * xTimerPendFunctionCallFromISR() function must conform.
  102. */
  103. typedef void (*PendedFunction_t)( void *, uint32_t );
  104. /**
  105. * TimerHandle_t xTimerCreate( const char * const pcTimerName,
  106. * TickType_t xTimerPeriodInTicks,
  107. * UBaseType_t uxAutoReload,
  108. * void * pvTimerID,
  109. * TimerCallbackFunction_t pxCallbackFunction );
  110. *
  111. * Creates a new software timer instance. This allocates the storage required
  112. * by the new timer, initialises the new timers internal state, and returns a
  113. * handle by which the new timer can be referenced.
  114. *
  115. * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  116. * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  117. * xTimerChangePeriodFromISR() API functions can all be used to transition a
  118. * timer into the active state.
  119. *
  120. * @param pcTimerName A text name that is assigned to the timer. This is done
  121. * purely to assist debugging. The kernel itself only ever references a timer
  122. * by its handle, and never by its name.
  123. *
  124. * @param xTimerPeriodInTicks The timer period. The time is defined in tick
  125. * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
  126. * has been specified in milliseconds. For example, if the timer must expire
  127. * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
  128. * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
  129. * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
  130. * equal to 1000.
  131. *
  132. * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
  133. * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
  134. * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
  135. * enter the dormant state after it expires.
  136. *
  137. * @param pvTimerID An identifier that is assigned to the timer being created.
  138. * Typically this would be used in the timer callback function to identify which
  139. * timer expired when the same callback function is assigned to more than one
  140. * timer.
  141. *
  142. * @param pxCallbackFunction The function to call when the timer expires.
  143. * Callback functions must have the prototype defined by TimerCallbackFunction_t,
  144. * which is "void vCallbackFunction( TimerHandle_t xTimer );".
  145. *
  146. * @return If the timer is successfully created then a handle to the newly
  147. * created timer is returned. If the timer cannot be created (because either
  148. * there is insufficient FreeRTOS heap remaining to allocate the timer
  149. * structures, or the timer period was set to 0) then NULL is returned.
  150. *
  151. * Example usage:
  152. * @verbatim
  153. * #define NUM_TIMERS 5
  154. *
  155. * // An array to hold handles to the created timers.
  156. * TimerHandle_t xTimers[ NUM_TIMERS ];
  157. *
  158. * // An array to hold a count of the number of times each timer expires.
  159. * int32_t lExpireCounters[ NUM_TIMERS ] = { 0 };
  160. *
  161. * // Define a callback function that will be used by multiple timer instances.
  162. * // The callback function does nothing but count the number of times the
  163. * // associated timer expires, and stop the timer once the timer has expired
  164. * // 10 times.
  165. * void vTimerCallback( TimerHandle_t pxTimer )
  166. * {
  167. * int32_t lArrayIndex;
  168. * const int32_t xMaxExpiryCountBeforeStopping = 10;
  169. *
  170. * // Optionally do something if the pxTimer parameter is NULL.
  171. * configASSERT( pxTimer );
  172. *
  173. * // Which timer expired?
  174. * lArrayIndex = ( int32_t ) pvTimerGetTimerID( pxTimer );
  175. *
  176. * // Increment the number of times that pxTimer has expired.
  177. * lExpireCounters[ lArrayIndex ] += 1;
  178. *
  179. * // If the timer has expired 10 times then stop it from running.
  180. * if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping )
  181. * {
  182. * // Do not use a block time if calling a timer API function from a
  183. * // timer callback function, as doing so could cause a deadlock!
  184. * xTimerStop( pxTimer, 0 );
  185. * }
  186. * }
  187. *
  188. * void main( void )
  189. * {
  190. * int32_t x;
  191. *
  192. * // Create then start some timers. Starting the timers before the scheduler
  193. * // has been started means the timers will start running immediately that
  194. * // the scheduler starts.
  195. * for( x = 0; x < NUM_TIMERS; x++ )
  196. * {
  197. * xTimers[ x ] = xTimerCreate( "Timer", // Just a text name, not used by the kernel.
  198. * ( 100 * x ), // The timer period in ticks.
  199. * pdTRUE, // The timers will auto-reload themselves when they expire.
  200. * ( void * ) x, // Assign each timer a unique id equal to its array index.
  201. * vTimerCallback // Each timer calls the same callback when it expires.
  202. * );
  203. *
  204. * if( xTimers[ x ] == NULL )
  205. * {
  206. * // The timer was not created.
  207. * }
  208. * else
  209. * {
  210. * // Start the timer. No block time is specified, and even if one was
  211. * // it would be ignored because the scheduler has not yet been
  212. * // started.
  213. * if( xTimerStart( xTimers[ x ], 0 ) != pdPASS )
  214. * {
  215. * // The timer could not be set into the Active state.
  216. * }
  217. * }
  218. * }
  219. *
  220. * // ...
  221. * // Create tasks here.
  222. * // ...
  223. *
  224. * // Starting the scheduler will start the timers running as they have already
  225. * // been set into the active state.
  226. * xTaskStartScheduler();
  227. *
  228. * // Should not reach here.
  229. * for( ;; );
  230. * }
  231. * @endverbatim
  232. */
  233. TimerHandle_t xTimerCreate( const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  234. /**
  235. * void *pvTimerGetTimerID( TimerHandle_t xTimer );
  236. *
  237. * Returns the ID assigned to the timer.
  238. *
  239. * IDs are assigned to timers using the pvTimerID parameter of the call to
  240. * xTimerCreated() that was used to create the timer.
  241. *
  242. * If the same callback function is assigned to multiple timers then the timer
  243. * ID can be used within the callback function to identify which timer actually
  244. * expired.
  245. *
  246. * @param xTimer The timer being queried.
  247. *
  248. * @return The ID assigned to the timer being queried.
  249. *
  250. * Example usage:
  251. *
  252. * See the xTimerCreate() API function example usage scenario.
  253. */
  254. void *pvTimerGetTimerID( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
  255. /**
  256. * BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer );
  257. *
  258. * Queries a timer to see if it is active or dormant.
  259. *
  260. * A timer will be dormant if:
  261. * 1) It has been created but not started, or
  262. * 2) It is an expired one-shot timer that has not been restarted.
  263. *
  264. * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  265. * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  266. * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the
  267. * active state.
  268. *
  269. * @param xTimer The timer being queried.
  270. *
  271. * @return pdFALSE will be returned if the timer is dormant. A value other than
  272. * pdFALSE will be returned if the timer is active.
  273. *
  274. * Example usage:
  275. * @verbatim
  276. * // This function assumes xTimer has already been created.
  277. * void vAFunction( TimerHandle_t xTimer )
  278. * {
  279. * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
  280. * {
  281. * // xTimer is active, do something.
  282. * }
  283. * else
  284. * {
  285. * // xTimer is not active, do something else.
  286. * }
  287. * }
  288. * @endverbatim
  289. */
  290. BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
  291. /**
  292. * TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
  293. *
  294. * xTimerGetTimerDaemonTaskHandle() is only available if
  295. * INCLUDE_xTimerGetTimerDaemonTaskHandle is set to 1 in FreeRTOSConfig.h.
  296. *
  297. * Simply returns the handle of the timer service/daemon task. It it not valid
  298. * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started.
  299. */
  300. TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
  301. /**
  302. * BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xTicksToWait );
  303. *
  304. * Timer functionality is provided by a timer service/daemon task. Many of the
  305. * public FreeRTOS timer API functions send commands to the timer service task
  306. * through a queue called the timer command queue. The timer command queue is
  307. * private to the kernel itself and is not directly accessible to application
  308. * code. The length of the timer command queue is set by the
  309. * configTIMER_QUEUE_LENGTH configuration constant.
  310. *
  311. * xTimerStart() starts a timer that was previously created using the
  312. * xTimerCreate() API function. If the timer had already been started and was
  313. * already in the active state, then xTimerStart() has equivalent functionality
  314. * to the xTimerReset() API function.
  315. *
  316. * Starting a timer ensures the timer is in the active state. If the timer
  317. * is not stopped, deleted, or reset in the mean time, the callback function
  318. * associated with the timer will get called 'n' ticks after xTimerStart() was
  319. * called, where 'n' is the timers defined period.
  320. *
  321. * It is valid to call xTimerStart() before the scheduler has been started, but
  322. * when this is done the timer will not actually start until the scheduler is
  323. * started, and the timers expiry time will be relative to when the scheduler is
  324. * started, not relative to when xTimerStart() was called.
  325. *
  326. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart()
  327. * to be available.
  328. *
  329. * @param xTimer The handle of the timer being started/restarted.
  330. *
  331. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  332. * be held in the Blocked state to wait for the start command to be successfully
  333. * sent to the timer command queue, should the queue already be full when
  334. * xTimerStart() was called. xTicksToWait is ignored if xTimerStart() is called
  335. * before the scheduler is started.
  336. *
  337. * @return pdFAIL will be returned if the start command could not be sent to
  338. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  339. * be returned if the command was successfully sent to the timer command queue.
  340. * When the command is actually processed will depend on the priority of the
  341. * timer service/daemon task relative to other tasks in the system, although the
  342. * timers expiry time is relative to when xTimerStart() is actually called. The
  343. * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  344. * configuration constant.
  345. *
  346. * Example usage:
  347. *
  348. * See the xTimerCreate() API function example usage scenario.
  349. *
  350. */
  351. #define xTimerStart( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
  352. /**
  353. * BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xTicksToWait );
  354. *
  355. * Timer functionality is provided by a timer service/daemon task. Many of the
  356. * public FreeRTOS timer API functions send commands to the timer service task
  357. * through a queue called the timer command queue. The timer command queue is
  358. * private to the kernel itself and is not directly accessible to application
  359. * code. The length of the timer command queue is set by the
  360. * configTIMER_QUEUE_LENGTH configuration constant.
  361. *
  362. * xTimerStop() stops a timer that was previously started using either of the
  363. * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(),
  364. * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions.
  365. *
  366. * Stopping a timer ensures the timer is not in the active state.
  367. *
  368. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop()
  369. * to be available.
  370. *
  371. * @param xTimer The handle of the timer being stopped.
  372. *
  373. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  374. * be held in the Blocked state to wait for the stop command to be successfully
  375. * sent to the timer command queue, should the queue already be full when
  376. * xTimerStop() was called. xTicksToWait is ignored if xTimerStop() is called
  377. * before the scheduler is started.
  378. *
  379. * @return pdFAIL will be returned if the stop command could not be sent to
  380. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  381. * be returned if the command was successfully sent to the timer command queue.
  382. * When the command is actually processed will depend on the priority of the
  383. * timer service/daemon task relative to other tasks in the system. The timer
  384. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  385. * configuration constant.
  386. *
  387. * Example usage:
  388. *
  389. * See the xTimerCreate() API function example usage scenario.
  390. *
  391. */
  392. #define xTimerStop( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )
  393. /**
  394. * BaseType_t xTimerChangePeriod( TimerHandle_t xTimer,
  395. * TickType_t xNewPeriod,
  396. * TickType_t xTicksToWait );
  397. *
  398. * Timer functionality is provided by a timer service/daemon task. Many of the
  399. * public FreeRTOS timer API functions send commands to the timer service task
  400. * through a queue called the timer command queue. The timer command queue is
  401. * private to the kernel itself and is not directly accessible to application
  402. * code. The length of the timer command queue is set by the
  403. * configTIMER_QUEUE_LENGTH configuration constant.
  404. *
  405. * xTimerChangePeriod() changes the period of a timer that was previously
  406. * created using the xTimerCreate() API function.
  407. *
  408. * xTimerChangePeriod() can be called to change the period of an active or
  409. * dormant state timer.
  410. *
  411. * The configUSE_TIMERS configuration constant must be set to 1 for
  412. * xTimerChangePeriod() to be available.
  413. *
  414. * @param xTimer The handle of the timer that is having its period changed.
  415. *
  416. * @param xNewPeriod The new period for xTimer. Timer periods are specified in
  417. * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
  418. * that has been specified in milliseconds. For example, if the timer must
  419. * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
  420. * if the timer must expire after 500ms, then xNewPeriod can be set to
  421. * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
  422. * or equal to 1000.
  423. *
  424. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  425. * be held in the Blocked state to wait for the change period command to be
  426. * successfully sent to the timer command queue, should the queue already be
  427. * full when xTimerChangePeriod() was called. xTicksToWait is ignored if
  428. * xTimerChangePeriod() is called before the scheduler is started.
  429. *
  430. * @return pdFAIL will be returned if the change period command could not be
  431. * sent to the timer command queue even after xTicksToWait ticks had passed.
  432. * pdPASS will be returned if the command was successfully sent to the timer
  433. * command queue. When the command is actually processed will depend on the
  434. * priority of the timer service/daemon task relative to other tasks in the
  435. * system. The timer service/daemon task priority is set by the
  436. * configTIMER_TASK_PRIORITY configuration constant.
  437. *
  438. * Example usage:
  439. * @verbatim
  440. * // This function assumes xTimer has already been created. If the timer
  441. * // referenced by xTimer is already active when it is called, then the timer
  442. * // is deleted. If the timer referenced by xTimer is not active when it is
  443. * // called, then the period of the timer is set to 500ms and the timer is
  444. * // started.
  445. * void vAFunction( TimerHandle_t xTimer )
  446. * {
  447. * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
  448. * {
  449. * // xTimer is already active - delete it.
  450. * xTimerDelete( xTimer );
  451. * }
  452. * else
  453. * {
  454. * // xTimer is not active, change its period to 500ms. This will also
  455. * // cause the timer to start. Block for a maximum of 100 ticks if the
  456. * // change period command cannot immediately be sent to the timer
  457. * // command queue.
  458. * if( xTimerChangePeriod( xTimer, 500 / portTICK_PERIOD_MS, 100 ) == pdPASS )
  459. * {
  460. * // The command was successfully sent.
  461. * }
  462. * else
  463. * {
  464. * // The command could not be sent, even after waiting for 100 ticks
  465. * // to pass. Take appropriate action here.
  466. * }
  467. * }
  468. * }
  469. * @endverbatim
  470. */
  471. #define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) )
  472. /**
  473. * BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait );
  474. *
  475. * Timer functionality is provided by a timer service/daemon task. Many of the
  476. * public FreeRTOS timer API functions send commands to the timer service task
  477. * through a queue called the timer command queue. The timer command queue is
  478. * private to the kernel itself and is not directly accessible to application
  479. * code. The length of the timer command queue is set by the
  480. * configTIMER_QUEUE_LENGTH configuration constant.
  481. *
  482. * xTimerDelete() deletes a timer that was previously created using the
  483. * xTimerCreate() API function.
  484. *
  485. * The configUSE_TIMERS configuration constant must be set to 1 for
  486. * xTimerDelete() to be available.
  487. *
  488. * @param xTimer The handle of the timer being deleted.
  489. *
  490. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  491. * be held in the Blocked state to wait for the delete command to be
  492. * successfully sent to the timer command queue, should the queue already be
  493. * full when xTimerDelete() was called. xTicksToWait is ignored if xTimerDelete()
  494. * is called before the scheduler is started.
  495. *
  496. * @return pdFAIL will be returned if the delete command could not be sent to
  497. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  498. * be returned if the command was successfully sent to the timer command queue.
  499. * When the command is actually processed will depend on the priority of the
  500. * timer service/daemon task relative to other tasks in the system. The timer
  501. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  502. * configuration constant.
  503. *
  504. * Example usage:
  505. *
  506. * See the xTimerChangePeriod() API function example usage scenario.
  507. */
  508. #define xTimerDelete( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
  509. /**
  510. * BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait );
  511. *
  512. * Timer functionality is provided by a timer service/daemon task. Many of the
  513. * public FreeRTOS timer API functions send commands to the timer service task
  514. * through a queue called the timer command queue. The timer command queue is
  515. * private to the kernel itself and is not directly accessible to application
  516. * code. The length of the timer command queue is set by the
  517. * configTIMER_QUEUE_LENGTH configuration constant.
  518. *
  519. * xTimerReset() re-starts a timer that was previously created using the
  520. * xTimerCreate() API function. If the timer had already been started and was
  521. * already in the active state, then xTimerReset() will cause the timer to
  522. * re-evaluate its expiry time so that it is relative to when xTimerReset() was
  523. * called. If the timer was in the dormant state then xTimerReset() has
  524. * equivalent functionality to the xTimerStart() API function.
  525. *
  526. * Resetting a timer ensures the timer is in the active state. If the timer
  527. * is not stopped, deleted, or reset in the mean time, the callback function
  528. * associated with the timer will get called 'n' ticks after xTimerReset() was
  529. * called, where 'n' is the timers defined period.
  530. *
  531. * It is valid to call xTimerReset() before the scheduler has been started, but
  532. * when this is done the timer will not actually start until the scheduler is
  533. * started, and the timers expiry time will be relative to when the scheduler is
  534. * started, not relative to when xTimerReset() was called.
  535. *
  536. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset()
  537. * to be available.
  538. *
  539. * @param xTimer The handle of the timer being reset/started/restarted.
  540. *
  541. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  542. * be held in the Blocked state to wait for the reset command to be successfully
  543. * sent to the timer command queue, should the queue already be full when
  544. * xTimerReset() was called. xTicksToWait is ignored if xTimerReset() is called
  545. * before the scheduler is started.
  546. *
  547. * @return pdFAIL will be returned if the reset command could not be sent to
  548. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  549. * be returned if the command was successfully sent to the timer command queue.
  550. * When the command is actually processed will depend on the priority of the
  551. * timer service/daemon task relative to other tasks in the system, although the
  552. * timers expiry time is relative to when xTimerStart() is actually called. The
  553. * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  554. * configuration constant.
  555. *
  556. * Example usage:
  557. * @verbatim
  558. * // When a key is pressed, an LCD back-light is switched on. If 5 seconds pass
  559. * // without a key being pressed, then the LCD back-light is switched off. In
  560. * // this case, the timer is a one-shot timer.
  561. *
  562. * TimerHandle_t xBacklightTimer = NULL;
  563. *
  564. * // The callback function assigned to the one-shot timer. In this case the
  565. * // parameter is not used.
  566. * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  567. * {
  568. * // The timer expired, therefore 5 seconds must have passed since a key
  569. * // was pressed. Switch off the LCD back-light.
  570. * vSetBacklightState( BACKLIGHT_OFF );
  571. * }
  572. *
  573. * // The key press event handler.
  574. * void vKeyPressEventHandler( char cKey )
  575. * {
  576. * // Ensure the LCD back-light is on, then reset the timer that is
  577. * // responsible for turning the back-light off after 5 seconds of
  578. * // key inactivity. Wait 10 ticks for the command to be successfully sent
  579. * // if it cannot be sent immediately.
  580. * vSetBacklightState( BACKLIGHT_ON );
  581. * if( xTimerReset( xBacklightTimer, 100 ) != pdPASS )
  582. * {
  583. * // The reset command was not executed successfully. Take appropriate
  584. * // action here.
  585. * }
  586. *
  587. * // Perform the rest of the key processing here.
  588. * }
  589. *
  590. * void main( void )
  591. * {
  592. * int32_t x;
  593. *
  594. * // Create then start the one-shot timer that is responsible for turning
  595. * // the back-light off if no keys are pressed within a 5 second period.
  596. * xBacklightTimer = xTimerCreate( "BacklightTimer", // Just a text name, not used by the kernel.
  597. * ( 5000 / portTICK_PERIOD_MS), // The timer period in ticks.
  598. * pdFALSE, // The timer is a one-shot timer.
  599. * 0, // The id is not used by the callback so can take any value.
  600. * vBacklightTimerCallback // The callback function that switches the LCD back-light off.
  601. * );
  602. *
  603. * if( xBacklightTimer == NULL )
  604. * {
  605. * // The timer was not created.
  606. * }
  607. * else
  608. * {
  609. * // Start the timer. No block time is specified, and even if one was
  610. * // it would be ignored because the scheduler has not yet been
  611. * // started.
  612. * if( xTimerStart( xBacklightTimer, 0 ) != pdPASS )
  613. * {
  614. * // The timer could not be set into the Active state.
  615. * }
  616. * }
  617. *
  618. * // ...
  619. * // Create tasks here.
  620. * // ...
  621. *
  622. * // Starting the scheduler will start the timer running as it has already
  623. * // been set into the active state.
  624. * xTaskStartScheduler();
  625. *
  626. * // Should not reach here.
  627. * for( ;; );
  628. * }
  629. * @endverbatim
  630. */
  631. #define xTimerReset( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
  632. /**
  633. * BaseType_t xTimerStartFromISR( TimerHandle_t xTimer,
  634. * BaseType_t *pxHigherPriorityTaskWoken );
  635. *
  636. * A version of xTimerStart() that can be called from an interrupt service
  637. * routine.
  638. *
  639. * @param xTimer The handle of the timer being started/restarted.
  640. *
  641. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  642. * of its time in the Blocked state, waiting for messages to arrive on the timer
  643. * command queue. Calling xTimerStartFromISR() writes a message to the timer
  644. * command queue, so has the potential to transition the timer service/daemon
  645. * task out of the Blocked state. If calling xTimerStartFromISR() causes the
  646. * timer service/daemon task to leave the Blocked state, and the timer service/
  647. * daemon task has a priority equal to or greater than the currently executing
  648. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  649. * get set to pdTRUE internally within the xTimerStartFromISR() function. If
  650. * xTimerStartFromISR() sets this value to pdTRUE then a context switch should
  651. * be performed before the interrupt exits.
  652. *
  653. * @return pdFAIL will be returned if the start command could not be sent to
  654. * the timer command queue. pdPASS will be returned if the command was
  655. * successfully sent to the timer command queue. When the command is actually
  656. * processed will depend on the priority of the timer service/daemon task
  657. * relative to other tasks in the system, although the timers expiry time is
  658. * relative to when xTimerStartFromISR() is actually called. The timer
  659. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  660. * configuration constant.
  661. *
  662. * Example usage:
  663. * @verbatim
  664. * // This scenario assumes xBacklightTimer has already been created. When a
  665. * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
  666. * // without a key being pressed, then the LCD back-light is switched off. In
  667. * // this case, the timer is a one-shot timer, and unlike the example given for
  668. * // the xTimerReset() function, the key press event handler is an interrupt
  669. * // service routine.
  670. *
  671. * // The callback function assigned to the one-shot timer. In this case the
  672. * // parameter is not used.
  673. * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  674. * {
  675. * // The timer expired, therefore 5 seconds must have passed since a key
  676. * // was pressed. Switch off the LCD back-light.
  677. * vSetBacklightState( BACKLIGHT_OFF );
  678. * }
  679. *
  680. * // The key press interrupt service routine.
  681. * void vKeyPressEventInterruptHandler( void )
  682. * {
  683. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  684. *
  685. * // Ensure the LCD back-light is on, then restart the timer that is
  686. * // responsible for turning the back-light off after 5 seconds of
  687. * // key inactivity. This is an interrupt service routine so can only
  688. * // call FreeRTOS API functions that end in "FromISR".
  689. * vSetBacklightState( BACKLIGHT_ON );
  690. *
  691. * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
  692. * // as both cause the timer to re-calculate its expiry time.
  693. * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
  694. * // declared (in this function).
  695. * if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  696. * {
  697. * // The start command was not executed successfully. Take appropriate
  698. * // action here.
  699. * }
  700. *
  701. * // Perform the rest of the key processing here.
  702. *
  703. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  704. * // should be performed. The syntax required to perform a context switch
  705. * // from inside an ISR varies from port to port, and from compiler to
  706. * // compiler. Inspect the demos for the port you are using to find the
  707. * // actual syntax required.
  708. * if( xHigherPriorityTaskWoken != pdFALSE )
  709. * {
  710. * // Call the interrupt safe yield function here (actual function
  711. * // depends on the FreeRTOS port being used).
  712. * }
  713. * }
  714. * @endverbatim
  715. */
  716. #define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
  717. /**
  718. * BaseType_t xTimerStopFromISR( TimerHandle_t xTimer,
  719. * BaseType_t *pxHigherPriorityTaskWoken );
  720. *
  721. * A version of xTimerStop() that can be called from an interrupt service
  722. * routine.
  723. *
  724. * @param xTimer The handle of the timer being stopped.
  725. *
  726. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  727. * of its time in the Blocked state, waiting for messages to arrive on the timer
  728. * command queue. Calling xTimerStopFromISR() writes a message to the timer
  729. * command queue, so has the potential to transition the timer service/daemon
  730. * task out of the Blocked state. If calling xTimerStopFromISR() causes the
  731. * timer service/daemon task to leave the Blocked state, and the timer service/
  732. * daemon task has a priority equal to or greater than the currently executing
  733. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  734. * get set to pdTRUE internally within the xTimerStopFromISR() function. If
  735. * xTimerStopFromISR() sets this value to pdTRUE then a context switch should
  736. * be performed before the interrupt exits.
  737. *
  738. * @return pdFAIL will be returned if the stop command could not be sent to
  739. * the timer command queue. pdPASS will be returned if the command was
  740. * successfully sent to the timer command queue. When the command is actually
  741. * processed will depend on the priority of the timer service/daemon task
  742. * relative to other tasks in the system. The timer service/daemon task
  743. * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  744. *
  745. * Example usage:
  746. * @verbatim
  747. * // This scenario assumes xTimer has already been created and started. When
  748. * // an interrupt occurs, the timer should be simply stopped.
  749. *
  750. * // The interrupt service routine that stops the timer.
  751. * void vAnExampleInterruptServiceRoutine( void )
  752. * {
  753. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  754. *
  755. * // The interrupt has occurred - simply stop the timer.
  756. * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
  757. * // (within this function). As this is an interrupt service routine, only
  758. * // FreeRTOS API functions that end in "FromISR" can be used.
  759. * if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  760. * {
  761. * // The stop command was not executed successfully. Take appropriate
  762. * // action here.
  763. * }
  764. *
  765. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  766. * // should be performed. The syntax required to perform a context switch
  767. * // from inside an ISR varies from port to port, and from compiler to
  768. * // compiler. Inspect the demos for the port you are using to find the
  769. * // actual syntax required.
  770. * if( xHigherPriorityTaskWoken != pdFALSE )
  771. * {
  772. * // Call the interrupt safe yield function here (actual function
  773. * // depends on the FreeRTOS port being used).
  774. * }
  775. * }
  776. * @endverbatim
  777. */
  778. #define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U )
  779. /**
  780. * BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer,
  781. * TickType_t xNewPeriod,
  782. * BaseType_t *pxHigherPriorityTaskWoken );
  783. *
  784. * A version of xTimerChangePeriod() that can be called from an interrupt
  785. * service routine.
  786. *
  787. * @param xTimer The handle of the timer that is having its period changed.
  788. *
  789. * @param xNewPeriod The new period for xTimer. Timer periods are specified in
  790. * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
  791. * that has been specified in milliseconds. For example, if the timer must
  792. * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
  793. * if the timer must expire after 500ms, then xNewPeriod can be set to
  794. * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
  795. * or equal to 1000.
  796. *
  797. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  798. * of its time in the Blocked state, waiting for messages to arrive on the timer
  799. * command queue. Calling xTimerChangePeriodFromISR() writes a message to the
  800. * timer command queue, so has the potential to transition the timer service/
  801. * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR()
  802. * causes the timer service/daemon task to leave the Blocked state, and the
  803. * timer service/daemon task has a priority equal to or greater than the
  804. * currently executing task (the task that was interrupted), then
  805. * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the
  806. * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets
  807. * this value to pdTRUE then a context switch should be performed before the
  808. * interrupt exits.
  809. *
  810. * @return pdFAIL will be returned if the command to change the timers period
  811. * could not be sent to the timer command queue. pdPASS will be returned if the
  812. * command was successfully sent to the timer command queue. When the command
  813. * is actually processed will depend on the priority of the timer service/daemon
  814. * task relative to other tasks in the system. The timer service/daemon task
  815. * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  816. *
  817. * Example usage:
  818. * @verbatim
  819. * // This scenario assumes xTimer has already been created and started. When
  820. * // an interrupt occurs, the period of xTimer should be changed to 500ms.
  821. *
  822. * // The interrupt service routine that changes the period of xTimer.
  823. * void vAnExampleInterruptServiceRoutine( void )
  824. * {
  825. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  826. *
  827. * // The interrupt has occurred - change the period of xTimer to 500ms.
  828. * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
  829. * // (within this function). As this is an interrupt service routine, only
  830. * // FreeRTOS API functions that end in "FromISR" can be used.
  831. * if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  832. * {
  833. * // The command to change the timers period was not executed
  834. * // successfully. Take appropriate action here.
  835. * }
  836. *
  837. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  838. * // should be performed. The syntax required to perform a context switch
  839. * // from inside an ISR varies from port to port, and from compiler to
  840. * // compiler. Inspect the demos for the port you are using to find the
  841. * // actual syntax required.
  842. * if( xHigherPriorityTaskWoken != pdFALSE )
  843. * {
  844. * // Call the interrupt safe yield function here (actual function
  845. * // depends on the FreeRTOS port being used).
  846. * }
  847. * }
  848. * @endverbatim
  849. */
  850. #define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )
  851. /**
  852. * BaseType_t xTimerResetFromISR( TimerHandle_t xTimer,
  853. * BaseType_t *pxHigherPriorityTaskWoken );
  854. *
  855. * A version of xTimerReset() that can be called from an interrupt service
  856. * routine.
  857. *
  858. * @param xTimer The handle of the timer that is to be started, reset, or
  859. * restarted.
  860. *
  861. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  862. * of its time in the Blocked state, waiting for messages to arrive on the timer
  863. * command queue. Calling xTimerResetFromISR() writes a message to the timer
  864. * command queue, so has the potential to transition the timer service/daemon
  865. * task out of the Blocked state. If calling xTimerResetFromISR() causes the
  866. * timer service/daemon task to leave the Blocked state, and the timer service/
  867. * daemon task has a priority equal to or greater than the currently executing
  868. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  869. * get set to pdTRUE internally within the xTimerResetFromISR() function. If
  870. * xTimerResetFromISR() sets this value to pdTRUE then a context switch should
  871. * be performed before the interrupt exits.
  872. *
  873. * @return pdFAIL will be returned if the reset command could not be sent to
  874. * the timer command queue. pdPASS will be returned if the command was
  875. * successfully sent to the timer command queue. When the command is actually
  876. * processed will depend on the priority of the timer service/daemon task
  877. * relative to other tasks in the system, although the timers expiry time is
  878. * relative to when xTimerResetFromISR() is actually called. The timer service/daemon
  879. * task priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  880. *
  881. * Example usage:
  882. * @verbatim
  883. * // This scenario assumes xBacklightTimer has already been created. When a
  884. * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
  885. * // without a key being pressed, then the LCD back-light is switched off. In
  886. * // this case, the timer is a one-shot timer, and unlike the example given for
  887. * // the xTimerReset() function, the key press event handler is an interrupt
  888. * // service routine.
  889. *
  890. * // The callback function assigned to the one-shot timer. In this case the
  891. * // parameter is not used.
  892. * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  893. * {
  894. * // The timer expired, therefore 5 seconds must have passed since a key
  895. * // was pressed. Switch off the LCD back-light.
  896. * vSetBacklightState( BACKLIGHT_OFF );
  897. * }
  898. *
  899. * // The key press interrupt service routine.
  900. * void vKeyPressEventInterruptHandler( void )
  901. * {
  902. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  903. *
  904. * // Ensure the LCD back-light is on, then reset the timer that is
  905. * // responsible for turning the back-light off after 5 seconds of
  906. * // key inactivity. This is an interrupt service routine so can only
  907. * // call FreeRTOS API functions that end in "FromISR".
  908. * vSetBacklightState( BACKLIGHT_ON );
  909. *
  910. * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
  911. * // as both cause the timer to re-calculate its expiry time.
  912. * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
  913. * // declared (in this function).
  914. * if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  915. * {
  916. * // The reset command was not executed successfully. Take appropriate
  917. * // action here.
  918. * }
  919. *
  920. * // Perform the rest of the key processing here.
  921. *
  922. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  923. * // should be performed. The syntax required to perform a context switch
  924. * // from inside an ISR varies from port to port, and from compiler to
  925. * // compiler. Inspect the demos for the port you are using to find the
  926. * // actual syntax required.
  927. * if( xHigherPriorityTaskWoken != pdFALSE )
  928. * {
  929. * // Call the interrupt safe yield function here (actual function
  930. * // depends on the FreeRTOS port being used).
  931. * }
  932. * }
  933. * @endverbatim
  934. */
  935. #define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
  936. /**
  937. * BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
  938. * void *pvParameter1,
  939. * uint32_t ulParameter2,
  940. * BaseType_t *pxHigherPriorityTaskWoken );
  941. *
  942. *
  943. * Used from application interrupt service routines to defer the execution of a
  944. * function to the RTOS daemon task (the timer service task, hence this function
  945. * is implemented in timers.c and is prefixed with 'Timer').
  946. *
  947. * Ideally an interrupt service routine (ISR) is kept as short as possible, but
  948. * sometimes an ISR either has a lot of processing to do, or needs to perform
  949. * processing that is not deterministic. In these cases
  950. * xTimerPendFunctionCallFromISR() can be used to defer processing of a function
  951. * to the RTOS daemon task.
  952. *
  953. * A mechanism is provided that allows the interrupt to return directly to the
  954. * task that will subsequently execute the pended callback function. This
  955. * allows the callback function to execute contiguously in time with the
  956. * interrupt - just as if the callback had executed in the interrupt itself.
  957. *
  958. * @param xFunctionToPend The function to execute from the timer service/
  959. * daemon task. The function must conform to the PendedFunction_t
  960. * prototype.
  961. *
  962. * @param pvParameter1 The value of the callback function's first parameter.
  963. * The parameter has a void * type to allow it to be used to pass any type.
  964. * For example, unsigned longs can be cast to a void *, or the void * can be
  965. * used to point to a structure.
  966. *
  967. * @param ulParameter2 The value of the callback function's second parameter.
  968. *
  969. * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
  970. * will result in a message being sent to the timer daemon task. If the
  971. * priority of the timer daemon task (which is set using
  972. * configTIMER_TASK_PRIORITY in FreeRTOSConfig.h) is higher than the priority of
  973. * the currently running task (the task the interrupt interrupted) then
  974. * *pxHigherPriorityTaskWoken will be set to pdTRUE within
  975. * xTimerPendFunctionCallFromISR(), indicating that a context switch should be
  976. * requested before the interrupt exits. For that reason
  977. * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
  978. * example code below.
  979. *
  980. * @return pdPASS is returned if the message was successfully sent to the
  981. * timer daemon task, otherwise pdFALSE is returned.
  982. *
  983. * Example usage:
  984. * @verbatim
  985. *
  986. * // The callback function that will execute in the context of the daemon task.
  987. * // Note callback functions must all use this same prototype.
  988. * void vProcessInterface( void *pvParameter1, uint32_t ulParameter2 )
  989. * {
  990. * BaseType_t xInterfaceToService;
  991. *
  992. * // The interface that requires servicing is passed in the second
  993. * // parameter. The first parameter is not used in this case.
  994. * xInterfaceToService = ( BaseType_t ) ulParameter2;
  995. *
  996. * // ...Perform the processing here...
  997. * }
  998. *
  999. * // An ISR that receives data packets from multiple interfaces
  1000. * void vAnISR( void )
  1001. * {
  1002. * BaseType_t xInterfaceToService, xHigherPriorityTaskWoken;
  1003. *
  1004. * // Query the hardware to determine which interface needs processing.
  1005. * xInterfaceToService = prvCheckInterfaces();
  1006. *
  1007. * // The actual processing is to be deferred to a task. Request the
  1008. * // vProcessInterface() callback function is executed, passing in the
  1009. * // number of the interface that needs processing. The interface to
  1010. * // service is passed in the second parameter. The first parameter is
  1011. * // not used in this case.
  1012. * xHigherPriorityTaskWoken = pdFALSE;
  1013. * xTimerPendFunctionCallFromISR( vProcessInterface, NULL, ( uint32_t ) xInterfaceToService, &xHigherPriorityTaskWoken );
  1014. *
  1015. * // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
  1016. * // switch should be requested. The macro used is port specific and will
  1017. * // be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to
  1018. * // the documentation page for the port being used.
  1019. * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  1020. *
  1021. * }
  1022. * @endverbatim
  1023. */
  1024. BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken );
  1025. /**
  1026. * BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
  1027. * void *pvParameter1,
  1028. * uint32_t ulParameter2,
  1029. * TickType_t xTicksToWait );
  1030. *
  1031. *
  1032. * Used to defer the execution of a function to the RTOS daemon task (the timer
  1033. * service task, hence this function is implemented in timers.c and is prefixed
  1034. * with 'Timer').
  1035. *
  1036. * @param xFunctionToPend The function to execute from the timer service/
  1037. * daemon task. The function must conform to the PendedFunction_t
  1038. * prototype.
  1039. *
  1040. * @param pvParameter1 The value of the callback function's first parameter.
  1041. * The parameter has a void * type to allow it to be used to pass any type.
  1042. * For example, unsigned longs can be cast to a void *, or the void * can be
  1043. * used to point to a structure.
  1044. *
  1045. * @param ulParameter2 The value of the callback function's second parameter.
  1046. *
  1047. * @param xTicksToWait Calling this function will result in a message being
  1048. * sent to the timer daemon task on a queue. xTicksToWait is the amount of
  1049. * time the calling task should remain in the Blocked state (so not using any
  1050. * processing time) for space to become available on the timer queue if the
  1051. * queue is found to be full.
  1052. *
  1053. * @return pdPASS is returned if the message was successfully sent to the
  1054. * timer daemon task, otherwise pdFALSE is returned.
  1055. *
  1056. */
  1057. BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait );
  1058. /**
  1059. * const char * const pcTimerGetTimerName( TimerHandle_t xTimer );
  1060. *
  1061. * Returns the name that was assigned to a timer when the timer was created.
  1062. *
  1063. * @param xTimer The handle of the timer being queried.
  1064. *
  1065. * @return The name assigned to the timer specified by the xTimer parameter.
  1066. */
  1067. const char * pcTimerGetTimerName( TimerHandle_t xTimer ); /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1068. /*
  1069. * Functions beyond this part are not part of the public API and are intended
  1070. * for use by the kernel only.
  1071. */
  1072. BaseType_t xTimerCreateTimerTask( void ) PRIVILEGED_FUNCTION;
  1073. BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  1074. #ifdef __cplusplus
  1075. }
  1076. #endif
  1077. #endif /* TIMERS_H */