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