timers.h 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  1. /*
  2. FreeRTOS V9.0.0 - Copyright (C) 2016 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, and returns a handle by which the
  112. * created software timer can be referenced.
  113. *
  114. * Internally, within the FreeRTOS implementation, software timers use a block
  115. * of memory, in which the timer data structure is stored. If a software timer
  116. * is created using xTimerCreate() then the required memory is automatically
  117. * dynamically allocated inside the xTimerCreate() function. (see
  118. * http://www.freertos.org/a00111.html). If a software timer is created using
  119. * xTimerCreateStatic() then the application writer must provide the memory that
  120. * will get used by the software timer. xTimerCreateStatic() therefore allows a
  121. * software timer to be created without using any dynamic memory allocation.
  122. *
  123. * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  124. * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  125. * xTimerChangePeriodFromISR() API functions can all be used to transition a
  126. * timer into the active state.
  127. *
  128. * @param pcTimerName A text name that is assigned to the timer. This is done
  129. * purely to assist debugging. The kernel itself only ever references a timer
  130. * by its handle, and never by its name.
  131. *
  132. * @param xTimerPeriodInTicks The timer period. The time is defined in tick
  133. * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
  134. * has been specified in milliseconds. For example, if the timer must expire
  135. * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
  136. * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
  137. * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
  138. * equal to 1000.
  139. *
  140. * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
  141. * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
  142. * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
  143. * enter the dormant state after it expires.
  144. *
  145. * @param pvTimerID An identifier that is assigned to the timer being created.
  146. * Typically this would be used in the timer callback function to identify which
  147. * timer expired when the same callback function is assigned to more than one
  148. * timer.
  149. *
  150. * @param pxCallbackFunction The function to call when the timer expires.
  151. * Callback functions must have the prototype defined by TimerCallbackFunction_t,
  152. * which is "void vCallbackFunction( TimerHandle_t xTimer );".
  153. *
  154. * @return If the timer is successfully created then a handle to the newly
  155. * created timer is returned. If the timer cannot be created (because either
  156. * there is insufficient FreeRTOS heap remaining to allocate the timer
  157. * structures, or the timer period was set to 0) then NULL is returned.
  158. *
  159. * Example usage:
  160. * @verbatim
  161. * #define NUM_TIMERS 5
  162. *
  163. * // An array to hold handles to the created timers.
  164. * TimerHandle_t xTimers[ NUM_TIMERS ];
  165. *
  166. * // An array to hold a count of the number of times each timer expires.
  167. * int32_t lExpireCounters[ NUM_TIMERS ] = { 0 };
  168. *
  169. * // Define a callback function that will be used by multiple timer instances.
  170. * // The callback function does nothing but count the number of times the
  171. * // associated timer expires, and stop the timer once the timer has expired
  172. * // 10 times.
  173. * void vTimerCallback( TimerHandle_t pxTimer )
  174. * {
  175. * int32_t lArrayIndex;
  176. * const int32_t xMaxExpiryCountBeforeStopping = 10;
  177. *
  178. * // Optionally do something if the pxTimer parameter is NULL.
  179. * configASSERT( pxTimer );
  180. *
  181. * // Which timer expired?
  182. * lArrayIndex = ( int32_t ) pvTimerGetTimerID( pxTimer );
  183. *
  184. * // Increment the number of times that pxTimer has expired.
  185. * lExpireCounters[ lArrayIndex ] += 1;
  186. *
  187. * // If the timer has expired 10 times then stop it from running.
  188. * if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping )
  189. * {
  190. * // Do not use a block time if calling a timer API function from a
  191. * // timer callback function, as doing so could cause a deadlock!
  192. * xTimerStop( pxTimer, 0 );
  193. * }
  194. * }
  195. *
  196. * void main( void )
  197. * {
  198. * int32_t x;
  199. *
  200. * // Create then start some timers. Starting the timers before the scheduler
  201. * // has been started means the timers will start running immediately that
  202. * // the scheduler starts.
  203. * for( x = 0; x < NUM_TIMERS; x++ )
  204. * {
  205. * xTimers[ x ] = xTimerCreate( "Timer", // Just a text name, not used by the kernel.
  206. * ( 100 * x ), // The timer period in ticks.
  207. * pdTRUE, // The timers will auto-reload themselves when they expire.
  208. * ( void * ) x, // Assign each timer a unique id equal to its array index.
  209. * vTimerCallback // Each timer calls the same callback when it expires.
  210. * );
  211. *
  212. * if( xTimers[ x ] == NULL )
  213. * {
  214. * // The timer was not created.
  215. * }
  216. * else
  217. * {
  218. * // Start the timer. No block time is specified, and even if one was
  219. * // it would be ignored because the scheduler has not yet been
  220. * // started.
  221. * if( xTimerStart( xTimers[ x ], 0 ) != pdPASS )
  222. * {
  223. * // The timer could not be set into the Active state.
  224. * }
  225. * }
  226. * }
  227. *
  228. * // ...
  229. * // Create tasks here.
  230. * // ...
  231. *
  232. * // Starting the scheduler will start the timers running as they have already
  233. * // been set into the active state.
  234. * vTaskStartScheduler();
  235. *
  236. * // Should not reach here.
  237. * for( ;; );
  238. * }
  239. * @endverbatim
  240. */
  241. #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  242. TimerHandle_t xTimerCreate( const char * const pcTimerName,
  243. const TickType_t xTimerPeriodInTicks,
  244. const UBaseType_t uxAutoReload,
  245. void * const pvTimerID,
  246. TimerCallbackFunction_t pxCallbackFunction ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  247. #endif
  248. /**
  249. * TimerHandle_t xTimerCreateStatic(const char * const pcTimerName,
  250. * TickType_t xTimerPeriodInTicks,
  251. * UBaseType_t uxAutoReload,
  252. * void * pvTimerID,
  253. * TimerCallbackFunction_t pxCallbackFunction,
  254. * StaticTimer_t *pxTimerBuffer );
  255. *
  256. * Creates a new software timer instance, and returns a handle by which the
  257. * created software timer can be referenced.
  258. *
  259. * Internally, within the FreeRTOS implementation, software timers use a block
  260. * of memory, in which the timer data structure is stored. If a software timer
  261. * is created using xTimerCreate() then the required memory is automatically
  262. * dynamically allocated inside the xTimerCreate() function. (see
  263. * http://www.freertos.org/a00111.html). If a software timer is created using
  264. * xTimerCreateStatic() then the application writer must provide the memory that
  265. * will get used by the software timer. xTimerCreateStatic() therefore allows a
  266. * software timer to be created without using any dynamic memory allocation.
  267. *
  268. * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  269. * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  270. * xTimerChangePeriodFromISR() API functions can all be used to transition a
  271. * timer into the active state.
  272. *
  273. * @param pcTimerName A text name that is assigned to the timer. This is done
  274. * purely to assist debugging. The kernel itself only ever references a timer
  275. * by its handle, and never by its name.
  276. *
  277. * @param xTimerPeriodInTicks The timer period. The time is defined in tick
  278. * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
  279. * has been specified in milliseconds. For example, if the timer must expire
  280. * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
  281. * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
  282. * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
  283. * equal to 1000.
  284. *
  285. * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
  286. * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
  287. * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
  288. * enter the dormant state after it expires.
  289. *
  290. * @param pvTimerID An identifier that is assigned to the timer being created.
  291. * Typically this would be used in the timer callback function to identify which
  292. * timer expired when the same callback function is assigned to more than one
  293. * timer.
  294. *
  295. * @param pxCallbackFunction The function to call when the timer expires.
  296. * Callback functions must have the prototype defined by TimerCallbackFunction_t,
  297. * which is "void vCallbackFunction( TimerHandle_t xTimer );".
  298. *
  299. * @param pxTimerBuffer Must point to a variable of type StaticTimer_t, which
  300. * will be then be used to hold the software timer's data structures, removing
  301. * the need for the memory to be allocated dynamically.
  302. *
  303. * @return If the timer is created then a handle to the created timer is
  304. * returned. If pxTimerBuffer was NULL then NULL is returned.
  305. *
  306. * Example usage:
  307. * @verbatim
  308. *
  309. * // The buffer used to hold the software timer's data structure.
  310. * static StaticTimer_t xTimerBuffer;
  311. *
  312. * // A variable that will be incremented by the software timer's callback
  313. * // function.
  314. * UBaseType_t uxVariableToIncrement = 0;
  315. *
  316. * // A software timer callback function that increments a variable passed to
  317. * // it when the software timer was created. After the 5th increment the
  318. * // callback function stops the software timer.
  319. * static void prvTimerCallback( TimerHandle_t xExpiredTimer )
  320. * {
  321. * UBaseType_t *puxVariableToIncrement;
  322. * BaseType_t xReturned;
  323. *
  324. * // Obtain the address of the variable to increment from the timer ID.
  325. * puxVariableToIncrement = ( UBaseType_t * ) pvTimerGetTimerID( xExpiredTimer );
  326. *
  327. * // Increment the variable to show the timer callback has executed.
  328. * ( *puxVariableToIncrement )++;
  329. *
  330. * // If this callback has executed the required number of times, stop the
  331. * // timer.
  332. * if( *puxVariableToIncrement == 5 )
  333. * {
  334. * // This is called from a timer callback so must not block.
  335. * xTimerStop( xExpiredTimer, staticDONT_BLOCK );
  336. * }
  337. * }
  338. *
  339. *
  340. * void main( void )
  341. * {
  342. * // Create the software time. xTimerCreateStatic() has an extra parameter
  343. * // than the normal xTimerCreate() API function. The parameter is a pointer
  344. * // to the StaticTimer_t structure that will hold the software timer
  345. * // structure. If the parameter is passed as NULL then the structure will be
  346. * // allocated dynamically, just as if xTimerCreate() had been called.
  347. * xTimer = xTimerCreateStatic( "T1", // Text name for the task. Helps debugging only. Not used by FreeRTOS.
  348. * xTimerPeriod, // The period of the timer in ticks.
  349. * pdTRUE, // This is an auto-reload timer.
  350. * ( void * ) &uxVariableToIncrement, // A variable incremented by the software timer's callback function
  351. * prvTimerCallback, // The function to execute when the timer expires.
  352. * &xTimerBuffer ); // The buffer that will hold the software timer structure.
  353. *
  354. * // The scheduler has not started yet so a block time is not used.
  355. * xReturned = xTimerStart( xTimer, 0 );
  356. *
  357. * // ...
  358. * // Create tasks here.
  359. * // ...
  360. *
  361. * // Starting the scheduler will start the timers running as they have already
  362. * // been set into the active state.
  363. * vTaskStartScheduler();
  364. *
  365. * // Should not reach here.
  366. * for( ;; );
  367. * }
  368. * @endverbatim
  369. */
  370. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  371. TimerHandle_t xTimerCreateStatic( const char * const pcTimerName,
  372. const TickType_t xTimerPeriodInTicks,
  373. const UBaseType_t uxAutoReload,
  374. void * const pvTimerID,
  375. TimerCallbackFunction_t pxCallbackFunction,
  376. StaticTimer_t *pxTimerBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  377. #endif /* configSUPPORT_STATIC_ALLOCATION */
  378. /**
  379. * void *pvTimerGetTimerID( TimerHandle_t xTimer );
  380. *
  381. * Returns the ID assigned to the timer.
  382. *
  383. * IDs are assigned to timers using the pvTimerID parameter of the call to
  384. * xTimerCreated() that was used to create the timer, and by calling the
  385. * vTimerSetTimerID() API function.
  386. *
  387. * If the same callback function is assigned to multiple timers then the timer
  388. * ID can be used as time specific (timer local) storage.
  389. *
  390. * @param xTimer The timer being queried.
  391. *
  392. * @return The ID assigned to the timer being queried.
  393. *
  394. * Example usage:
  395. *
  396. * See the xTimerCreate() API function example usage scenario.
  397. */
  398. void *pvTimerGetTimerID( const TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
  399. /**
  400. * void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID );
  401. *
  402. * Sets the ID assigned to the timer.
  403. *
  404. * IDs are assigned to timers using the pvTimerID parameter of the call to
  405. * xTimerCreated() that was used to create the timer.
  406. *
  407. * If the same callback function is assigned to multiple timers then the timer
  408. * ID can be used as time specific (timer local) storage.
  409. *
  410. * @param xTimer The timer being updated.
  411. *
  412. * @param pvNewID The ID to assign to the timer.
  413. *
  414. * Example usage:
  415. *
  416. * See the xTimerCreate() API function example usage scenario.
  417. */
  418. void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID ) PRIVILEGED_FUNCTION;
  419. /**
  420. * BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer );
  421. *
  422. * Queries a timer to see if it is active or dormant.
  423. *
  424. * A timer will be dormant if:
  425. * 1) It has been created but not started, or
  426. * 2) It is an expired one-shot timer that has not been restarted.
  427. *
  428. * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  429. * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  430. * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the
  431. * active state.
  432. *
  433. * @param xTimer The timer being queried.
  434. *
  435. * @return pdFALSE will be returned if the timer is dormant. A value other than
  436. * pdFALSE will be returned if the timer is active.
  437. *
  438. * Example usage:
  439. * @verbatim
  440. * // This function assumes xTimer has already been created.
  441. * void vAFunction( TimerHandle_t xTimer )
  442. * {
  443. * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
  444. * {
  445. * // xTimer is active, do something.
  446. * }
  447. * else
  448. * {
  449. * // xTimer is not active, do something else.
  450. * }
  451. * }
  452. * @endverbatim
  453. */
  454. BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
  455. /**
  456. * TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
  457. *
  458. * Simply returns the handle of the timer service/daemon task. It it not valid
  459. * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started.
  460. */
  461. TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ) PRIVILEGED_FUNCTION;
  462. /**
  463. * BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xTicksToWait );
  464. *
  465. * Timer functionality is provided by a timer service/daemon task. Many of the
  466. * public FreeRTOS timer API functions send commands to the timer service task
  467. * through a queue called the timer command queue. The timer command queue is
  468. * private to the kernel itself and is not directly accessible to application
  469. * code. The length of the timer command queue is set by the
  470. * configTIMER_QUEUE_LENGTH configuration constant.
  471. *
  472. * xTimerStart() starts a timer that was previously created using the
  473. * xTimerCreate() API function. If the timer had already been started and was
  474. * already in the active state, then xTimerStart() has equivalent functionality
  475. * to the xTimerReset() API function.
  476. *
  477. * Starting a timer ensures the timer is in the active state. If the timer
  478. * is not stopped, deleted, or reset in the mean time, the callback function
  479. * associated with the timer will get called 'n' ticks after xTimerStart() was
  480. * called, where 'n' is the timers defined period.
  481. *
  482. * It is valid to call xTimerStart() before the scheduler has been started, but
  483. * when this is done the timer will not actually start until the scheduler is
  484. * started, and the timers expiry time will be relative to when the scheduler is
  485. * started, not relative to when xTimerStart() was called.
  486. *
  487. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart()
  488. * to be available.
  489. *
  490. * @param xTimer The handle of the timer being started/restarted.
  491. *
  492. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  493. * be held in the Blocked state to wait for the start command to be successfully
  494. * sent to the timer command queue, should the queue already be full when
  495. * xTimerStart() was called. xTicksToWait is ignored if xTimerStart() is called
  496. * before the scheduler is started.
  497. *
  498. * @return pdFAIL will be returned if the start command could not be sent to
  499. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  500. * be returned if the command was successfully sent to the timer command queue.
  501. * When the command is actually processed will depend on the priority of the
  502. * timer service/daemon task relative to other tasks in the system, although the
  503. * timers expiry time is relative to when xTimerStart() is actually called. The
  504. * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  505. * configuration constant.
  506. *
  507. * Example usage:
  508. *
  509. * See the xTimerCreate() API function example usage scenario.
  510. *
  511. */
  512. #define xTimerStart( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
  513. /**
  514. * BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xTicksToWait );
  515. *
  516. * Timer functionality is provided by a timer service/daemon task. Many of the
  517. * public FreeRTOS timer API functions send commands to the timer service task
  518. * through a queue called the timer command queue. The timer command queue is
  519. * private to the kernel itself and is not directly accessible to application
  520. * code. The length of the timer command queue is set by the
  521. * configTIMER_QUEUE_LENGTH configuration constant.
  522. *
  523. * xTimerStop() stops a timer that was previously started using either of the
  524. * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(),
  525. * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions.
  526. *
  527. * Stopping a timer ensures the timer is not in the active state.
  528. *
  529. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop()
  530. * to be available.
  531. *
  532. * @param xTimer The handle of the timer being stopped.
  533. *
  534. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  535. * be held in the Blocked state to wait for the stop command to be successfully
  536. * sent to the timer command queue, should the queue already be full when
  537. * xTimerStop() was called. xTicksToWait is ignored if xTimerStop() is called
  538. * before the scheduler is started.
  539. *
  540. * @return pdFAIL will be returned if the stop command could not be sent to
  541. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  542. * be returned if the command was successfully sent to the timer command queue.
  543. * When the command is actually processed will depend on the priority of the
  544. * timer service/daemon task relative to other tasks in the system. The timer
  545. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  546. * configuration constant.
  547. *
  548. * Example usage:
  549. *
  550. * See the xTimerCreate() API function example usage scenario.
  551. *
  552. */
  553. #define xTimerStop( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )
  554. /**
  555. * BaseType_t xTimerChangePeriod( TimerHandle_t xTimer,
  556. * TickType_t xNewPeriod,
  557. * TickType_t xTicksToWait );
  558. *
  559. * Timer functionality is provided by a timer service/daemon task. Many of the
  560. * public FreeRTOS timer API functions send commands to the timer service task
  561. * through a queue called the timer command queue. The timer command queue is
  562. * private to the kernel itself and is not directly accessible to application
  563. * code. The length of the timer command queue is set by the
  564. * configTIMER_QUEUE_LENGTH configuration constant.
  565. *
  566. * xTimerChangePeriod() changes the period of a timer that was previously
  567. * created using the xTimerCreate() API function.
  568. *
  569. * xTimerChangePeriod() can be called to change the period of an active or
  570. * dormant state timer.
  571. *
  572. * The configUSE_TIMERS configuration constant must be set to 1 for
  573. * xTimerChangePeriod() to be available.
  574. *
  575. * @param xTimer The handle of the timer that is having its period changed.
  576. *
  577. * @param xNewPeriod The new period for xTimer. Timer periods are specified in
  578. * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
  579. * that has been specified in milliseconds. For example, if the timer must
  580. * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
  581. * if the timer must expire after 500ms, then xNewPeriod can be set to
  582. * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
  583. * or equal to 1000.
  584. *
  585. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  586. * be held in the Blocked state to wait for the change period command to be
  587. * successfully sent to the timer command queue, should the queue already be
  588. * full when xTimerChangePeriod() was called. xTicksToWait is ignored if
  589. * xTimerChangePeriod() is called before the scheduler is started.
  590. *
  591. * @return pdFAIL will be returned if the change period command could not be
  592. * sent to the timer command queue even after xTicksToWait ticks had passed.
  593. * pdPASS will be returned if the command was successfully sent to the timer
  594. * command queue. When the command is actually processed will depend on the
  595. * priority of the timer service/daemon task relative to other tasks in the
  596. * system. The timer service/daemon task priority is set by the
  597. * configTIMER_TASK_PRIORITY configuration constant.
  598. *
  599. * Example usage:
  600. * @verbatim
  601. * // This function assumes xTimer has already been created. If the timer
  602. * // referenced by xTimer is already active when it is called, then the timer
  603. * // is deleted. If the timer referenced by xTimer is not active when it is
  604. * // called, then the period of the timer is set to 500ms and the timer is
  605. * // started.
  606. * void vAFunction( TimerHandle_t xTimer )
  607. * {
  608. * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
  609. * {
  610. * // xTimer is already active - delete it.
  611. * xTimerDelete( xTimer );
  612. * }
  613. * else
  614. * {
  615. * // xTimer is not active, change its period to 500ms. This will also
  616. * // cause the timer to start. Block for a maximum of 100 ticks if the
  617. * // change period command cannot immediately be sent to the timer
  618. * // command queue.
  619. * if( xTimerChangePeriod( xTimer, 500 / portTICK_PERIOD_MS, 100 ) == pdPASS )
  620. * {
  621. * // The command was successfully sent.
  622. * }
  623. * else
  624. * {
  625. * // The command could not be sent, even after waiting for 100 ticks
  626. * // to pass. Take appropriate action here.
  627. * }
  628. * }
  629. * }
  630. * @endverbatim
  631. */
  632. #define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) )
  633. /**
  634. * BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait );
  635. *
  636. * Timer functionality is provided by a timer service/daemon task. Many of the
  637. * public FreeRTOS timer API functions send commands to the timer service task
  638. * through a queue called the timer command queue. The timer command queue is
  639. * private to the kernel itself and is not directly accessible to application
  640. * code. The length of the timer command queue is set by the
  641. * configTIMER_QUEUE_LENGTH configuration constant.
  642. *
  643. * xTimerDelete() deletes a timer that was previously created using the
  644. * xTimerCreate() API function.
  645. *
  646. * The configUSE_TIMERS configuration constant must be set to 1 for
  647. * xTimerDelete() to be available.
  648. *
  649. * @param xTimer The handle of the timer being deleted.
  650. *
  651. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  652. * be held in the Blocked state to wait for the delete command to be
  653. * successfully sent to the timer command queue, should the queue already be
  654. * full when xTimerDelete() was called. xTicksToWait is ignored if xTimerDelete()
  655. * is called before the scheduler is started.
  656. *
  657. * @return pdFAIL will be returned if the delete command could not be sent to
  658. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  659. * be returned if the command was successfully sent to the timer command queue.
  660. * When the command is actually processed will depend on the priority of the
  661. * timer service/daemon task relative to other tasks in the system. The timer
  662. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  663. * configuration constant.
  664. *
  665. * Example usage:
  666. *
  667. * See the xTimerChangePeriod() API function example usage scenario.
  668. */
  669. #define xTimerDelete( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
  670. /**
  671. * BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait );
  672. *
  673. * Timer functionality is provided by a timer service/daemon task. Many of the
  674. * public FreeRTOS timer API functions send commands to the timer service task
  675. * through a queue called the timer command queue. The timer command queue is
  676. * private to the kernel itself and is not directly accessible to application
  677. * code. The length of the timer command queue is set by the
  678. * configTIMER_QUEUE_LENGTH configuration constant.
  679. *
  680. * xTimerReset() re-starts a timer that was previously created using the
  681. * xTimerCreate() API function. If the timer had already been started and was
  682. * already in the active state, then xTimerReset() will cause the timer to
  683. * re-evaluate its expiry time so that it is relative to when xTimerReset() was
  684. * called. If the timer was in the dormant state then xTimerReset() has
  685. * equivalent functionality to the xTimerStart() API function.
  686. *
  687. * Resetting a timer ensures the timer is in the active state. If the timer
  688. * is not stopped, deleted, or reset in the mean time, the callback function
  689. * associated with the timer will get called 'n' ticks after xTimerReset() was
  690. * called, where 'n' is the timers defined period.
  691. *
  692. * It is valid to call xTimerReset() before the scheduler has been started, but
  693. * when this is done the timer will not actually start until the scheduler is
  694. * started, and the timers expiry time will be relative to when the scheduler is
  695. * started, not relative to when xTimerReset() was called.
  696. *
  697. * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset()
  698. * to be available.
  699. *
  700. * @param xTimer The handle of the timer being reset/started/restarted.
  701. *
  702. * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  703. * be held in the Blocked state to wait for the reset command to be successfully
  704. * sent to the timer command queue, should the queue already be full when
  705. * xTimerReset() was called. xTicksToWait is ignored if xTimerReset() is called
  706. * before the scheduler is started.
  707. *
  708. * @return pdFAIL will be returned if the reset command could not be sent to
  709. * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  710. * be returned if the command was successfully sent to the timer command queue.
  711. * When the command is actually processed will depend on the priority of the
  712. * timer service/daemon task relative to other tasks in the system, although the
  713. * timers expiry time is relative to when xTimerStart() is actually called. The
  714. * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  715. * configuration constant.
  716. *
  717. * Example usage:
  718. * @verbatim
  719. * // When a key is pressed, an LCD back-light is switched on. If 5 seconds pass
  720. * // without a key being pressed, then the LCD back-light is switched off. In
  721. * // this case, the timer is a one-shot timer.
  722. *
  723. * TimerHandle_t xBacklightTimer = NULL;
  724. *
  725. * // The callback function assigned to the one-shot timer. In this case the
  726. * // parameter is not used.
  727. * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  728. * {
  729. * // The timer expired, therefore 5 seconds must have passed since a key
  730. * // was pressed. Switch off the LCD back-light.
  731. * vSetBacklightState( BACKLIGHT_OFF );
  732. * }
  733. *
  734. * // The key press event handler.
  735. * void vKeyPressEventHandler( char cKey )
  736. * {
  737. * // Ensure the LCD back-light is on, then reset the timer that is
  738. * // responsible for turning the back-light off after 5 seconds of
  739. * // key inactivity. Wait 10 ticks for the command to be successfully sent
  740. * // if it cannot be sent immediately.
  741. * vSetBacklightState( BACKLIGHT_ON );
  742. * if( xTimerReset( xBacklightTimer, 100 ) != pdPASS )
  743. * {
  744. * // The reset command was not executed successfully. Take appropriate
  745. * // action here.
  746. * }
  747. *
  748. * // Perform the rest of the key processing here.
  749. * }
  750. *
  751. * void main( void )
  752. * {
  753. * int32_t x;
  754. *
  755. * // Create then start the one-shot timer that is responsible for turning
  756. * // the back-light off if no keys are pressed within a 5 second period.
  757. * xBacklightTimer = xTimerCreate( "BacklightTimer", // Just a text name, not used by the kernel.
  758. * ( 5000 / portTICK_PERIOD_MS), // The timer period in ticks.
  759. * pdFALSE, // The timer is a one-shot timer.
  760. * 0, // The id is not used by the callback so can take any value.
  761. * vBacklightTimerCallback // The callback function that switches the LCD back-light off.
  762. * );
  763. *
  764. * if( xBacklightTimer == NULL )
  765. * {
  766. * // The timer was not created.
  767. * }
  768. * else
  769. * {
  770. * // Start the timer. No block time is specified, and even if one was
  771. * // it would be ignored because the scheduler has not yet been
  772. * // started.
  773. * if( xTimerStart( xBacklightTimer, 0 ) != pdPASS )
  774. * {
  775. * // The timer could not be set into the Active state.
  776. * }
  777. * }
  778. *
  779. * // ...
  780. * // Create tasks here.
  781. * // ...
  782. *
  783. * // Starting the scheduler will start the timer running as it has already
  784. * // been set into the active state.
  785. * vTaskStartScheduler();
  786. *
  787. * // Should not reach here.
  788. * for( ;; );
  789. * }
  790. * @endverbatim
  791. */
  792. #define xTimerReset( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
  793. /**
  794. * BaseType_t xTimerStartFromISR( TimerHandle_t xTimer,
  795. * BaseType_t *pxHigherPriorityTaskWoken );
  796. *
  797. * A version of xTimerStart() that can be called from an interrupt service
  798. * routine.
  799. *
  800. * @param xTimer The handle of the timer being started/restarted.
  801. *
  802. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  803. * of its time in the Blocked state, waiting for messages to arrive on the timer
  804. * command queue. Calling xTimerStartFromISR() writes a message to the timer
  805. * command queue, so has the potential to transition the timer service/daemon
  806. * task out of the Blocked state. If calling xTimerStartFromISR() causes the
  807. * timer service/daemon task to leave the Blocked state, and the timer service/
  808. * daemon task has a priority equal to or greater than the currently executing
  809. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  810. * get set to pdTRUE internally within the xTimerStartFromISR() function. If
  811. * xTimerStartFromISR() sets this value to pdTRUE then a context switch should
  812. * be performed before the interrupt exits.
  813. *
  814. * @return pdFAIL will be returned if the start command could not be sent to
  815. * the timer command queue. pdPASS will be returned if the command was
  816. * successfully sent to the timer command queue. When the command is actually
  817. * processed will depend on the priority of the timer service/daemon task
  818. * relative to other tasks in the system, although the timers expiry time is
  819. * relative to when xTimerStartFromISR() is actually called. The timer
  820. * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  821. * configuration constant.
  822. *
  823. * Example usage:
  824. * @verbatim
  825. * // This scenario assumes xBacklightTimer has already been created. When a
  826. * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
  827. * // without a key being pressed, then the LCD back-light is switched off. In
  828. * // this case, the timer is a one-shot timer, and unlike the example given for
  829. * // the xTimerReset() function, the key press event handler is an interrupt
  830. * // service routine.
  831. *
  832. * // The callback function assigned to the one-shot timer. In this case the
  833. * // parameter is not used.
  834. * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  835. * {
  836. * // The timer expired, therefore 5 seconds must have passed since a key
  837. * // was pressed. Switch off the LCD back-light.
  838. * vSetBacklightState( BACKLIGHT_OFF );
  839. * }
  840. *
  841. * // The key press interrupt service routine.
  842. * void vKeyPressEventInterruptHandler( void )
  843. * {
  844. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  845. *
  846. * // Ensure the LCD back-light is on, then restart the timer that is
  847. * // responsible for turning the back-light off after 5 seconds of
  848. * // key inactivity. This is an interrupt service routine so can only
  849. * // call FreeRTOS API functions that end in "FromISR".
  850. * vSetBacklightState( BACKLIGHT_ON );
  851. *
  852. * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
  853. * // as both cause the timer to re-calculate its expiry time.
  854. * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
  855. * // declared (in this function).
  856. * if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  857. * {
  858. * // The start command was not executed successfully. Take appropriate
  859. * // action here.
  860. * }
  861. *
  862. * // Perform the rest of the key processing here.
  863. *
  864. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  865. * // should be performed. The syntax required to perform a context switch
  866. * // from inside an ISR varies from port to port, and from compiler to
  867. * // compiler. Inspect the demos for the port you are using to find the
  868. * // actual syntax required.
  869. * if( xHigherPriorityTaskWoken != pdFALSE )
  870. * {
  871. * // Call the interrupt safe yield function here (actual function
  872. * // depends on the FreeRTOS port being used).
  873. * }
  874. * }
  875. * @endverbatim
  876. */
  877. #define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
  878. /**
  879. * BaseType_t xTimerStopFromISR( TimerHandle_t xTimer,
  880. * BaseType_t *pxHigherPriorityTaskWoken );
  881. *
  882. * A version of xTimerStop() that can be called from an interrupt service
  883. * routine.
  884. *
  885. * @param xTimer The handle of the timer being stopped.
  886. *
  887. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  888. * of its time in the Blocked state, waiting for messages to arrive on the timer
  889. * command queue. Calling xTimerStopFromISR() writes a message to the timer
  890. * command queue, so has the potential to transition the timer service/daemon
  891. * task out of the Blocked state. If calling xTimerStopFromISR() causes the
  892. * timer service/daemon task to leave the Blocked state, and the timer service/
  893. * daemon task has a priority equal to or greater than the currently executing
  894. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  895. * get set to pdTRUE internally within the xTimerStopFromISR() function. If
  896. * xTimerStopFromISR() sets this value to pdTRUE then a context switch should
  897. * be performed before the interrupt exits.
  898. *
  899. * @return pdFAIL will be returned if the stop command could not be sent to
  900. * the timer command queue. pdPASS will be returned if the command was
  901. * successfully sent to the timer command queue. When the command is actually
  902. * processed will depend on the priority of the timer service/daemon task
  903. * relative to other tasks in the system. The timer service/daemon task
  904. * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  905. *
  906. * Example usage:
  907. * @verbatim
  908. * // This scenario assumes xTimer has already been created and started. When
  909. * // an interrupt occurs, the timer should be simply stopped.
  910. *
  911. * // The interrupt service routine that stops the timer.
  912. * void vAnExampleInterruptServiceRoutine( void )
  913. * {
  914. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  915. *
  916. * // The interrupt has occurred - simply stop the timer.
  917. * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
  918. * // (within this function). As this is an interrupt service routine, only
  919. * // FreeRTOS API functions that end in "FromISR" can be used.
  920. * if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  921. * {
  922. * // The stop command was not executed successfully. Take appropriate
  923. * // action here.
  924. * }
  925. *
  926. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  927. * // should be performed. The syntax required to perform a context switch
  928. * // from inside an ISR varies from port to port, and from compiler to
  929. * // compiler. Inspect the demos for the port you are using to find the
  930. * // actual syntax required.
  931. * if( xHigherPriorityTaskWoken != pdFALSE )
  932. * {
  933. * // Call the interrupt safe yield function here (actual function
  934. * // depends on the FreeRTOS port being used).
  935. * }
  936. * }
  937. * @endverbatim
  938. */
  939. #define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U )
  940. /**
  941. * BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer,
  942. * TickType_t xNewPeriod,
  943. * BaseType_t *pxHigherPriorityTaskWoken );
  944. *
  945. * A version of xTimerChangePeriod() that can be called from an interrupt
  946. * service routine.
  947. *
  948. * @param xTimer The handle of the timer that is having its period changed.
  949. *
  950. * @param xNewPeriod The new period for xTimer. Timer periods are specified in
  951. * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
  952. * that has been specified in milliseconds. For example, if the timer must
  953. * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
  954. * if the timer must expire after 500ms, then xNewPeriod can be set to
  955. * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
  956. * or equal to 1000.
  957. *
  958. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  959. * of its time in the Blocked state, waiting for messages to arrive on the timer
  960. * command queue. Calling xTimerChangePeriodFromISR() writes a message to the
  961. * timer command queue, so has the potential to transition the timer service/
  962. * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR()
  963. * causes the timer service/daemon task to leave the Blocked state, and the
  964. * timer service/daemon task has a priority equal to or greater than the
  965. * currently executing task (the task that was interrupted), then
  966. * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the
  967. * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets
  968. * this value to pdTRUE then a context switch should be performed before the
  969. * interrupt exits.
  970. *
  971. * @return pdFAIL will be returned if the command to change the timers period
  972. * could not be sent to the timer command queue. pdPASS will be returned if the
  973. * command was successfully sent to the timer command queue. When the command
  974. * is actually processed will depend on the priority of the timer service/daemon
  975. * task relative to other tasks in the system. The timer service/daemon task
  976. * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  977. *
  978. * Example usage:
  979. * @verbatim
  980. * // This scenario assumes xTimer has already been created and started. When
  981. * // an interrupt occurs, the period of xTimer should be changed to 500ms.
  982. *
  983. * // The interrupt service routine that changes the period of xTimer.
  984. * void vAnExampleInterruptServiceRoutine( void )
  985. * {
  986. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  987. *
  988. * // The interrupt has occurred - change the period of xTimer to 500ms.
  989. * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
  990. * // (within this function). As this is an interrupt service routine, only
  991. * // FreeRTOS API functions that end in "FromISR" can be used.
  992. * if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  993. * {
  994. * // The command to change the timers period was not executed
  995. * // successfully. Take appropriate action here.
  996. * }
  997. *
  998. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  999. * // should be performed. The syntax required to perform a context switch
  1000. * // from inside an ISR varies from port to port, and from compiler to
  1001. * // compiler. Inspect the demos for the port you are using to find the
  1002. * // actual syntax required.
  1003. * if( xHigherPriorityTaskWoken != pdFALSE )
  1004. * {
  1005. * // Call the interrupt safe yield function here (actual function
  1006. * // depends on the FreeRTOS port being used).
  1007. * }
  1008. * }
  1009. * @endverbatim
  1010. */
  1011. #define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )
  1012. /**
  1013. * BaseType_t xTimerResetFromISR( TimerHandle_t xTimer,
  1014. * BaseType_t *pxHigherPriorityTaskWoken );
  1015. *
  1016. * A version of xTimerReset() that can be called from an interrupt service
  1017. * routine.
  1018. *
  1019. * @param xTimer The handle of the timer that is to be started, reset, or
  1020. * restarted.
  1021. *
  1022. * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  1023. * of its time in the Blocked state, waiting for messages to arrive on the timer
  1024. * command queue. Calling xTimerResetFromISR() writes a message to the timer
  1025. * command queue, so has the potential to transition the timer service/daemon
  1026. * task out of the Blocked state. If calling xTimerResetFromISR() causes the
  1027. * timer service/daemon task to leave the Blocked state, and the timer service/
  1028. * daemon task has a priority equal to or greater than the currently executing
  1029. * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  1030. * get set to pdTRUE internally within the xTimerResetFromISR() function. If
  1031. * xTimerResetFromISR() sets this value to pdTRUE then a context switch should
  1032. * be performed before the interrupt exits.
  1033. *
  1034. * @return pdFAIL will be returned if the reset command could not be sent to
  1035. * the timer command queue. pdPASS will be returned if the command was
  1036. * successfully sent to the timer command queue. When the command is actually
  1037. * processed will depend on the priority of the timer service/daemon task
  1038. * relative to other tasks in the system, although the timers expiry time is
  1039. * relative to when xTimerResetFromISR() is actually called. The timer service/daemon
  1040. * task priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  1041. *
  1042. * Example usage:
  1043. * @verbatim
  1044. * // This scenario assumes xBacklightTimer has already been created. When a
  1045. * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
  1046. * // without a key being pressed, then the LCD back-light is switched off. In
  1047. * // this case, the timer is a one-shot timer, and unlike the example given for
  1048. * // the xTimerReset() function, the key press event handler is an interrupt
  1049. * // service routine.
  1050. *
  1051. * // The callback function assigned to the one-shot timer. In this case the
  1052. * // parameter is not used.
  1053. * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  1054. * {
  1055. * // The timer expired, therefore 5 seconds must have passed since a key
  1056. * // was pressed. Switch off the LCD back-light.
  1057. * vSetBacklightState( BACKLIGHT_OFF );
  1058. * }
  1059. *
  1060. * // The key press interrupt service routine.
  1061. * void vKeyPressEventInterruptHandler( void )
  1062. * {
  1063. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  1064. *
  1065. * // Ensure the LCD back-light is on, then reset the timer that is
  1066. * // responsible for turning the back-light off after 5 seconds of
  1067. * // key inactivity. This is an interrupt service routine so can only
  1068. * // call FreeRTOS API functions that end in "FromISR".
  1069. * vSetBacklightState( BACKLIGHT_ON );
  1070. *
  1071. * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
  1072. * // as both cause the timer to re-calculate its expiry time.
  1073. * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
  1074. * // declared (in this function).
  1075. * if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  1076. * {
  1077. * // The reset command was not executed successfully. Take appropriate
  1078. * // action here.
  1079. * }
  1080. *
  1081. * // Perform the rest of the key processing here.
  1082. *
  1083. * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  1084. * // should be performed. The syntax required to perform a context switch
  1085. * // from inside an ISR varies from port to port, and from compiler to
  1086. * // compiler. Inspect the demos for the port you are using to find the
  1087. * // actual syntax required.
  1088. * if( xHigherPriorityTaskWoken != pdFALSE )
  1089. * {
  1090. * // Call the interrupt safe yield function here (actual function
  1091. * // depends on the FreeRTOS port being used).
  1092. * }
  1093. * }
  1094. * @endverbatim
  1095. */
  1096. #define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
  1097. /**
  1098. * BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
  1099. * void *pvParameter1,
  1100. * uint32_t ulParameter2,
  1101. * BaseType_t *pxHigherPriorityTaskWoken );
  1102. *
  1103. *
  1104. * Used from application interrupt service routines to defer the execution of a
  1105. * function to the RTOS daemon task (the timer service task, hence this function
  1106. * is implemented in timers.c and is prefixed with 'Timer').
  1107. *
  1108. * Ideally an interrupt service routine (ISR) is kept as short as possible, but
  1109. * sometimes an ISR either has a lot of processing to do, or needs to perform
  1110. * processing that is not deterministic. In these cases
  1111. * xTimerPendFunctionCallFromISR() can be used to defer processing of a function
  1112. * to the RTOS daemon task.
  1113. *
  1114. * A mechanism is provided that allows the interrupt to return directly to the
  1115. * task that will subsequently execute the pended callback function. This
  1116. * allows the callback function to execute contiguously in time with the
  1117. * interrupt - just as if the callback had executed in the interrupt itself.
  1118. *
  1119. * @param xFunctionToPend The function to execute from the timer service/
  1120. * daemon task. The function must conform to the PendedFunction_t
  1121. * prototype.
  1122. *
  1123. * @param pvParameter1 The value of the callback function's first parameter.
  1124. * The parameter has a void * type to allow it to be used to pass any type.
  1125. * For example, unsigned longs can be cast to a void *, or the void * can be
  1126. * used to point to a structure.
  1127. *
  1128. * @param ulParameter2 The value of the callback function's second parameter.
  1129. *
  1130. * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
  1131. * will result in a message being sent to the timer daemon task. If the
  1132. * priority of the timer daemon task (which is set using
  1133. * configTIMER_TASK_PRIORITY in FreeRTOSConfig.h) is higher than the priority of
  1134. * the currently running task (the task the interrupt interrupted) then
  1135. * *pxHigherPriorityTaskWoken will be set to pdTRUE within
  1136. * xTimerPendFunctionCallFromISR(), indicating that a context switch should be
  1137. * requested before the interrupt exits. For that reason
  1138. * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
  1139. * example code below.
  1140. *
  1141. * @return pdPASS is returned if the message was successfully sent to the
  1142. * timer daemon task, otherwise pdFALSE is returned.
  1143. *
  1144. * Example usage:
  1145. * @verbatim
  1146. *
  1147. * // The callback function that will execute in the context of the daemon task.
  1148. * // Note callback functions must all use this same prototype.
  1149. * void vProcessInterface( void *pvParameter1, uint32_t ulParameter2 )
  1150. * {
  1151. * BaseType_t xInterfaceToService;
  1152. *
  1153. * // The interface that requires servicing is passed in the second
  1154. * // parameter. The first parameter is not used in this case.
  1155. * xInterfaceToService = ( BaseType_t ) ulParameter2;
  1156. *
  1157. * // ...Perform the processing here...
  1158. * }
  1159. *
  1160. * // An ISR that receives data packets from multiple interfaces
  1161. * void vAnISR( void )
  1162. * {
  1163. * BaseType_t xInterfaceToService, xHigherPriorityTaskWoken;
  1164. *
  1165. * // Query the hardware to determine which interface needs processing.
  1166. * xInterfaceToService = prvCheckInterfaces();
  1167. *
  1168. * // The actual processing is to be deferred to a task. Request the
  1169. * // vProcessInterface() callback function is executed, passing in the
  1170. * // number of the interface that needs processing. The interface to
  1171. * // service is passed in the second parameter. The first parameter is
  1172. * // not used in this case.
  1173. * xHigherPriorityTaskWoken = pdFALSE;
  1174. * xTimerPendFunctionCallFromISR( vProcessInterface, NULL, ( uint32_t ) xInterfaceToService, &xHigherPriorityTaskWoken );
  1175. *
  1176. * // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
  1177. * // switch should be requested. The macro used is port specific and will
  1178. * // be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to
  1179. * // the documentation page for the port being used.
  1180. * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  1181. *
  1182. * }
  1183. * @endverbatim
  1184. */
  1185. BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  1186. /**
  1187. * BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
  1188. * void *pvParameter1,
  1189. * uint32_t ulParameter2,
  1190. * TickType_t xTicksToWait );
  1191. *
  1192. *
  1193. * Used to defer the execution of a function to the RTOS daemon task (the timer
  1194. * service task, hence this function is implemented in timers.c and is prefixed
  1195. * with 'Timer').
  1196. *
  1197. * @param xFunctionToPend The function to execute from the timer service/
  1198. * daemon task. The function must conform to the PendedFunction_t
  1199. * prototype.
  1200. *
  1201. * @param pvParameter1 The value of the callback function's first parameter.
  1202. * The parameter has a void * type to allow it to be used to pass any type.
  1203. * For example, unsigned longs can be cast to a void *, or the void * can be
  1204. * used to point to a structure.
  1205. *
  1206. * @param ulParameter2 The value of the callback function's second parameter.
  1207. *
  1208. * @param xTicksToWait Calling this function will result in a message being
  1209. * sent to the timer daemon task on a queue. xTicksToWait is the amount of
  1210. * time the calling task should remain in the Blocked state (so not using any
  1211. * processing time) for space to become available on the timer queue if the
  1212. * queue is found to be full.
  1213. *
  1214. * @return pdPASS is returned if the message was successfully sent to the
  1215. * timer daemon task, otherwise pdFALSE is returned.
  1216. *
  1217. */
  1218. BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  1219. /**
  1220. * const char * const pcTimerGetName( TimerHandle_t xTimer );
  1221. *
  1222. * Returns the name that was assigned to a timer when the timer was created.
  1223. *
  1224. * @param xTimer The handle of the timer being queried.
  1225. *
  1226. * @return The name assigned to the timer specified by the xTimer parameter.
  1227. */
  1228. const char * pcTimerGetName( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1229. /**
  1230. * TickType_t xTimerGetPeriod( TimerHandle_t xTimer );
  1231. *
  1232. * Returns the period of a timer.
  1233. *
  1234. * @param xTimer The handle of the timer being queried.
  1235. *
  1236. * @return The period of the timer in ticks.
  1237. */
  1238. TickType_t xTimerGetPeriod( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
  1239. /**
  1240. * TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer );
  1241. *
  1242. * Returns the time in ticks at which the timer will expire. If this is less
  1243. * than the current tick count then the expiry time has overflowed from the
  1244. * current time.
  1245. *
  1246. * @param xTimer The handle of the timer being queried.
  1247. *
  1248. * @return If the timer is running then the time in ticks at which the timer
  1249. * will next expire is returned. If the timer is not running then the return
  1250. * value is undefined.
  1251. */
  1252. TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
  1253. /*
  1254. * Functions beyond this part are not part of the public API and are intended
  1255. * for use by the kernel only.
  1256. */
  1257. BaseType_t xTimerCreateTimerTask( void ) PRIVILEGED_FUNCTION;
  1258. BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  1259. #ifdef __cplusplus
  1260. }
  1261. #endif
  1262. #endif /* TIMERS_H */