timers.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. /*
  2. * FreeRTOS Kernel V10.0.0
  3. * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. * this software and associated documentation files (the "Software"), to deal in
  7. * the Software without restriction, including without limitation the rights to
  8. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. * the Software, and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software. If you wish to use our Amazon
  14. * FreeRTOS name, please do so in a fair use way that does not cause confusion.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * http://www.FreeRTOS.org
  24. * http://aws.amazon.com/freertos
  25. *
  26. * 1 tab == 4 spaces!
  27. */
  28. /* Standard includes. */
  29. #include <stdlib.h>
  30. /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
  31. all the API functions to use the MPU wrappers. That should only be done when
  32. task.h is included from an application file. */
  33. #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
  34. #include "FreeRTOS.h"
  35. #include "task.h"
  36. #include "queue.h"
  37. #include "timers.h"
  38. #if ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 0 )
  39. #error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available.
  40. #endif
  41. /* Lint e961 and e750 are suppressed as a MISRA exception justified because the
  42. MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the
  43. header files above, but not in this file, in order to generate the correct
  44. privileged Vs unprivileged linkage and placement. */
  45. #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */
  46. /* This entire source file will be skipped if the application is not configured
  47. to include software timer functionality. This #if is closed at the very bottom
  48. of this file. If you want to include software timer functionality then ensure
  49. configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
  50. #if ( configUSE_TIMERS == 1 )
  51. /* Misc definitions. */
  52. #define tmrNO_DELAY ( TickType_t ) 0U
  53. /* The name assigned to the timer service task. This can be overridden by
  54. defining trmTIMER_SERVICE_TASK_NAME in FreeRTOSConfig.h. */
  55. #ifndef configTIMER_SERVICE_TASK_NAME
  56. #define configTIMER_SERVICE_TASK_NAME "Tmr Svc"
  57. #endif
  58. /* The definition of the timers themselves. */
  59. typedef struct tmrTimerControl
  60. {
  61. const char *pcTimerName; /*<< Text name. This is not used by the kernel, it is included simply to make debugging easier. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  62. ListItem_t xTimerListItem; /*<< Standard linked list item as used by all kernel features for event management. */
  63. TickType_t xTimerPeriodInTicks;/*<< How quickly and often the timer expires. */
  64. UBaseType_t uxAutoReload; /*<< Set to pdTRUE if the timer should be automatically restarted once expired. Set to pdFALSE if the timer is, in effect, a one-shot timer. */
  65. void *pvTimerID; /*<< An ID to identify the timer. This allows the timer to be identified when the same callback is used for multiple timers. */
  66. TimerCallbackFunction_t pxCallbackFunction; /*<< The function that will be called when the timer expires. */
  67. #if( configUSE_TRACE_FACILITY == 1 )
  68. UBaseType_t uxTimerNumber; /*<< An ID assigned by trace tools such as FreeRTOS+Trace */
  69. #endif
  70. #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
  71. uint8_t ucStaticallyAllocated; /*<< Set to pdTRUE if the timer was created statically so no attempt is made to free the memory again if the timer is later deleted. */
  72. #endif
  73. } xTIMER;
  74. /* The old xTIMER name is maintained above then typedefed to the new Timer_t
  75. name below to enable the use of older kernel aware debuggers. */
  76. typedef xTIMER Timer_t;
  77. /* The definition of messages that can be sent and received on the timer queue.
  78. Two types of message can be queued - messages that manipulate a software timer,
  79. and messages that request the execution of a non-timer related callback. The
  80. two message types are defined in two separate structures, xTimerParametersType
  81. and xCallbackParametersType respectively. */
  82. typedef struct tmrTimerParameters
  83. {
  84. TickType_t xMessageValue; /*<< An optional value used by a subset of commands, for example, when changing the period of a timer. */
  85. Timer_t * pxTimer; /*<< The timer to which the command will be applied. */
  86. } TimerParameter_t;
  87. typedef struct tmrCallbackParameters
  88. {
  89. PendedFunction_t pxCallbackFunction; /* << The callback function to execute. */
  90. void *pvParameter1; /* << The value that will be used as the callback functions first parameter. */
  91. uint32_t ulParameter2; /* << The value that will be used as the callback functions second parameter. */
  92. } CallbackParameters_t;
  93. /* The structure that contains the two message types, along with an identifier
  94. that is used to determine which message type is valid. */
  95. typedef struct tmrTimerQueueMessage
  96. {
  97. BaseType_t xMessageID; /*<< The command being sent to the timer service task. */
  98. union
  99. {
  100. TimerParameter_t xTimerParameters;
  101. /* Don't include xCallbackParameters if it is not going to be used as
  102. it makes the structure (and therefore the timer queue) larger. */
  103. #if ( INCLUDE_xTimerPendFunctionCall == 1 )
  104. CallbackParameters_t xCallbackParameters;
  105. #endif /* INCLUDE_xTimerPendFunctionCall */
  106. } u;
  107. } DaemonTaskMessage_t;
  108. /*lint -save -e956 A manual analysis and inspection has been used to determine
  109. which static variables must be declared volatile. */
  110. /* The list in which active timers are stored. Timers are referenced in expire
  111. time order, with the nearest expiry time at the front of the list. Only the
  112. timer service task is allowed to access these lists. */
  113. PRIVILEGED_DATA static List_t xActiveTimerList1;
  114. PRIVILEGED_DATA static List_t xActiveTimerList2;
  115. PRIVILEGED_DATA static List_t *pxCurrentTimerList;
  116. PRIVILEGED_DATA static List_t *pxOverflowTimerList;
  117. /* A queue that is used to send commands to the timer service task. */
  118. PRIVILEGED_DATA static QueueHandle_t xTimerQueue = NULL;
  119. PRIVILEGED_DATA static TaskHandle_t xTimerTaskHandle = NULL;
  120. /*lint -restore */
  121. /*-----------------------------------------------------------*/
  122. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  123. /* If static allocation is supported then the application must provide the
  124. following callback function - which enables the application to optionally
  125. provide the memory that will be used by the timer task as the task's stack
  126. and TCB. */
  127. extern void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize );
  128. #endif
  129. /*
  130. * Initialise the infrastructure used by the timer service task if it has not
  131. * been initialised already.
  132. */
  133. static void prvCheckForValidListAndQueue( void ) PRIVILEGED_FUNCTION;
  134. /*
  135. * The timer service task (daemon). Timer functionality is controlled by this
  136. * task. Other tasks communicate with the timer service task using the
  137. * xTimerQueue queue.
  138. */
  139. static void prvTimerTask( void *pvParameters ) PRIVILEGED_FUNCTION;
  140. /*
  141. * Called by the timer service task to interpret and process a command it
  142. * received on the timer queue.
  143. */
  144. static void prvProcessReceivedCommands( void ) PRIVILEGED_FUNCTION;
  145. /*
  146. * Insert the timer into either xActiveTimerList1, or xActiveTimerList2,
  147. * depending on if the expire time causes a timer counter overflow.
  148. */
  149. static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer, const TickType_t xNextExpiryTime, const TickType_t xTimeNow, const TickType_t xCommandTime ) PRIVILEGED_FUNCTION;
  150. /*
  151. * An active timer has reached its expire time. Reload the timer if it is an
  152. * auto reload timer, then call its callback.
  153. */
  154. static void prvProcessExpiredTimer( const TickType_t xNextExpireTime, const TickType_t xTimeNow ) PRIVILEGED_FUNCTION;
  155. /*
  156. * The tick count has overflowed. Switch the timer lists after ensuring the
  157. * current timer list does not still reference some timers.
  158. */
  159. static void prvSwitchTimerLists( void ) PRIVILEGED_FUNCTION;
  160. /*
  161. * Obtain the current tick count, setting *pxTimerListsWereSwitched to pdTRUE
  162. * if a tick count overflow occurred since prvSampleTimeNow() was last called.
  163. */
  164. static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched ) PRIVILEGED_FUNCTION;
  165. /*
  166. * If the timer list contains any active timers then return the expire time of
  167. * the timer that will expire first and set *pxListWasEmpty to false. If the
  168. * timer list does not contain any timers then return 0 and set *pxListWasEmpty
  169. * to pdTRUE.
  170. */
  171. static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty ) PRIVILEGED_FUNCTION;
  172. /*
  173. * If a timer has expired, process it. Otherwise, block the timer service task
  174. * until either a timer does expire or a command is received.
  175. */
  176. static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, BaseType_t xListWasEmpty ) PRIVILEGED_FUNCTION;
  177. /*
  178. * Called after a Timer_t structure has been allocated either statically or
  179. * dynamically to fill in the structure's members.
  180. */
  181. static void prvInitialiseNewTimer( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  182. const TickType_t xTimerPeriodInTicks,
  183. const UBaseType_t uxAutoReload,
  184. void * const pvTimerID,
  185. TimerCallbackFunction_t pxCallbackFunction,
  186. Timer_t *pxNewTimer ) PRIVILEGED_FUNCTION;
  187. /*-----------------------------------------------------------*/
  188. BaseType_t xTimerCreateTimerTask( void )
  189. {
  190. BaseType_t xReturn = pdFAIL;
  191. /* This function is called when the scheduler is started if
  192. configUSE_TIMERS is set to 1. Check that the infrastructure used by the
  193. timer service task has been created/initialised. If timers have already
  194. been created then the initialisation will already have been performed. */
  195. prvCheckForValidListAndQueue();
  196. if( xTimerQueue != NULL )
  197. {
  198. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  199. {
  200. StaticTask_t *pxTimerTaskTCBBuffer = NULL;
  201. StackType_t *pxTimerTaskStackBuffer = NULL;
  202. uint32_t ulTimerTaskStackSize;
  203. vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize );
  204. xTimerTaskHandle = xTaskCreateStatic( prvTimerTask,
  205. configTIMER_SERVICE_TASK_NAME,
  206. ulTimerTaskStackSize,
  207. NULL,
  208. ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
  209. pxTimerTaskStackBuffer,
  210. pxTimerTaskTCBBuffer );
  211. if( xTimerTaskHandle != NULL )
  212. {
  213. xReturn = pdPASS;
  214. }
  215. }
  216. #else
  217. {
  218. xReturn = xTaskCreate( prvTimerTask,
  219. configTIMER_SERVICE_TASK_NAME,
  220. configTIMER_TASK_STACK_DEPTH,
  221. NULL,
  222. ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
  223. &xTimerTaskHandle );
  224. }
  225. #endif /* configSUPPORT_STATIC_ALLOCATION */
  226. }
  227. else
  228. {
  229. mtCOVERAGE_TEST_MARKER();
  230. }
  231. configASSERT( xReturn );
  232. return xReturn;
  233. }
  234. /*-----------------------------------------------------------*/
  235. #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  236. TimerHandle_t xTimerCreate( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  237. const TickType_t xTimerPeriodInTicks,
  238. const UBaseType_t uxAutoReload,
  239. void * const pvTimerID,
  240. TimerCallbackFunction_t pxCallbackFunction )
  241. {
  242. Timer_t *pxNewTimer;
  243. pxNewTimer = ( Timer_t * ) pvPortMalloc( sizeof( Timer_t ) );
  244. if( pxNewTimer != NULL )
  245. {
  246. prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
  247. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  248. {
  249. /* Timers can be created statically or dynamically, so note this
  250. timer was created dynamically in case the timer is later
  251. deleted. */
  252. pxNewTimer->ucStaticallyAllocated = pdFALSE;
  253. }
  254. #endif /* configSUPPORT_STATIC_ALLOCATION */
  255. }
  256. return pxNewTimer;
  257. }
  258. #endif /* configSUPPORT_STATIC_ALLOCATION */
  259. /*-----------------------------------------------------------*/
  260. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  261. TimerHandle_t xTimerCreateStatic( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  262. const TickType_t xTimerPeriodInTicks,
  263. const UBaseType_t uxAutoReload,
  264. void * const pvTimerID,
  265. TimerCallbackFunction_t pxCallbackFunction,
  266. StaticTimer_t *pxTimerBuffer )
  267. {
  268. Timer_t *pxNewTimer;
  269. #if( configASSERT_DEFINED == 1 )
  270. {
  271. /* Sanity check that the size of the structure used to declare a
  272. variable of type StaticTimer_t equals the size of the real timer
  273. structure. */
  274. volatile size_t xSize = sizeof( StaticTimer_t );
  275. configASSERT( xSize == sizeof( Timer_t ) );
  276. }
  277. #endif /* configASSERT_DEFINED */
  278. /* A pointer to a StaticTimer_t structure MUST be provided, use it. */
  279. configASSERT( pxTimerBuffer );
  280. pxNewTimer = ( Timer_t * ) pxTimerBuffer; /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */
  281. if( pxNewTimer != NULL )
  282. {
  283. prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
  284. #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  285. {
  286. /* Timers can be created statically or dynamically so note this
  287. timer was created statically in case it is later deleted. */
  288. pxNewTimer->ucStaticallyAllocated = pdTRUE;
  289. }
  290. #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
  291. }
  292. return pxNewTimer;
  293. }
  294. #endif /* configSUPPORT_STATIC_ALLOCATION */
  295. /*-----------------------------------------------------------*/
  296. static void prvInitialiseNewTimer( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  297. const TickType_t xTimerPeriodInTicks,
  298. const UBaseType_t uxAutoReload,
  299. void * const pvTimerID,
  300. TimerCallbackFunction_t pxCallbackFunction,
  301. Timer_t *pxNewTimer )
  302. {
  303. /* 0 is not a valid value for xTimerPeriodInTicks. */
  304. configASSERT( ( xTimerPeriodInTicks > 0 ) );
  305. if( pxNewTimer != NULL )
  306. {
  307. /* Ensure the infrastructure used by the timer service task has been
  308. created/initialised. */
  309. prvCheckForValidListAndQueue();
  310. /* Initialise the timer structure members using the function
  311. parameters. */
  312. pxNewTimer->pcTimerName = pcTimerName;
  313. pxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks;
  314. pxNewTimer->uxAutoReload = uxAutoReload;
  315. pxNewTimer->pvTimerID = pvTimerID;
  316. pxNewTimer->pxCallbackFunction = pxCallbackFunction;
  317. vListInitialiseItem( &( pxNewTimer->xTimerListItem ) );
  318. traceTIMER_CREATE( pxNewTimer );
  319. }
  320. }
  321. /*-----------------------------------------------------------*/
  322. BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait )
  323. {
  324. BaseType_t xReturn = pdFAIL;
  325. DaemonTaskMessage_t xMessage;
  326. configASSERT( xTimer );
  327. /* Send a message to the timer service task to perform a particular action
  328. on a particular timer definition. */
  329. if( xTimerQueue != NULL )
  330. {
  331. /* Send a command to the timer service task to start the xTimer timer. */
  332. xMessage.xMessageID = xCommandID;
  333. xMessage.u.xTimerParameters.xMessageValue = xOptionalValue;
  334. xMessage.u.xTimerParameters.pxTimer = ( Timer_t * ) xTimer;
  335. if( xCommandID < tmrFIRST_FROM_ISR_COMMAND )
  336. {
  337. if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )
  338. {
  339. xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait );
  340. }
  341. else
  342. {
  343. xReturn = xQueueSendToBack( xTimerQueue, &xMessage, tmrNO_DELAY );
  344. }
  345. }
  346. else
  347. {
  348. xReturn = xQueueSendToBackFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
  349. }
  350. traceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn );
  351. }
  352. else
  353. {
  354. mtCOVERAGE_TEST_MARKER();
  355. }
  356. return xReturn;
  357. }
  358. /*-----------------------------------------------------------*/
  359. TaskHandle_t xTimerGetTimerDaemonTaskHandle( void )
  360. {
  361. /* If xTimerGetTimerDaemonTaskHandle() is called before the scheduler has been
  362. started, then xTimerTaskHandle will be NULL. */
  363. configASSERT( ( xTimerTaskHandle != NULL ) );
  364. return xTimerTaskHandle;
  365. }
  366. /*-----------------------------------------------------------*/
  367. TickType_t xTimerGetPeriod( TimerHandle_t xTimer )
  368. {
  369. Timer_t *pxTimer = ( Timer_t * ) xTimer;
  370. configASSERT( xTimer );
  371. return pxTimer->xTimerPeriodInTicks;
  372. }
  373. /*-----------------------------------------------------------*/
  374. TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer )
  375. {
  376. Timer_t * pxTimer = ( Timer_t * ) xTimer;
  377. TickType_t xReturn;
  378. configASSERT( xTimer );
  379. xReturn = listGET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ) );
  380. return xReturn;
  381. }
  382. /*-----------------------------------------------------------*/
  383. const char * pcTimerGetName( TimerHandle_t xTimer ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  384. {
  385. Timer_t *pxTimer = ( Timer_t * ) xTimer;
  386. configASSERT( xTimer );
  387. return pxTimer->pcTimerName;
  388. }
  389. /*-----------------------------------------------------------*/
  390. static void prvProcessExpiredTimer( const TickType_t xNextExpireTime, const TickType_t xTimeNow )
  391. {
  392. BaseType_t xResult;
  393. Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );
  394. /* Remove the timer from the list of active timers. A check has already
  395. been performed to ensure the list is not empty. */
  396. ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
  397. traceTIMER_EXPIRED( pxTimer );
  398. /* If the timer is an auto reload timer then calculate the next
  399. expiry time and re-insert the timer in the list of active timers. */
  400. if( pxTimer->uxAutoReload == ( UBaseType_t ) pdTRUE )
  401. {
  402. /* The timer is inserted into a list using a time relative to anything
  403. other than the current time. It will therefore be inserted into the
  404. correct list relative to the time this task thinks it is now. */
  405. if( prvInsertTimerInActiveList( pxTimer, ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xNextExpireTime ) != pdFALSE )
  406. {
  407. /* The timer expired before it was added to the active timer
  408. list. Reload it now. */
  409. xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY );
  410. configASSERT( xResult );
  411. ( void ) xResult;
  412. }
  413. else
  414. {
  415. mtCOVERAGE_TEST_MARKER();
  416. }
  417. }
  418. else
  419. {
  420. mtCOVERAGE_TEST_MARKER();
  421. }
  422. /* Call the timer callback. */
  423. pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
  424. }
  425. /*-----------------------------------------------------------*/
  426. static void prvTimerTask( void *pvParameters )
  427. {
  428. TickType_t xNextExpireTime;
  429. BaseType_t xListWasEmpty;
  430. /* Just to avoid compiler warnings. */
  431. ( void ) pvParameters;
  432. #if( configUSE_DAEMON_TASK_STARTUP_HOOK == 1 )
  433. {
  434. extern void vApplicationDaemonTaskStartupHook( void );
  435. /* Allow the application writer to execute some code in the context of
  436. this task at the point the task starts executing. This is useful if the
  437. application includes initialisation code that would benefit from
  438. executing after the scheduler has been started. */
  439. vApplicationDaemonTaskStartupHook();
  440. }
  441. #endif /* configUSE_DAEMON_TASK_STARTUP_HOOK */
  442. for( ;; )
  443. {
  444. /* Query the timers list to see if it contains any timers, and if so,
  445. obtain the time at which the next timer will expire. */
  446. xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty );
  447. /* If a timer has expired, process it. Otherwise, block this task
  448. until either a timer does expire, or a command is received. */
  449. prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty );
  450. /* Empty the command queue. */
  451. prvProcessReceivedCommands();
  452. }
  453. }
  454. /*-----------------------------------------------------------*/
  455. static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, BaseType_t xListWasEmpty )
  456. {
  457. TickType_t xTimeNow;
  458. BaseType_t xTimerListsWereSwitched;
  459. vTaskSuspendAll();
  460. {
  461. /* Obtain the time now to make an assessment as to whether the timer
  462. has expired or not. If obtaining the time causes the lists to switch
  463. then don't process this timer as any timers that remained in the list
  464. when the lists were switched will have been processed within the
  465. prvSampleTimeNow() function. */
  466. xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
  467. if( xTimerListsWereSwitched == pdFALSE )
  468. {
  469. /* The tick count has not overflowed, has the timer expired? */
  470. if( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) )
  471. {
  472. ( void ) xTaskResumeAll();
  473. prvProcessExpiredTimer( xNextExpireTime, xTimeNow );
  474. }
  475. else
  476. {
  477. /* The tick count has not overflowed, and the next expire
  478. time has not been reached yet. This task should therefore
  479. block to wait for the next expire time or a command to be
  480. received - whichever comes first. The following line cannot
  481. be reached unless xNextExpireTime > xTimeNow, except in the
  482. case when the current timer list is empty. */
  483. if( xListWasEmpty != pdFALSE )
  484. {
  485. /* The current timer list is empty - is the overflow list
  486. also empty? */
  487. xListWasEmpty = listLIST_IS_EMPTY( pxOverflowTimerList );
  488. }
  489. vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ), xListWasEmpty );
  490. if( xTaskResumeAll() == pdFALSE )
  491. {
  492. /* Yield to wait for either a command to arrive, or the
  493. block time to expire. If a command arrived between the
  494. critical section being exited and this yield then the yield
  495. will not cause the task to block. */
  496. portYIELD_WITHIN_API();
  497. }
  498. else
  499. {
  500. mtCOVERAGE_TEST_MARKER();
  501. }
  502. }
  503. }
  504. else
  505. {
  506. ( void ) xTaskResumeAll();
  507. }
  508. }
  509. }
  510. /*-----------------------------------------------------------*/
  511. static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty )
  512. {
  513. TickType_t xNextExpireTime;
  514. /* Timers are listed in expiry time order, with the head of the list
  515. referencing the task that will expire first. Obtain the time at which
  516. the timer with the nearest expiry time will expire. If there are no
  517. active timers then just set the next expire time to 0. That will cause
  518. this task to unblock when the tick count overflows, at which point the
  519. timer lists will be switched and the next expiry time can be
  520. re-assessed. */
  521. *pxListWasEmpty = listLIST_IS_EMPTY( pxCurrentTimerList );
  522. if( *pxListWasEmpty == pdFALSE )
  523. {
  524. xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
  525. }
  526. else
  527. {
  528. /* Ensure the task unblocks when the tick count rolls over. */
  529. xNextExpireTime = ( TickType_t ) 0U;
  530. }
  531. return xNextExpireTime;
  532. }
  533. /*-----------------------------------------------------------*/
  534. static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched )
  535. {
  536. TickType_t xTimeNow;
  537. PRIVILEGED_DATA static TickType_t xLastTime = ( TickType_t ) 0U; /*lint !e956 Variable is only accessible to one task. */
  538. xTimeNow = xTaskGetTickCount();
  539. if( xTimeNow < xLastTime )
  540. {
  541. prvSwitchTimerLists();
  542. *pxTimerListsWereSwitched = pdTRUE;
  543. }
  544. else
  545. {
  546. *pxTimerListsWereSwitched = pdFALSE;
  547. }
  548. xLastTime = xTimeNow;
  549. return xTimeNow;
  550. }
  551. /*-----------------------------------------------------------*/
  552. static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer, const TickType_t xNextExpiryTime, const TickType_t xTimeNow, const TickType_t xCommandTime )
  553. {
  554. BaseType_t xProcessTimerNow = pdFALSE;
  555. listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xNextExpiryTime );
  556. listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );
  557. if( xNextExpiryTime <= xTimeNow )
  558. {
  559. /* Has the expiry time elapsed between the command to start/reset a
  560. timer was issued, and the time the command was processed? */
  561. if( ( ( TickType_t ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks ) /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
  562. {
  563. /* The time between a command being issued and the command being
  564. processed actually exceeds the timers period. */
  565. xProcessTimerNow = pdTRUE;
  566. }
  567. else
  568. {
  569. vListInsert( pxOverflowTimerList, &( pxTimer->xTimerListItem ) );
  570. }
  571. }
  572. else
  573. {
  574. if( ( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime ) )
  575. {
  576. /* If, since the command was issued, the tick count has overflowed
  577. but the expiry time has not, then the timer must have already passed
  578. its expiry time and should be processed immediately. */
  579. xProcessTimerNow = pdTRUE;
  580. }
  581. else
  582. {
  583. vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
  584. }
  585. }
  586. return xProcessTimerNow;
  587. }
  588. /*-----------------------------------------------------------*/
  589. static void prvProcessReceivedCommands( void )
  590. {
  591. DaemonTaskMessage_t xMessage;
  592. Timer_t *pxTimer;
  593. BaseType_t xTimerListsWereSwitched, xResult;
  594. TickType_t xTimeNow;
  595. while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL ) /*lint !e603 xMessage does not have to be initialised as it is passed out, not in, and it is not used unless xQueueReceive() returns pdTRUE. */
  596. {
  597. #if ( INCLUDE_xTimerPendFunctionCall == 1 )
  598. {
  599. /* Negative commands are pended function calls rather than timer
  600. commands. */
  601. if( xMessage.xMessageID < ( BaseType_t ) 0 )
  602. {
  603. const CallbackParameters_t * const pxCallback = &( xMessage.u.xCallbackParameters );
  604. /* The timer uses the xCallbackParameters member to request a
  605. callback be executed. Check the callback is not NULL. */
  606. configASSERT( pxCallback );
  607. /* Call the function. */
  608. pxCallback->pxCallbackFunction( pxCallback->pvParameter1, pxCallback->ulParameter2 );
  609. }
  610. else
  611. {
  612. mtCOVERAGE_TEST_MARKER();
  613. }
  614. }
  615. #endif /* INCLUDE_xTimerPendFunctionCall */
  616. /* Commands that are positive are timer commands rather than pended
  617. function calls. */
  618. if( xMessage.xMessageID >= ( BaseType_t ) 0 )
  619. {
  620. /* The messages uses the xTimerParameters member to work on a
  621. software timer. */
  622. pxTimer = xMessage.u.xTimerParameters.pxTimer;
  623. if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) /*lint !e961. The cast is only redundant when NULL is passed into the macro. */
  624. {
  625. /* The timer is in a list, remove it. */
  626. ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
  627. }
  628. else
  629. {
  630. mtCOVERAGE_TEST_MARKER();
  631. }
  632. traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.u.xTimerParameters.xMessageValue );
  633. /* In this case the xTimerListsWereSwitched parameter is not used, but
  634. it must be present in the function call. prvSampleTimeNow() must be
  635. called after the message is received from xTimerQueue so there is no
  636. possibility of a higher priority task adding a message to the message
  637. queue with a time that is ahead of the timer daemon task (because it
  638. pre-empted the timer daemon task after the xTimeNow value was set). */
  639. xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
  640. switch( xMessage.xMessageID )
  641. {
  642. case tmrCOMMAND_START :
  643. case tmrCOMMAND_START_FROM_ISR :
  644. case tmrCOMMAND_RESET :
  645. case tmrCOMMAND_RESET_FROM_ISR :
  646. case tmrCOMMAND_START_DONT_TRACE :
  647. /* Start or restart a timer. */
  648. if( prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE )
  649. {
  650. /* The timer expired before it was added to the active
  651. timer list. Process it now. */
  652. pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
  653. traceTIMER_EXPIRED( pxTimer );
  654. if( pxTimer->uxAutoReload == ( UBaseType_t ) pdTRUE )
  655. {
  656. xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, NULL, tmrNO_DELAY );
  657. configASSERT( xResult );
  658. ( void ) xResult;
  659. }
  660. else
  661. {
  662. mtCOVERAGE_TEST_MARKER();
  663. }
  664. }
  665. else
  666. {
  667. mtCOVERAGE_TEST_MARKER();
  668. }
  669. break;
  670. case tmrCOMMAND_STOP :
  671. case tmrCOMMAND_STOP_FROM_ISR :
  672. /* The timer has already been removed from the active list.
  673. There is nothing to do here. */
  674. break;
  675. case tmrCOMMAND_CHANGE_PERIOD :
  676. case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR :
  677. pxTimer->xTimerPeriodInTicks = xMessage.u.xTimerParameters.xMessageValue;
  678. configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) );
  679. /* The new period does not really have a reference, and can
  680. be longer or shorter than the old one. The command time is
  681. therefore set to the current time, and as the period cannot
  682. be zero the next expiry time can only be in the future,
  683. meaning (unlike for the xTimerStart() case above) there is
  684. no fail case that needs to be handled here. */
  685. ( void ) prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow );
  686. break;
  687. case tmrCOMMAND_DELETE :
  688. /* The timer has already been removed from the active list,
  689. just free up the memory if the memory was dynamically
  690. allocated. */
  691. #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )
  692. {
  693. /* The timer can only have been allocated dynamically -
  694. free it again. */
  695. vPortFree( pxTimer );
  696. }
  697. #elif( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  698. {
  699. /* The timer could have been allocated statically or
  700. dynamically, so check before attempting to free the
  701. memory. */
  702. if( pxTimer->ucStaticallyAllocated == ( uint8_t ) pdFALSE )
  703. {
  704. vPortFree( pxTimer );
  705. }
  706. else
  707. {
  708. mtCOVERAGE_TEST_MARKER();
  709. }
  710. }
  711. #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
  712. break;
  713. default :
  714. /* Don't expect to get here. */
  715. break;
  716. }
  717. }
  718. }
  719. }
  720. /*-----------------------------------------------------------*/
  721. static void prvSwitchTimerLists( void )
  722. {
  723. TickType_t xNextExpireTime, xReloadTime;
  724. List_t *pxTemp;
  725. Timer_t *pxTimer;
  726. BaseType_t xResult;
  727. /* The tick count has overflowed. The timer lists must be switched.
  728. If there are any timers still referenced from the current timer list
  729. then they must have expired and should be processed before the lists
  730. are switched. */
  731. while( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE )
  732. {
  733. xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
  734. /* Remove the timer from the list. */
  735. pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );
  736. ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
  737. traceTIMER_EXPIRED( pxTimer );
  738. /* Execute its callback, then send a command to restart the timer if
  739. it is an auto-reload timer. It cannot be restarted here as the lists
  740. have not yet been switched. */
  741. pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
  742. if( pxTimer->uxAutoReload == ( UBaseType_t ) pdTRUE )
  743. {
  744. /* Calculate the reload value, and if the reload value results in
  745. the timer going into the same timer list then it has already expired
  746. and the timer should be re-inserted into the current list so it is
  747. processed again within this loop. Otherwise a command should be sent
  748. to restart the timer to ensure it is only inserted into a list after
  749. the lists have been swapped. */
  750. xReloadTime = ( xNextExpireTime + pxTimer->xTimerPeriodInTicks );
  751. if( xReloadTime > xNextExpireTime )
  752. {
  753. listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xReloadTime );
  754. listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );
  755. vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
  756. }
  757. else
  758. {
  759. xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY );
  760. configASSERT( xResult );
  761. ( void ) xResult;
  762. }
  763. }
  764. else
  765. {
  766. mtCOVERAGE_TEST_MARKER();
  767. }
  768. }
  769. pxTemp = pxCurrentTimerList;
  770. pxCurrentTimerList = pxOverflowTimerList;
  771. pxOverflowTimerList = pxTemp;
  772. }
  773. /*-----------------------------------------------------------*/
  774. static void prvCheckForValidListAndQueue( void )
  775. {
  776. /* Check that the list from which active timers are referenced, and the
  777. queue used to communicate with the timer service, have been
  778. initialised. */
  779. taskENTER_CRITICAL();
  780. {
  781. if( xTimerQueue == NULL )
  782. {
  783. vListInitialise( &xActiveTimerList1 );
  784. vListInitialise( &xActiveTimerList2 );
  785. pxCurrentTimerList = &xActiveTimerList1;
  786. pxOverflowTimerList = &xActiveTimerList2;
  787. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  788. {
  789. /* The timer queue is allocated statically in case
  790. configSUPPORT_DYNAMIC_ALLOCATION is 0. */
  791. static StaticQueue_t xStaticTimerQueue; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */
  792. static uint8_t ucStaticTimerQueueStorage[ ( size_t ) configTIMER_QUEUE_LENGTH * sizeof( DaemonTaskMessage_t ) ]; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */
  793. xTimerQueue = xQueueCreateStatic( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, ( UBaseType_t ) sizeof( DaemonTaskMessage_t ), &( ucStaticTimerQueueStorage[ 0 ] ), &xStaticTimerQueue );
  794. }
  795. #else
  796. {
  797. xTimerQueue = xQueueCreate( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, sizeof( DaemonTaskMessage_t ) );
  798. }
  799. #endif
  800. #if ( configQUEUE_REGISTRY_SIZE > 0 )
  801. {
  802. if( xTimerQueue != NULL )
  803. {
  804. vQueueAddToRegistry( xTimerQueue, "TmrQ" );
  805. }
  806. else
  807. {
  808. mtCOVERAGE_TEST_MARKER();
  809. }
  810. }
  811. #endif /* configQUEUE_REGISTRY_SIZE */
  812. }
  813. else
  814. {
  815. mtCOVERAGE_TEST_MARKER();
  816. }
  817. }
  818. taskEXIT_CRITICAL();
  819. }
  820. /*-----------------------------------------------------------*/
  821. BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer )
  822. {
  823. BaseType_t xTimerIsInActiveList;
  824. Timer_t *pxTimer = ( Timer_t * ) xTimer;
  825. configASSERT( xTimer );
  826. /* Is the timer in the list of active timers? */
  827. taskENTER_CRITICAL();
  828. {
  829. /* Checking to see if it is in the NULL list in effect checks to see if
  830. it is referenced from either the current or the overflow timer lists in
  831. one go, but the logic has to be reversed, hence the '!'. */
  832. xTimerIsInActiveList = ( BaseType_t ) !( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) ); /*lint !e961. Cast is only redundant when NULL is passed into the macro. */
  833. }
  834. taskEXIT_CRITICAL();
  835. return xTimerIsInActiveList;
  836. } /*lint !e818 Can't be pointer to const due to the typedef. */
  837. /*-----------------------------------------------------------*/
  838. void *pvTimerGetTimerID( const TimerHandle_t xTimer )
  839. {
  840. Timer_t * const pxTimer = ( Timer_t * ) xTimer;
  841. void *pvReturn;
  842. configASSERT( xTimer );
  843. taskENTER_CRITICAL();
  844. {
  845. pvReturn = pxTimer->pvTimerID;
  846. }
  847. taskEXIT_CRITICAL();
  848. return pvReturn;
  849. }
  850. /*-----------------------------------------------------------*/
  851. void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID )
  852. {
  853. Timer_t * const pxTimer = ( Timer_t * ) xTimer;
  854. configASSERT( xTimer );
  855. taskENTER_CRITICAL();
  856. {
  857. pxTimer->pvTimerID = pvNewID;
  858. }
  859. taskEXIT_CRITICAL();
  860. }
  861. /*-----------------------------------------------------------*/
  862. #if( INCLUDE_xTimerPendFunctionCall == 1 )
  863. BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken )
  864. {
  865. DaemonTaskMessage_t xMessage;
  866. BaseType_t xReturn;
  867. /* Complete the message with the function parameters and post it to the
  868. daemon task. */
  869. xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR;
  870. xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;
  871. xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;
  872. xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;
  873. xReturn = xQueueSendFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
  874. tracePEND_FUNC_CALL_FROM_ISR( xFunctionToPend, pvParameter1, ulParameter2, xReturn );
  875. return xReturn;
  876. }
  877. #endif /* INCLUDE_xTimerPendFunctionCall */
  878. /*-----------------------------------------------------------*/
  879. #if( INCLUDE_xTimerPendFunctionCall == 1 )
  880. BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait )
  881. {
  882. DaemonTaskMessage_t xMessage;
  883. BaseType_t xReturn;
  884. /* This function can only be called after a timer has been created or
  885. after the scheduler has been started because, until then, the timer
  886. queue does not exist. */
  887. configASSERT( xTimerQueue );
  888. /* Complete the message with the function parameters and post it to the
  889. daemon task. */
  890. xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK;
  891. xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;
  892. xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;
  893. xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;
  894. xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait );
  895. tracePEND_FUNC_CALL( xFunctionToPend, pvParameter1, ulParameter2, xReturn );
  896. return xReturn;
  897. }
  898. #endif /* INCLUDE_xTimerPendFunctionCall */
  899. /*-----------------------------------------------------------*/
  900. #if ( configUSE_TRACE_FACILITY == 1 )
  901. UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer )
  902. {
  903. return ( ( Timer_t * ) xTimer )->uxTimerNumber;
  904. }
  905. #endif /* configUSE_TRACE_FACILITY */
  906. /*-----------------------------------------------------------*/
  907. #if ( configUSE_TRACE_FACILITY == 1 )
  908. void vTimerSetTimerNumber( TimerHandle_t xTimer, UBaseType_t uxTimerNumber )
  909. {
  910. ( ( Timer_t * ) xTimer )->uxTimerNumber = uxTimerNumber;
  911. }
  912. #endif /* configUSE_TRACE_FACILITY */
  913. /*-----------------------------------------------------------*/
  914. /* This entire source file will be skipped if the application is not configured
  915. to include software timer functionality. If you want to include software timer
  916. functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
  917. #endif /* configUSE_TIMERS == 1 */