2 FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS books - available as PDF or paperback *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
54 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
\r
55 all the API functions to use the MPU wrappers. That should only be done when
\r
56 task.h is included from an application file. */
\r
57 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
\r
59 #include "FreeRTOS.h"
\r
64 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
\r
66 /* This entire source file will be skipped if the application is not configured
\r
67 to include software timer functionality. This #if is closed at the very bottom
\r
68 of this file. If you want to include software timer functionality then ensure
\r
69 configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
\r
70 #if ( configUSE_TIMERS == 1 )
\r
72 /* Misc definitions. */
\r
73 #define tmrNO_DELAY ( portTickType ) 0U
\r
75 /* The definition of the timers themselves. */
\r
76 typedef struct tmrTimerControl
\r
78 const signed char *pcTimerName; /*<< Text name. This is not used by the kernel, it is included simply to make debugging easier. */
\r
79 xListItem xTimerListItem; /*<< Standard linked list item as used by all kernel features for event management. */
\r
80 portTickType xTimerPeriodInTicks;/*<< How quickly and often the timer expires. */
\r
81 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. */
\r
82 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
83 tmrTIMER_CALLBACK pxCallbackFunction; /*<< The function that will be called when the timer expires. */
\r
86 /* The definition of messages that can be sent and received on the timer
\r
88 typedef struct tmrTimerQueueMessage
\r
90 portBASE_TYPE xMessageID; /*<< The command being sent to the timer service task. */
\r
91 portTickType xMessageValue; /*<< An optional value used by a subset of commands, for example, when changing the period of a timer. */
\r
92 xTIMER * pxTimer; /*<< The timer to which the command will be applied. */
\r
96 /* The list in which active timers are stored. Timers are referenced in expire
\r
97 time order, with the nearest expiry time at the front of the list. Only the
\r
98 timer service task is allowed to access xActiveTimerList. */
\r
99 PRIVILEGED_DATA static xList xActiveTimerList1;
\r
100 PRIVILEGED_DATA static xList xActiveTimerList2;
\r
101 PRIVILEGED_DATA static xList *pxCurrentTimerList;
\r
102 PRIVILEGED_DATA static xList *pxOverflowTimerList;
\r
104 /* A queue that is used to send commands to the timer service task. */
\r
105 PRIVILEGED_DATA static xQueueHandle xTimerQueue = NULL;
\r
107 /*-----------------------------------------------------------*/
\r
110 * Initialise the infrastructure used by the timer service task if it has not
\r
111 * been initialised already.
\r
113 static void prvCheckForValidListAndQueue( void ) PRIVILEGED_FUNCTION;
\r
116 * The timer service task (daemon). Timer functionality is controlled by this
\r
117 * task. Other tasks communicate with the timer service task using the
\r
118 * xTimerQueue queue.
\r
120 static void prvTimerTask( void *pvParameters ) PRIVILEGED_FUNCTION;
\r
123 * Called by the timer service task to interpret and process a command it
\r
124 * received on the timer queue.
\r
126 static void prvProcessReceivedCommands( void ) PRIVILEGED_FUNCTION;
\r
129 * Insert the timer into either xActiveTimerList1, or xActiveTimerList2,
\r
130 * depending on if the expire time causes a timer counter overflow.
\r
132 static portBASE_TYPE prvInsertTimerInActiveList( xTIMER *pxTimer, portTickType xNextExpiryTime, portTickType xTimeNow, portTickType xCommandTime ) PRIVILEGED_FUNCTION;
\r
135 * An active timer has reached its expire time. Reload the timer if it is an
\r
136 * auto reload timer, then call its callback.
\r
138 static void prvProcessExpiredTimer( portTickType xNextExpireTime, portTickType xTimeNow ) PRIVILEGED_FUNCTION;
\r
141 * The tick count has overflowed. Switch the timer lists after ensuring the
\r
142 * current timer list does not still reference some timers.
\r
144 static void prvSwitchTimerLists( portTickType xLastTime ) PRIVILEGED_FUNCTION;
\r
147 * Obtain the current tick count, setting *pxTimerListsWereSwitched to pdTRUE
\r
148 * if a tick count overflow occurred since prvSampleTimeNow() was last called.
\r
150 static portTickType prvSampleTimeNow( portBASE_TYPE *pxTimerListsWereSwitched ) PRIVILEGED_FUNCTION;
\r
153 * If the timer list contains any active timers then return the expire time of
\r
154 * the timer that will expire first and set *pxListWasEmpty to false. If the
\r
155 * timer list does not contain any timers then return 0 and set *pxListWasEmpty
\r
158 static portTickType prvGetNextExpireTime( portBASE_TYPE *pxListWasEmpty ) PRIVILEGED_FUNCTION;
\r
161 * If a timer has expired, process it. Otherwise, block the timer service task
\r
162 * until either a timer does expire or a command is received.
\r
164 static void prvProcessTimerOrBlockTask( portTickType xNextExpireTime, portBASE_TYPE xListWasEmpty ) PRIVILEGED_FUNCTION;
\r
166 /*-----------------------------------------------------------*/
\r
168 portBASE_TYPE xTimerCreateTimerTask( void )
\r
170 portBASE_TYPE xReturn = pdFAIL;
\r
172 /* This function is called when the scheduler is started if
\r
173 configUSE_TIMERS is set to 1. Check that the infrastructure used by the
\r
174 timer service task has been created/initialised. If timers have already
\r
175 been created then the initialisation will already have been performed. */
\r
176 prvCheckForValidListAndQueue();
\r
178 if( xTimerQueue != NULL )
\r
180 xReturn = xTaskCreate( prvTimerTask, ( const signed char * ) "Tmr Svc", configTIMER_TASK_STACK_DEPTH, NULL, configTIMER_TASK_PRIORITY, NULL);
\r
183 configASSERT( xReturn );
\r
186 /*-----------------------------------------------------------*/
\r
188 xTimerHandle xTimerCreate( const signed char *pcTimerName, portTickType xTimerPeriodInTicks, unsigned portBASE_TYPE uxAutoReload, void *pvTimerID, tmrTIMER_CALLBACK pxCallbackFunction )
\r
190 xTIMER *pxNewTimer;
\r
192 /* Allocate the timer structure. */
\r
193 if( xTimerPeriodInTicks == ( portTickType ) 0U )
\r
196 configASSERT( ( xTimerPeriodInTicks > 0 ) );
\r
200 pxNewTimer = ( xTIMER * ) pvPortMalloc( sizeof( xTIMER ) );
\r
201 if( pxNewTimer != NULL )
\r
203 /* Ensure the infrastructure used by the timer service task has been
\r
204 created/initialised. */
\r
205 prvCheckForValidListAndQueue();
\r
207 /* Initialise the timer structure members using the function parameters. */
\r
208 pxNewTimer->pcTimerName = pcTimerName;
\r
209 pxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks;
\r
210 pxNewTimer->uxAutoReload = uxAutoReload;
\r
211 pxNewTimer->pvTimerID = pvTimerID;
\r
212 pxNewTimer->pxCallbackFunction = pxCallbackFunction;
\r
213 vListInitialiseItem( &( pxNewTimer->xTimerListItem ) );
\r
215 traceTIMER_CREATE( pxNewTimer );
\r
219 traceTIMER_CREATE_FAILED();
\r
223 return ( xTimerHandle ) pxNewTimer;
\r
225 /*-----------------------------------------------------------*/
\r
227 portBASE_TYPE xTimerGenericCommand( xTimerHandle xTimer, portBASE_TYPE xCommandID, portTickType xOptionalValue, portBASE_TYPE *pxHigherPriorityTaskWoken, portTickType xBlockTime )
\r
229 portBASE_TYPE xReturn = pdFAIL;
\r
230 xTIMER_MESSAGE xMessage;
\r
232 /* Send a message to the timer service task to perform a particular action
\r
233 on a particular timer definition. */
\r
234 if( xTimerQueue != NULL )
\r
236 /* Send a command to the timer service task to start the xTimer timer. */
\r
237 xMessage.xMessageID = xCommandID;
\r
238 xMessage.xMessageValue = xOptionalValue;
\r
239 xMessage.pxTimer = ( xTIMER * ) xTimer;
\r
241 if( pxHigherPriorityTaskWoken == NULL )
\r
243 if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )
\r
245 xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xBlockTime );
\r
249 xReturn = xQueueSendToBack( xTimerQueue, &xMessage, tmrNO_DELAY );
\r
254 xReturn = xQueueSendToBackFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
\r
257 traceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn );
\r
262 /*-----------------------------------------------------------*/
\r
264 static void prvProcessExpiredTimer( portTickType xNextExpireTime, portTickType xTimeNow )
\r
267 portBASE_TYPE xResult;
\r
269 /* Remove the timer from the list of active timers. A check has already
\r
270 been performed to ensure the list is not empty. */
\r
271 pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );
\r
272 vListRemove( &( pxTimer->xTimerListItem ) );
\r
273 traceTIMER_EXPIRED( pxTimer );
\r
275 /* If the timer is an auto reload timer then calculate the next
\r
276 expiry time and re-insert the timer in the list of active timers. */
\r
277 if( pxTimer->uxAutoReload == pdTRUE )
\r
279 /* This is the only time a timer is inserted into a list using
\r
280 a time relative to anything other than the current time. It
\r
281 will therefore be inserted into the correct list relative to
\r
282 the time this task thinks it is now, even if a command to
\r
283 switch lists due to a tick count overflow is already waiting in
\r
284 the timer queue. */
\r
285 if( prvInsertTimerInActiveList( pxTimer, ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xNextExpireTime ) == pdTRUE )
\r
287 /* The timer expired before it was added to the active timer
\r
288 list. Reload it now. */
\r
289 xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START, xNextExpireTime, NULL, tmrNO_DELAY );
\r
290 configASSERT( xResult );
\r
295 /* Call the timer callback. */
\r
296 pxTimer->pxCallbackFunction( ( xTimerHandle ) pxTimer );
\r
298 /*-----------------------------------------------------------*/
\r
300 static void prvTimerTask( void *pvParameters )
\r
302 portTickType xNextExpireTime;
\r
303 portBASE_TYPE xListWasEmpty;
\r
305 /* Just to avoid compiler warnings. */
\r
306 ( void ) pvParameters;
\r
310 /* Query the timers list to see if it contains any timers, and if so,
\r
311 obtain the time at which the next timer will expire. */
\r
312 xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty );
\r
314 /* If a timer has expired, process it. Otherwise, block this task
\r
315 until either a timer does expire, or a command is received. */
\r
316 prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty );
\r
318 /* Empty the command queue. */
\r
319 prvProcessReceivedCommands();
\r
322 /*-----------------------------------------------------------*/
\r
324 static void prvProcessTimerOrBlockTask( portTickType xNextExpireTime, portBASE_TYPE xListWasEmpty )
\r
326 portTickType xTimeNow;
\r
327 portBASE_TYPE xTimerListsWereSwitched;
\r
331 /* Obtain the time now to make an assessment as to whether the timer
\r
332 has expired or not. If obtaining the time causes the lists to switch
\r
333 then don't process this timer as any timers that remained in the list
\r
334 when the lists were switched will have been processed within the
\r
335 prvSampelTimeNow() function. */
\r
336 xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
\r
337 if( xTimerListsWereSwitched == pdFALSE )
\r
339 /* The tick count has not overflowed, has the timer expired? */
\r
340 if( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) )
\r
343 prvProcessExpiredTimer( xNextExpireTime, xTimeNow );
\r
347 /* The tick count has not overflowed, and the next expire
\r
348 time has not been reached yet. This task should therefore
\r
349 block to wait for the next expire time or a command to be
\r
350 received - whichever comes first. The following line cannot
\r
351 be reached unless xNextExpireTime > xTimeNow, except in the
\r
352 case when the current timer list is empty. */
\r
353 vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ) );
\r
355 if( xTaskResumeAll() == pdFALSE )
\r
357 /* Yield to wait for either a command to arrive, or the block time
\r
358 to expire. If a command arrived between the critical section being
\r
359 exited and this yield then the yield will not cause the task
\r
361 portYIELD_WITHIN_API();
\r
371 /*-----------------------------------------------------------*/
\r
373 static portTickType prvGetNextExpireTime( portBASE_TYPE *pxListWasEmpty )
\r
375 portTickType xNextExpireTime;
\r
377 /* Timers are listed in expiry time order, with the head of the list
\r
378 referencing the task that will expire first. Obtain the time at which
\r
379 the timer with the nearest expiry time will expire. If there are no
\r
380 active timers then just set the next expire time to 0. That will cause
\r
381 this task to unblock when the tick count overflows, at which point the
\r
382 timer lists will be switched and the next expiry time can be
\r
384 *pxListWasEmpty = listLIST_IS_EMPTY( pxCurrentTimerList );
\r
385 if( *pxListWasEmpty == pdFALSE )
\r
387 xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
\r
391 /* Ensure the task unblocks when the tick count rolls over. */
\r
392 xNextExpireTime = ( portTickType ) 0U;
\r
395 return xNextExpireTime;
\r
397 /*-----------------------------------------------------------*/
\r
399 static portTickType prvSampleTimeNow( portBASE_TYPE *pxTimerListsWereSwitched )
\r
401 portTickType xTimeNow;
\r
402 static portTickType xLastTime = ( portTickType ) 0U;
\r
404 xTimeNow = xTaskGetTickCount();
\r
406 if( xTimeNow < xLastTime )
\r
408 prvSwitchTimerLists( xLastTime );
\r
409 *pxTimerListsWereSwitched = pdTRUE;
\r
413 *pxTimerListsWereSwitched = pdFALSE;
\r
416 xLastTime = xTimeNow;
\r
420 /*-----------------------------------------------------------*/
\r
422 static portBASE_TYPE prvInsertTimerInActiveList( xTIMER *pxTimer, portTickType xNextExpiryTime, portTickType xTimeNow, portTickType xCommandTime )
\r
424 portBASE_TYPE xProcessTimerNow = pdFALSE;
\r
426 listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xNextExpiryTime );
\r
427 listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );
\r
429 if( xNextExpiryTime <= xTimeNow )
\r
431 /* Has the expiry time elapsed between the command to start/reset a
\r
432 timer was issued, and the time the command was processed? */
\r
433 if( ( ( portTickType ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks )
\r
435 /* The time between a command being issued and the command being
\r
436 processed actually exceeds the timers period. */
\r
437 xProcessTimerNow = pdTRUE;
\r
441 vListInsert( pxOverflowTimerList, &( pxTimer->xTimerListItem ) );
\r
446 if( ( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime ) )
\r
448 /* If, since the command was issued, the tick count has overflowed
\r
449 but the expiry time has not, then the timer must have already passed
\r
450 its expiry time and should be processed immediately. */
\r
451 xProcessTimerNow = pdTRUE;
\r
455 vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
\r
459 return xProcessTimerNow;
\r
461 /*-----------------------------------------------------------*/
\r
463 static void prvProcessReceivedCommands( void )
\r
465 xTIMER_MESSAGE xMessage;
\r
467 portBASE_TYPE xTimerListsWereSwitched, xResult;
\r
468 portTickType xTimeNow;
\r
470 /* In this case the xTimerListsWereSwitched parameter is not used, but it
\r
471 must be present in the function call. */
\r
472 xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
\r
474 while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL )
\r
476 pxTimer = xMessage.pxTimer;
\r
478 /* Is the timer already in a list of active timers? When the command
\r
479 is trmCOMMAND_PROCESS_TIMER_OVERFLOW, the timer will be NULL as the
\r
480 command is to the task rather than to an individual timer. */
\r
481 if( pxTimer != NULL )
\r
483 if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE )
\r
485 /* The timer is in a list, remove it. */
\r
486 vListRemove( &( pxTimer->xTimerListItem ) );
\r
490 traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.xMessageValue );
\r
492 switch( xMessage.xMessageID )
\r
494 case tmrCOMMAND_START :
\r
495 /* Start or restart a timer. */
\r
496 if( prvInsertTimerInActiveList( pxTimer, xMessage.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.xMessageValue ) == pdTRUE )
\r
498 /* The timer expired before it was added to the active timer
\r
499 list. Process it now. */
\r
500 pxTimer->pxCallbackFunction( ( xTimerHandle ) pxTimer );
\r
502 if( pxTimer->uxAutoReload == pdTRUE )
\r
504 xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START, xMessage.xMessageValue + pxTimer->xTimerPeriodInTicks, NULL, tmrNO_DELAY );
\r
505 configASSERT( xResult );
\r
511 case tmrCOMMAND_STOP :
\r
512 /* The timer has already been removed from the active list.
\r
513 There is nothing to do here. */
\r
516 case tmrCOMMAND_CHANGE_PERIOD :
\r
517 pxTimer->xTimerPeriodInTicks = xMessage.xMessageValue;
\r
518 configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) );
\r
519 prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow );
\r
522 case tmrCOMMAND_DELETE :
\r
523 /* The timer has already been removed from the active list,
\r
524 just free up the memory. */
\r
525 vPortFree( pxTimer );
\r
529 /* Don't expect to get here. */
\r
534 /*-----------------------------------------------------------*/
\r
536 static void prvSwitchTimerLists( portTickType xLastTime )
\r
538 portTickType xNextExpireTime, xReloadTime;
\r
541 portBASE_TYPE xResult;
\r
543 /* Remove compiler warnings if configASSERT() is not defined. */
\r
544 ( void ) xLastTime;
\r
546 /* The tick count has overflowed. The timer lists must be switched.
\r
547 If there are any timers still referenced from the current timer list
\r
548 then they must have expired and should be processed before the lists
\r
550 while( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE )
\r
552 xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
\r
554 /* Remove the timer from the list. */
\r
555 pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );
\r
556 vListRemove( &( pxTimer->xTimerListItem ) );
\r
558 /* Execute its callback, then send a command to restart the timer if
\r
559 it is an auto-reload timer. It cannot be restarted here as the lists
\r
560 have not yet been switched. */
\r
561 pxTimer->pxCallbackFunction( ( xTimerHandle ) pxTimer );
\r
563 if( pxTimer->uxAutoReload == pdTRUE )
\r
565 /* Calculate the reload value, and if the reload value results in
\r
566 the timer going into the same timer list then it has already expired
\r
567 and the timer should be re-inserted into the current list so it is
\r
568 processed again within this loop. Otherwise a command should be sent
\r
569 to restart the timer to ensure it is only inserted into a list after
\r
570 the lists have been swapped. */
\r
571 xReloadTime = ( xNextExpireTime + pxTimer->xTimerPeriodInTicks );
\r
572 if( xReloadTime > xNextExpireTime )
\r
574 listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xReloadTime );
\r
575 listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );
\r
576 vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
\r
580 xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START, xNextExpireTime, NULL, tmrNO_DELAY );
\r
581 configASSERT( xResult );
\r
587 pxTemp = pxCurrentTimerList;
\r
588 pxCurrentTimerList = pxOverflowTimerList;
\r
589 pxOverflowTimerList = pxTemp;
\r
591 /*-----------------------------------------------------------*/
\r
593 static void prvCheckForValidListAndQueue( void )
\r
595 /* Check that the list from which active timers are referenced, and the
\r
596 queue used to communicate with the timer service, have been
\r
598 taskENTER_CRITICAL();
\r
600 if( xTimerQueue == NULL )
\r
602 vListInitialise( &xActiveTimerList1 );
\r
603 vListInitialise( &xActiveTimerList2 );
\r
604 pxCurrentTimerList = &xActiveTimerList1;
\r
605 pxOverflowTimerList = &xActiveTimerList2;
\r
606 xTimerQueue = xQueueCreate( configTIMER_QUEUE_LENGTH, sizeof( xTIMER_MESSAGE ) );
\r
609 taskEXIT_CRITICAL();
\r
611 /*-----------------------------------------------------------*/
\r
613 portBASE_TYPE xTimerIsTimerActive( xTimerHandle xTimer )
\r
615 portBASE_TYPE xTimerIsInActiveList;
\r
616 xTIMER *pxTimer = ( xTIMER * ) xTimer;
\r
618 /* Is the timer in the list of active timers? */
\r
619 taskENTER_CRITICAL();
\r
621 /* Checking to see if it is in the NULL list in effect checks to see if
\r
622 it is referenced from either the current or the overflow timer lists in
\r
623 one go, but the logic has to be reversed, hence the '!'. */
\r
624 xTimerIsInActiveList = !( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) );
\r
626 taskEXIT_CRITICAL();
\r
628 return xTimerIsInActiveList;
\r
630 /*-----------------------------------------------------------*/
\r
632 void *pvTimerGetTimerID( xTimerHandle xTimer )
\r
634 xTIMER *pxTimer = ( xTIMER * ) xTimer;
\r
636 return pxTimer->pvTimerID;
\r
638 /*-----------------------------------------------------------*/
\r
640 /* This entire source file will be skipped if the application is not configured
\r
641 to include software timer functionality. If you want to include software timer
\r
642 functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
\r
643 #endif /* configUSE_TIMERS == 1 */
\r