timers.c 39 KB

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