2 * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
29 /* Standard includes. */
32 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
33 * all the API functions to use the MPU wrappers. That should only be done when
34 * task.h is included from an application file. */
35 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
42 #if ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 0 )
43 #error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available.
46 /* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified
47 * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
48 * for the header files above, but not in this file, in order to generate the
49 * correct privileged Vs unprivileged linkage and placement. */
50 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e9021 !e961 !e750. */
53 /* This entire source file will be skipped if the application is not configured
54 * to include software timer functionality. This #if is closed at the very bottom
55 * of this file. If you want to include software timer functionality then ensure
56 * configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
57 #if ( configUSE_TIMERS == 1 )
59 /* Misc definitions. */
60 #define tmrNO_DELAY ( ( TickType_t ) 0U )
61 #define tmrMAX_TIME_BEFORE_OVERFLOW ( ( TickType_t ) -1 )
63 /* The name assigned to the timer service task. This can be overridden by
64 * defining configTIMER_SERVICE_TASK_NAME in FreeRTOSConfig.h. */
65 #ifndef configTIMER_SERVICE_TASK_NAME
66 #define configTIMER_SERVICE_TASK_NAME "Tmr Svc"
69 #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
71 /* The core affinity assigned to the timer service task on SMP systems.
72 * This can be overridden by defining configTIMER_SERVICE_TASK_CORE_AFFINITY in FreeRTOSConfig.h. */
73 #ifndef configTIMER_SERVICE_TASK_CORE_AFFINITY
74 #define configTIMER_SERVICE_TASK_CORE_AFFINITY tskNO_AFFINITY
76 #endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) ) */
78 /* Bit definitions used in the ucStatus member of a timer structure. */
79 #define tmrSTATUS_IS_ACTIVE ( 0x01U )
80 #define tmrSTATUS_IS_STATICALLY_ALLOCATED ( 0x02U )
81 #define tmrSTATUS_IS_AUTORELOAD ( 0x04U )
83 /* The definition of the timers themselves. */
84 typedef struct tmrTimerControl /* The old naming convention is used to prevent breaking kernel aware debuggers. */
86 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. */
87 ListItem_t xTimerListItem; /**< Standard linked list item as used by all kernel features for event management. */
88 TickType_t xTimerPeriodInTicks; /**< How quickly and often the timer expires. */
89 void * pvTimerID; /**< An ID to identify the timer. This allows the timer to be identified when the same callback is used for multiple timers. */
90 portTIMER_CALLBACK_ATTRIBUTE TimerCallbackFunction_t pxCallbackFunction; /**< The function that will be called when the timer expires. */
91 #if ( configUSE_TRACE_FACILITY == 1 )
92 UBaseType_t uxTimerNumber; /**< An ID assigned by trace tools such as FreeRTOS+Trace */
94 uint8_t ucStatus; /**< Holds bits to say if the timer was statically allocated or not, and if it is active or not. */
97 /* The old xTIMER name is maintained above then typedefed to the new Timer_t
98 * name below to enable the use of older kernel aware debuggers. */
99 typedef xTIMER Timer_t;
101 /* The definition of messages that can be sent and received on the timer queue.
102 * Two types of message can be queued - messages that manipulate a software timer,
103 * and messages that request the execution of a non-timer related callback. The
104 * two message types are defined in two separate structures, xTimerParametersType
105 * and xCallbackParametersType respectively. */
106 typedef struct tmrTimerParameters
108 TickType_t xMessageValue; /**< An optional value used by a subset of commands, for example, when changing the period of a timer. */
109 Timer_t * pxTimer; /**< The timer to which the command will be applied. */
113 typedef struct tmrCallbackParameters
115 portTIMER_CALLBACK_ATTRIBUTE
116 PendedFunction_t pxCallbackFunction; /* << The callback function to execute. */
117 void * pvParameter1; /* << The value that will be used as the callback functions first parameter. */
118 uint32_t ulParameter2; /* << The value that will be used as the callback functions second parameter. */
119 } CallbackParameters_t;
121 /* The structure that contains the two message types, along with an identifier
122 * that is used to determine which message type is valid. */
123 typedef struct tmrTimerQueueMessage
125 BaseType_t xMessageID; /**< The command being sent to the timer service task. */
128 TimerParameter_t xTimerParameters;
130 /* Don't include xCallbackParameters if it is not going to be used as
131 * it makes the structure (and therefore the timer queue) larger. */
132 #if ( INCLUDE_xTimerPendFunctionCall == 1 )
133 CallbackParameters_t xCallbackParameters;
134 #endif /* INCLUDE_xTimerPendFunctionCall */
136 } DaemonTaskMessage_t;
138 /*lint -save -e956 A manual analysis and inspection has been used to determine
139 * which static variables must be declared volatile. */
141 /* The list in which active timers are stored. Timers are referenced in expire
142 * time order, with the nearest expiry time at the front of the list. Only the
143 * timer service task is allowed to access these lists.
144 * xActiveTimerList1 and xActiveTimerList2 could be at function scope but that
145 * breaks some kernel aware debuggers, and debuggers that reply on removing the
146 * static qualifier. */
147 PRIVILEGED_DATA static List_t xActiveTimerList1;
148 PRIVILEGED_DATA static List_t xActiveTimerList2;
149 PRIVILEGED_DATA static List_t * pxCurrentTimerList;
150 PRIVILEGED_DATA static List_t * pxOverflowTimerList;
152 /* A queue that is used to send commands to the timer service task. */
153 PRIVILEGED_DATA static QueueHandle_t xTimerQueue = NULL;
154 PRIVILEGED_DATA static TaskHandle_t xTimerTaskHandle = NULL;
158 /*-----------------------------------------------------------*/
161 * Initialise the infrastructure used by the timer service task if it has not
162 * been initialised already.
164 static void prvCheckForValidListAndQueue( void ) PRIVILEGED_FUNCTION;
167 * The timer service task (daemon). Timer functionality is controlled by this
168 * task. Other tasks communicate with the timer service task using the
171 static portTASK_FUNCTION_PROTO( prvTimerTask, pvParameters ) PRIVILEGED_FUNCTION;
174 * Called by the timer service task to interpret and process a command it
175 * received on the timer queue.
177 static void prvProcessReceivedCommands( void ) PRIVILEGED_FUNCTION;
180 * Insert the timer into either xActiveTimerList1, or xActiveTimerList2,
181 * depending on if the expire time causes a timer counter overflow.
183 static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer,
184 const TickType_t xNextExpiryTime,
185 const TickType_t xTimeNow,
186 const TickType_t xCommandTime ) PRIVILEGED_FUNCTION;
189 * Reload the specified auto-reload timer. If the reloading is backlogged,
190 * clear the backlog, calling the callback for each additional reload. When
191 * this function returns, the next expiry time is after xTimeNow.
193 static void prvReloadTimer( Timer_t * const pxTimer,
194 TickType_t xExpiredTime,
195 const TickType_t xTimeNow ) PRIVILEGED_FUNCTION;
198 * An active timer has reached its expire time. Reload the timer if it is an
199 * auto-reload timer, then call its callback.
201 static void prvProcessExpiredTimer( const TickType_t xNextExpireTime,
202 const TickType_t xTimeNow ) PRIVILEGED_FUNCTION;
205 * The tick count has overflowed. Switch the timer lists after ensuring the
206 * current timer list does not still reference some timers.
208 static void prvSwitchTimerLists( void ) PRIVILEGED_FUNCTION;
211 * Obtain the current tick count, setting *pxTimerListsWereSwitched to pdTRUE
212 * if a tick count overflow occurred since prvSampleTimeNow() was last called.
214 static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched ) PRIVILEGED_FUNCTION;
217 * If the timer list contains any active timers then return the expire time of
218 * the timer that will expire first and set *pxListWasEmpty to false. If the
219 * timer list does not contain any timers then return 0 and set *pxListWasEmpty
222 static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty ) PRIVILEGED_FUNCTION;
225 * If a timer has expired, process it. Otherwise, block the timer service task
226 * until either a timer does expire or a command is received.
228 static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime,
229 BaseType_t xListWasEmpty ) PRIVILEGED_FUNCTION;
232 * Called after a Timer_t structure has been allocated either statically or
233 * dynamically to fill in the structure's members.
235 static void prvInitialiseNewTimer( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
236 const TickType_t xTimerPeriodInTicks,
237 const BaseType_t xAutoReload,
238 void * const pvTimerID,
239 TimerCallbackFunction_t pxCallbackFunction,
240 Timer_t * pxNewTimer ) PRIVILEGED_FUNCTION;
241 /*-----------------------------------------------------------*/
243 BaseType_t xTimerCreateTimerTask( void )
245 BaseType_t xReturn = pdFAIL;
247 traceENTER_xTimerCreateTimerTask();
249 /* This function is called when the scheduler is started if
250 * configUSE_TIMERS is set to 1. Check that the infrastructure used by the
251 * timer service task has been created/initialised. If timers have already
252 * been created then the initialisation will already have been performed. */
253 prvCheckForValidListAndQueue();
255 if( xTimerQueue != NULL )
257 #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
259 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
261 StaticTask_t * pxTimerTaskTCBBuffer = NULL;
262 StackType_t * pxTimerTaskStackBuffer = NULL;
263 uint32_t ulTimerTaskStackSize;
265 vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize );
266 xTimerTaskHandle = xTaskCreateStaticAffinitySet( prvTimerTask,
267 configTIMER_SERVICE_TASK_NAME,
268 ulTimerTaskStackSize,
270 ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
271 pxTimerTaskStackBuffer,
272 pxTimerTaskTCBBuffer,
273 configTIMER_SERVICE_TASK_CORE_AFFINITY );
275 if( xTimerTaskHandle != NULL )
280 #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
282 xReturn = xTaskCreateAffinitySet( prvTimerTask,
283 configTIMER_SERVICE_TASK_NAME,
284 configTIMER_TASK_STACK_DEPTH,
286 ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
287 configTIMER_SERVICE_TASK_CORE_AFFINITY,
290 #endif /* configSUPPORT_STATIC_ALLOCATION */
292 #else /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) ) */
294 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
296 StaticTask_t * pxTimerTaskTCBBuffer = NULL;
297 StackType_t * pxTimerTaskStackBuffer = NULL;
298 uint32_t ulTimerTaskStackSize;
300 vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize );
301 xTimerTaskHandle = xTaskCreateStatic( prvTimerTask,
302 configTIMER_SERVICE_TASK_NAME,
303 ulTimerTaskStackSize,
305 ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
306 pxTimerTaskStackBuffer,
307 pxTimerTaskTCBBuffer );
309 if( xTimerTaskHandle != NULL )
314 #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
316 xReturn = xTaskCreate( prvTimerTask,
317 configTIMER_SERVICE_TASK_NAME,
318 configTIMER_TASK_STACK_DEPTH,
320 ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
323 #endif /* configSUPPORT_STATIC_ALLOCATION */
325 #endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) ) */
329 mtCOVERAGE_TEST_MARKER();
332 configASSERT( xReturn );
334 traceRETURN_xTimerCreateTimerTask( xReturn );
338 /*-----------------------------------------------------------*/
340 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
342 TimerHandle_t xTimerCreate( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
343 const TickType_t xTimerPeriodInTicks,
344 const BaseType_t xAutoReload,
345 void * const pvTimerID,
346 TimerCallbackFunction_t pxCallbackFunction )
348 Timer_t * pxNewTimer;
350 traceENTER_xTimerCreate( pcTimerName, xTimerPeriodInTicks, xAutoReload, pvTimerID, pxCallbackFunction );
352 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 name. */
354 if( pxNewTimer != NULL )
356 /* Status is thus far zero as the timer is not created statically
357 * and has not been started. The auto-reload bit may get set in
358 * prvInitialiseNewTimer. */
359 pxNewTimer->ucStatus = 0x00;
360 prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, xAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
363 traceRETURN_xTimerCreate( pxNewTimer );
368 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
369 /*-----------------------------------------------------------*/
371 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
373 TimerHandle_t xTimerCreateStatic( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
374 const TickType_t xTimerPeriodInTicks,
375 const BaseType_t xAutoReload,
376 void * const pvTimerID,
377 TimerCallbackFunction_t pxCallbackFunction,
378 StaticTimer_t * pxTimerBuffer )
380 Timer_t * pxNewTimer;
382 traceENTER_xTimerCreateStatic( pcTimerName, xTimerPeriodInTicks, xAutoReload, pvTimerID, pxCallbackFunction, pxTimerBuffer );
384 #if ( configASSERT_DEFINED == 1 )
386 /* Sanity check that the size of the structure used to declare a
387 * variable of type StaticTimer_t equals the size of the real timer
389 volatile size_t xSize = sizeof( StaticTimer_t );
390 configASSERT( xSize == sizeof( Timer_t ) );
391 ( void ) xSize; /* Keeps lint quiet when configASSERT() is not defined. */
393 #endif /* configASSERT_DEFINED */
395 /* A pointer to a StaticTimer_t structure MUST be provided, use it. */
396 configASSERT( pxTimerBuffer );
397 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. */
399 if( pxNewTimer != NULL )
401 /* Timers can be created statically or dynamically so note this
402 * timer was created statically in case it is later deleted. The
403 * auto-reload bit may get set in prvInitialiseNewTimer(). */
404 pxNewTimer->ucStatus = ( uint8_t ) tmrSTATUS_IS_STATICALLY_ALLOCATED;
406 prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, xAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
409 traceRETURN_xTimerCreateStatic( pxNewTimer );
414 #endif /* configSUPPORT_STATIC_ALLOCATION */
415 /*-----------------------------------------------------------*/
417 static void prvInitialiseNewTimer( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
418 const TickType_t xTimerPeriodInTicks,
419 const BaseType_t xAutoReload,
420 void * const pvTimerID,
421 TimerCallbackFunction_t pxCallbackFunction,
422 Timer_t * pxNewTimer )
424 /* 0 is not a valid value for xTimerPeriodInTicks. */
425 configASSERT( ( xTimerPeriodInTicks > 0 ) );
427 /* Ensure the infrastructure used by the timer service task has been
428 * created/initialised. */
429 prvCheckForValidListAndQueue();
431 /* Initialise the timer structure members using the function
433 pxNewTimer->pcTimerName = pcTimerName;
434 pxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks;
435 pxNewTimer->pvTimerID = pvTimerID;
436 pxNewTimer->pxCallbackFunction = pxCallbackFunction;
437 vListInitialiseItem( &( pxNewTimer->xTimerListItem ) );
439 if( xAutoReload != pdFALSE )
441 pxNewTimer->ucStatus |= ( uint8_t ) tmrSTATUS_IS_AUTORELOAD;
444 traceTIMER_CREATE( pxNewTimer );
446 /*-----------------------------------------------------------*/
448 BaseType_t xTimerGenericCommandFromTask( TimerHandle_t xTimer,
449 const BaseType_t xCommandID,
450 const TickType_t xOptionalValue,
451 BaseType_t * const pxHigherPriorityTaskWoken,
452 const TickType_t xTicksToWait )
454 BaseType_t xReturn = pdFAIL;
455 DaemonTaskMessage_t xMessage;
457 ( void ) pxHigherPriorityTaskWoken;
459 traceENTER_xTimerGenericCommandFromTask( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait );
461 configASSERT( xTimer );
463 /* Send a message to the timer service task to perform a particular action
464 * on a particular timer definition. */
465 if( xTimerQueue != NULL )
467 /* Send a command to the timer service task to start the xTimer timer. */
468 xMessage.xMessageID = xCommandID;
469 xMessage.u.xTimerParameters.xMessageValue = xOptionalValue;
470 xMessage.u.xTimerParameters.pxTimer = xTimer;
472 configASSERT( xCommandID < tmrFIRST_FROM_ISR_COMMAND );
474 if( xCommandID < tmrFIRST_FROM_ISR_COMMAND )
476 if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )
478 xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait );
482 xReturn = xQueueSendToBack( xTimerQueue, &xMessage, tmrNO_DELAY );
486 traceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn );
490 mtCOVERAGE_TEST_MARKER();
493 traceRETURN_xTimerGenericCommandFromTask( xReturn );
497 /*-----------------------------------------------------------*/
499 BaseType_t xTimerGenericCommandFromISR( TimerHandle_t xTimer,
500 const BaseType_t xCommandID,
501 const TickType_t xOptionalValue,
502 BaseType_t * const pxHigherPriorityTaskWoken,
503 const TickType_t xTicksToWait )
505 BaseType_t xReturn = pdFAIL;
506 DaemonTaskMessage_t xMessage;
508 ( void ) xTicksToWait;
510 traceENTER_xTimerGenericCommandFromISR( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait );
512 configASSERT( xTimer );
514 /* Send a message to the timer service task to perform a particular action
515 * on a particular timer definition. */
516 if( xTimerQueue != NULL )
518 /* Send a command to the timer service task to start the xTimer timer. */
519 xMessage.xMessageID = xCommandID;
520 xMessage.u.xTimerParameters.xMessageValue = xOptionalValue;
521 xMessage.u.xTimerParameters.pxTimer = xTimer;
523 configASSERT( xCommandID >= tmrFIRST_FROM_ISR_COMMAND );
525 if( xCommandID >= tmrFIRST_FROM_ISR_COMMAND )
527 xReturn = xQueueSendToBackFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
530 traceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn );
534 mtCOVERAGE_TEST_MARKER();
537 traceRETURN_xTimerGenericCommandFromISR( xReturn );
541 /*-----------------------------------------------------------*/
543 TaskHandle_t xTimerGetTimerDaemonTaskHandle( void )
545 traceENTER_xTimerGetTimerDaemonTaskHandle();
547 /* If xTimerGetTimerDaemonTaskHandle() is called before the scheduler has been
548 * started, then xTimerTaskHandle will be NULL. */
549 configASSERT( ( xTimerTaskHandle != NULL ) );
551 traceRETURN_xTimerGetTimerDaemonTaskHandle( xTimerTaskHandle );
553 return xTimerTaskHandle;
555 /*-----------------------------------------------------------*/
557 TickType_t xTimerGetPeriod( TimerHandle_t xTimer )
559 Timer_t * pxTimer = xTimer;
561 traceENTER_xTimerGetPeriod( xTimer );
563 configASSERT( xTimer );
565 traceRETURN_xTimerGetPeriod( pxTimer->xTimerPeriodInTicks );
567 return pxTimer->xTimerPeriodInTicks;
569 /*-----------------------------------------------------------*/
571 void vTimerSetReloadMode( TimerHandle_t xTimer,
572 const BaseType_t xAutoReload )
574 Timer_t * pxTimer = xTimer;
576 traceENTER_vTimerSetReloadMode( xTimer, xAutoReload );
578 configASSERT( xTimer );
579 taskENTER_CRITICAL();
581 if( xAutoReload != pdFALSE )
583 pxTimer->ucStatus |= ( uint8_t ) tmrSTATUS_IS_AUTORELOAD;
587 pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_AUTORELOAD );
592 traceRETURN_vTimerSetReloadMode();
594 /*-----------------------------------------------------------*/
596 BaseType_t xTimerGetReloadMode( TimerHandle_t xTimer )
598 Timer_t * pxTimer = xTimer;
601 traceENTER_xTimerGetReloadMode( xTimer );
603 configASSERT( xTimer );
604 taskENTER_CRITICAL();
606 if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0 )
608 /* Not an auto-reload timer. */
613 /* Is an auto-reload timer. */
619 traceRETURN_xTimerGetReloadMode( xReturn );
624 UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer )
626 UBaseType_t uxReturn;
628 traceENTER_uxTimerGetReloadMode( xTimer );
630 uxReturn = ( UBaseType_t ) xTimerGetReloadMode( xTimer );
632 traceRETURN_uxTimerGetReloadMode( uxReturn );
636 /*-----------------------------------------------------------*/
638 TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer )
640 Timer_t * pxTimer = xTimer;
643 traceENTER_xTimerGetExpiryTime( xTimer );
645 configASSERT( xTimer );
646 xReturn = listGET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ) );
648 traceRETURN_xTimerGetExpiryTime( xReturn );
652 /*-----------------------------------------------------------*/
654 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
655 BaseType_t xTimerGetStaticBuffer( TimerHandle_t xTimer,
656 StaticTimer_t ** ppxTimerBuffer )
659 Timer_t * pxTimer = xTimer;
661 traceENTER_xTimerGetStaticBuffer( xTimer, ppxTimerBuffer );
663 configASSERT( ppxTimerBuffer != NULL );
665 if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) != 0 )
667 *ppxTimerBuffer = ( StaticTimer_t * ) pxTimer;
675 traceRETURN_xTimerGetStaticBuffer( xReturn );
679 #endif /* configSUPPORT_STATIC_ALLOCATION */
680 /*-----------------------------------------------------------*/
682 const char * pcTimerGetName( TimerHandle_t xTimer ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
684 Timer_t * pxTimer = xTimer;
686 traceENTER_pcTimerGetName( xTimer );
688 configASSERT( xTimer );
690 traceRETURN_pcTimerGetName( pxTimer->pcTimerName );
692 return pxTimer->pcTimerName;
694 /*-----------------------------------------------------------*/
696 static void prvReloadTimer( Timer_t * const pxTimer,
697 TickType_t xExpiredTime,
698 const TickType_t xTimeNow )
700 /* Insert the timer into the appropriate list for the next expiry time.
701 * If the next expiry time has already passed, advance the expiry time,
702 * call the callback function, and try again. */
703 while( prvInsertTimerInActiveList( pxTimer, ( xExpiredTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xExpiredTime ) != pdFALSE )
705 /* Advance the expiry time. */
706 xExpiredTime += pxTimer->xTimerPeriodInTicks;
708 /* Call the timer callback. */
709 traceTIMER_EXPIRED( pxTimer );
710 pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
713 /*-----------------------------------------------------------*/
715 static void prvProcessExpiredTimer( const TickType_t xNextExpireTime,
716 const TickType_t xTimeNow )
718 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. */
720 /* Remove the timer from the list of active timers. A check has already
721 * been performed to ensure the list is not empty. */
723 ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
725 /* If the timer is an auto-reload timer then calculate the next
726 * expiry time and re-insert the timer in the list of active timers. */
727 if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
729 prvReloadTimer( pxTimer, xNextExpireTime, xTimeNow );
733 pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE );
736 /* Call the timer callback. */
737 traceTIMER_EXPIRED( pxTimer );
738 pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
740 /*-----------------------------------------------------------*/
742 static portTASK_FUNCTION( prvTimerTask, pvParameters )
744 TickType_t xNextExpireTime;
745 BaseType_t xListWasEmpty;
747 /* Just to avoid compiler warnings. */
748 ( void ) pvParameters;
750 #if ( configUSE_DAEMON_TASK_STARTUP_HOOK == 1 )
752 /* Allow the application writer to execute some code in the context of
753 * this task at the point the task starts executing. This is useful if the
754 * application includes initialisation code that would benefit from
755 * executing after the scheduler has been started. */
756 vApplicationDaemonTaskStartupHook();
758 #endif /* configUSE_DAEMON_TASK_STARTUP_HOOK */
760 for( ; configCONTROL_INFINITE_LOOP(); )
762 /* Query the timers list to see if it contains any timers, and if so,
763 * obtain the time at which the next timer will expire. */
764 xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty );
766 /* If a timer has expired, process it. Otherwise, block this task
767 * until either a timer does expire, or a command is received. */
768 prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty );
770 /* Empty the command queue. */
771 prvProcessReceivedCommands();
774 /*-----------------------------------------------------------*/
776 static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime,
777 BaseType_t xListWasEmpty )
780 BaseType_t xTimerListsWereSwitched;
784 /* Obtain the time now to make an assessment as to whether the timer
785 * has expired or not. If obtaining the time causes the lists to switch
786 * then don't process this timer as any timers that remained in the list
787 * when the lists were switched will have been processed within the
788 * prvSampleTimeNow() function. */
789 xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
791 if( xTimerListsWereSwitched == pdFALSE )
793 /* The tick count has not overflowed, has the timer expired? */
794 if( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) )
796 ( void ) xTaskResumeAll();
797 prvProcessExpiredTimer( xNextExpireTime, xTimeNow );
801 /* The tick count has not overflowed, and the next expire
802 * time has not been reached yet. This task should therefore
803 * block to wait for the next expire time or a command to be
804 * received - whichever comes first. The following line cannot
805 * be reached unless xNextExpireTime > xTimeNow, except in the
806 * case when the current timer list is empty. */
807 if( xListWasEmpty != pdFALSE )
809 /* The current timer list is empty - is the overflow list
811 xListWasEmpty = listLIST_IS_EMPTY( pxOverflowTimerList );
814 vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ), xListWasEmpty );
816 if( xTaskResumeAll() == pdFALSE )
818 /* Yield to wait for either a command to arrive, or the
819 * block time to expire. If a command arrived between the
820 * critical section being exited and this yield then the yield
821 * will not cause the task to block. */
822 taskYIELD_WITHIN_API();
826 mtCOVERAGE_TEST_MARKER();
832 ( void ) xTaskResumeAll();
836 /*-----------------------------------------------------------*/
838 static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty )
840 TickType_t xNextExpireTime;
842 /* Timers are listed in expiry time order, with the head of the list
843 * referencing the task that will expire first. Obtain the time at which
844 * the timer with the nearest expiry time will expire. If there are no
845 * active timers then just set the next expire time to 0. That will cause
846 * this task to unblock when the tick count overflows, at which point the
847 * timer lists will be switched and the next expiry time can be
849 *pxListWasEmpty = listLIST_IS_EMPTY( pxCurrentTimerList );
851 if( *pxListWasEmpty == pdFALSE )
853 xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
857 /* Ensure the task unblocks when the tick count rolls over. */
858 xNextExpireTime = ( TickType_t ) 0U;
861 return xNextExpireTime;
863 /*-----------------------------------------------------------*/
865 static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched )
868 PRIVILEGED_DATA static TickType_t xLastTime = ( TickType_t ) 0U; /*lint !e956 Variable is only accessible to one task. */
870 xTimeNow = xTaskGetTickCount();
872 if( xTimeNow < xLastTime )
874 prvSwitchTimerLists();
875 *pxTimerListsWereSwitched = pdTRUE;
879 *pxTimerListsWereSwitched = pdFALSE;
882 xLastTime = xTimeNow;
886 /*-----------------------------------------------------------*/
888 static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer,
889 const TickType_t xNextExpiryTime,
890 const TickType_t xTimeNow,
891 const TickType_t xCommandTime )
893 BaseType_t xProcessTimerNow = pdFALSE;
895 listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xNextExpiryTime );
896 listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );
898 if( xNextExpiryTime <= xTimeNow )
900 /* Has the expiry time elapsed between the command to start/reset a
901 * timer was issued, and the time the command was processed? */
902 if( ( ( TickType_t ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks ) /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
904 /* The time between a command being issued and the command being
905 * processed actually exceeds the timers period. */
906 xProcessTimerNow = pdTRUE;
910 vListInsert( pxOverflowTimerList, &( pxTimer->xTimerListItem ) );
915 if( ( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime ) )
917 /* If, since the command was issued, the tick count has overflowed
918 * but the expiry time has not, then the timer must have already passed
919 * its expiry time and should be processed immediately. */
920 xProcessTimerNow = pdTRUE;
924 vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
928 return xProcessTimerNow;
930 /*-----------------------------------------------------------*/
932 static void prvProcessReceivedCommands( void )
934 DaemonTaskMessage_t xMessage;
936 BaseType_t xTimerListsWereSwitched;
939 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. */
941 #if ( INCLUDE_xTimerPendFunctionCall == 1 )
943 /* Negative commands are pended function calls rather than timer
945 if( xMessage.xMessageID < ( BaseType_t ) 0 )
947 const CallbackParameters_t * const pxCallback = &( xMessage.u.xCallbackParameters );
949 /* The timer uses the xCallbackParameters member to request a
950 * callback be executed. Check the callback is not NULL. */
951 configASSERT( pxCallback );
953 /* Call the function. */
954 pxCallback->pxCallbackFunction( pxCallback->pvParameter1, pxCallback->ulParameter2 );
958 mtCOVERAGE_TEST_MARKER();
961 #endif /* INCLUDE_xTimerPendFunctionCall */
963 /* Commands that are positive are timer commands rather than pended
965 if( xMessage.xMessageID >= ( BaseType_t ) 0 )
967 /* The messages uses the xTimerParameters member to work on a
969 pxTimer = xMessage.u.xTimerParameters.pxTimer;
971 if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) /*lint !e961. The cast is only redundant when NULL is passed into the macro. */
973 /* The timer is in a list, remove it. */
974 ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
978 mtCOVERAGE_TEST_MARKER();
981 traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.u.xTimerParameters.xMessageValue );
983 /* In this case the xTimerListsWereSwitched parameter is not used, but
984 * it must be present in the function call. prvSampleTimeNow() must be
985 * called after the message is received from xTimerQueue so there is no
986 * possibility of a higher priority task adding a message to the message
987 * queue with a time that is ahead of the timer daemon task (because it
988 * pre-empted the timer daemon task after the xTimeNow value was set). */
989 xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
991 switch( xMessage.xMessageID )
993 case tmrCOMMAND_START:
994 case tmrCOMMAND_START_FROM_ISR:
995 case tmrCOMMAND_RESET:
996 case tmrCOMMAND_RESET_FROM_ISR:
997 /* Start or restart a timer. */
998 pxTimer->ucStatus |= ( uint8_t ) tmrSTATUS_IS_ACTIVE;
1000 if( prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE )
1002 /* The timer expired before it was added to the active
1003 * timer list. Process it now. */
1004 if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
1006 prvReloadTimer( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow );
1010 pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE );
1013 /* Call the timer callback. */
1014 traceTIMER_EXPIRED( pxTimer );
1015 pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
1019 mtCOVERAGE_TEST_MARKER();
1024 case tmrCOMMAND_STOP:
1025 case tmrCOMMAND_STOP_FROM_ISR:
1026 /* The timer has already been removed from the active list. */
1027 pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE );
1030 case tmrCOMMAND_CHANGE_PERIOD:
1031 case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR:
1032 pxTimer->ucStatus |= ( uint8_t ) tmrSTATUS_IS_ACTIVE;
1033 pxTimer->xTimerPeriodInTicks = xMessage.u.xTimerParameters.xMessageValue;
1034 configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) );
1036 /* The new period does not really have a reference, and can
1037 * be longer or shorter than the old one. The command time is
1038 * therefore set to the current time, and as the period cannot
1039 * be zero the next expiry time can only be in the future,
1040 * meaning (unlike for the xTimerStart() case above) there is
1041 * no fail case that needs to be handled here. */
1042 ( void ) prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow );
1045 case tmrCOMMAND_DELETE:
1046 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1048 /* The timer has already been removed from the active list,
1049 * just free up the memory if the memory was dynamically
1051 if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) 0 )
1053 vPortFree( pxTimer );
1057 pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE );
1060 #else /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */
1062 /* If dynamic allocation is not enabled, the memory
1063 * could not have been dynamically allocated. So there is
1064 * no need to free the memory - just mark the timer as
1066 pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE );
1068 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
1072 /* Don't expect to get here. */
1078 /*-----------------------------------------------------------*/
1080 static void prvSwitchTimerLists( void )
1082 TickType_t xNextExpireTime;
1085 /* The tick count has overflowed. The timer lists must be switched.
1086 * If there are any timers still referenced from the current timer list
1087 * then they must have expired and should be processed before the lists
1089 while( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE )
1091 xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
1093 /* Process the expired timer. For auto-reload timers, be careful to
1094 * process only expirations that occur on the current list. Further
1095 * expirations must wait until after the lists are switched. */
1096 prvProcessExpiredTimer( xNextExpireTime, tmrMAX_TIME_BEFORE_OVERFLOW );
1099 pxTemp = pxCurrentTimerList;
1100 pxCurrentTimerList = pxOverflowTimerList;
1101 pxOverflowTimerList = pxTemp;
1103 /*-----------------------------------------------------------*/
1105 static void prvCheckForValidListAndQueue( void )
1107 /* Check that the list from which active timers are referenced, and the
1108 * queue used to communicate with the timer service, have been
1110 taskENTER_CRITICAL();
1112 if( xTimerQueue == NULL )
1114 vListInitialise( &xActiveTimerList1 );
1115 vListInitialise( &xActiveTimerList2 );
1116 pxCurrentTimerList = &xActiveTimerList1;
1117 pxOverflowTimerList = &xActiveTimerList2;
1119 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1121 /* The timer queue is allocated statically in case
1122 * configSUPPORT_DYNAMIC_ALLOCATION is 0. */
1123 PRIVILEGED_DATA static StaticQueue_t xStaticTimerQueue; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */
1124 PRIVILEGED_DATA 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. */
1126 xTimerQueue = xQueueCreateStatic( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, ( UBaseType_t ) sizeof( DaemonTaskMessage_t ), &( ucStaticTimerQueueStorage[ 0 ] ), &xStaticTimerQueue );
1130 xTimerQueue = xQueueCreate( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, sizeof( DaemonTaskMessage_t ) );
1132 #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
1134 #if ( configQUEUE_REGISTRY_SIZE > 0 )
1136 if( xTimerQueue != NULL )
1138 vQueueAddToRegistry( xTimerQueue, "TmrQ" );
1142 mtCOVERAGE_TEST_MARKER();
1145 #endif /* configQUEUE_REGISTRY_SIZE */
1149 mtCOVERAGE_TEST_MARKER();
1152 taskEXIT_CRITICAL();
1154 /*-----------------------------------------------------------*/
1156 BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer )
1159 Timer_t * pxTimer = xTimer;
1161 traceENTER_xTimerIsTimerActive( xTimer );
1163 configASSERT( xTimer );
1165 /* Is the timer in the list of active timers? */
1166 taskENTER_CRITICAL();
1168 if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0 )
1177 taskEXIT_CRITICAL();
1179 traceRETURN_xTimerIsTimerActive( xReturn );
1182 } /*lint !e818 Can't be pointer to const due to the typedef. */
1183 /*-----------------------------------------------------------*/
1185 void * pvTimerGetTimerID( const TimerHandle_t xTimer )
1187 Timer_t * const pxTimer = xTimer;
1190 traceENTER_pvTimerGetTimerID( xTimer );
1192 configASSERT( xTimer );
1194 taskENTER_CRITICAL();
1196 pvReturn = pxTimer->pvTimerID;
1198 taskEXIT_CRITICAL();
1200 traceRETURN_pvTimerGetTimerID( pvReturn );
1204 /*-----------------------------------------------------------*/
1206 void vTimerSetTimerID( TimerHandle_t xTimer,
1209 Timer_t * const pxTimer = xTimer;
1211 traceENTER_vTimerSetTimerID( xTimer, pvNewID );
1213 configASSERT( xTimer );
1215 taskENTER_CRITICAL();
1217 pxTimer->pvTimerID = pvNewID;
1219 taskEXIT_CRITICAL();
1221 traceRETURN_vTimerSetTimerID();
1223 /*-----------------------------------------------------------*/
1225 #if ( INCLUDE_xTimerPendFunctionCall == 1 )
1227 BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
1228 void * pvParameter1,
1229 uint32_t ulParameter2,
1230 BaseType_t * pxHigherPriorityTaskWoken )
1232 DaemonTaskMessage_t xMessage;
1235 traceENTER_xTimerPendFunctionCallFromISR( xFunctionToPend, pvParameter1, ulParameter2, pxHigherPriorityTaskWoken );
1237 /* Complete the message with the function parameters and post it to the
1239 xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR;
1240 xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;
1241 xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;
1242 xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;
1244 xReturn = xQueueSendFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
1246 tracePEND_FUNC_CALL_FROM_ISR( xFunctionToPend, pvParameter1, ulParameter2, xReturn );
1247 traceRETURN_xTimerPendFunctionCallFromISR( xReturn );
1252 #endif /* INCLUDE_xTimerPendFunctionCall */
1253 /*-----------------------------------------------------------*/
1255 #if ( INCLUDE_xTimerPendFunctionCall == 1 )
1257 BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
1258 void * pvParameter1,
1259 uint32_t ulParameter2,
1260 TickType_t xTicksToWait )
1262 DaemonTaskMessage_t xMessage;
1265 traceENTER_xTimerPendFunctionCall( xFunctionToPend, pvParameter1, ulParameter2, xTicksToWait );
1267 /* This function can only be called after a timer has been created or
1268 * after the scheduler has been started because, until then, the timer
1269 * queue does not exist. */
1270 configASSERT( xTimerQueue );
1272 /* Complete the message with the function parameters and post it to the
1274 xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK;
1275 xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;
1276 xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;
1277 xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;
1279 xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait );
1281 tracePEND_FUNC_CALL( xFunctionToPend, pvParameter1, ulParameter2, xReturn );
1282 traceRETURN_xTimerPendFunctionCall( xReturn );
1287 #endif /* INCLUDE_xTimerPendFunctionCall */
1288 /*-----------------------------------------------------------*/
1290 #if ( configUSE_TRACE_FACILITY == 1 )
1292 UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer )
1294 traceENTER_uxTimerGetTimerNumber( xTimer );
1296 traceRETURN_uxTimerGetTimerNumber( ( ( Timer_t * ) xTimer )->uxTimerNumber );
1298 return ( ( Timer_t * ) xTimer )->uxTimerNumber;
1301 #endif /* configUSE_TRACE_FACILITY */
1302 /*-----------------------------------------------------------*/
1304 #if ( configUSE_TRACE_FACILITY == 1 )
1306 void vTimerSetTimerNumber( TimerHandle_t xTimer,
1307 UBaseType_t uxTimerNumber )
1309 traceENTER_vTimerSetTimerNumber( xTimer, uxTimerNumber );
1311 ( ( Timer_t * ) xTimer )->uxTimerNumber = uxTimerNumber;
1313 traceRETURN_vTimerSetTimerNumber();
1316 #endif /* configUSE_TRACE_FACILITY */
1317 /*-----------------------------------------------------------*/
1319 /* This entire source file will be skipped if the application is not configured
1320 * to include software timer functionality. If you want to include software timer
1321 * functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
1322 #endif /* configUSE_TIMERS == 1 */