timers.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. /*
  2. FreeRTOS V8.2.3 - 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, and by calling the
  241. * vTimerSetTimerID() API function.
  242. *
  243. * If the same callback function is assigned to multiple timers then the timer
  244. * ID can be used as time specific (timer local) storage.
  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( const TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
  255. /**
  256. * void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID );
  257. *
  258. * Sets the ID assigned to the timer.
  259. *
  260. * IDs are assigned to timers using the pvTimerID parameter of the call to
  261. * xTimerCreated() that was used to create the timer.
  262. *
  263. * If the same callback function is assigned to multiple timers then the timer
  264. * ID can be used as time specific (timer local) storage.
  265. *
  266. * @param xTimer The timer being updated.
  267. *
  268. * @param pvNewID The ID to assign to the timer.
  269. *
  270. * Example usage:
  271. *
  272. * See the xTimerCreate() API function example usage scenario.
  273. */
  274. void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID ) PRIVILEGED_FUNCTION;
  275. /**
  276. * BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer );
  277. *
  278. * Queries a timer to see if it is active or dormant.
  279. *
  280. * A timer will be dormant if:
  281. * 1) It has been created but not started, or
  282. * 2) It is an expired one-shot timer that has not been restarted.
  283. *
  284. * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  285. * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  286. * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the
  287. * active state.
  288. *
  289. * @param xTimer The timer being queried.
  290. *
  291. * @return pdFALSE will be returned if the timer is dormant. A value other than
  292. * pdFALSE will be returned if the timer is active.
  293. *
  294. * Example usage:
  295. * @verbatim
  296. * // This function assumes xTimer has already been created.
  297. * void vAFunction( TimerHandle_t xTimer )
  298. * {
  299. * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
  300. * {
  301. * // xTimer is active, do something.
  302. * }
  303. * else
  304. * {
  305. * // xTimer is not active, do something else.
  306. * }
  307. * }
  308. * @endverbatim
  309. */
  310. BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
  311. /**
  312. * TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
  313. *
  314. * xTimerGetTimerDaemonTaskHandle() is only available if
  315. * INCLUDE_xTimerGetTimerDaemonTaskHandle is set to 1 in FreeRTOSConfig.h.
  316. *
  317. * Simply returns the handle of the timer service/daemon task. It it not valid
  318. * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started.
  319. */
  320. TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ) PRIVILEGED_FUNCTION;
  321. /**
  322. * BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xTicksToWait );
  323. *
  324. * Timer functionality is provided by a timer service/daemon task. Many of the
  325. * public FreeRTOS timer API functions send commands to the timer service task
  326. * through a queue called the timer command queue. The timer command queue is
  327. * private to the kernel itself and is not directly accessible to application
  328. * code. The length of the timer command queue is set by the
  329. * configTIMER_QUEUE_LENGTH configuration constant.
  330. *
  331. * xTimerStart() starts a timer that was previously created using the
  332. * xTimerCreate() API function. If the timer had already been started and was
  333. * already in the active state, then xTimerStart() has equivalent functionality
  334. * to the xTimerReset() API function.
  335. *
  336. * Starting a timer ensures the timer is in the active state. If the timer
  337. * is not stopped, deleted, or reset in the mean time, the callback function
  338. * associated with the timer will get called 'n' ticks after xTimerStart() was
  339. * called, where 'n' is the timers defined period.
  340. *
  341. * It is valid to call xTimerStart() before the scheduler has been started, but
  342. * when this is done the timer will not actually start until the scheduler is
  343. * started, and the timers expiry time will be relative to when the scheduler is
  344. * started, not relative to when xTimerStart() was called.
  345. *
  346. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart()
  347. * to be available.
  348. *
  349. * @param xTimer The handle of the timer being started/restarted.
  350. *
  351. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  352. * be held in the Blocked state to wait for the start command to be successfully
  353. * sent to the timer command queue, should the queue already be full when
  354. * xTimerStart() was called. xTicksToWait is ignored if xTimerStart() is called
  355. * before the scheduler is started.
  356. *
  357. * @return pdFAIL will be returned if the start command could not be sent to
  358. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  359. * be returned if the command was successfully sent to the timer command queue.
  360. * When the command is actually processed will depend on the priority of the
  361. * timer service/daemon task relative to other tasks in the system, although the
  362. * timers expiry time is relative to when xTimerStart() is actually called. The
  363. * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  364. * configuration constant.
  365. *
  366. * Example usage:
  367. *
  368. * See the xTimerCreate() API function example usage scenario.
  369. *
  370. */
  371. #define xTimerStart( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
  372. /**
  373. * BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xTicksToWait );
  374. *
  375. * Timer functionality is provided by a timer service/daemon task. Many of the
  376. * public FreeRTOS timer API functions send commands to the timer service task
  377. * through a queue called the timer command queue. The timer command queue is
  378. * private to the kernel itself and is not directly accessible to application
  379. * code. The length of the timer command queue is set by the
  380. * configTIMER_QUEUE_LENGTH configuration constant.
  381. *
  382. * xTimerStop() stops a timer that was previously started using either of the
  383. * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(),
  384. * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions.
  385. *
  386. * Stopping a timer ensures the timer is not in the active state.
  387. *
  388. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop()
  389. * to be available.
  390. *
  391. * @param xTimer The handle of the timer being stopped.
  392. *
  393. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  394. * be held in the Blocked state to wait for the stop command to be successfully
  395. * sent to the timer command queue, should the queue already be full when
  396. * xTimerStop() was called. xTicksToWait is ignored if xTimerStop() is called
  397. * before the scheduler is started.
  398. *
  399. * @return pdFAIL will be returned if the stop command could not be sent to
  400. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  401. * be returned if the command was successfully sent to the timer command queue.
  402. * When the command is actually processed will depend on the priority of the
  403. * timer service/daemon task relative to other tasks in the system. The timer
  404. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  405. * configuration constant.
  406. *
  407. * Example usage:
  408. *
  409. * See the xTimerCreate() API function example usage scenario.
  410. *
  411. */
  412. #define xTimerStop( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )
  413. /**
  414. * BaseType_t xTimerChangePeriod( TimerHandle_t xTimer,
  415. * TickType_t xNewPeriod,
  416. * TickType_t xTicksToWait );
  417. *
  418. * Timer functionality is provided by a timer service/daemon task. Many of the
  419. * public FreeRTOS timer API functions send commands to the timer service task
  420. * through a queue called the timer command queue. The timer command queue is
  421. * private to the kernel itself and is not directly accessible to application
  422. * code. The length of the timer command queue is set by the
  423. * configTIMER_QUEUE_LENGTH configuration constant.
  424. *
  425. * xTimerChangePeriod() changes the period of a timer that was previously
  426. * created using the xTimerCreate() API function.
  427. *
  428. * xTimerChangePeriod() can be called to change the period of an active or
  429. * dormant state timer.
  430. *
  431. * The configUSE_TIMERS configuration constant must be set to 1 for
  432. * xTimerChangePeriod() to be available.
  433. *
  434. * @param xTimer The handle of the timer that is having its period changed.
  435. *
  436. * @param xNewPeriod The new period for xTimer. Timer periods are specified in
  437. * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
  438. * that has been specified in milliseconds. For example, if the timer must
  439. * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
  440. * if the timer must expire after 500ms, then xNewPeriod can be set to
  441. * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
  442. * or equal to 1000.
  443. *
  444. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  445. * be held in the Blocked state to wait for the change period command to be
  446. * successfully sent to the timer command queue, should the queue already be
  447. * full when xTimerChangePeriod() was called. xTicksToWait is ignored if
  448. * xTimerChangePeriod() is called before the scheduler is started.
  449. *
  450. * @return pdFAIL will be returned if the change period command could not be
  451. * sent to the timer command queue even after xTicksToWait ticks had passed.
  452. * pdPASS will be returned if the command was successfully sent to the timer
  453. * command queue. When the command is actually processed will depend on the
  454. * priority of the timer service/daemon task relative to other tasks in the
  455. * system. The timer service/daemon task priority is set by the
  456. * configTIMER_TASK_PRIORITY configuration constant.
  457. *
  458. * Example usage:
  459. * @verbatim
  460. * // This function assumes xTimer has already been created. If the timer
  461. * // referenced by xTimer is already active when it is called, then the timer
  462. * // is deleted. If the timer referenced by xTimer is not active when it is
  463. * // called, then the period of the timer is set to 500ms and the timer is
  464. * // started.
  465. * void vAFunction( TimerHandle_t xTimer )
  466. * {
  467. * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
  468. * {
  469. * // xTimer is already active - delete it.
  470. * xTimerDelete( xTimer );
  471. * }
  472. * else
  473. * {
  474. * // xTimer is not active, change its period to 500ms. This will also
  475. * // cause the timer to start. Block for a maximum of 100 ticks if the
  476. * // change period command cannot immediately be sent to the timer
  477. * // command queue.
  478. * if( xTimerChangePeriod( xTimer, 500 / portTICK_PERIOD_MS, 100 ) == pdPASS )
  479. * {
  480. * // The command was successfully sent.
  481. * }
  482. * else
  483. * {
  484. * // The command could not be sent, even after waiting for 100 ticks
  485. * // to pass. Take appropriate action here.
  486. * }
  487. * }
  488. * }
  489. * @endverbatim
  490. */
  491. #define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) )
  492. /**
  493. * BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait );
  494. *
  495. * Timer functionality is provided by a timer service/daemon task. Many of the
  496. * public FreeRTOS timer API functions send commands to the timer service task
  497. * through a queue called the timer command queue. The timer command queue is
  498. * private to the kernel itself and is not directly accessible to application
  499. * code. The length of the timer command queue is set by the
  500. * configTIMER_QUEUE_LENGTH configuration constant.
  501. *
  502. * xTimerDelete() deletes a timer that was previously created using the
  503. * xTimerCreate() API function.
  504. *
  505. * The configUSE_TIMERS configuration constant must be set to 1 for
  506. * xTimerDelete() to be available.
  507. *
  508. * @param xTimer The handle of the timer being deleted.
  509. *
  510. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  511. * be held in the Blocked state to wait for the delete command to be
  512. * successfully sent to the timer command queue, should the queue already be
  513. * full when xTimerDelete() was called. xTicksToWait is ignored if xTimerDelete()
  514. * is called before the scheduler is started.
  515. *
  516. * @return pdFAIL will be returned if the delete command could not be sent to
  517. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  518. * be returned if the command was successfully sent to the timer command queue.
  519. * When the command is actually processed will depend on the priority of the
  520. * timer service/daemon task relative to other tasks in the system. The timer
  521. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  522. * configuration constant.
  523. *
  524. * Example usage:
  525. *
  526. * See the xTimerChangePeriod() API function example usage scenario.
  527. */
  528. #define xTimerDelete( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
  529. /**
  530. * BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait );
  531. *
  532. * Timer functionality is provided by a timer service/daemon task. Many of the
  533. * public FreeRTOS timer API functions send commands to the timer service task
  534. * through a queue called the timer command queue. The timer command queue is
  535. * private to the kernel itself and is not directly accessible to application
  536. * code. The length of the timer command queue is set by the
  537. * configTIMER_QUEUE_LENGTH configuration constant.
  538. *
  539. * xTimerReset() re-starts a timer that was previously created using the
  540. * xTimerCreate() API function. If the timer had already been started and was
  541. * already in the active state, then xTimerReset() will cause the timer to
  542. * re-evaluate its expiry time so that it is relative to when xTimerReset() was
  543. * called. If the timer was in the dormant state then xTimerReset() has
  544. * equivalent functionality to the xTimerStart() API function.
  545. *
  546. * Resetting a timer ensures the timer is in the active state. If the timer
  547. * is not stopped, deleted, or reset in the mean time, the callback function
  548. * associated with the timer will get called 'n' ticks after xTimerReset() was
  549. * called, where 'n' is the timers defined period.
  550. *
  551. * It is valid to call xTimerReset() before the scheduler has been started, but
  552. * when this is done the timer will not actually start until the scheduler is
  553. * started, and the timers expiry time will be relative to when the scheduler is
  554. * started, not relative to when xTimerReset() was called.
  555. *
  556. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset()
  557. * to be available.
  558. *
  559. * @param xTimer The handle of the timer being reset/started/restarted.
  560. *
  561. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  562. * be held in the Blocked state to wait for the reset command to be successfully
  563. * sent to the timer command queue, should the queue already be full when
  564. * xTimerReset() was called. xTicksToWait is ignored if xTimerReset() is called
  565. * before the scheduler is started.
  566. *
  567. * @return pdFAIL will be returned if the reset command could not be sent to
  568. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  569. * be returned if the command was successfully sent to the timer command queue.
  570. * When the command is actually processed will depend on the priority of the
  571. * timer service/daemon task relative to other tasks in the system, although the
  572. * timers expiry time is relative to when xTimerStart() is actually called. The
  573. * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  574. * configuration constant.
  575. *
  576. * Example usage:
  577. * @verbatim
  578. * // When a key is pressed, an LCD back-light is switched on. If 5 seconds pass
  579. * // without a key being pressed, then the LCD back-light is switched off. In
  580. * // this case, the timer is a one-shot timer.
  581. *
  582. * TimerHandle_t xBacklightTimer = NULL;
  583. *
  584. * // The callback function assigned to the one-shot timer. In this case the
  585. * // parameter is not used.
  586. * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  587. * {
  588. * // The timer expired, therefore 5 seconds must have passed since a key
  589. * // was pressed. Switch off the LCD back-light.
  590. * vSetBacklightState( BACKLIGHT_OFF );
  591. * }
  592. *
  593. * // The key press event handler.
  594. * void vKeyPressEventHandler( char cKey )
  595. * {
  596. * // Ensure the LCD back-light is on, then reset the timer that is
  597. * // responsible for turning the back-light off after 5 seconds of
  598. * // key inactivity. Wait 10 ticks for the command to be successfully sent
  599. * // if it cannot be sent immediately.
  600. * vSetBacklightState( BACKLIGHT_ON );
  601. * if( xTimerReset( xBacklightTimer, 100 ) != pdPASS )
  602. * {
  603. * // The reset command was not executed successfully. Take appropriate
  604. * // action here.
  605. * }
  606. *
  607. * // Perform the rest of the key processing here.
  608. * }
  609. *
  610. * void main( void )
  611. * {
  612. * int32_t x;
  613. *
  614. * // Create then start the one-shot timer that is responsible for turning
  615. * // the back-light off if no keys are pressed within a 5 second period.
  616. * xBacklightTimer = xTimerCreate( "BacklightTimer", // Just a text name, not used by the kernel.
  617. * ( 5000 / portTICK_PERIOD_MS), // The timer period in ticks.
  618. * pdFALSE, // The timer is a one-shot timer.
  619. * 0, // The id is not used by the callback so can take any value.
  620. * vBacklightTimerCallback // The callback function that switches the LCD back-light off.
  621. * );
  622. *
  623. * if( xBacklightTimer == NULL )
  624. * {
  625. * // The timer was not created.
  626. * }
  627. * else
  628. * {
  629. * // Start the timer. No block time is specified, and even if one was
  630. * // it would be ignored because the scheduler has not yet been
  631. * // started.
  632. * if( xTimerStart( xBacklightTimer, 0 ) != pdPASS )
  633. * {
  634. * // The timer could not be set into the Active state.
  635. * }
  636. * }
  637. *
  638. * // ...
  639. * // Create tasks here.
  640. * // ...
  641. *
  642. * // Starting the scheduler will start the timer running as it has already
  643. * // been set into the active state.
  644. * xTaskStartScheduler();
  645. *
  646. * // Should not reach here.
  647. * for( ;; );
  648. * }
  649. * @endverbatim
  650. */
  651. #define xTimerReset( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
  652. /**
  653. * BaseType_t xTimerStartFromISR( TimerHandle_t xTimer,
  654. * BaseType_t *pxHigherPriorityTaskWoken );
  655. *
  656. * A version of xTimerStart() that can be called from an interrupt service
  657. * routine.
  658. *
  659. * @param xTimer The handle of the timer being started/restarted.
  660. *
  661. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  662. * of its time in the Blocked state, waiting for messages to arrive on the timer
  663. * command queue. Calling xTimerStartFromISR() writes a message to the timer
  664. * command queue, so has the potential to transition the timer service/daemon
  665. * task out of the Blocked state. If calling xTimerStartFromISR() causes the
  666. * timer service/daemon task to leave the Blocked state, and the timer service/
  667. * daemon task has a priority equal to or greater than the currently executing
  668. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  669. * get set to pdTRUE internally within the xTimerStartFromISR() function. If
  670. * xTimerStartFromISR() sets this value to pdTRUE then a context switch should
  671. * be performed before the interrupt exits.
  672. *
  673. * @return pdFAIL will be returned if the start command could not be sent to
  674. * the timer command queue. pdPASS will be returned if the command was
  675. * successfully sent to the timer command queue. When the command is actually
  676. * processed will depend on the priority of the timer service/daemon task
  677. * relative to other tasks in the system, although the timers expiry time is
  678. * relative to when xTimerStartFromISR() is actually called. The timer
  679. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  680. * configuration constant.
  681. *
  682. * Example usage:
  683. * @verbatim
  684. * // This scenario assumes xBacklightTimer has already been created. When a
  685. * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
  686. * // without a key being pressed, then the LCD back-light is switched off. In
  687. * // this case, the timer is a one-shot timer, and unlike the example given for
  688. * // the xTimerReset() function, the key press event handler is an interrupt
  689. * // service routine.
  690. *
  691. * // The callback function assigned to the one-shot timer. In this case the
  692. * // parameter is not used.
  693. * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  694. * {
  695. * // The timer expired, therefore 5 seconds must have passed since a key
  696. * // was pressed. Switch off the LCD back-light.
  697. * vSetBacklightState( BACKLIGHT_OFF );
  698. * }
  699. *
  700. * // The key press interrupt service routine.
  701. * void vKeyPressEventInterruptHandler( void )
  702. * {
  703. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  704. *
  705. * // Ensure the LCD back-light is on, then restart the timer that is
  706. * // responsible for turning the back-light off after 5 seconds of
  707. * // key inactivity. This is an interrupt service routine so can only
  708. * // call FreeRTOS API functions that end in "FromISR".
  709. * vSetBacklightState( BACKLIGHT_ON );
  710. *
  711. * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
  712. * // as both cause the timer to re-calculate its expiry time.
  713. * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
  714. * // declared (in this function).
  715. * if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  716. * {
  717. * // The start command was not executed successfully. Take appropriate
  718. * // action here.
  719. * }
  720. *
  721. * // Perform the rest of the key processing here.
  722. *
  723. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  724. * // should be performed. The syntax required to perform a context switch
  725. * // from inside an ISR varies from port to port, and from compiler to
  726. * // compiler. Inspect the demos for the port you are using to find the
  727. * // actual syntax required.
  728. * if( xHigherPriorityTaskWoken != pdFALSE )
  729. * {
  730. * // Call the interrupt safe yield function here (actual function
  731. * // depends on the FreeRTOS port being used).
  732. * }
  733. * }
  734. * @endverbatim
  735. */
  736. #define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
  737. /**
  738. * BaseType_t xTimerStopFromISR( TimerHandle_t xTimer,
  739. * BaseType_t *pxHigherPriorityTaskWoken );
  740. *
  741. * A version of xTimerStop() that can be called from an interrupt service
  742. * routine.
  743. *
  744. * @param xTimer The handle of the timer being stopped.
  745. *
  746. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  747. * of its time in the Blocked state, waiting for messages to arrive on the timer
  748. * command queue. Calling xTimerStopFromISR() writes a message to the timer
  749. * command queue, so has the potential to transition the timer service/daemon
  750. * task out of the Blocked state. If calling xTimerStopFromISR() causes the
  751. * timer service/daemon task to leave the Blocked state, and the timer service/
  752. * daemon task has a priority equal to or greater than the currently executing
  753. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  754. * get set to pdTRUE internally within the xTimerStopFromISR() function. If
  755. * xTimerStopFromISR() sets this value to pdTRUE then a context switch should
  756. * be performed before the interrupt exits.
  757. *
  758. * @return pdFAIL will be returned if the stop command could not be sent to
  759. * the timer command queue. pdPASS will be returned if the command was
  760. * successfully sent to the timer command queue. When the command is actually
  761. * processed will depend on the priority of the timer service/daemon task
  762. * relative to other tasks in the system. The timer service/daemon task
  763. * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  764. *
  765. * Example usage:
  766. * @verbatim
  767. * // This scenario assumes xTimer has already been created and started. When
  768. * // an interrupt occurs, the timer should be simply stopped.
  769. *
  770. * // The interrupt service routine that stops the timer.
  771. * void vAnExampleInterruptServiceRoutine( void )
  772. * {
  773. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  774. *
  775. * // The interrupt has occurred - simply stop the timer.
  776. * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
  777. * // (within this function). As this is an interrupt service routine, only
  778. * // FreeRTOS API functions that end in "FromISR" can be used.
  779. * if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  780. * {
  781. * // The stop command was not executed successfully. Take appropriate
  782. * // action here.
  783. * }
  784. *
  785. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  786. * // should be performed. The syntax required to perform a context switch
  787. * // from inside an ISR varies from port to port, and from compiler to
  788. * // compiler. Inspect the demos for the port you are using to find the
  789. * // actual syntax required.
  790. * if( xHigherPriorityTaskWoken != pdFALSE )
  791. * {
  792. * // Call the interrupt safe yield function here (actual function
  793. * // depends on the FreeRTOS port being used).
  794. * }
  795. * }
  796. * @endverbatim
  797. */
  798. #define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U )
  799. /**
  800. * BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer,
  801. * TickType_t xNewPeriod,
  802. * BaseType_t *pxHigherPriorityTaskWoken );
  803. *
  804. * A version of xTimerChangePeriod() that can be called from an interrupt
  805. * service routine.
  806. *
  807. * @param xTimer The handle of the timer that is having its period changed.
  808. *
  809. * @param xNewPeriod The new period for xTimer. Timer periods are specified in
  810. * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
  811. * that has been specified in milliseconds. For example, if the timer must
  812. * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
  813. * if the timer must expire after 500ms, then xNewPeriod can be set to
  814. * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
  815. * or equal to 1000.
  816. *
  817. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  818. * of its time in the Blocked state, waiting for messages to arrive on the timer
  819. * command queue. Calling xTimerChangePeriodFromISR() writes a message to the
  820. * timer command queue, so has the potential to transition the timer service/
  821. * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR()
  822. * causes the timer service/daemon task to leave the Blocked state, and the
  823. * timer service/daemon task has a priority equal to or greater than the
  824. * currently executing task (the task that was interrupted), then
  825. * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the
  826. * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets
  827. * this value to pdTRUE then a context switch should be performed before the
  828. * interrupt exits.
  829. *
  830. * @return pdFAIL will be returned if the command to change the timers period
  831. * could not be sent to the timer command queue. pdPASS will be returned if the
  832. * command was successfully sent to the timer command queue. When the command
  833. * is actually processed will depend on the priority of the timer service/daemon
  834. * task relative to other tasks in the system. The timer service/daemon task
  835. * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  836. *
  837. * Example usage:
  838. * @verbatim
  839. * // This scenario assumes xTimer has already been created and started. When
  840. * // an interrupt occurs, the period of xTimer should be changed to 500ms.
  841. *
  842. * // The interrupt service routine that changes the period of xTimer.
  843. * void vAnExampleInterruptServiceRoutine( void )
  844. * {
  845. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  846. *
  847. * // The interrupt has occurred - change the period of xTimer to 500ms.
  848. * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
  849. * // (within this function). As this is an interrupt service routine, only
  850. * // FreeRTOS API functions that end in "FromISR" can be used.
  851. * if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  852. * {
  853. * // The command to change the timers period was not executed
  854. * // successfully. Take appropriate action here.
  855. * }
  856. *
  857. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  858. * // should be performed. The syntax required to perform a context switch
  859. * // from inside an ISR varies from port to port, and from compiler to
  860. * // compiler. Inspect the demos for the port you are using to find the
  861. * // actual syntax required.
  862. * if( xHigherPriorityTaskWoken != pdFALSE )
  863. * {
  864. * // Call the interrupt safe yield function here (actual function
  865. * // depends on the FreeRTOS port being used).
  866. * }
  867. * }
  868. * @endverbatim
  869. */
  870. #define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )
  871. /**
  872. * BaseType_t xTimerResetFromISR( TimerHandle_t xTimer,
  873. * BaseType_t *pxHigherPriorityTaskWoken );
  874. *
  875. * A version of xTimerReset() that can be called from an interrupt service
  876. * routine.
  877. *
  878. * @param xTimer The handle of the timer that is to be started, reset, or
  879. * restarted.
  880. *
  881. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  882. * of its time in the Blocked state, waiting for messages to arrive on the timer
  883. * command queue. Calling xTimerResetFromISR() writes a message to the timer
  884. * command queue, so has the potential to transition the timer service/daemon
  885. * task out of the Blocked state. If calling xTimerResetFromISR() causes the
  886. * timer service/daemon task to leave the Blocked state, and the timer service/
  887. * daemon task has a priority equal to or greater than the currently executing
  888. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  889. * get set to pdTRUE internally within the xTimerResetFromISR() function. If
  890. * xTimerResetFromISR() sets this value to pdTRUE then a context switch should
  891. * be performed before the interrupt exits.
  892. *
  893. * @return pdFAIL will be returned if the reset command could not be sent to
  894. * the timer command queue. pdPASS will be returned if the command was
  895. * successfully sent to the timer command queue. When the command is actually
  896. * processed will depend on the priority of the timer service/daemon task
  897. * relative to other tasks in the system, although the timers expiry time is
  898. * relative to when xTimerResetFromISR() is actually called. The timer service/daemon
  899. * task priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  900. *
  901. * Example usage:
  902. * @verbatim
  903. * // This scenario assumes xBacklightTimer has already been created. When a
  904. * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
  905. * // without a key being pressed, then the LCD back-light is switched off. In
  906. * // this case, the timer is a one-shot timer, and unlike the example given for
  907. * // the xTimerReset() function, the key press event handler is an interrupt
  908. * // service routine.
  909. *
  910. * // The callback function assigned to the one-shot timer. In this case the
  911. * // parameter is not used.
  912. * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  913. * {
  914. * // The timer expired, therefore 5 seconds must have passed since a key
  915. * // was pressed. Switch off the LCD back-light.
  916. * vSetBacklightState( BACKLIGHT_OFF );
  917. * }
  918. *
  919. * // The key press interrupt service routine.
  920. * void vKeyPressEventInterruptHandler( void )
  921. * {
  922. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  923. *
  924. * // Ensure the LCD back-light is on, then reset the timer that is
  925. * // responsible for turning the back-light off after 5 seconds of
  926. * // key inactivity. This is an interrupt service routine so can only
  927. * // call FreeRTOS API functions that end in "FromISR".
  928. * vSetBacklightState( BACKLIGHT_ON );
  929. *
  930. * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
  931. * // as both cause the timer to re-calculate its expiry time.
  932. * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
  933. * // declared (in this function).
  934. * if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  935. * {
  936. * // The reset command was not executed successfully. Take appropriate
  937. * // action here.
  938. * }
  939. *
  940. * // Perform the rest of the key processing here.
  941. *
  942. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  943. * // should be performed. The syntax required to perform a context switch
  944. * // from inside an ISR varies from port to port, and from compiler to
  945. * // compiler. Inspect the demos for the port you are using to find the
  946. * // actual syntax required.
  947. * if( xHigherPriorityTaskWoken != pdFALSE )
  948. * {
  949. * // Call the interrupt safe yield function here (actual function
  950. * // depends on the FreeRTOS port being used).
  951. * }
  952. * }
  953. * @endverbatim
  954. */
  955. #define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
  956. /**
  957. * BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
  958. * void *pvParameter1,
  959. * uint32_t ulParameter2,
  960. * BaseType_t *pxHigherPriorityTaskWoken );
  961. *
  962. *
  963. * Used from application interrupt service routines to defer the execution of a
  964. * function to the RTOS daemon task (the timer service task, hence this function
  965. * is implemented in timers.c and is prefixed with 'Timer').
  966. *
  967. * Ideally an interrupt service routine (ISR) is kept as short as possible, but
  968. * sometimes an ISR either has a lot of processing to do, or needs to perform
  969. * processing that is not deterministic. In these cases
  970. * xTimerPendFunctionCallFromISR() can be used to defer processing of a function
  971. * to the RTOS daemon task.
  972. *
  973. * A mechanism is provided that allows the interrupt to return directly to the
  974. * task that will subsequently execute the pended callback function. This
  975. * allows the callback function to execute contiguously in time with the
  976. * interrupt - just as if the callback had executed in the interrupt itself.
  977. *
  978. * @param xFunctionToPend The function to execute from the timer service/
  979. * daemon task. The function must conform to the PendedFunction_t
  980. * prototype.
  981. *
  982. * @param pvParameter1 The value of the callback function's first parameter.
  983. * The parameter has a void * type to allow it to be used to pass any type.
  984. * For example, unsigned longs can be cast to a void *, or the void * can be
  985. * used to point to a structure.
  986. *
  987. * @param ulParameter2 The value of the callback function's second parameter.
  988. *
  989. * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
  990. * will result in a message being sent to the timer daemon task. If the
  991. * priority of the timer daemon task (which is set using
  992. * configTIMER_TASK_PRIORITY in FreeRTOSConfig.h) is higher than the priority of
  993. * the currently running task (the task the interrupt interrupted) then
  994. * *pxHigherPriorityTaskWoken will be set to pdTRUE within
  995. * xTimerPendFunctionCallFromISR(), indicating that a context switch should be
  996. * requested before the interrupt exits. For that reason
  997. * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
  998. * example code below.
  999. *
  1000. * @return pdPASS is returned if the message was successfully sent to the
  1001. * timer daemon task, otherwise pdFALSE is returned.
  1002. *
  1003. * Example usage:
  1004. * @verbatim
  1005. *
  1006. * // The callback function that will execute in the context of the daemon task.
  1007. * // Note callback functions must all use this same prototype.
  1008. * void vProcessInterface( void *pvParameter1, uint32_t ulParameter2 )
  1009. * {
  1010. * BaseType_t xInterfaceToService;
  1011. *
  1012. * // The interface that requires servicing is passed in the second
  1013. * // parameter. The first parameter is not used in this case.
  1014. * xInterfaceToService = ( BaseType_t ) ulParameter2;
  1015. *
  1016. * // ...Perform the processing here...
  1017. * }
  1018. *
  1019. * // An ISR that receives data packets from multiple interfaces
  1020. * void vAnISR( void )
  1021. * {
  1022. * BaseType_t xInterfaceToService, xHigherPriorityTaskWoken;
  1023. *
  1024. * // Query the hardware to determine which interface needs processing.
  1025. * xInterfaceToService = prvCheckInterfaces();
  1026. *
  1027. * // The actual processing is to be deferred to a task. Request the
  1028. * // vProcessInterface() callback function is executed, passing in the
  1029. * // number of the interface that needs processing. The interface to
  1030. * // service is passed in the second parameter. The first parameter is
  1031. * // not used in this case.
  1032. * xHigherPriorityTaskWoken = pdFALSE;
  1033. * xTimerPendFunctionCallFromISR( vProcessInterface, NULL, ( uint32_t ) xInterfaceToService, &xHigherPriorityTaskWoken );
  1034. *
  1035. * // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
  1036. * // switch should be requested. The macro used is port specific and will
  1037. * // be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to
  1038. * // the documentation page for the port being used.
  1039. * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  1040. *
  1041. * }
  1042. * @endverbatim
  1043. */
  1044. BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  1045. /**
  1046. * BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
  1047. * void *pvParameter1,
  1048. * uint32_t ulParameter2,
  1049. * TickType_t xTicksToWait );
  1050. *
  1051. *
  1052. * Used to defer the execution of a function to the RTOS daemon task (the timer
  1053. * service task, hence this function is implemented in timers.c and is prefixed
  1054. * with 'Timer').
  1055. *
  1056. * @param xFunctionToPend The function to execute from the timer service/
  1057. * daemon task. The function must conform to the PendedFunction_t
  1058. * prototype.
  1059. *
  1060. * @param pvParameter1 The value of the callback function's first parameter.
  1061. * The parameter has a void * type to allow it to be used to pass any type.
  1062. * For example, unsigned longs can be cast to a void *, or the void * can be
  1063. * used to point to a structure.
  1064. *
  1065. * @param ulParameter2 The value of the callback function's second parameter.
  1066. *
  1067. * @param xTicksToWait Calling this function will result in a message being
  1068. * sent to the timer daemon task on a queue. xTicksToWait is the amount of
  1069. * time the calling task should remain in the Blocked state (so not using any
  1070. * processing time) for space to become available on the timer queue if the
  1071. * queue is found to be full.
  1072. *
  1073. * @return pdPASS is returned if the message was successfully sent to the
  1074. * timer daemon task, otherwise pdFALSE is returned.
  1075. *
  1076. */
  1077. BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  1078. /**
  1079. * const char * const pcTimerGetTimerName( TimerHandle_t xTimer );
  1080. *
  1081. * Returns the name that was assigned to a timer when the timer was created.
  1082. *
  1083. * @param xTimer The handle of the timer being queried.
  1084. *
  1085. * @return The name assigned to the timer specified by the xTimer parameter.
  1086. */
  1087. const char * pcTimerGetTimerName( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1088. /*
  1089. * Functions beyond this part are not part of the public API and are intended
  1090. * for use by the kernel only.
  1091. */
  1092. BaseType_t xTimerCreateTimerTask( void ) PRIVILEGED_FUNCTION;
  1093. BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  1094. #ifdef __cplusplus
  1095. }
  1096. #endif
  1097. #endif /* TIMERS_H */