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