2 FreeRTOS.org V4.6.1 - Copyright (C) 2003-2007 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
31 Also see http://www.SafeRTOS.com a version that has been certified for use
\r
32 in safety critical systems, plus commercial licensing, development and
\r
34 ***************************************************************************
\r
40 + Call to portRESTORE_CONTEXT has been removed. The first context
\r
41 switch is now performed within sPortStartScheduler().
\r
45 + More use of 8bit data types.
\r
46 + Function name prefixes changed where the data type returned has changed.
\r
47 + configUSE_TRACE_FACILITY is no longer defined by default.
\r
51 + Introduced ucTopReadyPriority. This tracks the highest priority ready
\r
52 queue that contains a valid TCB and thus makes the context switch
\r
55 + prvAddTaskToReadyQueue() has been made a macro.
\r
59 + Added conditional compilation directives.
\r
61 + Rearranged function order.
\r
62 + Creating a task now causes a context switch if the task being created
\r
63 has a higher priority than the calling task - assuming the kernel is
\r
65 + vTaskDelete() now only causes a context switch if the calling task is
\r
66 the task being deleted.
\r
70 + Allow the type of the tick count to be 16 or 32 bits.
\r
71 + Introduce xPendingReadyList feature to allow the time interrupts have to
\r
72 be disabled to be minimised.
\r
73 + Remove the #if( INCLUDE_vTaskSuspendAll ) statements. vTaskSuspendAll()
\r
74 is now always included as it is used by the scheduler itself.
\r
78 + Bug fix - pxCurrentTCB is now initialised before the call to
\r
79 prvInitializeTaskLists(). Previously pxCurrentTCB could be accessed
\r
84 + Change to where lStackSize is declared within sTaskCreate() to prevent
\r
85 compiler warnings with 8051 port.
\r
89 + Explicit use of 'signed' qualifier on portCHAR types added.
\r
90 + Changed odd calculation of initial pxTopOfStack value when
\r
91 portSTACK_GROWTH < 0.
\r
92 + Removed pcVersionNumber definition.
\r
96 + cTaskResumeAll() modified to ensure it can be called prior to the task
\r
97 lists being initialised.
\r
101 + Added API function vTaskDelayUntil().
\r
102 + Added INCLUDE_vTaskDelay conditional compilation.
\r
104 Changes from V2.6.0
\r
106 + Updated the vWriteTraceToBuffer macro to always be 4 byte aligned so it
\r
107 can be used on ARM architectures.
\r
108 + tskMAX_TASK_NAME_LEN definition replaced with the port specific
\r
109 configMAX_TASK_NAME_LEN definition.
\r
110 + Removed the call to strcpy when copying across the task name into the
\r
112 + Added ucTasksDeleted variable to prevent vTaskSuspendAll() being called
\r
113 too often in the idle task.
\r
115 Changes between V3.0.0 and V2.6.1
\r
117 + When resuming the scheduler a yield is performed if either a tick has
\r
118 been missed, or a task is moved from the pending ready list into a ready
\r
119 list. Previously a yield was not performed on this second condition.
\r
120 + Introduced the type portBASE_TYPE. This necessitates several API
\r
122 + Removed the sUsingPreemption variable. The constant defined in
\r
123 portmacro.h is now used directly.
\r
124 + The idle task can now include an optional hook function - and no longer
\r
125 completes its time slice if other tasks with equal priority to it are
\r
127 + See the FreeRTOS.org documentation for more information on V2.x.x to
\r
128 V3.x.x modifications.
\r
130 Changes from V3.1.1
\r
132 + Modified vTaskPrioritySet() and vTaskResume() to allow these functions to
\r
133 be called while the scheduler is suspended.
\r
134 + Corrected the task ordering within event lists.
\r
136 Changes from V3.2.0
\r
138 + Added function xTaskGetCurrentTaskHandle().
\r
140 Changes from V3.2.4
\r
142 + Changed the volatile declarations on some variables to reflect the
\r
143 changes to the list definitions.
\r
144 + Changed the order of the TCB definition so there is commonality between
\r
145 the task control block and a co-routine control block.
\r
146 + Allow the scheduler to be started even if no tasks other than the idle
\r
147 task has been created. This allows co-routines to run even when no tasks
\r
149 + The need for a context switch is now signalled if a task woken by an
\r
150 event has a priority greater or equal to the currently running task.
\r
151 Previously this was only greater than.
\r
153 Changes from V4.0.0
\r
155 + Added the xMissedYield handling.
\r
157 Changes from V4.0.1
\r
159 + The function vTaskList() now suspends the scheduler rather than disabling
\r
160 interrupts during the creation of the task list.
\r
161 + Allow a task to delete itself by passing in its own handle. Previously
\r
162 this could only be done by passing in NULL.
\r
163 + The tick hook function is now called only within a tick isr. Previously
\r
164 it was also called when the tick function was called during the scheduler
\r
167 Changes from V4.0.3
\r
169 + Extra checks have been placed in vTaskPrioritySet() to avoid unnecessary
\r
172 Changed from V4.0.4
\r
174 + Bug fix: The 'value' of the event list item is updated when the priority
\r
175 of a task is changed. Previously only the priority of the TCB itself was
\r
177 + When resuming a task a check is first made to see if the task is actually
\r
179 + vTaskPrioritySet() and vTaskResume() no longer use the event list item.
\r
180 This has not been necessary since V4.0.1 when the xMissedYield handling
\r
182 + Implement xTaskResumeFromISR().
\r
184 Changes from V4.0.5
\r
186 + Added utility functions and xOverflowCount variable to facilitate the
\r
189 Changes from V4.1.2
\r
191 + Tasks that block on events with a timeout of portMAX_DELAY are now
\r
192 blocked indefinitely if configINCLUDE_vTaskSuspend is defined.
\r
193 Previously portMAX_DELAY was just the longest block time possible.
\r
195 Changes from V4.1.3
\r
197 + Very small change made to xTaskCheckForTimeout() as a result of the
\r
198 SafeRTOS testing. This corrects the case where the function can return an
\r
199 invalid value - but only in an extremely unlikely scenario.
\r
201 Changes since V4.3.1:
\r
203 + Added xTaskGetSchedulerState() function.
\r
204 + Added prvIsTaskSuspended() to take into account the Occurrence of
\r
205 vTaskResume() or vTaskResumeFromISR() being called passing in the
\r
206 handle of a task that appears in the Suspended list only because it
\r
207 is blocked on an event without a timeout being specified.
\r
208 + Updated xTaskCheckForTimeout() to take into account that tasks blocked
\r
209 using the Suspended list should never time out.
\r
213 #include <stdlib.h>
\r
214 #include <string.h>
\r
216 #include "FreeRTOS.h"
\r
220 * Macro to define the amount of stack available to the idle task.
\r
222 #define tskIDLE_STACK_SIZE configMINIMAL_STACK_SIZE
\r
226 * Default a definitions for backwards compatibility with old
\r
227 * portmacro.h files.
\r
229 #ifndef configMAX_TASK_NAME_LEN
\r
230 #define configMAX_TASK_NAME_LEN 16
\r
233 #ifndef configIDLE_SHOULD_YIELD
\r
234 #define configIDLE_SHOULD_YIELD 1
\r
237 #if configMAX_TASK_NAME_LEN < 1
\r
238 #undef configMAX_TASK_NAME_LEN
\r
239 #define configMAX_TASK_NAME_LEN 1
\r
242 #ifndef INCLUDE_xTaskResumeFromISR
\r
243 #define INCLUDE_xTaskResumeFromISR 1
\r
246 #ifndef INCLUDE_xTaskGetSchedulerState
\r
247 #define INCLUDE_xTaskGetSchedulerState 0
\r
251 * Task control block. A task control block (TCB) is allocated to each task,
\r
252 * and stores the context of the task.
\r
254 typedef struct tskTaskControlBlock
\r
256 volatile portSTACK_TYPE *pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE STRUCT. */
\r
257 xListItem xGenericListItem; /*< List item used to place the TCB in ready and blocked queues. */
\r
258 xListItem xEventListItem; /*< List item used to place the TCB in event lists. */
\r
259 unsigned portBASE_TYPE uxPriority; /*< The priority of the task where 0 is the lowest priority. */
\r
260 portSTACK_TYPE *pxStack; /*< Points to the start of the stack. */
\r
261 signed portCHAR pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created. Facilitates debugging only. */
\r
263 #if ( configUSE_TRACE_FACILITY == 1 )
\r
264 unsigned portBASE_TYPE uxTCBNumber; /*< This is used for tracing the scheduler and making debugging easier only. */
\r
267 #if ( configUSE_MUTEXES == 1 )
\r
268 unsigned portBASE_TYPE uxBasePriority;
\r
275 tskTCB * volatile pxCurrentTCB = NULL;
\r
277 /* Lists for ready and blocked tasks. --------------------*/
\r
279 static xList pxReadyTasksLists[ configMAX_PRIORITIES ]; /*< Prioritised ready tasks. */
\r
280 static xList xDelayedTaskList1; /*< Delayed tasks. */
\r
281 static xList xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */
\r
282 static xList * volatile pxDelayedTaskList; /*< Points to the delayed task list currently being used. */
\r
283 static xList * volatile pxOverflowDelayedTaskList; /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */
\r
284 static xList xPendingReadyList; /*< Tasks that have been readied while the scheduler was suspended. They will be moved to the ready queue when the scheduler is resumed. */
\r
286 #if ( INCLUDE_vTaskDelete == 1 )
\r
288 static volatile xList xTasksWaitingTermination; /*< Tasks that have been deleted - but the their memory not yet freed. */
\r
289 static volatile unsigned portBASE_TYPE uxTasksDeleted = ( unsigned portBASE_TYPE ) 0;
\r
293 #if ( INCLUDE_vTaskSuspend == 1 )
\r
295 static xList xSuspendedTaskList; /*< Tasks that are currently suspended. */
\r
299 /* File private variables. --------------------------------*/
\r
300 static volatile unsigned portBASE_TYPE uxCurrentNumberOfTasks = ( unsigned portBASE_TYPE ) 0;
\r
301 static volatile portTickType xTickCount = ( portTickType ) 0;
\r
302 static unsigned portBASE_TYPE uxTopUsedPriority = tskIDLE_PRIORITY;
\r
303 static volatile unsigned portBASE_TYPE uxTopReadyPriority = tskIDLE_PRIORITY;
\r
304 static volatile signed portBASE_TYPE xSchedulerRunning = pdFALSE;
\r
305 static volatile unsigned portBASE_TYPE uxSchedulerSuspended = ( unsigned portBASE_TYPE ) pdFALSE;
\r
306 static volatile unsigned portBASE_TYPE uxMissedTicks = ( unsigned portBASE_TYPE ) 0;
\r
307 static volatile portBASE_TYPE xMissedYield = ( portBASE_TYPE ) pdFALSE;
\r
308 static volatile portBASE_TYPE xNumOfOverflows = ( portBASE_TYPE ) 0;
\r
309 /* Debugging and trace facilities private variables and macros. ------------*/
\r
312 * The value used to fill the stack of a task when the task is created. This
\r
313 * is used purely for checking the high water mark for tasks.
\r
315 #define tskSTACK_FILL_BYTE ( 0xa5 )
\r
318 * Macros used by vListTask to indicate which state a task is in.
\r
320 #define tskBLOCKED_CHAR ( ( signed portCHAR ) 'B' )
\r
321 #define tskREADY_CHAR ( ( signed portCHAR ) 'R' )
\r
322 #define tskDELETED_CHAR ( ( signed portCHAR ) 'D' )
\r
323 #define tskSUSPENDED_CHAR ( ( signed portCHAR ) 'S' )
\r
326 * Macros and private variables used by the trace facility.
\r
328 #if ( configUSE_TRACE_FACILITY == 1 )
\r
330 #define tskSIZE_OF_EACH_TRACE_LINE ( ( unsigned portLONG ) ( sizeof( unsigned portLONG ) + sizeof( unsigned portLONG ) ) )
\r
331 static volatile signed portCHAR * volatile pcTraceBuffer;
\r
332 static signed portCHAR *pcTraceBufferStart;
\r
333 static signed portCHAR *pcTraceBufferEnd;
\r
334 static signed portBASE_TYPE xTracing = pdFALSE;
\r
339 * Macro that writes a trace of scheduler activity to a buffer. This trace
\r
340 * shows which task is running when and is very useful as a debugging tool.
\r
341 * As this macro is called each context switch it is a good idea to undefine
\r
342 * it if not using the facility.
\r
344 #if ( configUSE_TRACE_FACILITY == 1 )
\r
346 #define vWriteTraceToBuffer() \
\r
350 static unsigned portBASE_TYPE uxPreviousTask = 255; \
\r
352 if( uxPreviousTask != pxCurrentTCB->uxTCBNumber ) \
\r
354 if( ( pcTraceBuffer + tskSIZE_OF_EACH_TRACE_LINE ) < pcTraceBufferEnd ) \
\r
356 uxPreviousTask = pxCurrentTCB->uxTCBNumber; \
\r
357 *( unsigned portLONG * ) pcTraceBuffer = ( unsigned portLONG ) xTickCount; \
\r
358 pcTraceBuffer += sizeof( unsigned portLONG ); \
\r
359 *( unsigned portLONG * ) pcTraceBuffer = ( unsigned portLONG ) uxPreviousTask; \
\r
360 pcTraceBuffer += sizeof( unsigned portLONG ); \
\r
364 xTracing = pdFALSE; \
\r
372 #define vWriteTraceToBuffer()
\r
378 * Place the task represented by pxTCB into the appropriate ready queue for
\r
379 * the task. It is inserted at the end of the list. One quirk of this is
\r
380 * that if the task being inserted is at the same priority as the currently
\r
381 * executing task, then it will only be rescheduled after the currently
\r
382 * executing task has been rescheduled.
\r
384 #define prvAddTaskToReadyQueue( pxTCB ) \
\r
386 if( pxTCB->uxPriority > uxTopReadyPriority ) \
\r
388 uxTopReadyPriority = pxTCB->uxPriority; \
\r
390 vListInsertEnd( ( xList * ) &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ); \
\r
394 * Macro that looks at the list of tasks that are currently delayed to see if
\r
395 * any require waking.
\r
397 * Tasks are stored in the queue in the order of their wake time - meaning
\r
398 * once one tasks has been found whose timer has not expired we need not look
\r
399 * any further down the list.
\r
401 #define prvCheckDelayedTasks() \
\r
403 register tskTCB *pxTCB; \
\r
405 while( ( pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList ) ) != NULL ) \
\r
407 if( xTickCount < listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) ) ) \
\r
411 vListRemove( &( pxTCB->xGenericListItem ) ); \
\r
412 /* Is the task waiting on an event also? */ \
\r
413 if( pxTCB->xEventListItem.pvContainer ) \
\r
415 vListRemove( &( pxTCB->xEventListItem ) ); \
\r
417 prvAddTaskToReadyQueue( pxTCB ); \
\r
422 * Several functions take an xTaskHandle parameter that can optionally be NULL,
\r
423 * where NULL is used to indicate that the handle of the currently executing
\r
424 * task should be used in place of the parameter. This macro simply checks to
\r
425 * see if the parameter is NULL and returns a pointer to the appropriate TCB.
\r
427 #define prvGetTCBFromHandle( pxHandle ) ( ( pxHandle == NULL ) ? ( tskTCB * ) pxCurrentTCB : ( tskTCB * ) pxHandle )
\r
430 /* File private functions. --------------------------------*/
\r
433 * Utility to ready a TCB for a given task. Mainly just copies the parameters
\r
434 * into the TCB structure.
\r
436 static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed portCHAR * const pcName, unsigned portBASE_TYPE uxPriority );
\r
439 * Utility to ready all the lists used by the scheduler. This is called
\r
440 * automatically upon the creation of the first task.
\r
442 static void prvInitialiseTaskLists( void );
\r
445 * The idle task, which as all tasks is implemented as a never ending loop.
\r
446 * The idle task is automatically created and added to the ready lists upon
\r
447 * creation of the first user task.
\r
449 * The portTASK_FUNCTION_PROTO() macro is used to allow port/compiler specific
\r
450 * language extensions. The equivalent prototype for this function is:
\r
452 * void prvIdleTask( void *pvParameters );
\r
455 static portTASK_FUNCTION_PROTO( prvIdleTask, pvParameters );
\r
458 * Utility to free all memory allocated by the scheduler to hold a TCB,
\r
459 * including the stack pointed to by the TCB.
\r
461 * This does not free memory allocated by the task itself (i.e. memory
\r
462 * allocated by calls to pvPortMalloc from within the tasks application code).
\r
464 #if ( ( INCLUDE_vTaskDelete == 1 ) || ( INCLUDE_vTaskCleanUpResources == 1 ) )
\r
465 static void prvDeleteTCB( tskTCB *pxTCB );
\r
469 * Used only by the idle task. This checks to see if anything has been placed
\r
470 * in the list of tasks waiting to be deleted. If so the task is cleaned up
\r
471 * and its TCB deleted.
\r
473 static void prvCheckTasksWaitingTermination( void );
\r
476 * Allocates memory from the heap for a TCB and associated stack. Checks the
\r
477 * allocation was successful.
\r
479 static tskTCB *prvAllocateTCBAndStack( unsigned portSHORT usStackDepth );
\r
482 * Called from vTaskList. vListTasks details all the tasks currently under
\r
483 * control of the scheduler. The tasks may be in one of a number of lists.
\r
484 * prvListTaskWithinSingleList accepts a list and details the tasks from
\r
485 * within just that list.
\r
487 * THIS FUNCTION IS INTENDED FOR DEBUGGING ONLY, AND SHOULD NOT BE CALLED FROM
\r
488 * NORMAL APPLICATION CODE.
\r
490 #if ( configUSE_TRACE_FACILITY == 1 )
\r
492 static void prvListTaskWithinSingleList( const signed portCHAR *pcWriteBuffer, xList *pxList, signed portCHAR cStatus );
\r
497 * When a task is created, the stack of the task is filled with a known value.
\r
498 * This function determines the 'high water mark' of the task stack by
\r
499 * determining how much of the stack remains at the original preset value.
\r
501 #if ( configUSE_TRACE_FACILITY == 1 )
\r
503 unsigned portSHORT usTaskCheckFreeStackSpace( const unsigned portCHAR * pucStackByte );
\r
508 * Checks that a task being resumed (unsuspended) is actually in the Suspended
\r
511 #if ( INCLUDE_vTaskSuspend == 1 )
\r
513 static portBASE_TYPE prvIsTaskSuspended( const tskTCB * const pxTCB );
\r
523 /*-----------------------------------------------------------
\r
524 * TASK CREATION API documented in task.h
\r
525 *----------------------------------------------------------*/
\r
527 signed portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, const signed portCHAR * const pcName, unsigned portSHORT usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pxCreatedTask )
\r
529 signed portBASE_TYPE xReturn;
\r
531 #if ( configUSE_TRACE_FACILITY == 1 )
\r
532 static unsigned portBASE_TYPE uxTaskNumber = 0; /*lint !e956 Static is deliberate - this is guarded before use. */
\r
535 /* Allocate the memory required by the TCB and stack for the new task.
\r
536 checking that the allocation was successful. */
\r
537 pxNewTCB = prvAllocateTCBAndStack( usStackDepth );
\r
539 if( pxNewTCB != NULL )
\r
541 portSTACK_TYPE *pxTopOfStack;
\r
543 /* Setup the newly allocated TCB with the initial state of the task. */
\r
544 prvInitialiseTCBVariables( pxNewTCB, pcName, uxPriority );
\r
546 /* Calculate the top of stack address. This depends on whether the
\r
547 stack grows from high memory to low (as per the 80x86) or visa versa.
\r
548 portSTACK_GROWTH is used to make the result positive or negative as
\r
549 required by the port. */
\r
550 #if portSTACK_GROWTH < 0
\r
552 pxTopOfStack = pxNewTCB->pxStack + ( usStackDepth - 1 );
\r
556 pxTopOfStack = pxNewTCB->pxStack;
\r
560 /* Initialize the TCB stack to look as if the task was already running,
\r
561 but had been interrupted by the scheduler. The return address is set
\r
562 to the start of the task function. Once the stack has been initialised
\r
563 the top of stack variable is updated. */
\r
564 pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pvTaskCode, pvParameters );
\r
566 /* We are going to manipulate the task queues to add this task to a
\r
567 ready list, so must make sure no interrupts occur. */
\r
568 portENTER_CRITICAL();
\r
570 uxCurrentNumberOfTasks++;
\r
571 if( uxCurrentNumberOfTasks == ( unsigned portBASE_TYPE ) 1 )
\r
573 /* As this is the first task it must also be the current task. */
\r
574 pxCurrentTCB = pxNewTCB;
\r
576 /* This is the first task to be created so do the preliminary
\r
577 initialisation required. We will not recover if this call
\r
578 fails, but we will report the failure. */
\r
579 prvInitialiseTaskLists();
\r
583 /* If the scheduler is not already running, make this task the
\r
584 current task if it is the highest priority task to be created
\r
586 if( xSchedulerRunning == pdFALSE )
\r
588 if( pxCurrentTCB->uxPriority <= uxPriority )
\r
590 pxCurrentTCB = pxNewTCB;
\r
595 /* Remember the top priority to make context switching faster. Use
\r
596 the priority in pxNewTCB as this has been capped to a valid value. */
\r
597 if( pxNewTCB->uxPriority > uxTopUsedPriority )
\r
599 uxTopUsedPriority = pxNewTCB->uxPriority;
\r
602 #if ( configUSE_TRACE_FACILITY == 1 )
\r
604 /* Add a counter into the TCB for tracing only. */
\r
605 pxNewTCB->uxTCBNumber = uxTaskNumber;
\r
610 prvAddTaskToReadyQueue( pxNewTCB );
\r
614 portEXIT_CRITICAL();
\r
618 xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;
\r
621 if( xReturn == pdPASS )
\r
623 if( ( void * ) pxCreatedTask != NULL )
\r
625 /* Pass the TCB out - in an anonymous way. The calling function/
\r
626 task can use this as a handle to delete the task later if
\r
628 *pxCreatedTask = ( xTaskHandle ) pxNewTCB;
\r
631 if( xSchedulerRunning != pdFALSE )
\r
633 /* If the created task is of a higher priority than the current task
\r
634 then it should run now. */
\r
635 if( pxCurrentTCB->uxPriority < uxPriority )
\r
644 /*-----------------------------------------------------------*/
\r
646 #if ( INCLUDE_vTaskDelete == 1 )
\r
648 void vTaskDelete( xTaskHandle pxTaskToDelete )
\r
652 taskENTER_CRITICAL();
\r
654 /* Ensure a yield is performed if the current task is being
\r
656 if( pxTaskToDelete == pxCurrentTCB )
\r
658 pxTaskToDelete = NULL;
\r
661 /* If null is passed in here then we are deleting ourselves. */
\r
662 pxTCB = prvGetTCBFromHandle( pxTaskToDelete );
\r
664 /* Remove task from the ready list and place in the termination list.
\r
665 This will stop the task from be scheduled. The idle task will check
\r
666 the termination list and free up any memory allocated by the
\r
667 scheduler for the TCB and stack. */
\r
668 vListRemove( &( pxTCB->xGenericListItem ) );
\r
670 /* Is the task waiting on an event also? */
\r
671 if( pxTCB->xEventListItem.pvContainer )
\r
673 vListRemove( &( pxTCB->xEventListItem ) );
\r
676 vListInsertEnd( ( xList * ) &xTasksWaitingTermination, &( pxTCB->xGenericListItem ) );
\r
678 /* Increment the ucTasksDeleted variable so the idle task knows
\r
679 there is a task that has been deleted and that it should therefore
\r
680 check the xTasksWaitingTermination list. */
\r
683 taskEXIT_CRITICAL();
\r
685 /* Force a reschedule if we have just deleted the current task. */
\r
686 if( xSchedulerRunning != pdFALSE )
\r
688 if( ( void * ) pxTaskToDelete == NULL )
\r
702 /*-----------------------------------------------------------
\r
703 * TASK CONTROL API documented in task.h
\r
704 *----------------------------------------------------------*/
\r
706 #if ( INCLUDE_vTaskDelayUntil == 1 )
\r
708 void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement )
\r
710 portTickType xTimeToWake;
\r
711 portBASE_TYPE xAlreadyYielded, xShouldDelay = pdFALSE;
\r
715 /* Generate the tick time at which the task wants to wake. */
\r
716 xTimeToWake = *pxPreviousWakeTime + xTimeIncrement;
\r
718 if( xTickCount < *pxPreviousWakeTime )
\r
720 /* The tick count has overflowed since this function was
\r
721 lasted called. In this case the only time we should ever
\r
722 actually delay is if the wake time has also overflowed,
\r
723 and the wake time is greater than the tick time. When this
\r
724 is the case it is as if neither time had overflowed. */
\r
725 if( ( xTimeToWake < *pxPreviousWakeTime ) && ( xTimeToWake > xTickCount ) )
\r
727 xShouldDelay = pdTRUE;
\r
732 /* The tick time has not overflowed. In this case we will
\r
733 delay if either the wake time has overflowed, and/or the
\r
734 tick time is less than the wake time. */
\r
735 if( ( xTimeToWake < *pxPreviousWakeTime ) || ( xTimeToWake > xTickCount ) )
\r
737 xShouldDelay = pdTRUE;
\r
741 /* Update the wake time ready for the next call. */
\r
742 *pxPreviousWakeTime = xTimeToWake;
\r
746 /* We must remove ourselves from the ready list before adding
\r
747 ourselves to the blocked list as the same list item is used for
\r
749 vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );
\r
751 /* The list item will be inserted in wake time order. */
\r
752 listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xGenericListItem ), xTimeToWake );
\r
754 if( xTimeToWake < xTickCount )
\r
756 /* Wake time has overflowed. Place this item in the
\r
758 vListInsert( ( xList * ) pxOverflowDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );
\r
762 /* The wake time has not overflowed, so we can use the
\r
763 current block list. */
\r
764 vListInsert( ( xList * ) pxDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );
\r
768 xAlreadyYielded = xTaskResumeAll();
\r
770 /* Force a reschedule if xTaskResumeAll has not already done so, we may
\r
771 have put ourselves to sleep. */
\r
772 if( !xAlreadyYielded )
\r
779 /*-----------------------------------------------------------*/
\r
781 #if ( INCLUDE_vTaskDelay == 1 )
\r
783 void vTaskDelay( portTickType xTicksToDelay )
\r
785 portTickType xTimeToWake;
\r
786 signed portBASE_TYPE xAlreadyYielded = pdFALSE;
\r
788 /* A delay time of zero just forces a reschedule. */
\r
789 if( xTicksToDelay > ( portTickType ) 0 )
\r
793 /* A task that is removed from the event list while the
\r
794 scheduler is suspended will not get placed in the ready
\r
795 list or removed from the blocked list until the scheduler
\r
798 This task cannot be in an event list as it is the currently
\r
801 /* Calculate the time to wake - this may overflow but this is
\r
803 xTimeToWake = xTickCount + xTicksToDelay;
\r
805 /* We must remove ourselves from the ready list before adding
\r
806 ourselves to the blocked list as the same list item is used for
\r
808 vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );
\r
810 /* The list item will be inserted in wake time order. */
\r
811 listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xGenericListItem ), xTimeToWake );
\r
813 if( xTimeToWake < xTickCount )
\r
815 /* Wake time has overflowed. Place this item in the
\r
817 vListInsert( ( xList * ) pxOverflowDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );
\r
821 /* The wake time has not overflowed, so we can use the
\r
822 current block list. */
\r
823 vListInsert( ( xList * ) pxDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );
\r
826 xAlreadyYielded = xTaskResumeAll();
\r
829 /* Force a reschedule if xTaskResumeAll has not already done so, we may
\r
830 have put ourselves to sleep. */
\r
831 if( !xAlreadyYielded )
\r
838 /*-----------------------------------------------------------*/
\r
840 #if ( INCLUDE_uxTaskPriorityGet == 1 )
\r
842 unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask )
\r
845 unsigned portBASE_TYPE uxReturn;
\r
847 taskENTER_CRITICAL();
\r
849 /* If null is passed in here then we are changing the
\r
850 priority of the calling function. */
\r
851 pxTCB = prvGetTCBFromHandle( pxTask );
\r
852 uxReturn = pxTCB->uxPriority;
\r
854 taskEXIT_CRITICAL();
\r
860 /*-----------------------------------------------------------*/
\r
862 #if ( INCLUDE_vTaskPrioritySet == 1 )
\r
864 void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority )
\r
867 unsigned portBASE_TYPE uxCurrentPriority, xYieldRequired = pdFALSE;
\r
869 /* Ensure the new priority is valid. */
\r
870 if( uxNewPriority >= configMAX_PRIORITIES )
\r
872 uxNewPriority = configMAX_PRIORITIES - 1;
\r
875 taskENTER_CRITICAL();
\r
877 /* If null is passed in here then we are changing the
\r
878 priority of the calling function. */
\r
879 pxTCB = prvGetTCBFromHandle( pxTask );
\r
881 #if ( configUSE_MUTEXES == 1 )
\r
883 uxCurrentPriority = pxTCB->uxBasePriority;
\r
887 uxCurrentPriority = pxTCB->uxPriority;
\r
891 if( uxCurrentPriority != uxNewPriority )
\r
893 /* The priority change may have readied a task of higher
\r
894 priority than the calling task. */
\r
895 if( uxNewPriority > uxCurrentPriority )
\r
897 if( pxTask != NULL )
\r
899 /* The priority of another task is being raised. If we
\r
900 were raising the priority of the currently running task
\r
901 there would be no need to switch as it must have already
\r
902 been the highest priority task. */
\r
903 xYieldRequired = pdTRUE;
\r
906 else if( pxTask == NULL )
\r
908 /* Setting our own priority down means there may now be another
\r
909 task of higher priority that is ready to execute. */
\r
910 xYieldRequired = pdTRUE;
\r
915 #if ( configUSE_MUTEXES == 1 )
\r
917 /* Only change the priority being used if the task is not
\r
918 currently using an inherited priority. */
\r
919 if( pxTCB->uxBasePriority == pxTCB->uxPriority )
\r
921 pxTCB->uxPriority = uxNewPriority;
\r
924 /* The base priority gets set whatever. */
\r
925 pxTCB->uxBasePriority = uxNewPriority;
\r
929 pxTCB->uxPriority = uxNewPriority;
\r
933 listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( configMAX_PRIORITIES - ( portTickType ) uxNewPriority ) );
\r
935 /* If the task is in the blocked or suspended list we need do
\r
936 nothing more than change it's priority variable. However, if
\r
937 the task is in a ready list it needs to be removed and placed
\r
938 in the queue appropriate to its new priority. */
\r
939 if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxCurrentPriority ] ), &( pxTCB->xGenericListItem ) ) )
\r
941 /* The task is currently in its ready list - remove before adding
\r
942 it to it's new ready list. As we are in a critical section we
\r
943 can do this even if the scheduler is suspended. */
\r
944 vListRemove( &( pxTCB->xGenericListItem ) );
\r
945 prvAddTaskToReadyQueue( pxTCB );
\r
948 if( xYieldRequired == pdTRUE )
\r
954 taskEXIT_CRITICAL();
\r
958 /*-----------------------------------------------------------*/
\r
960 #if ( INCLUDE_vTaskSuspend == 1 )
\r
962 void vTaskSuspend( xTaskHandle pxTaskToSuspend )
\r
966 taskENTER_CRITICAL();
\r
968 /* Ensure a yield is performed if the current task is being
\r
970 if( pxTaskToSuspend == pxCurrentTCB )
\r
972 pxTaskToSuspend = NULL;
\r
975 /* If null is passed in here then we are suspending ourselves. */
\r
976 pxTCB = prvGetTCBFromHandle( pxTaskToSuspend );
\r
978 /* Remove task from the ready/delayed list and place in the suspended list. */
\r
979 vListRemove( &( pxTCB->xGenericListItem ) );
\r
981 /* Is the task waiting on an event also? */
\r
982 if( pxTCB->xEventListItem.pvContainer )
\r
984 vListRemove( &( pxTCB->xEventListItem ) );
\r
987 vListInsertEnd( ( xList * ) &xSuspendedTaskList, &( pxTCB->xGenericListItem ) );
\r
989 taskEXIT_CRITICAL();
\r
991 /* We may have just suspended the current task. */
\r
992 if( ( void * ) pxTaskToSuspend == NULL )
\r
999 /*-----------------------------------------------------------*/
\r
1001 #if ( INCLUDE_vTaskSuspend == 1 )
\r
1003 static portBASE_TYPE prvIsTaskSuspended( const tskTCB * const pxTCB )
\r
1005 portBASE_TYPE xReturn = pdFALSE;
\r
1007 /* Is the task we are attempting to resume actually in the
\r
1008 suspended list? */
\r
1009 if( listIS_CONTAINED_WITHIN( &xSuspendedTaskList, &( pxTCB->xGenericListItem ) ) != pdFALSE )
\r
1011 /* Has the task already been resumed from within an ISR? */
\r
1012 if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) != pdTRUE )
\r
1014 /* Is it in the suspended list because it is in the
\r
1015 Suspended state? It is possible to be in the suspended
\r
1016 list because it is blocked on a task with no timeout
\r
1018 if( listIS_CONTAINED_WITHIN( NULL, &( pxTCB->xEventListItem ) ) == pdTRUE )
\r
1029 /*-----------------------------------------------------------*/
\r
1031 #if ( INCLUDE_vTaskSuspend == 1 )
\r
1033 void vTaskResume( xTaskHandle pxTaskToResume )
\r
1037 /* Remove the task from whichever list it is currently in, and place
\r
1038 it in the ready list. */
\r
1039 pxTCB = ( tskTCB * ) pxTaskToResume;
\r
1041 /* The parameter cannot be NULL as it is impossible to resume the
\r
1042 currently executing task. */
\r
1043 if( pxTCB != NULL )
\r
1045 taskENTER_CRITICAL();
\r
1047 if( prvIsTaskSuspended( pxTCB ) == pdTRUE )
\r
1049 /* As we are in a critical section we can access the ready
\r
1050 lists even if the scheduler is suspended. */
\r
1051 vListRemove( &( pxTCB->xGenericListItem ) );
\r
1052 prvAddTaskToReadyQueue( pxTCB );
\r
1054 /* We may have just resumed a higher priority task. */
\r
1055 if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )
\r
1057 /* This yield may not cause the task just resumed to run, but
\r
1058 will leave the lists in the correct state for the next yield. */
\r
1063 taskEXIT_CRITICAL();
\r
1069 /*-----------------------------------------------------------*/
\r
1071 #if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )
\r
1073 portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume )
\r
1075 portBASE_TYPE xYieldRequired = pdFALSE;
\r
1078 pxTCB = ( tskTCB * ) pxTaskToResume;
\r
1080 if( prvIsTaskSuspended( pxTCB ) == pdTRUE )
\r
1082 if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )
\r
1084 xYieldRequired = ( pxTCB->uxPriority >= pxCurrentTCB->uxPriority );
\r
1085 vListRemove( &( pxTCB->xGenericListItem ) );
\r
1086 prvAddTaskToReadyQueue( pxTCB );
\r
1090 /* We cannot access the delayed or ready lists, so will hold this
\r
1091 task pending until the scheduler is resumed, at which point a
\r
1092 yield will be performed if necessary. */
\r
1093 vListInsertEnd( ( xList * ) &( xPendingReadyList ), &( pxTCB->xEventListItem ) );
\r
1097 return xYieldRequired;
\r
1105 /*-----------------------------------------------------------
\r
1106 * PUBLIC SCHEDULER CONTROL documented in task.h
\r
1107 *----------------------------------------------------------*/
\r
1110 void vTaskStartScheduler( void )
\r
1112 portBASE_TYPE xReturn;
\r
1114 /* Add the idle task at the lowest priority. */
\r
1115 xReturn = xTaskCreate( prvIdleTask, ( signed portCHAR * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL );
\r
1117 if( xReturn == pdPASS )
\r
1119 /* Interrupts are turned off here, to ensure a tick does not occur
\r
1120 before or during the call to xPortStartScheduler(). The stacks of
\r
1121 the created tasks contain a status word with interrupts switched on
\r
1122 so interrupts will automatically get re-enabled when the first task
\r
1125 STEPPING THROUGH HERE USING A DEBUGGER CAN CAUSE BIG PROBLEMS IF THE
\r
1126 DEBUGGER ALLOWS INTERRUPTS TO BE PROCESSED. */
\r
1127 portDISABLE_INTERRUPTS();
\r
1129 xSchedulerRunning = pdTRUE;
\r
1130 xTickCount = ( portTickType ) 0;
\r
1132 /* Setting up the timer tick is hardware specific and thus in the
\r
1133 portable interface. */
\r
1134 if( xPortStartScheduler() )
\r
1136 /* Should not reach here as if the scheduler is running the
\r
1137 function will not return. */
\r
1141 /* Should only reach here if a task calls xTaskEndScheduler(). */
\r
1145 /*-----------------------------------------------------------*/
\r
1147 void vTaskEndScheduler( void )
\r
1149 /* Stop the scheduler interrupts and call the portable scheduler end
\r
1150 routine so the original ISRs can be restored if necessary. The port
\r
1151 layer must ensure interrupts enable bit is left in the correct state. */
\r
1152 portDISABLE_INTERRUPTS();
\r
1153 xSchedulerRunning = pdFALSE;
\r
1154 vPortEndScheduler();
\r
1156 /*----------------------------------------------------------*/
\r
1158 void vTaskSuspendAll( void )
\r
1160 portENTER_CRITICAL();
\r
1161 ++uxSchedulerSuspended;
\r
1162 portEXIT_CRITICAL();
\r
1164 /*----------------------------------------------------------*/
\r
1166 signed portBASE_TYPE xTaskResumeAll( void )
\r
1168 register tskTCB *pxTCB;
\r
1169 signed portBASE_TYPE xAlreadyYielded = pdFALSE;
\r
1171 /* It is possible that an ISR caused a task to be removed from an event
\r
1172 list while the scheduler was suspended. If this was the case then the
\r
1173 removed task will have been added to the xPendingReadyList. Once the
\r
1174 scheduler has been resumed it is safe to move all the pending ready
\r
1175 tasks from this list into their appropriate ready list. */
\r
1176 portENTER_CRITICAL();
\r
1178 --uxSchedulerSuspended;
\r
1180 if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )
\r
1182 if( uxCurrentNumberOfTasks > ( unsigned portBASE_TYPE ) 0 )
\r
1184 portBASE_TYPE xYieldRequired = pdFALSE;
\r
1186 /* Move any readied tasks from the pending list into the
\r
1187 appropriate ready list. */
\r
1188 while( ( pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xPendingReadyList ) ) ) != NULL )
\r
1190 vListRemove( &( pxTCB->xEventListItem ) );
\r
1191 vListRemove( &( pxTCB->xGenericListItem ) );
\r
1192 prvAddTaskToReadyQueue( pxTCB );
\r
1194 /* If we have moved a task that has a priority higher than
\r
1195 the current task then we should yield. */
\r
1196 if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )
\r
1198 xYieldRequired = pdTRUE;
\r
1202 /* If any ticks occurred while the scheduler was suspended then
\r
1203 they should be processed now. This ensures the tick count does not
\r
1204 slip, and that any delayed tasks are resumed at the correct time. */
\r
1205 if( uxMissedTicks > ( unsigned portBASE_TYPE ) 0 )
\r
1207 while( uxMissedTicks > ( unsigned portBASE_TYPE ) 0 )
\r
1209 vTaskIncrementTick();
\r
1213 /* As we have processed some ticks it is appropriate to yield
\r
1214 to ensure the highest priority task that is ready to run is
\r
1215 the task actually running. */
\r
1216 xYieldRequired = pdTRUE;
\r
1219 if( ( xYieldRequired == pdTRUE ) || ( xMissedYield == pdTRUE ) )
\r
1221 xAlreadyYielded = pdTRUE;
\r
1222 xMissedYield = pdFALSE;
\r
1228 portEXIT_CRITICAL();
\r
1230 return xAlreadyYielded;
\r
1238 /*-----------------------------------------------------------
\r
1239 * PUBLIC TASK UTILITIES documented in task.h
\r
1240 *----------------------------------------------------------*/
\r
1244 portTickType xTaskGetTickCount( void )
\r
1246 portTickType xTicks;
\r
1248 /* Critical section required if running on a 16 bit processor. */
\r
1249 taskENTER_CRITICAL();
\r
1251 xTicks = xTickCount;
\r
1253 taskEXIT_CRITICAL();
\r
1257 /*-----------------------------------------------------------*/
\r
1259 unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
\r
1261 unsigned portBASE_TYPE uxNumberOfTasks;
\r
1263 taskENTER_CRITICAL();
\r
1264 uxNumberOfTasks = uxCurrentNumberOfTasks;
\r
1265 taskEXIT_CRITICAL();
\r
1267 return uxNumberOfTasks;
\r
1269 /*-----------------------------------------------------------*/
\r
1271 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_vTaskDelete == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )
\r
1273 void vTaskList( signed portCHAR *pcWriteBuffer )
\r
1275 unsigned portBASE_TYPE uxQueue;
\r
1277 /* This is a VERY costly function that should be used for debug only.
\r
1278 It leaves interrupts disabled for a LONG time. */
\r
1280 vTaskSuspendAll();
\r
1282 /* Run through all the lists that could potentially contain a TCB and
\r
1283 report the task name, state and stack high water mark. */
\r
1285 pcWriteBuffer[ 0 ] = ( signed portCHAR ) 0x00;
\r
1286 strcat( ( portCHAR * ) pcWriteBuffer, ( const portCHAR * ) "\r\n" );
\r
1288 uxQueue = uxTopUsedPriority + 1;
\r
1294 if( !listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxQueue ] ) ) )
\r
1296 prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) &( pxReadyTasksLists[ uxQueue ] ), tskREADY_CHAR );
\r
1298 }while( uxQueue > ( unsigned portSHORT ) tskIDLE_PRIORITY );
\r
1300 if( !listLIST_IS_EMPTY( pxDelayedTaskList ) )
\r
1302 prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) pxDelayedTaskList, tskBLOCKED_CHAR );
\r
1305 if( !listLIST_IS_EMPTY( pxOverflowDelayedTaskList ) )
\r
1307 prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) pxOverflowDelayedTaskList, tskBLOCKED_CHAR );
\r
1310 if( !listLIST_IS_EMPTY( &xTasksWaitingTermination ) )
\r
1312 prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) &xTasksWaitingTermination, tskDELETED_CHAR );
\r
1315 if( !listLIST_IS_EMPTY( &xSuspendedTaskList ) )
\r
1317 prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) &xSuspendedTaskList, tskSUSPENDED_CHAR );
\r
1324 /*----------------------------------------------------------*/
\r
1326 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1328 void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize )
\r
1330 portENTER_CRITICAL();
\r
1332 pcTraceBuffer = ( volatile signed portCHAR * volatile )pcBuffer;
\r
1333 pcTraceBufferStart = pcBuffer;
\r
1334 pcTraceBufferEnd = pcBuffer + ( ulBufferSize - tskSIZE_OF_EACH_TRACE_LINE );
\r
1335 xTracing = pdTRUE;
\r
1337 portEXIT_CRITICAL();
\r
1341 /*----------------------------------------------------------*/
\r
1343 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1345 unsigned portLONG ulTaskEndTrace( void )
\r
1347 unsigned portLONG ulBufferLength;
\r
1349 portENTER_CRITICAL();
\r
1350 xTracing = pdFALSE;
\r
1351 portEXIT_CRITICAL();
\r
1353 ulBufferLength = ( unsigned portLONG ) ( pcTraceBuffer - pcTraceBufferStart );
\r
1355 return ulBufferLength;
\r
1362 /*-----------------------------------------------------------
\r
1363 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
\r
1364 * documented in task.h
\r
1365 *----------------------------------------------------------*/
\r
1368 inline void vTaskIncrementTick( void )
\r
1370 /* Called by the portable layer each time a tick interrupt occurs.
\r
1371 Increments the tick then checks to see if the new tick value will cause any
\r
1372 tasks to be unblocked. */
\r
1373 if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )
\r
1376 if( xTickCount == ( portTickType ) 0 )
\r
1380 /* Tick count has overflowed so we need to swap the delay lists.
\r
1381 If there are any items in pxDelayedTaskList here then there is
\r
1383 pxTemp = pxDelayedTaskList;
\r
1384 pxDelayedTaskList = pxOverflowDelayedTaskList;
\r
1385 pxOverflowDelayedTaskList = pxTemp;
\r
1386 xNumOfOverflows++;
\r
1389 /* See if this tick has made a timeout expire. */
\r
1390 prvCheckDelayedTasks();
\r
1396 /* The tick hook gets called at regular intervals, even if the
\r
1397 scheduler is locked. */
\r
1398 #if ( configUSE_TICK_HOOK == 1 )
\r
1400 extern void vApplicationTickHook( void );
\r
1402 vApplicationTickHook();
\r
1407 #if ( configUSE_TICK_HOOK == 1 )
\r
1409 extern void vApplicationTickHook( void );
\r
1411 /* Guard against the tick hook being called when the missed tick
\r
1412 count is being unwound (when the scheduler is being unlocked. */
\r
1413 if( uxMissedTicks == 0 )
\r
1415 vApplicationTickHook();
\r
1420 /*-----------------------------------------------------------*/
\r
1422 #if ( ( INCLUDE_vTaskCleanUpResources == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )
\r
1424 void vTaskCleanUpResources( void )
\r
1426 unsigned portSHORT usQueue;
\r
1427 volatile tskTCB *pxTCB;
\r
1429 usQueue = ( unsigned portSHORT ) uxTopUsedPriority + ( unsigned portSHORT ) 1;
\r
1431 /* Remove any TCB's from the ready queues. */
\r
1436 while( !listLIST_IS_EMPTY( &( pxReadyTasksLists[ usQueue ] ) ) )
\r
1438 listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &( pxReadyTasksLists[ usQueue ] ) );
\r
1439 vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );
\r
1441 prvDeleteTCB( ( tskTCB * ) pxTCB );
\r
1443 }while( usQueue > ( unsigned portSHORT ) tskIDLE_PRIORITY );
\r
1445 /* Remove any TCB's from the delayed queue. */
\r
1446 while( !listLIST_IS_EMPTY( &xDelayedTaskList1 ) )
\r
1448 listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &xDelayedTaskList1 );
\r
1449 vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );
\r
1451 prvDeleteTCB( ( tskTCB * ) pxTCB );
\r
1454 /* Remove any TCB's from the overflow delayed queue. */
\r
1455 while( !listLIST_IS_EMPTY( &xDelayedTaskList2 ) )
\r
1457 listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &xDelayedTaskList2 );
\r
1458 vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );
\r
1460 prvDeleteTCB( ( tskTCB * ) pxTCB );
\r
1463 while( !listLIST_IS_EMPTY( &xSuspendedTaskList ) )
\r
1465 listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &xSuspendedTaskList );
\r
1466 vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );
\r
1468 prvDeleteTCB( ( tskTCB * ) pxTCB );
\r
1473 /*-----------------------------------------------------------*/
\r
1475 void vTaskSwitchContext( void )
\r
1477 if( uxSchedulerSuspended != ( unsigned portBASE_TYPE ) pdFALSE )
\r
1479 /* The scheduler is currently suspended - do not allow a context
\r
1481 xMissedYield = pdTRUE;
\r
1485 /* Find the highest priority queue that contains ready tasks. */
\r
1486 while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopReadyPriority ] ) ) )
\r
1488 --uxTopReadyPriority;
\r
1491 /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the tasks of the
\r
1492 same priority get an equal share of the processor time. */
\r
1493 listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) );
\r
1494 vWriteTraceToBuffer();
\r
1496 /*-----------------------------------------------------------*/
\r
1498 void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait )
\r
1500 portTickType xTimeToWake;
\r
1502 /* THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED OR THE
\r
1503 SCHEDULER SUSPENDED. */
\r
1505 /* Place the event list item of the TCB in the appropriate event list.
\r
1506 This is placed in the list in priority order so the highest priority task
\r
1507 is the first to be woken by the event. */
\r
1508 vListInsert( ( xList * ) pxEventList, ( xListItem * ) &( pxCurrentTCB->xEventListItem ) );
\r
1510 /* We must remove ourselves from the ready list before adding ourselves
\r
1511 to the blocked list as the same list item is used for both lists. We have
\r
1512 exclusive access to the ready lists as the scheduler is locked. */
\r
1513 vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );
\r
1516 #if ( INCLUDE_vTaskSuspend == 1 )
\r
1518 if( xTicksToWait == portMAX_DELAY )
\r
1520 /* Add ourselves to the suspended task list instead of a delayed task
\r
1521 list to ensure we are not woken by a timing event. We will block
\r
1523 vListInsertEnd( ( xList * ) &xSuspendedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );
\r
1527 /* Calculate the time at which the task should be woken if the event does
\r
1528 not occur. This may overflow but this doesn't matter. */
\r
1529 xTimeToWake = xTickCount + xTicksToWait;
\r
1531 listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xGenericListItem ), xTimeToWake );
\r
1533 if( xTimeToWake < xTickCount )
\r
1535 /* Wake time has overflowed. Place this item in the overflow list. */
\r
1536 vListInsert( ( xList * ) pxOverflowDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );
\r
1540 /* The wake time has not overflowed, so we can use the current block list. */
\r
1541 vListInsert( ( xList * ) pxDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );
\r
1547 /* Calculate the time at which the task should be woken if the event does
\r
1548 not occur. This may overflow but this doesn't matter. */
\r
1549 xTimeToWake = xTickCount + xTicksToWait;
\r
1551 listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xGenericListItem ), xTimeToWake );
\r
1553 if( xTimeToWake < xTickCount )
\r
1555 /* Wake time has overflowed. Place this item in the overflow list. */
\r
1556 vListInsert( ( xList * ) pxOverflowDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );
\r
1560 /* The wake time has not overflowed, so we can use the current block list. */
\r
1561 vListInsert( ( xList * ) pxDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );
\r
1566 /*-----------------------------------------------------------*/
\r
1568 signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList )
\r
1570 tskTCB *pxUnblockedTCB;
\r
1571 portBASE_TYPE xReturn;
\r
1573 /* THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED OR THE
\r
1574 SCHEDULER SUSPENDED. It can also be called from within an ISR. */
\r
1576 /* The event list is sorted in priority order, so we can remove the
\r
1577 first in the list, remove the TCB from the delayed list, and add
\r
1578 it to the ready list.
\r
1580 If an event is for a queue that is locked then this function will never
\r
1581 get called - the lock count on the queue will get modified instead. This
\r
1582 means we can always expect exclusive access to the event list here. */
\r
1583 pxUnblockedTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );
\r
1584 vListRemove( &( pxUnblockedTCB->xEventListItem ) );
\r
1586 if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )
\r
1588 vListRemove( &( pxUnblockedTCB->xGenericListItem ) );
\r
1589 prvAddTaskToReadyQueue( pxUnblockedTCB );
\r
1593 /* We cannot access the delayed or ready lists, so will hold this
\r
1594 task pending until the scheduler is resumed. */
\r
1595 vListInsertEnd( ( xList * ) &( xPendingReadyList ), &( pxUnblockedTCB->xEventListItem ) );
\r
1598 if( pxUnblockedTCB->uxPriority >= pxCurrentTCB->uxPriority )
\r
1600 /* Return true if the task removed from the event list has
\r
1601 a higher priority than the calling task. This allows
\r
1602 the calling task to know if it should force a context
\r
1608 xReturn = pdFALSE;
\r
1613 /*-----------------------------------------------------------*/
\r
1615 void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut )
\r
1617 pxTimeOut->xOverflowCount = xNumOfOverflows;
\r
1618 pxTimeOut->xTimeOnEntering = xTickCount;
\r
1620 /*-----------------------------------------------------------*/
\r
1622 portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait )
\r
1624 portBASE_TYPE xReturn;
\r
1626 #if ( INCLUDE_vTaskSuspend == 1 )
\r
1627 /* If INCLUDE_vTaskSuspend is set to 1 and the block time specified is
\r
1628 the maximum block time then the task should block indefinitely, and
\r
1629 therefore never time out. */
\r
1630 if( *pxTicksToWait == portMAX_DELAY )
\r
1632 xReturn = pdFALSE;
\r
1634 else /* We are not blocking indefinitely, perform the checks below. */
\r
1637 if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( xTickCount >= pxTimeOut->xTimeOnEntering ) )
\r
1639 /* The tick count is greater than the time at which vTaskSetTimeout()
\r
1640 was called, but has also overflowed since vTaskSetTimeOut() was called.
\r
1641 It must have wrapped all the way around and gone past us again. This
\r
1642 passed since vTaskSetTimeout() was called. */
\r
1645 else if( ( xTickCount - pxTimeOut->xTimeOnEntering ) < *pxTicksToWait )
\r
1647 /* Not a genuine timeout. Adjust parameters for time remaining. */
\r
1648 *pxTicksToWait -= ( xTickCount - pxTimeOut->xTimeOnEntering );
\r
1649 vTaskSetTimeOutState( pxTimeOut );
\r
1650 xReturn = pdFALSE;
\r
1659 /*-----------------------------------------------------------*/
\r
1661 void vTaskMissedYield( void )
\r
1663 xMissedYield = pdTRUE;
\r
1667 * -----------------------------------------------------------
\r
1669 * ----------------------------------------------------------
\r
1671 * The portTASK_FUNCTION() macro is used to allow port/compiler specific
\r
1672 * language extensions. The equivalent prototype for this function is:
\r
1674 * void prvIdleTask( void *pvParameters );
\r
1677 static portTASK_FUNCTION( prvIdleTask, pvParameters )
\r
1679 /* Stop warnings. */
\r
1680 ( void ) pvParameters;
\r
1684 /* See if any tasks have been deleted. */
\r
1685 prvCheckTasksWaitingTermination();
\r
1687 #if ( configUSE_PREEMPTION == 0 )
\r
1689 /* If we are not using preemption we keep forcing a task switch to
\r
1690 see if any other task has become available. If we are using
\r
1691 preemption we don't need to do this as any task becoming available
\r
1692 will automatically get the processor anyway. */
\r
1697 #if ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) )
\r
1699 /* When using preemption tasks of equal priority will be
\r
1700 timesliced. If a task that is sharing the idle priority is ready
\r
1701 to run then the idle task should yield before the end of the
\r
1704 A critical region is not required here as we are just reading from
\r
1705 the list, and an occasional incorrect value will not matter. If
\r
1706 the ready list at the idle priority contains more than one task
\r
1707 then a task other than the idle task is ready to execute. */
\r
1708 if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > ( unsigned portBASE_TYPE ) 1 )
\r
1715 #if ( configUSE_IDLE_HOOK == 1 )
\r
1717 extern void vApplicationIdleHook( void );
\r
1719 /* Call the user defined function from within the idle task. This
\r
1720 allows the application designer to add background functionality
\r
1721 without the overhead of a separate task.
\r
1722 NOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES,
\r
1723 CALL A FUNCTION THAT MIGHT BLOCK. */
\r
1724 vApplicationIdleHook();
\r
1728 } /*lint !e715 pvParameters is not accessed but all task functions require the same prototype. */
\r
1736 /*-----------------------------------------------------------
\r
1737 * File private functions documented at the top of the file.
\r
1738 *----------------------------------------------------------*/
\r
1742 static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed portCHAR * const pcName, unsigned portBASE_TYPE uxPriority )
\r
1744 /* Store the function name in the TCB. */
\r
1745 strncpy( ( char * ) pxTCB->pcTaskName, ( const char * ) pcName, ( unsigned portSHORT ) configMAX_TASK_NAME_LEN );
\r
1746 pxTCB->pcTaskName[ ( unsigned portSHORT ) configMAX_TASK_NAME_LEN - ( unsigned portSHORT ) 1 ] = '\0';
\r
1748 /* This is used as an array index so must ensure it's not too large. */
\r
1749 if( uxPriority >= configMAX_PRIORITIES )
\r
1751 uxPriority = configMAX_PRIORITIES - 1;
\r
1754 pxTCB->uxPriority = uxPriority;
\r
1755 #if ( configUSE_MUTEXES == 1 )
\r
1757 pxTCB->uxBasePriority = uxPriority;
\r
1761 vListInitialiseItem( &( pxTCB->xGenericListItem ) );
\r
1762 vListInitialiseItem( &( pxTCB->xEventListItem ) );
\r
1764 /* Set the pxTCB as a link back from the xListItem. This is so we can get
\r
1765 back to the containing TCB from a generic item in a list. */
\r
1766 listSET_LIST_ITEM_OWNER( &( pxTCB->xGenericListItem ), pxTCB );
\r
1768 /* Event lists are always in priority order. */
\r
1769 listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority );
\r
1770 listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
\r
1772 /*-----------------------------------------------------------*/
\r
1774 static void prvInitialiseTaskLists( void )
\r
1776 unsigned portBASE_TYPE uxPriority;
\r
1778 for( uxPriority = 0; uxPriority < configMAX_PRIORITIES; uxPriority++ )
\r
1780 vListInitialise( ( xList * ) &( pxReadyTasksLists[ uxPriority ] ) );
\r
1783 vListInitialise( ( xList * ) &xDelayedTaskList1 );
\r
1784 vListInitialise( ( xList * ) &xDelayedTaskList2 );
\r
1785 vListInitialise( ( xList * ) &xPendingReadyList );
\r
1787 #if ( INCLUDE_vTaskDelete == 1 )
\r
1789 vListInitialise( ( xList * ) &xTasksWaitingTermination );
\r
1793 #if ( INCLUDE_vTaskSuspend == 1 )
\r
1795 vListInitialise( ( xList * ) &xSuspendedTaskList );
\r
1799 /* Start with pxDelayedTaskList using list1 and the pxOverflowDelayedTaskList
\r
1801 pxDelayedTaskList = &xDelayedTaskList1;
\r
1802 pxOverflowDelayedTaskList = &xDelayedTaskList2;
\r
1804 /*-----------------------------------------------------------*/
\r
1806 static void prvCheckTasksWaitingTermination( void )
\r
1808 #if ( INCLUDE_vTaskDelete == 1 )
\r
1810 portBASE_TYPE xListIsEmpty;
\r
1812 /* ucTasksDeleted is used to prevent vTaskSuspendAll() being called
\r
1813 too often in the idle task. */
\r
1814 if( uxTasksDeleted > ( unsigned portBASE_TYPE ) 0 )
\r
1816 vTaskSuspendAll();
\r
1817 xListIsEmpty = listLIST_IS_EMPTY( &xTasksWaitingTermination );
\r
1820 if( !xListIsEmpty )
\r
1824 portENTER_CRITICAL();
\r
1826 pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xTasksWaitingTermination ) );
\r
1827 vListRemove( &( pxTCB->xGenericListItem ) );
\r
1828 --uxCurrentNumberOfTasks;
\r
1831 portEXIT_CRITICAL();
\r
1833 prvDeleteTCB( pxTCB );
\r
1839 /*-----------------------------------------------------------*/
\r
1841 static tskTCB *prvAllocateTCBAndStack( unsigned portSHORT usStackDepth )
\r
1845 /* Allocate space for the TCB. Where the memory comes from depends on
\r
1846 the implementation of the port malloc function. */
\r
1847 pxNewTCB = ( tskTCB * ) pvPortMalloc( sizeof( tskTCB ) );
\r
1849 if( pxNewTCB != NULL )
\r
1851 /* Allocate space for the stack used by the task being created.
\r
1852 The base of the stack memory stored in the TCB so the task can
\r
1853 be deleted later if required. */
\r
1854 pxNewTCB->pxStack = ( portSTACK_TYPE * ) pvPortMalloc( ( ( size_t )usStackDepth ) * sizeof( portSTACK_TYPE ) );
\r
1856 if( pxNewTCB->pxStack == NULL )
\r
1858 /* Could not allocate the stack. Delete the allocated TCB. */
\r
1859 vPortFree( pxNewTCB );
\r
1864 /* Just to help debugging. */
\r
1865 memset( pxNewTCB->pxStack, tskSTACK_FILL_BYTE, usStackDepth * sizeof( portSTACK_TYPE ) );
\r
1871 /*-----------------------------------------------------------*/
\r
1873 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1875 static void prvListTaskWithinSingleList( const signed portCHAR *pcWriteBuffer, xList *pxList, signed portCHAR cStatus )
\r
1877 volatile tskTCB *pxNextTCB, *pxFirstTCB;
\r
1878 static portCHAR pcStatusString[ 50 ];
\r
1879 unsigned portSHORT usStackRemaining;
\r
1881 /* Write the details of all the TCB's in pxList into the buffer. */
\r
1882 listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );
\r
1885 listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );
\r
1886 usStackRemaining = usTaskCheckFreeStackSpace( ( unsigned portCHAR * ) pxNextTCB->pxStack );
\r
1887 sprintf( pcStatusString, ( portCHAR * ) "%s\t\t%c\t%u\t%u\t%u\r\n", pxNextTCB->pcTaskName, cStatus, ( unsigned int ) pxNextTCB->uxPriority, usStackRemaining, ( unsigned int ) pxNextTCB->uxTCBNumber );
\r
1888 strcat( ( portCHAR * ) pcWriteBuffer, ( portCHAR * ) pcStatusString );
\r
1890 } while( pxNextTCB != pxFirstTCB );
\r
1894 /*-----------------------------------------------------------*/
\r
1896 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1897 unsigned portSHORT usTaskCheckFreeStackSpace( const unsigned portCHAR * pucStackByte )
\r
1899 register unsigned portSHORT usCount = 0;
\r
1901 while( *pucStackByte == tskSTACK_FILL_BYTE )
\r
1903 pucStackByte -= portSTACK_GROWTH;
\r
1907 usCount /= sizeof( portSTACK_TYPE );
\r
1912 /*-----------------------------------------------------------*/
\r
1916 #if ( ( INCLUDE_vTaskDelete == 1 ) || ( INCLUDE_vTaskCleanUpResources == 1 ) )
\r
1918 static void prvDeleteTCB( tskTCB *pxTCB )
\r
1920 /* Free up the memory allocated by the scheduler for the task. It is up to
\r
1921 the task to free any memory allocated at the application level. */
\r
1922 vPortFree( pxTCB->pxStack );
\r
1923 vPortFree( pxTCB );
\r
1929 /*-----------------------------------------------------------*/
\r
1931 #if ( INCLUDE_xTaskGetCurrentTaskHandle == 1 )
\r
1933 xTaskHandle xTaskGetCurrentTaskHandle( void )
\r
1935 xTaskHandle xReturn;
\r
1937 portENTER_CRITICAL();
\r
1939 xReturn = ( xTaskHandle ) pxCurrentTCB;
\r
1941 portEXIT_CRITICAL();
\r
1948 /*-----------------------------------------------------------*/
\r
1950 #if ( INCLUDE_xTaskGetSchedulerState == 1 )
\r
1952 portBASE_TYPE xTaskGetSchedulerState( void )
\r
1954 portBASE_TYPE xReturn;
\r
1956 if( xSchedulerRunning == pdFALSE )
\r
1958 xReturn = taskSCHEDULER_NOT_STARTED;
\r
1962 if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )
\r
1964 xReturn = taskSCHEDULER_RUNNING;
\r
1968 xReturn = taskSCHEDULER_SUSPENDED;
\r
1977 #if ( configUSE_MUTEXES == 1 )
\r
1979 void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder )
\r
1981 tskTCB * const pxTCB = ( tskTCB * ) pxMutexHolder;
\r
1983 if( pxTCB->uxPriority < pxCurrentTCB->uxPriority )
\r
1985 /* Adjust the mutex holder state to account for its new priority. */
\r
1986 listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) pxCurrentTCB->uxPriority );
\r
1988 /* If the task being modified is in the read state it will need to
\r
1989 be moved in to a new list. */
\r
1990 if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ) )
\r
1992 vListRemove( &( pxTCB->xGenericListItem ) );
\r
1994 /* Inherit the priority before being moved into the new list. */
\r
1995 pxTCB->uxPriority = pxCurrentTCB->uxPriority;
\r
1996 prvAddTaskToReadyQueue( pxTCB );
\r
2000 /* Just inherit the priority. */
\r
2001 pxTCB->uxPriority = pxCurrentTCB->uxPriority;
\r
2008 #if ( configUSE_MUTEXES == 1 )
\r
2010 void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder )
\r
2012 tskTCB * const pxTCB = ( tskTCB * ) pxMutexHolder;
\r
2014 if( pxMutexHolder != NULL )
\r
2016 if( pxTCB->uxPriority != pxTCB->uxBasePriority )
\r
2018 /* We must be the running task to be able to give the mutex back.
\r
2019 Remove ourselves from the ready list we currently appear in. */
\r
2020 vListRemove( &( pxTCB->xGenericListItem ) );
\r
2022 /* Disinherit the priority before adding ourselves into the new
\r
2024 pxTCB->uxPriority = pxTCB->uxBasePriority;
\r
2025 listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) pxTCB->uxPriority );
\r
2026 prvAddTaskToReadyQueue( pxTCB );
\r