timers.h 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. #ifndef TIMERS_H
  29. #define TIMERS_H
  30. #ifndef INC_FREERTOS_H
  31. #error "include FreeRTOS.h must appear in source files before include timers.h"
  32. #endif
  33. #include "task.h"
  34. /* *INDENT-OFF* */
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /* *INDENT-ON* */
  39. /*-----------------------------------------------------------
  40. * MACROS AND DEFINITIONS
  41. *----------------------------------------------------------*/
  42. /* IDs for commands that can be sent/received on the timer queue. These are to
  43. * be used solely through the macros that make up the public software timer API,
  44. * as defined below. The commands that are sent from interrupts must use the
  45. * highest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task
  46. * or interrupt version of the queue send function should be used. */
  47. #define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 )
  48. #define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 )
  49. #define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 )
  50. #define tmrCOMMAND_START ( ( BaseType_t ) 1 )
  51. #define tmrCOMMAND_RESET ( ( BaseType_t ) 2 )
  52. #define tmrCOMMAND_STOP ( ( BaseType_t ) 3 )
  53. #define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 )
  54. #define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 )
  55. #define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 )
  56. #define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 )
  57. #define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 )
  58. #define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 )
  59. #define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 )
  60. /**
  61. * Type by which software timers are referenced. For example, a call to
  62. * xTimerCreate() returns an TimerHandle_t variable that can then be used to
  63. * reference the subject timer in calls to other software timer API functions
  64. * (for example, xTimerStart(), xTimerReset(), etc.).
  65. */
  66. struct tmrTimerControl; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
  67. typedef struct tmrTimerControl * TimerHandle_t;
  68. /*
  69. * Defines the prototype to which timer callback functions must conform.
  70. */
  71. typedef void (* TimerCallbackFunction_t)( TimerHandle_t xTimer );
  72. /**
  73. * TimerHandle_t xTimerCreate( const char * const pcTimerName,
  74. * TickType_t xTimerPeriodInTicks,
  75. * UBaseType_t uxAutoReload,
  76. * void * pvTimerID,
  77. * TimerCallbackFunction_t pxCallbackFunction );
  78. *
  79. * Creates a new software timer instance, and returns a handle by which the
  80. * created software timer can be referenced.
  81. *
  82. * Internally, within the FreeRTOS implementation, software timers use a block
  83. * of memory, in which the timer data structure is stored. If a software timer
  84. * is created using xTimerCreate() then the required memory is automatically
  85. * dynamically allocated inside the xTimerCreate() function. (see
  86. * https://www.FreeRTOS.org/a00111.html). If a software timer is created using
  87. * xTimerCreateStatic() then the application writer must provide the memory that
  88. * will get used by the software timer. xTimerCreateStatic() therefore allows a
  89. * software timer to be created without using any dynamic memory allocation.
  90. *
  91. * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  92. * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  93. * xTimerChangePeriodFromISR() API functions can all be used to transition a
  94. * timer into the active state.
  95. *
  96. * @param pcTimerName A text name that is assigned to the timer. This is done
  97. * purely to assist debugging. The kernel itself only ever references a timer
  98. * by its handle, and never by its name.
  99. *
  100. * @param xTimerPeriodInTicks The timer period. The time is defined in tick
  101. * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
  102. * has been specified in milliseconds. For example, if the timer must expire
  103. * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
  104. * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
  105. * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
  106. * equal to 1000. Time timer period must be greater than 0.
  107. *
  108. * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
  109. * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
  110. * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
  111. * enter the dormant state after it expires.
  112. *
  113. * @param pvTimerID An identifier that is assigned to the timer being created.
  114. * Typically this would be used in the timer callback function to identify which
  115. * timer expired when the same callback function is assigned to more than one
  116. * timer.
  117. *
  118. * @param pxCallbackFunction The function to call when the timer expires.
  119. * Callback functions must have the prototype defined by TimerCallbackFunction_t,
  120. * which is "void vCallbackFunction( TimerHandle_t xTimer );".
  121. *
  122. * @return If the timer is successfully created then a handle to the newly
  123. * created timer is returned. If the timer cannot be created because there is
  124. * insufficient FreeRTOS heap remaining to allocate the timer
  125. * structures then NULL is returned.
  126. *
  127. * Example usage:
  128. * @verbatim
  129. * #define NUM_TIMERS 5
  130. *
  131. * // An array to hold handles to the created timers.
  132. * TimerHandle_t xTimers[ NUM_TIMERS ];
  133. *
  134. * // An array to hold a count of the number of times each timer expires.
  135. * int32_t lExpireCounters[ NUM_TIMERS ] = { 0 };
  136. *
  137. * // Define a callback function that will be used by multiple timer instances.
  138. * // The callback function does nothing but count the number of times the
  139. * // associated timer expires, and stop the timer once the timer has expired
  140. * // 10 times.
  141. * void vTimerCallback( TimerHandle_t pxTimer )
  142. * {
  143. * int32_t lArrayIndex;
  144. * const int32_t xMaxExpiryCountBeforeStopping = 10;
  145. *
  146. * // Optionally do something if the pxTimer parameter is NULL.
  147. * configASSERT( pxTimer );
  148. *
  149. * // Which timer expired?
  150. * lArrayIndex = ( int32_t ) pvTimerGetTimerID( pxTimer );
  151. *
  152. * // Increment the number of times that pxTimer has expired.
  153. * lExpireCounters[ lArrayIndex ] += 1;
  154. *
  155. * // If the timer has expired 10 times then stop it from running.
  156. * if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping )
  157. * {
  158. * // Do not use a block time if calling a timer API function from a
  159. * // timer callback function, as doing so could cause a deadlock!
  160. * xTimerStop( pxTimer, 0 );
  161. * }
  162. * }
  163. *
  164. * void main( void )
  165. * {
  166. * int32_t x;
  167. *
  168. * // Create then start some timers. Starting the timers before the scheduler
  169. * // has been started means the timers will start running immediately that
  170. * // the scheduler starts.
  171. * for( x = 0; x < NUM_TIMERS; x++ )
  172. * {
  173. * xTimers[ x ] = xTimerCreate( "Timer", // Just a text name, not used by the kernel.
  174. * ( 100 * x ), // The timer period in ticks.
  175. * pdTRUE, // The timers will auto-reload themselves when they expire.
  176. * ( void * ) x, // Assign each timer a unique id equal to its array index.
  177. * vTimerCallback // Each timer calls the same callback when it expires.
  178. * );
  179. *
  180. * if( xTimers[ x ] == NULL )
  181. * {
  182. * // The timer was not created.
  183. * }
  184. * else
  185. * {
  186. * // Start the timer. No block time is specified, and even if one was
  187. * // it would be ignored because the scheduler has not yet been
  188. * // started.
  189. * if( xTimerStart( xTimers[ x ], 0 ) != pdPASS )
  190. * {
  191. * // The timer could not be set into the Active state.
  192. * }
  193. * }
  194. * }
  195. *
  196. * // ...
  197. * // Create tasks here.
  198. * // ...
  199. *
  200. * // Starting the scheduler will start the timers running as they have already
  201. * // been set into the active state.
  202. * vTaskStartScheduler();
  203. *
  204. * // Should not reach here.
  205. * for( ;; );
  206. * }
  207. * @endverbatim
  208. */
  209. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  210. TimerHandle_t xTimerCreate( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  211. const TickType_t xTimerPeriodInTicks,
  212. const UBaseType_t uxAutoReload,
  213. void * const pvTimerID,
  214. TimerCallbackFunction_t pxCallbackFunction );
  215. #endif
  216. /**
  217. * TimerHandle_t xTimerCreateStatic(const char * const pcTimerName,
  218. * TickType_t xTimerPeriodInTicks,
  219. * UBaseType_t uxAutoReload,
  220. * void * pvTimerID,
  221. * TimerCallbackFunction_t pxCallbackFunction,
  222. * StaticTimer_t *pxTimerBuffer );
  223. *
  224. * Creates a new software timer instance, and returns a handle by which the
  225. * created software timer can be referenced.
  226. *
  227. * Internally, within the FreeRTOS implementation, software timers use a block
  228. * of memory, in which the timer data structure is stored. If a software timer
  229. * is created using xTimerCreate() then the required memory is automatically
  230. * dynamically allocated inside the xTimerCreate() function. (see
  231. * https://www.FreeRTOS.org/a00111.html). If a software timer is created using
  232. * xTimerCreateStatic() then the application writer must provide the memory that
  233. * will get used by the software timer. xTimerCreateStatic() therefore allows a
  234. * software timer to be created without using any dynamic memory allocation.
  235. *
  236. * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  237. * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  238. * xTimerChangePeriodFromISR() API functions can all be used to transition a
  239. * timer into the active state.
  240. *
  241. * @param pcTimerName A text name that is assigned to the timer. This is done
  242. * purely to assist debugging. The kernel itself only ever references a timer
  243. * by its handle, and never by its name.
  244. *
  245. * @param xTimerPeriodInTicks The timer period. The time is defined in tick
  246. * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
  247. * has been specified in milliseconds. For example, if the timer must expire
  248. * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
  249. * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
  250. * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
  251. * equal to 1000. The timer period must be greater than 0.
  252. *
  253. * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
  254. * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
  255. * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
  256. * enter the dormant state after it expires.
  257. *
  258. * @param pvTimerID An identifier that is assigned to the timer being created.
  259. * Typically this would be used in the timer callback function to identify which
  260. * timer expired when the same callback function is assigned to more than one
  261. * timer.
  262. *
  263. * @param pxCallbackFunction The function to call when the timer expires.
  264. * Callback functions must have the prototype defined by TimerCallbackFunction_t,
  265. * which is "void vCallbackFunction( TimerHandle_t xTimer );".
  266. *
  267. * @param pxTimerBuffer Must point to a variable of type StaticTimer_t, which
  268. * will be then be used to hold the software timer's data structures, removing
  269. * the need for the memory to be allocated dynamically.
  270. *
  271. * @return If the timer is created then a handle to the created timer is
  272. * returned. If pxTimerBuffer was NULL then NULL is returned.
  273. *
  274. * Example usage:
  275. * @verbatim
  276. *
  277. * // The buffer used to hold the software timer's data structure.
  278. * static StaticTimer_t xTimerBuffer;
  279. *
  280. * // A variable that will be incremented by the software timer's callback
  281. * // function.
  282. * UBaseType_t uxVariableToIncrement = 0;
  283. *
  284. * // A software timer callback function that increments a variable passed to
  285. * // it when the software timer was created. After the 5th increment the
  286. * // callback function stops the software timer.
  287. * static void prvTimerCallback( TimerHandle_t xExpiredTimer )
  288. * {
  289. * UBaseType_t *puxVariableToIncrement;
  290. * BaseType_t xReturned;
  291. *
  292. * // Obtain the address of the variable to increment from the timer ID.
  293. * puxVariableToIncrement = ( UBaseType_t * ) pvTimerGetTimerID( xExpiredTimer );
  294. *
  295. * // Increment the variable to show the timer callback has executed.
  296. * ( *puxVariableToIncrement )++;
  297. *
  298. * // If this callback has executed the required number of times, stop the
  299. * // timer.
  300. * if( *puxVariableToIncrement == 5 )
  301. * {
  302. * // This is called from a timer callback so must not block.
  303. * xTimerStop( xExpiredTimer, staticDONT_BLOCK );
  304. * }
  305. * }
  306. *
  307. *
  308. * void main( void )
  309. * {
  310. * // Create the software time. xTimerCreateStatic() has an extra parameter
  311. * // than the normal xTimerCreate() API function. The parameter is a pointer
  312. * // to the StaticTimer_t structure that will hold the software timer
  313. * // structure. If the parameter is passed as NULL then the structure will be
  314. * // allocated dynamically, just as if xTimerCreate() had been called.
  315. * xTimer = xTimerCreateStatic( "T1", // Text name for the task. Helps debugging only. Not used by FreeRTOS.
  316. * xTimerPeriod, // The period of the timer in ticks.
  317. * pdTRUE, // This is an auto-reload timer.
  318. * ( void * ) &uxVariableToIncrement, // A variable incremented by the software timer's callback function
  319. * prvTimerCallback, // The function to execute when the timer expires.
  320. * &xTimerBuffer ); // The buffer that will hold the software timer structure.
  321. *
  322. * // The scheduler has not started yet so a block time is not used.
  323. * xReturned = xTimerStart( xTimer, 0 );
  324. *
  325. * // ...
  326. * // Create tasks here.
  327. * // ...
  328. *
  329. * // Starting the scheduler will start the timers running as they have already
  330. * // been set into the active state.
  331. * vTaskStartScheduler();
  332. *
  333. * // Should not reach here.
  334. * for( ;; );
  335. * }
  336. * @endverbatim
  337. */
  338. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  339. TimerHandle_t xTimerCreateStatic( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  340. const TickType_t xTimerPeriodInTicks,
  341. const UBaseType_t uxAutoReload,
  342. void * const pvTimerID,
  343. TimerCallbackFunction_t pxCallbackFunction,
  344. StaticTimer_t * pxTimerBuffer );
  345. #endif /* configSUPPORT_STATIC_ALLOCATION */
  346. /**
  347. * void *pvTimerGetTimerID( TimerHandle_t xTimer );
  348. *
  349. * Returns the ID assigned to the timer.
  350. *
  351. * IDs are assigned to timers using the pvTimerID parameter of the call to
  352. * xTimerCreated() that was used to create the timer, and by calling the
  353. * vTimerSetTimerID() API function.
  354. *
  355. * If the same callback function is assigned to multiple timers then the timer
  356. * ID can be used as time specific (timer local) storage.
  357. *
  358. * @param xTimer The timer being queried.
  359. *
  360. * @return The ID assigned to the timer being queried.
  361. *
  362. * Example usage:
  363. *
  364. * See the xTimerCreate() API function example usage scenario.
  365. */
  366. void * pvTimerGetTimerID( const TimerHandle_t xTimer );
  367. /**
  368. * void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID );
  369. *
  370. * Sets the ID assigned to the timer.
  371. *
  372. * IDs are assigned to timers using the pvTimerID parameter of the call to
  373. * xTimerCreated() that was used to create the timer.
  374. *
  375. * If the same callback function is assigned to multiple timers then the timer
  376. * ID can be used as time specific (timer local) storage.
  377. *
  378. * @param xTimer The timer being updated.
  379. *
  380. * @param pvNewID The ID to assign to the timer.
  381. *
  382. * Example usage:
  383. *
  384. * See the xTimerCreate() API function example usage scenario.
  385. */
  386. void vTimerSetTimerID( TimerHandle_t xTimer,
  387. void * pvNewID );
  388. /**
  389. * BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer );
  390. *
  391. * Queries a timer to see if it is active or dormant.
  392. *
  393. * A timer will be dormant if:
  394. * 1) It has been created but not started, or
  395. * 2) It is an expired one-shot timer that has not been restarted.
  396. *
  397. * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  398. * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  399. * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the
  400. * active state.
  401. *
  402. * @param xTimer The timer being queried.
  403. *
  404. * @return pdFALSE will be returned if the timer is dormant. A value other than
  405. * pdFALSE will be returned if the timer is active.
  406. *
  407. * Example usage:
  408. * @verbatim
  409. * // This function assumes xTimer has already been created.
  410. * void vAFunction( TimerHandle_t xTimer )
  411. * {
  412. * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
  413. * {
  414. * // xTimer is active, do something.
  415. * }
  416. * else
  417. * {
  418. * // xTimer is not active, do something else.
  419. * }
  420. * }
  421. * @endverbatim
  422. */
  423. BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer );
  424. /**
  425. * TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
  426. *
  427. * Simply returns the handle of the timer service/daemon task. It it not valid
  428. * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started.
  429. */
  430. TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
  431. /**
  432. * BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xTicksToWait );
  433. *
  434. * Timer functionality is provided by a timer service/daemon task. Many of the
  435. * public FreeRTOS timer API functions send commands to the timer service task
  436. * through a queue called the timer command queue. The timer command queue is
  437. * private to the kernel itself and is not directly accessible to application
  438. * code. The length of the timer command queue is set by the
  439. * configTIMER_QUEUE_LENGTH configuration constant.
  440. *
  441. * xTimerStart() starts a timer that was previously created using the
  442. * xTimerCreate() API function. If the timer had already been started and was
  443. * already in the active state, then xTimerStart() has equivalent functionality
  444. * to the xTimerReset() API function.
  445. *
  446. * Starting a timer ensures the timer is in the active state. If the timer
  447. * is not stopped, deleted, or reset in the mean time, the callback function
  448. * associated with the timer will get called 'n' ticks after xTimerStart() was
  449. * called, where 'n' is the timers defined period.
  450. *
  451. * It is valid to call xTimerStart() before the scheduler has been started, but
  452. * when this is done the timer will not actually start until the scheduler is
  453. * started, and the timers expiry time will be relative to when the scheduler is
  454. * started, not relative to when xTimerStart() was called.
  455. *
  456. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart()
  457. * to be available.
  458. *
  459. * @param xTimer The handle of the timer being started/restarted.
  460. *
  461. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  462. * be held in the Blocked state to wait for the start command to be successfully
  463. * sent to the timer command queue, should the queue already be full when
  464. * xTimerStart() was called. xTicksToWait is ignored if xTimerStart() is called
  465. * before the scheduler is started.
  466. *
  467. * @return pdFAIL will be returned if the start command could not be sent to
  468. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  469. * be returned if the command was successfully sent to the timer command queue.
  470. * When the command is actually processed will depend on the priority of the
  471. * timer service/daemon task relative to other tasks in the system, although the
  472. * timers expiry time is relative to when xTimerStart() is actually called. The
  473. * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  474. * configuration constant.
  475. *
  476. * Example usage:
  477. *
  478. * See the xTimerCreate() API function example usage scenario.
  479. *
  480. */
  481. #define xTimerStart( xTimer, xTicksToWait ) \
  482. xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
  483. /**
  484. * BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xTicksToWait );
  485. *
  486. * Timer functionality is provided by a timer service/daemon task. Many of the
  487. * public FreeRTOS timer API functions send commands to the timer service task
  488. * through a queue called the timer command queue. The timer command queue is
  489. * private to the kernel itself and is not directly accessible to application
  490. * code. The length of the timer command queue is set by the
  491. * configTIMER_QUEUE_LENGTH configuration constant.
  492. *
  493. * xTimerStop() stops a timer that was previously started using either of the
  494. * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(),
  495. * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions.
  496. *
  497. * Stopping a timer ensures the timer is not in the active state.
  498. *
  499. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop()
  500. * to be available.
  501. *
  502. * @param xTimer The handle of the timer being stopped.
  503. *
  504. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  505. * be held in the Blocked state to wait for the stop command to be successfully
  506. * sent to the timer command queue, should the queue already be full when
  507. * xTimerStop() was called. xTicksToWait is ignored if xTimerStop() is called
  508. * before the scheduler is started.
  509. *
  510. * @return pdFAIL will be returned if the stop command could not be sent to
  511. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  512. * be returned if the command was successfully sent to the timer command queue.
  513. * When the command is actually processed will depend on the priority of the
  514. * timer service/daemon task relative to other tasks in the system. The timer
  515. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  516. * configuration constant.
  517. *
  518. * Example usage:
  519. *
  520. * See the xTimerCreate() API function example usage scenario.
  521. *
  522. */
  523. #define xTimerStop( xTimer, xTicksToWait ) \
  524. xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )
  525. /**
  526. * BaseType_t xTimerChangePeriod( TimerHandle_t xTimer,
  527. * TickType_t xNewPeriod,
  528. * TickType_t xTicksToWait );
  529. *
  530. * Timer functionality is provided by a timer service/daemon task. Many of the
  531. * public FreeRTOS timer API functions send commands to the timer service task
  532. * through a queue called the timer command queue. The timer command queue is
  533. * private to the kernel itself and is not directly accessible to application
  534. * code. The length of the timer command queue is set by the
  535. * configTIMER_QUEUE_LENGTH configuration constant.
  536. *
  537. * xTimerChangePeriod() changes the period of a timer that was previously
  538. * created using the xTimerCreate() API function.
  539. *
  540. * xTimerChangePeriod() can be called to change the period of an active or
  541. * dormant state timer.
  542. *
  543. * The configUSE_TIMERS configuration constant must be set to 1 for
  544. * xTimerChangePeriod() to be available.
  545. *
  546. * @param xTimer The handle of the timer that is having its period changed.
  547. *
  548. * @param xNewPeriod The new period for xTimer. Timer periods are specified in
  549. * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
  550. * that has been specified in milliseconds. For example, if the timer must
  551. * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
  552. * if the timer must expire after 500ms, then xNewPeriod can be set to
  553. * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
  554. * or equal to 1000.
  555. *
  556. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  557. * be held in the Blocked state to wait for the change period command to be
  558. * successfully sent to the timer command queue, should the queue already be
  559. * full when xTimerChangePeriod() was called. xTicksToWait is ignored if
  560. * xTimerChangePeriod() is called before the scheduler is started.
  561. *
  562. * @return pdFAIL will be returned if the change period command could not be
  563. * sent to the timer command queue even after xTicksToWait ticks had passed.
  564. * pdPASS will be returned if the command was successfully sent to the timer
  565. * command queue. When the command is actually processed will depend on the
  566. * priority of the timer service/daemon task relative to other tasks in the
  567. * system. The timer service/daemon task priority is set by the
  568. * configTIMER_TASK_PRIORITY configuration constant.
  569. *
  570. * Example usage:
  571. * @verbatim
  572. * // This function assumes xTimer has already been created. If the timer
  573. * // referenced by xTimer is already active when it is called, then the timer
  574. * // is deleted. If the timer referenced by xTimer is not active when it is
  575. * // called, then the period of the timer is set to 500ms and the timer is
  576. * // started.
  577. * void vAFunction( TimerHandle_t xTimer )
  578. * {
  579. * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
  580. * {
  581. * // xTimer is already active - delete it.
  582. * xTimerDelete( xTimer );
  583. * }
  584. * else
  585. * {
  586. * // xTimer is not active, change its period to 500ms. This will also
  587. * // cause the timer to start. Block for a maximum of 100 ticks if the
  588. * // change period command cannot immediately be sent to the timer
  589. * // command queue.
  590. * if( xTimerChangePeriod( xTimer, 500 / portTICK_PERIOD_MS, 100 ) == pdPASS )
  591. * {
  592. * // The command was successfully sent.
  593. * }
  594. * else
  595. * {
  596. * // The command could not be sent, even after waiting for 100 ticks
  597. * // to pass. Take appropriate action here.
  598. * }
  599. * }
  600. * }
  601. * @endverbatim
  602. */
  603. #define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) \
  604. xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) )
  605. /**
  606. * BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait );
  607. *
  608. * Timer functionality is provided by a timer service/daemon task. Many of the
  609. * public FreeRTOS timer API functions send commands to the timer service task
  610. * through a queue called the timer command queue. The timer command queue is
  611. * private to the kernel itself and is not directly accessible to application
  612. * code. The length of the timer command queue is set by the
  613. * configTIMER_QUEUE_LENGTH configuration constant.
  614. *
  615. * xTimerDelete() deletes a timer that was previously created using the
  616. * xTimerCreate() API function.
  617. *
  618. * The configUSE_TIMERS configuration constant must be set to 1 for
  619. * xTimerDelete() to be available.
  620. *
  621. * @param xTimer The handle of the timer being deleted.
  622. *
  623. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  624. * be held in the Blocked state to wait for the delete command to be
  625. * successfully sent to the timer command queue, should the queue already be
  626. * full when xTimerDelete() was called. xTicksToWait is ignored if xTimerDelete()
  627. * is called before the scheduler is started.
  628. *
  629. * @return pdFAIL will be returned if the delete command could not be sent to
  630. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  631. * be returned if the command was successfully sent to the timer command queue.
  632. * When the command is actually processed will depend on the priority of the
  633. * timer service/daemon task relative to other tasks in the system. The timer
  634. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  635. * configuration constant.
  636. *
  637. * Example usage:
  638. *
  639. * See the xTimerChangePeriod() API function example usage scenario.
  640. */
  641. #define xTimerDelete( xTimer, xTicksToWait ) \
  642. xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
  643. /**
  644. * BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait );
  645. *
  646. * Timer functionality is provided by a timer service/daemon task. Many of the
  647. * public FreeRTOS timer API functions send commands to the timer service task
  648. * through a queue called the timer command queue. The timer command queue is
  649. * private to the kernel itself and is not directly accessible to application
  650. * code. The length of the timer command queue is set by the
  651. * configTIMER_QUEUE_LENGTH configuration constant.
  652. *
  653. * xTimerReset() re-starts a timer that was previously created using the
  654. * xTimerCreate() API function. If the timer had already been started and was
  655. * already in the active state, then xTimerReset() will cause the timer to
  656. * re-evaluate its expiry time so that it is relative to when xTimerReset() was
  657. * called. If the timer was in the dormant state then xTimerReset() has
  658. * equivalent functionality to the xTimerStart() API function.
  659. *
  660. * Resetting a timer ensures the timer is in the active state. If the timer
  661. * is not stopped, deleted, or reset in the mean time, the callback function
  662. * associated with the timer will get called 'n' ticks after xTimerReset() was
  663. * called, where 'n' is the timers defined period.
  664. *
  665. * It is valid to call xTimerReset() before the scheduler has been started, but
  666. * when this is done the timer will not actually start until the scheduler is
  667. * started, and the timers expiry time will be relative to when the scheduler is
  668. * started, not relative to when xTimerReset() was called.
  669. *
  670. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset()
  671. * to be available.
  672. *
  673. * @param xTimer The handle of the timer being reset/started/restarted.
  674. *
  675. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  676. * be held in the Blocked state to wait for the reset command to be successfully
  677. * sent to the timer command queue, should the queue already be full when
  678. * xTimerReset() was called. xTicksToWait is ignored if xTimerReset() is called
  679. * before the scheduler is started.
  680. *
  681. * @return pdFAIL will be returned if the reset command could not be sent to
  682. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  683. * be returned if the command was successfully sent to the timer command queue.
  684. * When the command is actually processed will depend on the priority of the
  685. * timer service/daemon task relative to other tasks in the system, although the
  686. * timers expiry time is relative to when xTimerStart() is actually called. The
  687. * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  688. * configuration constant.
  689. *
  690. * Example usage:
  691. * @verbatim
  692. * // When a key is pressed, an LCD back-light is switched on. If 5 seconds pass
  693. * // without a key being pressed, then the LCD back-light is switched off. In
  694. * // this case, the timer is a one-shot timer.
  695. *
  696. * TimerHandle_t xBacklightTimer = NULL;
  697. *
  698. * // The callback function assigned to the one-shot timer. In this case the
  699. * // parameter is not used.
  700. * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  701. * {
  702. * // The timer expired, therefore 5 seconds must have passed since a key
  703. * // was pressed. Switch off the LCD back-light.
  704. * vSetBacklightState( BACKLIGHT_OFF );
  705. * }
  706. *
  707. * // The key press event handler.
  708. * void vKeyPressEventHandler( char cKey )
  709. * {
  710. * // Ensure the LCD back-light is on, then reset the timer that is
  711. * // responsible for turning the back-light off after 5 seconds of
  712. * // key inactivity. Wait 10 ticks for the command to be successfully sent
  713. * // if it cannot be sent immediately.
  714. * vSetBacklightState( BACKLIGHT_ON );
  715. * if( xTimerReset( xBacklightTimer, 100 ) != pdPASS )
  716. * {
  717. * // The reset command was not executed successfully. Take appropriate
  718. * // action here.
  719. * }
  720. *
  721. * // Perform the rest of the key processing here.
  722. * }
  723. *
  724. * void main( void )
  725. * {
  726. * int32_t x;
  727. *
  728. * // Create then start the one-shot timer that is responsible for turning
  729. * // the back-light off if no keys are pressed within a 5 second period.
  730. * xBacklightTimer = xTimerCreate( "BacklightTimer", // Just a text name, not used by the kernel.
  731. * ( 5000 / portTICK_PERIOD_MS), // The timer period in ticks.
  732. * pdFALSE, // The timer is a one-shot timer.
  733. * 0, // The id is not used by the callback so can take any value.
  734. * vBacklightTimerCallback // The callback function that switches the LCD back-light off.
  735. * );
  736. *
  737. * if( xBacklightTimer == NULL )
  738. * {
  739. * // The timer was not created.
  740. * }
  741. * else
  742. * {
  743. * // Start the timer. No block time is specified, and even if one was
  744. * // it would be ignored because the scheduler has not yet been
  745. * // started.
  746. * if( xTimerStart( xBacklightTimer, 0 ) != pdPASS )
  747. * {
  748. * // The timer could not be set into the Active state.
  749. * }
  750. * }
  751. *
  752. * // ...
  753. * // Create tasks here.
  754. * // ...
  755. *
  756. * // Starting the scheduler will start the timer running as it has already
  757. * // been set into the active state.
  758. * vTaskStartScheduler();
  759. *
  760. * // Should not reach here.
  761. * for( ;; );
  762. * }
  763. * @endverbatim
  764. */
  765. #define xTimerReset( xTimer, xTicksToWait ) \
  766. xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
  767. /**
  768. * BaseType_t xTimerStartFromISR( TimerHandle_t xTimer,
  769. * BaseType_t *pxHigherPriorityTaskWoken );
  770. *
  771. * A version of xTimerStart() that can be called from an interrupt service
  772. * routine.
  773. *
  774. * @param xTimer The handle of the timer being started/restarted.
  775. *
  776. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  777. * of its time in the Blocked state, waiting for messages to arrive on the timer
  778. * command queue. Calling xTimerStartFromISR() writes a message to the timer
  779. * command queue, so has the potential to transition the timer service/daemon
  780. * task out of the Blocked state. If calling xTimerStartFromISR() causes the
  781. * timer service/daemon task to leave the Blocked state, and the timer service/
  782. * daemon task has a priority equal to or greater than the currently executing
  783. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  784. * get set to pdTRUE internally within the xTimerStartFromISR() function. If
  785. * xTimerStartFromISR() sets this value to pdTRUE then a context switch should
  786. * be performed before the interrupt exits.
  787. *
  788. * @return pdFAIL will be returned if the start command could not be sent to
  789. * the timer command queue. pdPASS will be returned if the command was
  790. * successfully sent to the timer command queue. When the command is actually
  791. * processed will depend on the priority of the timer service/daemon task
  792. * relative to other tasks in the system, although the timers expiry time is
  793. * relative to when xTimerStartFromISR() is actually called. The timer
  794. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  795. * configuration constant.
  796. *
  797. * Example usage:
  798. * @verbatim
  799. * // This scenario assumes xBacklightTimer has already been created. When a
  800. * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
  801. * // without a key being pressed, then the LCD back-light is switched off. In
  802. * // this case, the timer is a one-shot timer, and unlike the example given for
  803. * // the xTimerReset() function, the key press event handler is an interrupt
  804. * // service routine.
  805. *
  806. * // The callback function assigned to the one-shot timer. In this case the
  807. * // parameter is not used.
  808. * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  809. * {
  810. * // The timer expired, therefore 5 seconds must have passed since a key
  811. * // was pressed. Switch off the LCD back-light.
  812. * vSetBacklightState( BACKLIGHT_OFF );
  813. * }
  814. *
  815. * // The key press interrupt service routine.
  816. * void vKeyPressEventInterruptHandler( void )
  817. * {
  818. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  819. *
  820. * // Ensure the LCD back-light is on, then restart the timer that is
  821. * // responsible for turning the back-light off after 5 seconds of
  822. * // key inactivity. This is an interrupt service routine so can only
  823. * // call FreeRTOS API functions that end in "FromISR".
  824. * vSetBacklightState( BACKLIGHT_ON );
  825. *
  826. * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
  827. * // as both cause the timer to re-calculate its expiry time.
  828. * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
  829. * // declared (in this function).
  830. * if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  831. * {
  832. * // The start command was not executed successfully. Take appropriate
  833. * // action here.
  834. * }
  835. *
  836. * // Perform the rest of the key processing here.
  837. *
  838. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  839. * // should be performed. The syntax required to perform a context switch
  840. * // from inside an ISR varies from port to port, and from compiler to
  841. * // compiler. Inspect the demos for the port you are using to find the
  842. * // actual syntax required.
  843. * if( xHigherPriorityTaskWoken != pdFALSE )
  844. * {
  845. * // Call the interrupt safe yield function here (actual function
  846. * // depends on the FreeRTOS port being used).
  847. * }
  848. * }
  849. * @endverbatim
  850. */
  851. #define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) \
  852. xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
  853. /**
  854. * BaseType_t xTimerStopFromISR( TimerHandle_t xTimer,
  855. * BaseType_t *pxHigherPriorityTaskWoken );
  856. *
  857. * A version of xTimerStop() that can be called from an interrupt service
  858. * routine.
  859. *
  860. * @param xTimer The handle of the timer being stopped.
  861. *
  862. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  863. * of its time in the Blocked state, waiting for messages to arrive on the timer
  864. * command queue. Calling xTimerStopFromISR() writes a message to the timer
  865. * command queue, so has the potential to transition the timer service/daemon
  866. * task out of the Blocked state. If calling xTimerStopFromISR() causes the
  867. * timer service/daemon task to leave the Blocked state, and the timer service/
  868. * daemon task has a priority equal to or greater than the currently executing
  869. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  870. * get set to pdTRUE internally within the xTimerStopFromISR() function. If
  871. * xTimerStopFromISR() sets this value to pdTRUE then a context switch should
  872. * be performed before the interrupt exits.
  873. *
  874. * @return pdFAIL will be returned if the stop command could not be sent to
  875. * the timer command queue. pdPASS will be returned if the command was
  876. * successfully sent to the timer command queue. When the command is actually
  877. * processed will depend on the priority of the timer service/daemon task
  878. * relative to other tasks in the system. The timer service/daemon task
  879. * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  880. *
  881. * Example usage:
  882. * @verbatim
  883. * // This scenario assumes xTimer has already been created and started. When
  884. * // an interrupt occurs, the timer should be simply stopped.
  885. *
  886. * // The interrupt service routine that stops the timer.
  887. * void vAnExampleInterruptServiceRoutine( void )
  888. * {
  889. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  890. *
  891. * // The interrupt has occurred - simply stop the timer.
  892. * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
  893. * // (within this function). As this is an interrupt service routine, only
  894. * // FreeRTOS API functions that end in "FromISR" can be used.
  895. * if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  896. * {
  897. * // The stop command was not executed successfully. Take appropriate
  898. * // action here.
  899. * }
  900. *
  901. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  902. * // should be performed. The syntax required to perform a context switch
  903. * // from inside an ISR varies from port to port, and from compiler to
  904. * // compiler. Inspect the demos for the port you are using to find the
  905. * // actual syntax required.
  906. * if( xHigherPriorityTaskWoken != pdFALSE )
  907. * {
  908. * // Call the interrupt safe yield function here (actual function
  909. * // depends on the FreeRTOS port being used).
  910. * }
  911. * }
  912. * @endverbatim
  913. */
  914. #define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) \
  915. xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U )
  916. /**
  917. * BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer,
  918. * TickType_t xNewPeriod,
  919. * BaseType_t *pxHigherPriorityTaskWoken );
  920. *
  921. * A version of xTimerChangePeriod() that can be called from an interrupt
  922. * service routine.
  923. *
  924. * @param xTimer The handle of the timer that is having its period changed.
  925. *
  926. * @param xNewPeriod The new period for xTimer. Timer periods are specified in
  927. * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
  928. * that has been specified in milliseconds. For example, if the timer must
  929. * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
  930. * if the timer must expire after 500ms, then xNewPeriod can be set to
  931. * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
  932. * or equal to 1000.
  933. *
  934. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  935. * of its time in the Blocked state, waiting for messages to arrive on the timer
  936. * command queue. Calling xTimerChangePeriodFromISR() writes a message to the
  937. * timer command queue, so has the potential to transition the timer service/
  938. * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR()
  939. * causes the timer service/daemon task to leave the Blocked state, and the
  940. * timer service/daemon task has a priority equal to or greater than the
  941. * currently executing task (the task that was interrupted), then
  942. * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the
  943. * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets
  944. * this value to pdTRUE then a context switch should be performed before the
  945. * interrupt exits.
  946. *
  947. * @return pdFAIL will be returned if the command to change the timers period
  948. * could not be sent to the timer command queue. pdPASS will be returned if the
  949. * command was successfully sent to the timer command queue. When the command
  950. * is actually processed will depend on the priority of the timer service/daemon
  951. * task relative to other tasks in the system. The timer service/daemon task
  952. * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  953. *
  954. * Example usage:
  955. * @verbatim
  956. * // This scenario assumes xTimer has already been created and started. When
  957. * // an interrupt occurs, the period of xTimer should be changed to 500ms.
  958. *
  959. * // The interrupt service routine that changes the period of xTimer.
  960. * void vAnExampleInterruptServiceRoutine( void )
  961. * {
  962. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  963. *
  964. * // The interrupt has occurred - change the period of xTimer to 500ms.
  965. * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
  966. * // (within this function). As this is an interrupt service routine, only
  967. * // FreeRTOS API functions that end in "FromISR" can be used.
  968. * if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  969. * {
  970. * // The command to change the timers period was not executed
  971. * // successfully. Take appropriate action here.
  972. * }
  973. *
  974. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  975. * // should be performed. The syntax required to perform a context switch
  976. * // from inside an ISR varies from port to port, and from compiler to
  977. * // compiler. Inspect the demos for the port you are using to find the
  978. * // actual syntax required.
  979. * if( xHigherPriorityTaskWoken != pdFALSE )
  980. * {
  981. * // Call the interrupt safe yield function here (actual function
  982. * // depends on the FreeRTOS port being used).
  983. * }
  984. * }
  985. * @endverbatim
  986. */
  987. #define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) \
  988. xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )
  989. /**
  990. * BaseType_t xTimerResetFromISR( TimerHandle_t xTimer,
  991. * BaseType_t *pxHigherPriorityTaskWoken );
  992. *
  993. * A version of xTimerReset() that can be called from an interrupt service
  994. * routine.
  995. *
  996. * @param xTimer The handle of the timer that is to be started, reset, or
  997. * restarted.
  998. *
  999. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  1000. * of its time in the Blocked state, waiting for messages to arrive on the timer
  1001. * command queue. Calling xTimerResetFromISR() writes a message to the timer
  1002. * command queue, so has the potential to transition the timer service/daemon
  1003. * task out of the Blocked state. If calling xTimerResetFromISR() causes the
  1004. * timer service/daemon task to leave the Blocked state, and the timer service/
  1005. * daemon task has a priority equal to or greater than the currently executing
  1006. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  1007. * get set to pdTRUE internally within the xTimerResetFromISR() function. If
  1008. * xTimerResetFromISR() sets this value to pdTRUE then a context switch should
  1009. * be performed before the interrupt exits.
  1010. *
  1011. * @return pdFAIL will be returned if the reset command could not be sent to
  1012. * the timer command queue. pdPASS will be returned if the command was
  1013. * successfully sent to the timer command queue. When the command is actually
  1014. * processed will depend on the priority of the timer service/daemon task
  1015. * relative to other tasks in the system, although the timers expiry time is
  1016. * relative to when xTimerResetFromISR() is actually called. The timer service/daemon
  1017. * task priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  1018. *
  1019. * Example usage:
  1020. * @verbatim
  1021. * // This scenario assumes xBacklightTimer has already been created. When a
  1022. * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
  1023. * // without a key being pressed, then the LCD back-light is switched off. In
  1024. * // this case, the timer is a one-shot timer, and unlike the example given for
  1025. * // the xTimerReset() function, the key press event handler is an interrupt
  1026. * // service routine.
  1027. *
  1028. * // The callback function assigned to the one-shot timer. In this case the
  1029. * // parameter is not used.
  1030. * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  1031. * {
  1032. * // The timer expired, therefore 5 seconds must have passed since a key
  1033. * // was pressed. Switch off the LCD back-light.
  1034. * vSetBacklightState( BACKLIGHT_OFF );
  1035. * }
  1036. *
  1037. * // The key press interrupt service routine.
  1038. * void vKeyPressEventInterruptHandler( void )
  1039. * {
  1040. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  1041. *
  1042. * // Ensure the LCD back-light is on, then reset the timer that is
  1043. * // responsible for turning the back-light off after 5 seconds of
  1044. * // key inactivity. This is an interrupt service routine so can only
  1045. * // call FreeRTOS API functions that end in "FromISR".
  1046. * vSetBacklightState( BACKLIGHT_ON );
  1047. *
  1048. * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
  1049. * // as both cause the timer to re-calculate its expiry time.
  1050. * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
  1051. * // declared (in this function).
  1052. * if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  1053. * {
  1054. * // The reset command was not executed successfully. Take appropriate
  1055. * // action here.
  1056. * }
  1057. *
  1058. * // Perform the rest of the key processing here.
  1059. *
  1060. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  1061. * // should be performed. The syntax required to perform a context switch
  1062. * // from inside an ISR varies from port to port, and from compiler to
  1063. * // compiler. Inspect the demos for the port you are using to find the
  1064. * // actual syntax required.
  1065. * if( xHigherPriorityTaskWoken != pdFALSE )
  1066. * {
  1067. * // Call the interrupt safe yield function here (actual function
  1068. * // depends on the FreeRTOS port being used).
  1069. * }
  1070. * }
  1071. * @endverbatim
  1072. */
  1073. #define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) \
  1074. xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
  1075. /**
  1076. * const char * const pcTimerGetName( TimerHandle_t xTimer );
  1077. *
  1078. * Returns the name that was assigned to a timer when the timer was created.
  1079. *
  1080. * @param xTimer The handle of the timer being queried.
  1081. *
  1082. * @return The name assigned to the timer specified by the xTimer parameter.
  1083. */
  1084. const char * pcTimerGetName( TimerHandle_t xTimer );
  1085. /**
  1086. * void vTimerSetReloadMode( TimerHandle_t xTimer, const UBaseType_t uxAutoReload );
  1087. *
  1088. * Updates a timer to be either an auto-reload timer, in which case the timer
  1089. * automatically resets itself each time it expires, or a one-shot timer, in
  1090. * which case the timer will only expire once unless it is manually restarted.
  1091. *
  1092. * @param xTimer The handle of the timer being updated.
  1093. *
  1094. * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
  1095. * expire repeatedly with a frequency set by the timer's period (see the
  1096. * xTimerPeriodInTicks parameter of the xTimerCreate() API function). If
  1097. * uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
  1098. * enter the dormant state after it expires.
  1099. */
  1100. void vTimerSetReloadMode( TimerHandle_t xTimer,
  1101. const UBaseType_t uxAutoReload );
  1102. /**
  1103. * UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer );
  1104. *
  1105. * Queries a timer to determine if it is an auto-reload timer, in which case the timer
  1106. * automatically resets itself each time it expires, or a one-shot timer, in
  1107. * which case the timer will only expire once unless it is manually restarted.
  1108. *
  1109. * @param xTimer The handle of the timer being queried.
  1110. *
  1111. * @return If the timer is an auto-reload timer then pdTRUE is returned, otherwise
  1112. * pdFALSE is returned.
  1113. */
  1114. UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer );
  1115. /**
  1116. * TickType_t xTimerGetPeriod( TimerHandle_t xTimer );
  1117. *
  1118. * Returns the period of a timer.
  1119. *
  1120. * @param xTimer The handle of the timer being queried.
  1121. *
  1122. * @return The period of the timer in ticks.
  1123. */
  1124. TickType_t xTimerGetPeriod( TimerHandle_t xTimer );
  1125. /**
  1126. * TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer );
  1127. *
  1128. * Returns the time in ticks at which the timer will expire. If this is less
  1129. * than the current tick count then the expiry time has overflowed from the
  1130. * current time.
  1131. *
  1132. * @param xTimer The handle of the timer being queried.
  1133. *
  1134. * @return If the timer is running then the time in ticks at which the timer
  1135. * will next expire is returned. If the timer is not running then the return
  1136. * value is undefined.
  1137. */
  1138. TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer );
  1139. /*
  1140. * Functions beyond this part are not part of the public API and are intended
  1141. * for use by the kernel only.
  1142. */
  1143. BaseType_t xTimerGenericCommand( TimerHandle_t xTimer,
  1144. const BaseType_t xCommandID,
  1145. const TickType_t xOptionalValue,
  1146. BaseType_t * const pxHigherPriorityTaskWoken,
  1147. const TickType_t xTicksToWait );
  1148. /* *INDENT-OFF* */
  1149. #ifdef __cplusplus
  1150. }
  1151. #endif
  1152. /* *INDENT-ON* */
  1153. #endif /* TIMERS_H */