2 FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 ***************************************************************************
9 * FreeRTOS tutorial books are available in pdf and paperback. *
10 * Complete, revised, and edited pdf reference manuals are also *
13 * Purchasing FreeRTOS documentation will not only help you, by *
14 * ensuring you get running as quickly as possible and with an *
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
16 * the FreeRTOS project to continue with its mission of providing *
17 * professional grade, cross platform, de facto standard solutions *
18 * for microcontrollers - completely free of charge! *
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
22 * Thank you for using FreeRTOS, and thank you for your support! *
24 ***************************************************************************
27 This file is part of the FreeRTOS distribution.
29 FreeRTOS is free software; you can redistribute it and/or modify it under
30 the terms of the GNU General Public License (version 2) as published by the
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
34 distribute a combined work that includes FreeRTOS without being obliged to
35 provide the source code for proprietary components outside of the FreeRTOS
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
41 details. You should have received a copy of the GNU General Public License
42 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
44 writing to Real Time Engineers Ltd., contact details for whom are available
45 on the FreeRTOS WEB site.
49 ***************************************************************************
51 * Having a problem? Start by reading the FAQ "My application does *
52 * not run, what could be wrong?" *
54 * http://www.FreeRTOS.org/FAQHelp.html *
56 ***************************************************************************
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
60 license and Real Time Engineers Ltd. contact details.
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
64 fully thread aware and reentrant UDP/IP stack.
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
67 Integrity Systems, who sell the code with commercial support,
68 indemnification and middleware, under the OpenRTOS brand.
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
71 engineered and independently SIL3 certified version for use in safety and
72 mission critical applications that require provable dependability.
75 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
76 all the API functions to use the MPU wrappers. That should only be done when
77 task.h is included from an application file. */
78 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
80 #include "os/FreeRTOS.h"
83 #include "os/timers.h"
85 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
87 /* This entire source file will be skipped if the application is not configured
88 to include software timer functionality. This #if is closed at the very bottom
89 of this file. If you want to include software timer functionality then ensure
90 configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
91 #if ( configUSE_TIMERS == 1 )
93 /* Misc definitions. */
94 #define tmrNO_DELAY ( portTickType ) 0U
96 /* The definition of the timers themselves. */
97 typedef struct tmrTimerControl
99 const signed char *pcTimerName; /*<< Text name. This is not used by the kernel, it is included simply to make debugging easier. */
100 xListItem xTimerListItem; /*<< Standard linked list item as used by all kernel features for event management. */
101 portTickType xTimerPeriodInTicks;/*<< How quickly and often the timer expires. */
102 unsigned portBASE_TYPE 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. */
103 void *pvTimerID; /*<< An ID to identify the timer. This allows the timer to be identified when the same callback is used for multiple timers. */
104 tmrTIMER_CALLBACK pxCallbackFunction; /*<< The function that will be called when the timer expires. */
107 /* The definition of messages that can be sent and received on the timer
109 typedef struct tmrTimerQueueMessage
111 portBASE_TYPE xMessageID; /*<< The command being sent to the timer service task. */
112 portTickType xMessageValue; /*<< An optional value used by a subset of commands, for example, when changing the period of a timer. */
113 xTIMER * pxTimer; /*<< The timer to which the command will be applied. */
116 #pragma SET_DATA_SECTION(".kernelBSS")
118 /* The list in which active timers are stored. Timers are referenced in expire
119 time order, with the nearest expiry time at the front of the list. Only the
120 timer service task is allowed to access xActiveTimerList. */
121 PRIVILEGED_DATA static xList xActiveTimerList1;
122 PRIVILEGED_DATA static xList xActiveTimerList2;
123 PRIVILEGED_DATA static xList *pxCurrentTimerList;
124 PRIVILEGED_DATA static xList *pxOverflowTimerList;
126 /* A queue that is used to send commands to the timer service task. */
127 PRIVILEGED_DATA static xQueueHandle xTimerQueue = NULL;
129 #if ( INCLUDE_xTimerGetTimerDaemonTaskHandle == 1 )
131 PRIVILEGED_DATA static xTaskHandle xTimerTaskHandle = NULL;
135 #pragma SET_DATA_SECTION()
137 /*-----------------------------------------------------------*/
140 * Initialise the infrastructure used by the timer service task if it has not
141 * been initialised already.
143 static void prvCheckForValidListAndQueue( void ) PRIVILEGED_FUNCTION;
146 * The timer service task (daemon). Timer functionality is controlled by this
147 * task. Other tasks communicate with the timer service task using the
150 static void prvTimerTask( void *pvParameters ) PRIVILEGED_FUNCTION;
153 * Called by the timer service task to interpret and process a command it
154 * received on the timer queue.
156 static void prvProcessReceivedCommands( void ) PRIVILEGED_FUNCTION;
159 * Insert the timer into either xActiveTimerList1, or xActiveTimerList2,
160 * depending on if the expire time causes a timer counter overflow.
162 static portBASE_TYPE prvInsertTimerInActiveList( xTIMER *pxTimer, portTickType xNextExpiryTime, portTickType xTimeNow, portTickType xCommandTime ) PRIVILEGED_FUNCTION;
165 * An active timer has reached its expire time. Reload the timer if it is an
166 * auto reload timer, then call its callback.
168 static void prvProcessExpiredTimer( portTickType xNextExpireTime, portTickType xTimeNow ) PRIVILEGED_FUNCTION;
171 * The tick count has overflowed. Switch the timer lists after ensuring the
172 * current timer list does not still reference some timers.
174 static void prvSwitchTimerLists( portTickType xLastTime ) PRIVILEGED_FUNCTION;
177 * Obtain the current tick count, setting *pxTimerListsWereSwitched to pdTRUE
178 * if a tick count overflow occurred since prvSampleTimeNow() was last called.
180 static portTickType prvSampleTimeNow( portBASE_TYPE *pxTimerListsWereSwitched ) PRIVILEGED_FUNCTION;
183 * If the timer list contains any active timers then return the expire time of
184 * the timer that will expire first and set *pxListWasEmpty to false. If the
185 * timer list does not contain any timers then return 0 and set *pxListWasEmpty
188 static portTickType prvGetNextExpireTime( portBASE_TYPE *pxListWasEmpty ) PRIVILEGED_FUNCTION;
191 * If a timer has expired, process it. Otherwise, block the timer service task
192 * until either a timer does expire or a command is received.
194 static void prvProcessTimerOrBlockTask( portTickType xNextExpireTime, portBASE_TYPE xListWasEmpty ) PRIVILEGED_FUNCTION;
196 /*-----------------------------------------------------------*/
198 #pragma SET_CODE_SECTION(".kernelTEXT")
200 portBASE_TYPE xTimerCreateTimerTask( void )
202 portBASE_TYPE xReturn = pdFAIL;
204 /* This function is called when the scheduler is started if
205 configUSE_TIMERS is set to 1. Check that the infrastructure used by the
206 timer service task has been created/initialised. If timers have already
207 been created then the initialisation will already have been performed. */
208 prvCheckForValidListAndQueue();
210 if( xTimerQueue != NULL )
212 #if ( INCLUDE_xTimerGetTimerDaemonTaskHandle == 1 )
214 /* Create the timer task, storing its handle in xTimerTaskHandle so
215 it can be returned by the xTimerGetTimerDaemonTaskHandle() function. */
216 xReturn = xTaskCreate( prvTimerTask, ( const signed char * ) "Tmr Svc", ( unsigned short ) configTIMER_TASK_STACK_DEPTH, NULL, ( ( unsigned portBASE_TYPE ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, &xTimerTaskHandle );
220 /* Create the timer task without storing its handle. */
221 xReturn = xTaskCreate( prvTimerTask, ( const signed char * ) "Tmr Svc", ( unsigned short ) configTIMER_TASK_STACK_DEPTH, NULL, ( ( unsigned portBASE_TYPE ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, NULL);
226 configASSERT( xReturn );
229 /*-----------------------------------------------------------*/
231 xTimerHandle xTimerCreate( const signed char * const pcTimerName, portTickType xTimerPeriodInTicks, unsigned portBASE_TYPE uxAutoReload, void *pvTimerID, tmrTIMER_CALLBACK pxCallbackFunction )
235 /* Allocate the timer structure. */
236 if( xTimerPeriodInTicks == ( portTickType ) 0U )
239 configASSERT( ( xTimerPeriodInTicks > 0 ) );
243 pxNewTimer = ( xTIMER * ) pvPortMalloc( sizeof( xTIMER ) );
244 if( pxNewTimer != NULL )
246 /* Ensure the infrastructure used by the timer service task has been
247 created/initialised. */
248 prvCheckForValidListAndQueue();
250 /* Initialise the timer structure members using the function parameters. */
251 pxNewTimer->pcTimerName = pcTimerName;
252 pxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks;
253 pxNewTimer->uxAutoReload = uxAutoReload;
254 pxNewTimer->pvTimerID = pvTimerID;
255 pxNewTimer->pxCallbackFunction = pxCallbackFunction;
256 vListInitialiseItem( &( pxNewTimer->xTimerListItem ) );
258 traceTIMER_CREATE( pxNewTimer );
262 traceTIMER_CREATE_FAILED();
266 return ( xTimerHandle ) pxNewTimer;
268 /*-----------------------------------------------------------*/
270 portBASE_TYPE xTimerGenericCommand( xTimerHandle xTimer, portBASE_TYPE xCommandID, portTickType xOptionalValue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portTickType xBlockTime )
272 portBASE_TYPE xReturn = pdFAIL;
273 xTIMER_MESSAGE xMessage;
275 /* Send a message to the timer service task to perform a particular action
276 on a particular timer definition. */
277 if( xTimerQueue != NULL )
279 /* Send a command to the timer service task to start the xTimer timer. */
280 xMessage.xMessageID = xCommandID;
281 xMessage.xMessageValue = xOptionalValue;
282 xMessage.pxTimer = ( xTIMER * ) xTimer;
284 if( pxHigherPriorityTaskWoken == NULL )
286 if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )
288 xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xBlockTime );
292 xReturn = xQueueSendToBack( xTimerQueue, &xMessage, tmrNO_DELAY );
297 xReturn = xQueueSendToBackFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
300 traceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn );
306 #pragma SET_CODE_SECTION()
308 /*-----------------------------------------------------------*/
310 #if ( INCLUDE_xTimerGetTimerDaemonTaskHandle == 1 )
312 xTaskHandle xTimerGetTimerDaemonTaskHandle( void )
314 /* If xTimerGetTimerDaemonTaskHandle() is called before the scheduler has been
315 started, then xTimerTaskHandle will be NULL. */
316 configASSERT( ( xTimerTaskHandle != NULL ) );
317 return xTimerTaskHandle;
321 /*-----------------------------------------------------------*/
323 #pragma SET_CODE_SECTION(".kernelTEXT")
325 static void prvProcessExpiredTimer( portTickType xNextExpireTime, portTickType xTimeNow )
328 portBASE_TYPE xResult;
330 /* Remove the timer from the list of active timers. A check has already
331 been performed to ensure the list is not empty. */
332 pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );
333 uxListRemove( &( pxTimer->xTimerListItem ) );
334 traceTIMER_EXPIRED( pxTimer );
336 /* If the timer is an auto reload timer then calculate the next
337 expiry time and re-insert the timer in the list of active timers. */
338 if( pxTimer->uxAutoReload == ( unsigned portBASE_TYPE ) pdTRUE )
340 /* This is the only time a timer is inserted into a list using
341 a time relative to anything other than the current time. It
342 will therefore be inserted into the correct list relative to
343 the time this task thinks it is now, even if a command to
344 switch lists due to a tick count overflow is already waiting in
346 if( prvInsertTimerInActiveList( pxTimer, ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xNextExpireTime ) == pdTRUE )
348 /* The timer expired before it was added to the active timer
349 list. Reload it now. */
350 xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START, xNextExpireTime, NULL, tmrNO_DELAY );
351 configASSERT( xResult );
356 /* Call the timer callback. */
357 pxTimer->pxCallbackFunction( ( xTimerHandle ) pxTimer );
359 /*-----------------------------------------------------------*/
361 #pragma TASK( prvTimerTask )
363 static void prvTimerTask( void *pvParameters )
365 portTickType xNextExpireTime;
366 portBASE_TYPE xListWasEmpty;
368 /* Just to avoid compiler warnings. */
369 ( void ) pvParameters;
373 /* Query the timers list to see if it contains any timers, and if so,
374 obtain the time at which the next timer will expire. */
375 xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty );
377 /* If a timer has expired, process it. Otherwise, block this task
378 until either a timer does expire, or a command is received. */
379 prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty );
381 /* Empty the command queue. */
382 prvProcessReceivedCommands();
385 /*-----------------------------------------------------------*/
387 static void prvProcessTimerOrBlockTask( portTickType xNextExpireTime, portBASE_TYPE xListWasEmpty )
389 portTickType xTimeNow;
390 portBASE_TYPE xTimerListsWereSwitched;
394 /* Obtain the time now to make an assessment as to whether the timer
395 has expired or not. If obtaining the time causes the lists to switch
396 then don't process this timer as any timers that remained in the list
397 when the lists were switched will have been processed within the
398 prvSampelTimeNow() function. */
399 xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
400 if( xTimerListsWereSwitched == pdFALSE )
402 /* The tick count has not overflowed, has the timer expired? */
403 if( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) )
406 prvProcessExpiredTimer( xNextExpireTime, xTimeNow );
410 /* The tick count has not overflowed, and the next expire
411 time has not been reached yet. This task should therefore
412 block to wait for the next expire time or a command to be
413 received - whichever comes first. The following line cannot
414 be reached unless xNextExpireTime > xTimeNow, except in the
415 case when the current timer list is empty. */
416 vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ) );
418 if( xTaskResumeAll() == pdFALSE )
420 /* Yield to wait for either a command to arrive, or the block time
421 to expire. If a command arrived between the critical section being
422 exited and this yield then the yield will not cause the task
424 portYIELD_WITHIN_API();
434 /*-----------------------------------------------------------*/
436 static portTickType prvGetNextExpireTime( portBASE_TYPE *pxListWasEmpty )
438 portTickType xNextExpireTime;
440 /* Timers are listed in expiry time order, with the head of the list
441 referencing the task that will expire first. Obtain the time at which
442 the timer with the nearest expiry time will expire. If there are no
443 active timers then just set the next expire time to 0. That will cause
444 this task to unblock when the tick count overflows, at which point the
445 timer lists will be switched and the next expiry time can be
447 *pxListWasEmpty = listLIST_IS_EMPTY( pxCurrentTimerList );
448 if( *pxListWasEmpty == pdFALSE )
450 xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
454 /* Ensure the task unblocks when the tick count rolls over. */
455 xNextExpireTime = ( portTickType ) 0U;
458 return xNextExpireTime;
460 /*-----------------------------------------------------------*/
463 #pragma SET_DATA_SECTION(".kernelBSS")
465 static portTickType prvSampleTimeNow( portBASE_TYPE *pxTimerListsWereSwitched )
467 portTickType xTimeNow;
468 PRIVILEGED_DATA static portTickType xLastTime = ( portTickType ) 0U;
470 xTimeNow = xTaskGetTickCount();
472 if( xTimeNow < xLastTime )
474 prvSwitchTimerLists( xLastTime );
475 *pxTimerListsWereSwitched = pdTRUE;
479 *pxTimerListsWereSwitched = pdFALSE;
482 xLastTime = xTimeNow;
487 #pragma SET_DATA_SECTION()
488 /*-----------------------------------------------------------*/
490 static portBASE_TYPE prvInsertTimerInActiveList( xTIMER *pxTimer, portTickType xNextExpiryTime, portTickType xTimeNow, portTickType xCommandTime )
492 portBASE_TYPE xProcessTimerNow = pdFALSE;
494 listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xNextExpiryTime );
495 listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );
497 if( xNextExpiryTime <= xTimeNow )
499 /* Has the expiry time elapsed between the command to start/reset a
500 timer was issued, and the time the command was processed? */
501 if( ( ( portTickType ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks )
503 /* The time between a command being issued and the command being
504 processed actually exceeds the timers period. */
505 xProcessTimerNow = pdTRUE;
509 vListInsert( pxOverflowTimerList, &( pxTimer->xTimerListItem ) );
514 if( ( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime ) )
516 /* If, since the command was issued, the tick count has overflowed
517 but the expiry time has not, then the timer must have already passed
518 its expiry time and should be processed immediately. */
519 xProcessTimerNow = pdTRUE;
523 vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
527 return xProcessTimerNow;
529 /*-----------------------------------------------------------*/
531 static void prvProcessReceivedCommands( void )
533 xTIMER_MESSAGE xMessage;
535 portBASE_TYPE xTimerListsWereSwitched, xResult;
536 portTickType xTimeNow;
538 while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL )
540 pxTimer = xMessage.pxTimer;
542 if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE )
544 /* The timer is in a list, remove it. */
545 uxListRemove( &( pxTimer->xTimerListItem ) );
548 traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.xMessageValue );
550 /* In this case the xTimerListsWereSwitched parameter is not used, but
551 it must be present in the function call. prvSampleTimeNow() must be
552 called after the message is received from xTimerQueue so there is no
553 possibility of a higher priority task adding a message to the message
554 queue with a time that is ahead of the timer daemon task (because it
555 pre-empted the timer daemon task after the xTimeNow value was set). */
556 xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
558 switch( xMessage.xMessageID )
560 case tmrCOMMAND_START :
561 /* Start or restart a timer. */
562 if( prvInsertTimerInActiveList( pxTimer, xMessage.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.xMessageValue ) == pdTRUE )
564 /* The timer expired before it was added to the active timer
565 list. Process it now. */
566 pxTimer->pxCallbackFunction( ( xTimerHandle ) pxTimer );
568 if( pxTimer->uxAutoReload == ( unsigned portBASE_TYPE ) pdTRUE )
570 xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START, xMessage.xMessageValue + pxTimer->xTimerPeriodInTicks, NULL, tmrNO_DELAY );
571 configASSERT( xResult );
577 case tmrCOMMAND_STOP :
578 /* The timer has already been removed from the active list.
579 There is nothing to do here. */
582 case tmrCOMMAND_CHANGE_PERIOD :
583 pxTimer->xTimerPeriodInTicks = xMessage.xMessageValue;
584 configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) );
585 prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow );
588 case tmrCOMMAND_DELETE :
589 /* The timer has already been removed from the active list,
590 just free up the memory. */
591 vPortFree( pxTimer );
595 /* Don't expect to get here. */
600 /*-----------------------------------------------------------*/
602 static void prvSwitchTimerLists( portTickType xLastTime )
604 portTickType xNextExpireTime, xReloadTime;
607 portBASE_TYPE xResult;
609 /* Remove compiler warnings if configASSERT() is not defined. */
612 /* The tick count has overflowed. The timer lists must be switched.
613 If there are any timers still referenced from the current timer list
614 then they must have expired and should be processed before the lists
616 while( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE )
618 xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
620 /* Remove the timer from the list. */
621 pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );
622 uxListRemove( &( pxTimer->xTimerListItem ) );
624 /* Execute its callback, then send a command to restart the timer if
625 it is an auto-reload timer. It cannot be restarted here as the lists
626 have not yet been switched. */
627 pxTimer->pxCallbackFunction( ( xTimerHandle ) pxTimer );
629 if( pxTimer->uxAutoReload == ( unsigned portBASE_TYPE ) pdTRUE )
631 /* Calculate the reload value, and if the reload value results in
632 the timer going into the same timer list then it has already expired
633 and the timer should be re-inserted into the current list so it is
634 processed again within this loop. Otherwise a command should be sent
635 to restart the timer to ensure it is only inserted into a list after
636 the lists have been swapped. */
637 xReloadTime = ( xNextExpireTime + pxTimer->xTimerPeriodInTicks );
638 if( xReloadTime > xNextExpireTime )
640 listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xReloadTime );
641 listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );
642 vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
646 xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START, xNextExpireTime, NULL, tmrNO_DELAY );
647 configASSERT( xResult );
653 pxTemp = pxCurrentTimerList;
654 pxCurrentTimerList = pxOverflowTimerList;
655 pxOverflowTimerList = pxTemp;
657 /*-----------------------------------------------------------*/
659 static void prvCheckForValidListAndQueue( void )
661 /* Check that the list from which active timers are referenced, and the
662 queue used to communicate with the timer service, have been
664 taskENTER_CRITICAL();
666 if( xTimerQueue == NULL )
668 vListInitialise( &xActiveTimerList1 );
669 vListInitialise( &xActiveTimerList2 );
670 pxCurrentTimerList = &xActiveTimerList1;
671 pxOverflowTimerList = &xActiveTimerList2;
672 xTimerQueue = xQueueCreate( ( unsigned portBASE_TYPE ) configTIMER_QUEUE_LENGTH, sizeof( xTIMER_MESSAGE ) );
677 /*-----------------------------------------------------------*/
679 portBASE_TYPE xTimerIsTimerActive( xTimerHandle xTimer )
681 portBASE_TYPE xTimerIsInActiveList;
682 xTIMER *pxTimer = ( xTIMER * ) xTimer;
684 /* Is the timer in the list of active timers? */
685 taskENTER_CRITICAL();
687 /* Checking to see if it is in the NULL list in effect checks to see if
688 it is referenced from either the current or the overflow timer lists in
689 one go, but the logic has to be reversed, hence the '!'. */
690 xTimerIsInActiveList = !( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) );
694 return xTimerIsInActiveList;
696 /*-----------------------------------------------------------*/
698 void *pvTimerGetTimerID( xTimerHandle xTimer )
700 xTIMER *pxTimer = ( xTIMER * ) xTimer;
702 return pxTimer->pvTimerID;
704 /*-----------------------------------------------------------*/
706 /* This entire source file will be skipped if the application is not configured
707 to include software timer functionality. If you want to include software timer
708 functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
709 #endif /* configUSE_TIMERS == 1 */