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