timers.c 38 KB

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