/*\r
- FreeRTOS.org V4.1.2 - Copyright (C) 2003-2006 Richard Barry.\r
-\r
- This file is part of the FreeRTOS.org distribution.\r
-\r
- FreeRTOS.org is free software; you can redistribute it and/or modify\r
- it under the terms of the GNU General Public License as published by\r
- the Free Software Foundation; either version 2 of the License, or\r
- (at your option) any later version.\r
-\r
- FreeRTOS.org is distributed in the hope that it will be useful,\r
- but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- GNU General Public License for more details.\r
-\r
- You should have received a copy of the GNU General Public License\r
- along with FreeRTOS.org; if not, write to the Free Software\r
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
-\r
- A special exception to the GPL can be applied should you wish to distribute\r
- a combined work that includes FreeRTOS.org, without being obliged to provide\r
- the source code for any proprietary components. See the licensing section\r
- of http://www.FreeRTOS.org for full details of how and when the exception\r
- can be applied.\r
-\r
- ***************************************************************************\r
- See http://www.FreeRTOS.org for documentation, latest information, license\r
- and contact details. Please ensure to read the configuration and relevant\r
- port sections of the online documentation.\r
- ***************************************************************************\r
-*/\r
-\r
-/*\r
-Changes from V1.00:\r
+ FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.\r
\r
- + Call to portRESTORE_CONTEXT has been removed. The first context\r
- switch is now performed within sPortStartScheduler().\r
-\r
-Changes from V1.01:\r
-\r
- + More use of 8bit data types.\r
- + Function name prefixes changed where the data type returned has changed.\r
- + configUSE_TRACE_FACILITY is no longer defined by default.\r
-\r
-Changes from V1.2.0\r
-\r
- + Introduced ucTopReadyPriority. This tracks the highest priority ready\r
- queue that contains a valid TCB and thus makes the context switch\r
- slightly faster.\r
-\r
- + prvAddTaskToReadyQueue() has been made a macro.\r
-\r
-Changes from V1.2.6\r
-\r
- + Added conditional compilation directives.\r
- + Extended API.\r
- + Rearranged function order.\r
- + Creating a task now causes a context switch if the task being created\r
- has a higher priority than the calling task - assuming the kernel is\r
- running.\r
- + vTaskDelete() now only causes a context switch if the calling task is\r
- the task being deleted.\r
-\r
-Changes from V2.0.0\r
-\r
- + Allow the type of the tick count to be 16 or 32 bits.\r
- + Introduce xPendingReadyList feature to allow the time interrupts have to\r
- be disabled to be minimised.\r
- + Remove the #if( INCLUDE_vTaskSuspendAll ) statements. vTaskSuspendAll()\r
- is now always included as it is used by the scheduler itself.\r
-\r
-Changes from V2.1.0\r
-\r
- + Bug fix - pxCurrentTCB is now initialised before the call to\r
- prvInitializeTaskLists(). Previously pxCurrentTCB could be accessed\r
- while null.\r
-\r
-Changed from V2.1.1\r
-\r
- + Change to where lStackSize is declared within sTaskCreate() to prevent\r
- compiler warnings with 8051 port.\r
-\r
-Changes from V2.2.0\r
-\r
- + Explicit use of 'signed' qualifier on portCHAR types added.\r
- + Changed odd calculation of initial pxTopOfStack value when\r
- portSTACK_GROWTH < 0.\r
- + Removed pcVersionNumber definition.\r
-\r
-Changes from V2.5.3\r
-\r
- + cTaskResumeAll() modified to ensure it can be called prior to the task\r
- lists being initialised.\r
-\r
-Changes from V2.5.5\r
-\r
- + Added API function vTaskDelayUntil().\r
- + Added INCLUDE_vTaskDelay conditional compilation.\r
-\r
-Changes from V2.6.0\r
-\r
- + Updated the vWriteTraceToBuffer macro to always be 4 byte aligned so it\r
- can be used on ARM architectures.\r
- + tskMAX_TASK_NAME_LEN definition replaced with the port specific\r
- configMAX_TASK_NAME_LEN definition.\r
- + Removed the call to strcpy when copying across the task name into the\r
- TCB.\r
- + Added ucTasksDeleted variable to prevent vTaskSuspendAll() being called\r
- too often in the idle task.\r
-\r
-Changes between V3.0.0 and V2.6.1\r
-\r
- + When resuming the scheduler a yield is performed if either a tick has\r
- been missed, or a task is moved from the pending ready list into a ready\r
- list. Previously a yield was not performed on this second condition.\r
- + Introduced the type portBASE_TYPE. This necessitates several API\r
- changes.\r
- + Removed the sUsingPreemption variable. The constant defined in\r
- portmacro.h is now used directly.\r
- + The idle task can now include an optional hook function - and no longer\r
- completes its time slice if other tasks with equal priority to it are\r
- ready to run.\r
- + See the FreeRTOS.org documentation for more information on V2.x.x to\r
- V3.x.x modifications.\r
-\r
-Changes from V3.1.1\r
-\r
- + Modified vTaskPrioritySet() and vTaskResume() to allow these functions to\r
- be called while the scheduler is suspended.\r
- + Corrected the task ordering within event lists.\r
-\r
-Changes from V3.2.0\r
-\r
- + Added function xTaskGetCurrentTaskHandle().\r
-\r
-Changes from V3.2.4\r
-\r
- + Changed the volatile declarations on some variables to reflect the \r
- changes to the list definitions.\r
- + Changed the order of the TCB definition so there is commonality between\r
- the task control block and a co-routine control block.\r
- + Allow the scheduler to be started even if no tasks other than the idle\r
- task has been created. This allows co-routines to run even when no tasks\r
- have been created.\r
- + The need for a context switch is now signalled if a task woken by an \r
- event has a priority greater or equal to the currently running task.\r
- Previously this was only greater than.\r
\r
-Changes from V4.0.0\r
-\r
- + Added the xMissedYield handling.\r
-\r
-Changes from V4.0.1\r
-\r
- + The function vTaskList() now suspends the scheduler rather than disabling\r
- interrupts during the creation of the task list. \r
- + Allow a task to delete itself by passing in its own handle. Previously \r
- this could only be done by passing in NULL.\r
- + The tick hook function is now called only within a tick isr. Previously\r
- it was also called when the tick function was called during the scheduler\r
- unlocking process.\r
-\r
-Changes from V4.0.3\r
-\r
- + Extra checks have been placed in vTaskPrioritySet() to avoid unnecessary\r
- yields.\r
-\r
-Changed from V4.0.4\r
-\r
- + Bug fix: The 'value' of the event list item is updated when the priority\r
- of a task is changed. Previously only the priority of the TCB itself was\r
- changed.\r
- + When resuming a task a check is first made to see if the task is actually\r
- suspended.\r
- + vTaskPrioritySet() and vTaskResume() no longer use the event list item.\r
- This has not been necessary since V4.0.1 when the xMissedYield handling\r
- was added.\r
- + Implement xTaskResumeFromISR().\r
-\r
-Changes from V4.0.5\r
-\r
- + Added utility functions and xOverflowCount variable to facilitate the\r
- queue.c changes.\r
-\r
-Changes from V4.1.2\r
- \r
- + Tasks that block with a timeout of portMAX_DELAY are now blocked \r
- indefinitely. Previously portMAX_DELAY was just the longest block time\r
- possible.\r
+ ***************************************************************************\r
+ * *\r
+ * FreeRTOS tutorial books are available in pdf and paperback. *\r
+ * Complete, revised, and edited pdf reference manuals are also *\r
+ * available. *\r
+ * *\r
+ * Purchasing FreeRTOS documentation will not only help you, by *\r
+ * ensuring you get running as quickly as possible and with an *\r
+ * in-depth knowledge of how to use FreeRTOS, it will also help *\r
+ * the FreeRTOS project to continue with its mission of providing *\r
+ * professional grade, cross platform, de facto standard solutions *\r
+ * for microcontrollers - completely free of charge! *\r
+ * *\r
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
+ * *\r
+ * Thank you for using FreeRTOS, and thank you for your support! *\r
+ * *\r
+ ***************************************************************************\r
+\r
+\r
+ This file is part of the FreeRTOS distribution.\r
+\r
+ FreeRTOS is free software; you can redistribute it and/or modify it under\r
+ the terms of the GNU General Public License (version 2) as published by the\r
+ Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+ >>>NOTE<<< The modification to the GPL is included to allow you to\r
+ distribute a combined work that includes FreeRTOS without being obliged to\r
+ provide the source code for proprietary components outside of the FreeRTOS\r
+ kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
+ more details. You should have received a copy of the GNU General Public\r
+ License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+ can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
+ by writing to Richard Barry, contact details for whom are available on the\r
+ FreeRTOS WEB site.\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ http://www.FreeRTOS.org - Documentation, latest information, license and\r
+ contact details.\r
+\r
+ http://www.SafeRTOS.com - A version that is certified for use in safety\r
+ critical systems.\r
+\r
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
+ licensing and training services.\r
*/\r
\r
+\r
#include <stdio.h>\r
#include <stdlib.h>\r
#include <string.h>\r
\r
+/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining\r
+all the API functions to use the MPU wrappers. That should only be done when\r
+task.h is included from an application file. */\r
+#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE\r
+\r
#include "FreeRTOS.h"\r
#include "task.h"\r
+#include "timers.h"\r
+#include "StackMacros.h"\r
+\r
+#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE\r
\r
/*\r
* Macro to define the amount of stack available to the idle task.\r
*/\r
#define tskIDLE_STACK_SIZE configMINIMAL_STACK_SIZE\r
\r
-\r
-/*\r
- * Default a definitions for backwards compatibility with old\r
- * portmacro.h files.\r
- */\r
-#ifndef configMAX_TASK_NAME_LEN\r
- #define configMAX_TASK_NAME_LEN 16\r
-#endif\r
-\r
-#ifndef INCLUDE_xTaskGetCurrentTaskHandle\r
- #define INCLUDE_xTaskGetCurrentTaskHandle 0\r
-#endif\r
-\r
-#ifndef configIDLE_SHOULD_YIELD\r
- #define configIDLE_SHOULD_YIELD 1\r
-#endif\r
-\r
-#if configMAX_TASK_NAME_LEN < 1\r
- #undef configMAX_TASK_NAME_LEN\r
- #define configMAX_TASK_NAME_LEN 1\r
-#endif\r
-\r
-#ifndef INCLUDE_xTaskResumeFromISR\r
- #define INCLUDE_xTaskResumeFromISR 1\r
-#endif \r
-\r
/*\r
* Task control block. A task control block (TCB) is allocated to each task,\r
* and stores the context of the task.\r
typedef struct tskTaskControlBlock\r
{\r
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
+\r
+ #if ( portUSING_MPU_WRAPPERS == 1 )\r
+ xMPU_SETTINGS xMPUSettings; /*< The MPU settings are defined as part of the port layer. THIS MUST BE THE SECOND MEMBER OF THE STRUCT. */\r
+ #endif \r
+ \r
xListItem xGenericListItem; /*< List item used to place the TCB in ready and blocked queues. */\r
xListItem xEventListItem; /*< List item used to place the TCB in event lists. */\r
unsigned portBASE_TYPE uxPriority; /*< The priority of the task where 0 is the lowest priority. */\r
portSTACK_TYPE *pxStack; /*< Points to the start of the stack. */\r
- unsigned portBASE_TYPE uxTCBNumber; /*< This is used for tracing the scheduler and making debugging easier only. */\r
- signed portCHAR pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created. Facilitates debugging only. */\r
- unsigned portSHORT usStackDepth; /*< Total depth of the stack (when empty). This is defined as the number of variables the stack can hold, not the number of bytes. */\r
+ signed char pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created. Facilitates debugging only. */\r
+\r
+ #if ( portSTACK_GROWTH > 0 )\r
+ portSTACK_TYPE *pxEndOfStack; /*< Used for stack overflow checking on architectures where the stack grows up from low memory. */\r
+ #endif\r
+\r
+ #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
+ unsigned portBASE_TYPE uxCriticalNesting;\r
+ #endif\r
+\r
+ #if ( configUSE_TRACE_FACILITY == 1 )\r
+ unsigned portBASE_TYPE uxTCBNumber; /*< This stores a number that increments each time a TCB is created. It allows debuggers to determine when a task has been deleted and then recreated. */\r
+ unsigned portBASE_TYPE uxTaskNumber; /*< This stores a number specifically for use by third party trace code. */\r
+ #endif\r
+\r
+ #if ( configUSE_MUTEXES == 1 )\r
+ unsigned portBASE_TYPE uxBasePriority; /*< The priority last assigned to the task - used by the priority inheritance mechanism. */\r
+ #endif\r
+\r
+ #if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
+ pdTASK_HOOK_CODE pxTaskTag;\r
+ #endif\r
+\r
+ #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
+ unsigned long ulRunTimeCounter; /*< Used for calculating how much CPU time each task is utilising. */\r
+ #endif\r
+\r
} tskTCB;\r
\r
-/*lint -e956 */\r
\r
-tskTCB * volatile pxCurrentTCB = NULL; \r
+/*\r
+ * Some kernel aware debuggers require data to be viewed to be global, rather\r
+ * than file scope.\r
+ */\r
+#ifdef portREMOVE_STATIC_QUALIFIER\r
+ #define static\r
+#endif\r
+\r
+/*lint -e956 */\r
+PRIVILEGED_DATA tskTCB * volatile pxCurrentTCB = NULL;\r
\r
/* Lists for ready and blocked tasks. --------------------*/\r
\r
-static xList pxReadyTasksLists[ configMAX_PRIORITIES ]; /*< Prioritised ready tasks. */\r
-static xList xDelayedTaskList1; /*< Delayed tasks. */\r
-static xList xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */\r
-static xList * volatile pxDelayedTaskList; /*< Points to the delayed task list currently being used. */\r
-static xList * volatile pxOverflowDelayedTaskList; /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */\r
-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
+PRIVILEGED_DATA static xList pxReadyTasksLists[ configMAX_PRIORITIES ]; /*< Prioritised ready tasks. */\r
+PRIVILEGED_DATA static xList xDelayedTaskList1; /*< Delayed tasks. */\r
+PRIVILEGED_DATA static xList xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */\r
+PRIVILEGED_DATA static xList * volatile pxDelayedTaskList ; /*< Points to the delayed task list currently being used. */\r
+PRIVILEGED_DATA static xList * volatile pxOverflowDelayedTaskList; /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */\r
+PRIVILEGED_DATA 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
\r
#if ( INCLUDE_vTaskDelete == 1 )\r
\r
- static volatile xList xTasksWaitingTermination; /*< Tasks that have been deleted - but the their memory not yet freed. */\r
- static volatile unsigned portBASE_TYPE uxTasksDeleted = ( unsigned portBASE_TYPE ) 0;\r
+ PRIVILEGED_DATA static xList xTasksWaitingTermination; /*< Tasks that have been deleted - but the their memory not yet freed. */\r
+ PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxTasksDeleted = ( unsigned portBASE_TYPE ) 0U;\r
\r
#endif\r
\r
#if ( INCLUDE_vTaskSuspend == 1 )\r
\r
- static xList xSuspendedTaskList; /*< Tasks that are currently suspended. */\r
+ PRIVILEGED_DATA static xList xSuspendedTaskList; /*< Tasks that are currently suspended. */\r
+\r
+#endif\r
\r
+#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\r
+ \r
+ PRIVILEGED_DATA static xTaskHandle xIdleTaskHandle = NULL;\r
+ \r
#endif\r
\r
/* File private variables. --------------------------------*/\r
-static volatile unsigned portBASE_TYPE uxCurrentNumberOfTasks = ( unsigned portBASE_TYPE ) 0;\r
-static volatile portTickType xTickCount = ( portTickType ) 0;\r
-static unsigned portBASE_TYPE uxTopUsedPriority = tskIDLE_PRIORITY;\r
-static volatile unsigned portBASE_TYPE uxTopReadyPriority = tskIDLE_PRIORITY;\r
-static volatile signed portBASE_TYPE xSchedulerRunning = pdFALSE;\r
-static volatile unsigned portBASE_TYPE uxSchedulerSuspended = ( unsigned portBASE_TYPE ) pdFALSE;\r
-static volatile unsigned portBASE_TYPE uxMissedTicks = ( unsigned portBASE_TYPE ) 0;\r
-static volatile portBASE_TYPE xMissedYield = ( portBASE_TYPE ) pdFALSE;\r
-static volatile portBASE_TYPE xNumOfOverflows = ( portBASE_TYPE ) 0;\r
+PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxCurrentNumberOfTasks = ( unsigned portBASE_TYPE ) 0U;\r
+PRIVILEGED_DATA static volatile portTickType xTickCount = ( portTickType ) 0U;\r
+PRIVILEGED_DATA static unsigned portBASE_TYPE uxTopUsedPriority = tskIDLE_PRIORITY;\r
+PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxTopReadyPriority = tskIDLE_PRIORITY;\r
+PRIVILEGED_DATA static volatile signed portBASE_TYPE xSchedulerRunning = pdFALSE;\r
+PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxSchedulerSuspended = ( unsigned portBASE_TYPE ) pdFALSE;\r
+PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxMissedTicks = ( unsigned portBASE_TYPE ) 0U;\r
+PRIVILEGED_DATA static volatile portBASE_TYPE xMissedYield = ( portBASE_TYPE ) pdFALSE;\r
+PRIVILEGED_DATA static volatile portBASE_TYPE xNumOfOverflows = ( portBASE_TYPE ) 0;\r
+PRIVILEGED_DATA static unsigned portBASE_TYPE uxTCBNumber = ( unsigned portBASE_TYPE ) 0U;\r
+PRIVILEGED_DATA static portTickType xNextTaskUnblockTime = ( portTickType ) portMAX_DELAY;\r
+\r
+#if ( configGENERATE_RUN_TIME_STATS == 1 )\r
+\r
+ PRIVILEGED_DATA static char pcStatsString[ 50 ] ;\r
+ PRIVILEGED_DATA static unsigned long ulTaskSwitchedInTime = 0UL; /*< Holds the value of a timer/counter the last time a task was switched in. */\r
+ static void prvGenerateRunTimeStatsForTasksInList( const signed char *pcWriteBuffer, xList *pxList, unsigned long ulTotalRunTime ) PRIVILEGED_FUNCTION;\r
+\r
+#endif\r
+\r
/* Debugging and trace facilities private variables and macros. ------------*/\r
\r
/*\r
* The value used to fill the stack of a task when the task is created. This\r
* is used purely for checking the high water mark for tasks.\r
*/\r
-#define tskSTACK_FILL_BYTE ( 0xa5 )\r
+#define tskSTACK_FILL_BYTE ( 0xa5U )\r
\r
/*\r
* Macros used by vListTask to indicate which state a task is in.\r
*/\r
-#define tskBLOCKED_CHAR ( ( signed portCHAR ) 'B' )\r
-#define tskREADY_CHAR ( ( signed portCHAR ) 'R' )\r
-#define tskDELETED_CHAR ( ( signed portCHAR ) 'D' )\r
-#define tskSUSPENDED_CHAR ( ( signed portCHAR ) 'S' )\r
-\r
-/*\r
- * Macros and private variables used by the trace facility.\r
- */\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
-\r
- #define tskSIZE_OF_EACH_TRACE_LINE ( ( unsigned portLONG ) ( sizeof( unsigned portLONG ) + sizeof( unsigned portLONG ) ) )\r
- static volatile signed portCHAR * volatile pcTraceBuffer;\r
- static signed portCHAR *pcTraceBufferStart;\r
- static signed portCHAR *pcTraceBufferEnd;\r
- static signed portBASE_TYPE xTracing = pdFALSE;\r
-\r
-#endif\r
-\r
-/*\r
- * Macro that writes a trace of scheduler activity to a buffer. This trace\r
- * shows which task is running when and is very useful as a debugging tool.\r
- * As this macro is called each context switch it is a good idea to undefine\r
- * it if not using the facility.\r
- */\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
-\r
- #define vWriteTraceToBuffer() \\r
- { \\r
- if( xTracing ) \\r
- { \\r
- static unsigned portBASE_TYPE uxPreviousTask = 255; \\r
- \\r
- if( uxPreviousTask != pxCurrentTCB->uxTCBNumber ) \\r
- { \\r
- if( ( pcTraceBuffer + tskSIZE_OF_EACH_TRACE_LINE ) < pcTraceBufferEnd ) \\r
- { \\r
- uxPreviousTask = pxCurrentTCB->uxTCBNumber; \\r
- *( unsigned portLONG * ) pcTraceBuffer = ( unsigned portLONG ) xTickCount; \\r
- pcTraceBuffer += sizeof( unsigned portLONG ); \\r
- *( unsigned portLONG * ) pcTraceBuffer = ( unsigned portLONG ) uxPreviousTask; \\r
- pcTraceBuffer += sizeof( unsigned portLONG ); \\r
- } \\r
- else \\r
- { \\r
- xTracing = pdFALSE; \\r
- } \\r
- } \\r
- } \\r
- }\r
-\r
-#else\r
-\r
- #define vWriteTraceToBuffer()\r
-\r
-#endif\r
+#define tskBLOCKED_CHAR ( ( signed char ) 'B' )\r
+#define tskREADY_CHAR ( ( signed char ) 'R' )\r
+#define tskDELETED_CHAR ( ( signed char ) 'D' )\r
+#define tskSUSPENDED_CHAR ( ( signed char ) 'S' )\r
\r
+/*-----------------------------------------------------------*/\r
\r
/*\r
* Place the task represented by pxTCB into the appropriate ready queue for\r
* executing task, then it will only be rescheduled after the currently\r
* executing task has been rescheduled.\r
*/\r
-#define prvAddTaskToReadyQueue( pxTCB ) \\r
-{ \\r
- if( pxTCB->uxPriority > uxTopReadyPriority ) \\r
- { \\r
- uxTopReadyPriority = pxTCB->uxPriority; \\r
- } \\r
- vListInsertEnd( ( xList * ) &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ); \\r
-} \r
+#define prvAddTaskToReadyQueue( pxTCB ) \\r
+ if( ( pxTCB )->uxPriority > uxTopReadyPriority ) \\r
+ { \\r
+ uxTopReadyPriority = ( pxTCB )->uxPriority; \\r
+ } \\r
+ vListInsertEnd( ( xList * ) &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xGenericListItem ) )\r
+/*-----------------------------------------------------------*/\r
\r
/*\r
* Macro that looks at the list of tasks that are currently delayed to see if\r
* once one tasks has been found whose timer has not expired we need not look\r
* any further down the list.\r
*/\r
-#define prvCheckDelayedTasks() \\r
-{ \\r
-register tskTCB *pxTCB; \\r
- \\r
- while( ( pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList ) ) != NULL ) \\r
- { \\r
- if( xTickCount < listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) ) ) \\r
- { \\r
- break; \\r
- } \\r
- vListRemove( &( pxTCB->xGenericListItem ) ); \\r
- /* Is the task waiting on an event also? */ \\r
- if( pxTCB->xEventListItem.pvContainer ) \\r
- { \\r
- vListRemove( &( pxTCB->xEventListItem ) ); \\r
- } \\r
- prvAddTaskToReadyQueue( pxTCB ); \\r
- } \\r
-} \r
+#define prvCheckDelayedTasks() \\r
+{ \\r
+portTickType xItemValue; \\r
+ \\r
+ /* Is the tick count greater than or equal to the wake time of the first \\r
+ task referenced from the delayed tasks list? */ \\r
+ if( xTickCount >= xNextTaskUnblockTime ) \\r
+ { \\r
+ for( ;; ) \\r
+ { \\r
+ if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE ) \\r
+ { \\r
+ /* The delayed list is empty. Set xNextTaskUnblockTime to the \\r
+ maximum possible value so it is extremely unlikely that the \\r
+ if( xTickCount >= xNextTaskUnblockTime ) test will pass next \\r
+ time through. */ \\r
+ xNextTaskUnblockTime = portMAX_DELAY; \\r
+ break; \\r
+ } \\r
+ else \\r
+ { \\r
+ /* The delayed list is not empty, get the value of the item at \\r
+ the head of the delayed list. This is the time at which the \\r
+ task at the head of the delayed list should be removed from \\r
+ the Blocked state. */ \\r
+ pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList ); \\r
+ xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) ); \\r
+ \\r
+ if( xTickCount < xItemValue ) \\r
+ { \\r
+ /* It is not time to unblock this item yet, but the item \\r
+ value is the time at which the task at the head of the \\r
+ blocked list should be removed from the Blocked state - \\r
+ so record the item value in xNextTaskUnblockTime. */ \\r
+ xNextTaskUnblockTime = xItemValue; \\r
+ break; \\r
+ } \\r
+ \\r
+ /* It is time to remove the item from the Blocked state. */ \\r
+ vListRemove( &( pxTCB->xGenericListItem ) ); \\r
+ \\r
+ /* Is the task waiting on an event also? */ \\r
+ if( pxTCB->xEventListItem.pvContainer != NULL ) \\r
+ { \\r
+ vListRemove( &( pxTCB->xEventListItem ) ); \\r
+ } \\r
+ prvAddTaskToReadyQueue( pxTCB ); \\r
+ } \\r
+ } \\r
+ } \\r
+}\r
+/*-----------------------------------------------------------*/\r
\r
/*\r
* Several functions take an xTaskHandle parameter that can optionally be NULL,\r
* task should be used in place of the parameter. This macro simply checks to\r
* see if the parameter is NULL and returns a pointer to the appropriate TCB.\r
*/\r
-#define prvGetTCBFromHandle( pxHandle ) ( ( pxHandle == NULL ) ? ( tskTCB * ) pxCurrentTCB : ( tskTCB * ) pxHandle )\r
-\r
+#define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( tskTCB * ) pxCurrentTCB : ( tskTCB * ) ( pxHandle ) )\r
\r
+/* Callback function prototypes. --------------------------*/\r
+extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );\r
+extern void vApplicationTickHook( void );\r
+ \r
/* File private functions. --------------------------------*/\r
\r
/*\r
* Utility to ready a TCB for a given task. Mainly just copies the parameters\r
* into the TCB structure.\r
*/\r
-static void prvInitialiseTCBVariables( tskTCB *pxTCB, unsigned portSHORT usStackDepth, const signed portCHAR * const pcName, unsigned portBASE_TYPE uxPriority );\r
+static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed char * const pcName, unsigned portBASE_TYPE uxPriority, const xMemoryRegion * const xRegions, unsigned short usStackDepth ) PRIVILEGED_FUNCTION;\r
\r
/*\r
* Utility to ready all the lists used by the scheduler. This is called\r
* automatically upon the creation of the first task.\r
*/\r
-static void prvInitialiseTaskLists( void );\r
+static void prvInitialiseTaskLists( void ) PRIVILEGED_FUNCTION;\r
\r
/*\r
* The idle task, which as all tasks is implemented as a never ending loop.\r
* This does not free memory allocated by the task itself (i.e. memory\r
* allocated by calls to pvPortMalloc from within the tasks application code).\r
*/\r
-#if ( ( INCLUDE_vTaskDelete == 1 ) || ( INCLUDE_vTaskCleanUpResources == 1 ) )\r
- static void prvDeleteTCB( tskTCB *pxTCB );\r
+#if ( INCLUDE_vTaskDelete == 1 )\r
+\r
+ static void prvDeleteTCB( tskTCB *pxTCB ) PRIVILEGED_FUNCTION;\r
+\r
#endif\r
\r
/*\r
* in the list of tasks waiting to be deleted. If so the task is cleaned up\r
* and its TCB deleted.\r
*/\r
-static void prvCheckTasksWaitingTermination( void );\r
+static void prvCheckTasksWaitingTermination( void ) PRIVILEGED_FUNCTION;\r
+\r
+/*\r
+ * The currently executing task is entering the Blocked state. Add the task to\r
+ * either the current or the overflow delayed task list.\r
+ */\r
+static void prvAddCurrentTaskToDelayedList( portTickType xTimeToWake ) PRIVILEGED_FUNCTION;\r
\r
/*\r
* Allocates memory from the heap for a TCB and associated stack. Checks the\r
* allocation was successful.\r
*/\r
-static tskTCB *prvAllocateTCBAndStack( unsigned portSHORT usStackDepth );\r
+static tskTCB *prvAllocateTCBAndStack( unsigned short usStackDepth, portSTACK_TYPE *puxStackBuffer ) PRIVILEGED_FUNCTION;\r
\r
/*\r
* Called from vTaskList. vListTasks details all the tasks currently under\r
*/\r
#if ( configUSE_TRACE_FACILITY == 1 )\r
\r
- static void prvListTaskWithinSingleList( signed portCHAR *pcWriteBuffer, xList *pxList, signed portCHAR cStatus );\r
+ static void prvListTaskWithinSingleList( const signed char *pcWriteBuffer, xList *pxList, signed char cStatus ) PRIVILEGED_FUNCTION;\r
\r
#endif\r
\r
* This function determines the 'high water mark' of the task stack by\r
* determining how much of the stack remains at the original preset value.\r
*/\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
\r
- unsigned portSHORT usTaskCheckFreeStackSpace( const unsigned portCHAR *pucStackByte );\r
+ static unsigned short usTaskCheckFreeStackSpace( const unsigned char * pucStackByte ) PRIVILEGED_FUNCTION;\r
\r
#endif\r
\r
-/*lint +e956 */\r
-\r
\r
+/*lint +e956 */\r
\r
\r
\r
* TASK CREATION API documented in task.h\r
*----------------------------------------------------------*/\r
\r
-signed portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, const signed portCHAR * const pcName, unsigned portSHORT usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pxCreatedTask )\r
+signed portBASE_TYPE xTaskGenericCreate( pdTASK_CODE pxTaskCode, const signed char * const pcName, unsigned short usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pxCreatedTask, portSTACK_TYPE *puxStackBuffer, const xMemoryRegion * const xRegions )\r
{\r
signed portBASE_TYPE xReturn;\r
tskTCB * pxNewTCB;\r
-static unsigned portBASE_TYPE uxTaskNumber = 0; /*lint !e956 Static is deliberate - this is guarded before use. */\r
\r
- /* Allocate the memory required by the TCB and stack for the new task.\r
+ configASSERT( pxTaskCode );\r
+ configASSERT( ( uxPriority < configMAX_PRIORITIES ) );\r
+\r
+ /* Allocate the memory required by the TCB and stack for the new task,\r
checking that the allocation was successful. */\r
- pxNewTCB = prvAllocateTCBAndStack( usStackDepth );\r
+ pxNewTCB = prvAllocateTCBAndStack( usStackDepth, puxStackBuffer );\r
\r
if( pxNewTCB != NULL )\r
- { \r
+ {\r
portSTACK_TYPE *pxTopOfStack;\r
\r
- /* Setup the newly allocated TCB with the initial state of the task. */\r
- prvInitialiseTCBVariables( pxNewTCB, usStackDepth, pcName, uxPriority );\r
+ #if( portUSING_MPU_WRAPPERS == 1 )\r
+ /* Should the task be created in privileged mode? */\r
+ portBASE_TYPE xRunPrivileged;\r
+ if( ( uxPriority & portPRIVILEGE_BIT ) != 0U )\r
+ {\r
+ xRunPrivileged = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ xRunPrivileged = pdFALSE;\r
+ }\r
+ uxPriority &= ~portPRIVILEGE_BIT;\r
+ #endif /* portUSING_MPU_WRAPPERS == 1 */\r
\r
/* Calculate the top of stack address. This depends on whether the\r
stack grows from high memory to low (as per the 80x86) or visa versa.\r
portSTACK_GROWTH is used to make the result positive or negative as\r
required by the port. */\r
- #if portSTACK_GROWTH < 0\r
+ #if( portSTACK_GROWTH < 0 )\r
{\r
- pxTopOfStack = pxNewTCB->pxStack + ( pxNewTCB->usStackDepth - 1 );\r
+ pxTopOfStack = pxNewTCB->pxStack + ( usStackDepth - ( unsigned short ) 1 );\r
+ pxTopOfStack = ( portSTACK_TYPE * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ( portPOINTER_SIZE_TYPE ) ~portBYTE_ALIGNMENT_MASK ) );\r
+\r
+ /* Check the alignment of the calculated top of stack is correct. */\r
+ configASSERT( ( ( ( unsigned long ) pxTopOfStack & ( unsigned long ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
}\r
#else\r
{\r
- pxTopOfStack = pxNewTCB->pxStack; \r
+ pxTopOfStack = pxNewTCB->pxStack;\r
+ \r
+ /* Check the alignment of the stack buffer is correct. */\r
+ configASSERT( ( ( ( unsigned long ) pxNewTCB->pxStack & ( unsigned long ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
+\r
+ /* If we want to use stack checking on architectures that use\r
+ a positive stack growth direction then we also need to store the\r
+ other extreme of the stack space. */\r
+ pxNewTCB->pxEndOfStack = pxNewTCB->pxStack + ( usStackDepth - 1 );\r
}\r
#endif\r
\r
+ /* Setup the newly allocated TCB with the initial state of the task. */\r
+ prvInitialiseTCBVariables( pxNewTCB, pcName, uxPriority, xRegions, usStackDepth );\r
+\r
/* Initialize the TCB stack to look as if the task was already running,\r
but had been interrupted by the scheduler. The return address is set\r
to the start of the task function. Once the stack has been initialised\r
the top of stack variable is updated. */\r
- pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pvTaskCode, pvParameters );\r
+ #if( portUSING_MPU_WRAPPERS == 1 )\r
+ {\r
+ pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters, xRunPrivileged );\r
+ }\r
+ #else\r
+ {\r
+ pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters );\r
+ }\r
+ #endif\r
\r
+ /* Check the alignment of the initialised stack. */\r
+ portALIGNMENT_ASSERT_pxCurrentTCB( ( ( ( unsigned long ) pxNewTCB->pxTopOfStack & ( unsigned long ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
+\r
+ if( ( void * ) pxCreatedTask != NULL )\r
+ {\r
+ /* Pass the TCB out - in an anonymous way. The calling function/\r
+ task can use this as a handle to delete the task later if\r
+ required.*/\r
+ *pxCreatedTask = ( xTaskHandle ) pxNewTCB;\r
+ }\r
+ \r
/* We are going to manipulate the task queues to add this task to a\r
ready list, so must make sure no interrupts occur. */\r
- portENTER_CRITICAL();\r
+ taskENTER_CRITICAL();\r
{\r
uxCurrentNumberOfTasks++;\r
- if( uxCurrentNumberOfTasks == ( unsigned portBASE_TYPE ) 1 )\r
+ if( pxCurrentTCB == NULL )\r
{\r
- /* As this is the first task it must also be the current task. */\r
+ /* There are no other tasks, or all the other tasks are in\r
+ the suspended state - make this the current task. */\r
pxCurrentTCB = pxNewTCB;\r
\r
- /* This is the first task to be created so do the preliminary\r
- initialisation required. We will not recover if this call\r
- fails, but we will report the failure. */\r
- prvInitialiseTaskLists();\r
+ if( uxCurrentNumberOfTasks == ( unsigned portBASE_TYPE ) 1 )\r
+ {\r
+ /* This is the first task to be created so do the preliminary\r
+ initialisation required. We will not recover if this call\r
+ fails, but we will report the failure. */\r
+ prvInitialiseTaskLists();\r
+ }\r
}\r
else\r
- { \r
+ {\r
/* If the scheduler is not already running, make this task the\r
current task if it is the highest priority task to be created\r
so far. */\r
{\r
if( pxCurrentTCB->uxPriority <= uxPriority )\r
{\r
- pxCurrentTCB = pxNewTCB; \r
+ pxCurrentTCB = pxNewTCB;\r
}\r
}\r
- } \r
+ }\r
\r
/* Remember the top priority to make context switching faster. Use\r
the priority in pxNewTCB as this has been capped to a valid value. */\r
uxTopUsedPriority = pxNewTCB->uxPriority;\r
}\r
\r
- /* Add a counter into the TCB for tracing only. */\r
- pxNewTCB->uxTCBNumber = uxTaskNumber;\r
- uxTaskNumber++;\r
+ #if ( configUSE_TRACE_FACILITY == 1 )\r
+ {\r
+ /* Add a counter into the TCB for tracing only. */\r
+ pxNewTCB->uxTCBNumber = uxTCBNumber;\r
+ }\r
+ #endif\r
+ uxTCBNumber++;\r
\r
prvAddTaskToReadyQueue( pxNewTCB );\r
\r
xReturn = pdPASS;\r
+ traceTASK_CREATE( pxNewTCB );\r
}\r
- portEXIT_CRITICAL();\r
+ taskEXIT_CRITICAL();\r
}\r
else\r
{\r
xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;\r
+ traceTASK_CREATE_FAILED();\r
}\r
\r
if( xReturn == pdPASS )\r
{\r
- if( ( void * ) pxCreatedTask != NULL )\r
- {\r
- /* Pass the TCB out - in an anonymous way. The calling function/\r
- task can use this as a handle to delete the task later if\r
- required.*/\r
- *pxCreatedTask = ( xTaskHandle ) pxNewTCB;\r
- }\r
-\r
if( xSchedulerRunning != pdFALSE )\r
{\r
/* If the created task is of a higher priority than the current task\r
then it should run now. */\r
if( pxCurrentTCB->uxPriority < uxPriority )\r
{\r
- taskYIELD();\r
+ portYIELD_WITHIN_API();\r
}\r
}\r
}\r
\r
taskENTER_CRITICAL();\r
{\r
- /* Ensure a yield is performed if the current task is being \r
+ /* Ensure a yield is performed if the current task is being\r
deleted. */\r
if( pxTaskToDelete == pxCurrentTCB )\r
{\r
scheduler for the TCB and stack. */\r
vListRemove( &( pxTCB->xGenericListItem ) );\r
\r
- /* Is the task waiting on an event also? */ \r
- if( pxTCB->xEventListItem.pvContainer )\r
+ /* Is the task waiting on an event also? */\r
+ if( pxTCB->xEventListItem.pvContainer != NULL )\r
{\r
vListRemove( &( pxTCB->xEventListItem ) );\r
}\r
there is a task that has been deleted and that it should therefore\r
check the xTasksWaitingTermination list. */\r
++uxTasksDeleted;\r
+\r
+ /* Increment the uxTaskNumberVariable also so kernel aware debuggers\r
+ can detect that the task lists need re-generating. */\r
+ uxTCBNumber++;\r
+\r
+ traceTASK_DELETE( pxTCB );\r
}\r
taskEXIT_CRITICAL();\r
\r
/* Force a reschedule if we have just deleted the current task. */\r
- if( xSchedulerRunning != pdFALSE ) \r
+ if( xSchedulerRunning != pdFALSE )\r
{\r
if( ( void * ) pxTaskToDelete == NULL )\r
{\r
- taskYIELD();\r
+ portYIELD_WITHIN_API();\r
}\r
}\r
}\r
\r
#if ( INCLUDE_vTaskDelayUntil == 1 )\r
\r
- void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement )\r
+ void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement )\r
{\r
portTickType xTimeToWake;\r
portBASE_TYPE xAlreadyYielded, xShouldDelay = pdFALSE;\r
\r
+ configASSERT( pxPreviousWakeTime );\r
+ configASSERT( ( xTimeIncrement > 0U ) );\r
+\r
vTaskSuspendAll();\r
{\r
/* Generate the tick time at which the task wants to wake. */\r
/* Update the wake time ready for the next call. */\r
*pxPreviousWakeTime = xTimeToWake;\r
\r
- if( xShouldDelay )\r
+ if( xShouldDelay != pdFALSE )\r
{\r
+ traceTASK_DELAY_UNTIL();\r
+\r
/* We must remove ourselves from the ready list before adding\r
ourselves to the blocked list as the same list item is used for\r
both lists. */\r
vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
-\r
- /* The list item will be inserted in wake time order. */\r
- listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xGenericListItem ), xTimeToWake );\r
-\r
- if( xTimeToWake < xTickCount )\r
- {\r
- /* Wake time has overflowed. Place this item in the\r
- overflow list. */\r
- vListInsert( ( xList * ) pxOverflowDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
- }\r
- else\r
- {\r
- /* The wake time has not overflowed, so we can use the\r
- current block list. */\r
- vListInsert( ( xList * ) pxDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
- }\r
+ prvAddCurrentTaskToDelayedList( xTimeToWake );\r
}\r
}\r
xAlreadyYielded = xTaskResumeAll();\r
\r
/* Force a reschedule if xTaskResumeAll has not already done so, we may\r
have put ourselves to sleep. */\r
- if( !xAlreadyYielded )\r
+ if( xAlreadyYielded == pdFALSE )\r
{\r
- taskYIELD();\r
+ portYIELD_WITHIN_API();\r
}\r
- } \r
- \r
+ }\r
+\r
#endif\r
/*-----------------------------------------------------------*/\r
\r
signed portBASE_TYPE xAlreadyYielded = pdFALSE;\r
\r
/* A delay time of zero just forces a reschedule. */\r
- if( xTicksToDelay > ( portTickType ) 0 )\r
+ if( xTicksToDelay > ( portTickType ) 0U )\r
{\r
vTaskSuspendAll();\r
{\r
+ traceTASK_DELAY();\r
+\r
/* A task that is removed from the event list while the\r
scheduler is suspended will not get placed in the ready\r
list or removed from the blocked list until the scheduler\r
is resumed.\r
- \r
+\r
This task cannot be in an event list as it is the currently\r
executing task. */\r
\r
ourselves to the blocked list as the same list item is used for\r
both lists. */\r
vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
-\r
- /* The list item will be inserted in wake time order. */\r
- listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xGenericListItem ), xTimeToWake );\r
-\r
- if( xTimeToWake < xTickCount )\r
- {\r
- /* Wake time has overflowed. Place this item in the\r
- overflow list. */\r
- vListInsert( ( xList * ) pxOverflowDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
- }\r
- else\r
- {\r
- /* The wake time has not overflowed, so we can use the\r
- current block list. */\r
- vListInsert( ( xList * ) pxDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
- }\r
+ prvAddCurrentTaskToDelayedList( xTimeToWake );\r
}\r
xAlreadyYielded = xTaskResumeAll();\r
}\r
- \r
+\r
/* Force a reschedule if xTaskResumeAll has not already done so, we may\r
have put ourselves to sleep. */\r
- if( !xAlreadyYielded )\r
+ if( xAlreadyYielded == pdFALSE )\r
{\r
- taskYIELD();\r
+ portYIELD_WITHIN_API();\r
}\r
}\r
- \r
+\r
#endif\r
/*-----------------------------------------------------------*/\r
\r
void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority )\r
{\r
tskTCB *pxTCB;\r
- unsigned portBASE_TYPE uxCurrentPriority, xYieldRequired = pdFALSE;\r
+ unsigned portBASE_TYPE uxCurrentPriority;\r
+ portBASE_TYPE xYieldRequired = pdFALSE;\r
+\r
+ configASSERT( ( uxNewPriority < configMAX_PRIORITIES ) );\r
\r
/* Ensure the new priority is valid. */\r
if( uxNewPriority >= configMAX_PRIORITIES )\r
{\r
- uxNewPriority = configMAX_PRIORITIES - 1;\r
+ uxNewPriority = configMAX_PRIORITIES - ( unsigned portBASE_TYPE ) 1U;\r
}\r
\r
taskENTER_CRITICAL();\r
{\r
+ if( pxTask == pxCurrentTCB )\r
+ {\r
+ pxTask = NULL;\r
+ }\r
+\r
/* If null is passed in here then we are changing the\r
priority of the calling function. */\r
pxTCB = prvGetTCBFromHandle( pxTask );\r
- uxCurrentPriority = pxTCB->uxPriority;\r
+\r
+ traceTASK_PRIORITY_SET( pxTCB, uxNewPriority );\r
+\r
+ #if ( configUSE_MUTEXES == 1 )\r
+ {\r
+ uxCurrentPriority = pxTCB->uxBasePriority;\r
+ }\r
+ #else\r
+ {\r
+ uxCurrentPriority = pxTCB->uxPriority;\r
+ }\r
+ #endif\r
\r
if( uxCurrentPriority != uxNewPriority )\r
{\r
/* The priority change may have readied a task of higher\r
priority than the calling task. */\r
- if( uxNewPriority > pxCurrentTCB->uxPriority ) \r
+ if( uxNewPriority > uxCurrentPriority )\r
{\r
if( pxTask != NULL )\r
{\r
task of higher priority that is ready to execute. */\r
xYieldRequired = pdTRUE;\r
}\r
- \r
- pxTCB->uxPriority = uxNewPriority;\r
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxNewPriority );\r
+\r
+\r
+\r
+ #if ( configUSE_MUTEXES == 1 )\r
+ {\r
+ /* Only change the priority being used if the task is not\r
+ currently using an inherited priority. */\r
+ if( pxTCB->uxBasePriority == pxTCB->uxPriority )\r
+ {\r
+ pxTCB->uxPriority = uxNewPriority;\r
+ }\r
+\r
+ /* The base priority gets set whatever. */\r
+ pxTCB->uxBasePriority = uxNewPriority;\r
+ }\r
+ #else\r
+ {\r
+ pxTCB->uxPriority = uxNewPriority;\r
+ }\r
+ #endif\r
+\r
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( configMAX_PRIORITIES - ( portTickType ) uxNewPriority ) );\r
\r
/* If the task is in the blocked or suspended list we need do\r
nothing more than change it's priority variable. However, if\r
can do this even if the scheduler is suspended. */\r
vListRemove( &( pxTCB->xGenericListItem ) );\r
prvAddTaskToReadyQueue( pxTCB );\r
- } \r
- \r
+ }\r
+\r
if( xYieldRequired == pdTRUE )\r
{\r
- taskYIELD();\r
- } \r
+ portYIELD_WITHIN_API();\r
+ }\r
}\r
}\r
taskEXIT_CRITICAL();\r
\r
taskENTER_CRITICAL();\r
{\r
- /* Ensure a yield is performed if the current task is being \r
+ /* Ensure a yield is performed if the current task is being\r
suspended. */\r
if( pxTaskToSuspend == pxCurrentTCB )\r
{\r
/* If null is passed in here then we are suspending ourselves. */\r
pxTCB = prvGetTCBFromHandle( pxTaskToSuspend );\r
\r
+ traceTASK_SUSPEND( pxTCB );\r
+\r
/* Remove task from the ready/delayed list and place in the suspended list. */\r
vListRemove( &( pxTCB->xGenericListItem ) );\r
\r
- /* Is the task waiting on an event also? */ \r
- if( pxTCB->xEventListItem.pvContainer )\r
+ /* Is the task waiting on an event also? */\r
+ if( pxTCB->xEventListItem.pvContainer != NULL )\r
{\r
vListRemove( &( pxTCB->xEventListItem ) );\r
}\r
}\r
taskEXIT_CRITICAL();\r
\r
- /* We may have just suspended the current task. */\r
if( ( void * ) pxTaskToSuspend == NULL )\r
{\r
- taskYIELD();\r
+ if( xSchedulerRunning != pdFALSE )\r
+ {\r
+ /* We have just suspended the current task. */\r
+ portYIELD_WITHIN_API();\r
+ }\r
+ else\r
+ {\r
+ /* The scheduler is not running, but the task that was pointed\r
+ to by pxCurrentTCB has just been suspended and pxCurrentTCB\r
+ must be adjusted to point to a different task. */\r
+ if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == uxCurrentNumberOfTasks )\r
+ {\r
+ /* No other tasks are ready, so set pxCurrentTCB back to\r
+ NULL so when the next task is created pxCurrentTCB will\r
+ be set to point to it no matter what its relative priority\r
+ is. */\r
+ pxCurrentTCB = NULL;\r
+ }\r
+ else\r
+ {\r
+ vTaskSwitchContext();\r
+ }\r
+ }\r
}\r
}\r
\r
\r
#if ( INCLUDE_vTaskSuspend == 1 )\r
\r
- void vTaskResume( xTaskHandle pxTaskToResume )\r
+ signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask )\r
{\r
- tskTCB *pxTCB;\r
+ portBASE_TYPE xReturn = pdFALSE;\r
+ const tskTCB * const pxTCB = ( tskTCB * ) xTask;\r
\r
- /* Remove the task from whichever list it is currently in, and place\r
- it in the ready list. */\r
- pxTCB = ( tskTCB * ) pxTaskToResume;\r
+ /* It does not make sense to check if the calling task is suspended. */\r
+ configASSERT( xTask );\r
\r
- /* The parameter cannot be NULL as it is impossible to resume the\r
- currently executing task. */\r
- if( pxTCB != NULL )\r
+ /* Is the task we are attempting to resume actually in the\r
+ suspended list? */\r
+ if( listIS_CONTAINED_WITHIN( &xSuspendedTaskList, &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
{\r
- taskENTER_CRITICAL();\r
+ /* Has the task already been resumed from within an ISR? */\r
+ if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) != pdTRUE )\r
{\r
- /* Is the task we are attempting to resume actually suspended? */\r
- if( listIS_CONTAINED_WITHIN( &xSuspendedTaskList, &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
+ /* Is it in the suspended list because it is in the\r
+ Suspended state? It is possible to be in the suspended\r
+ list because it is blocked on a task with no timeout\r
+ specified. */\r
+ if( listIS_CONTAINED_WITHIN( NULL, &( pxTCB->xEventListItem ) ) == pdTRUE )\r
{\r
- /* Has the task already been resumed from within an ISR? */\r
- if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) != pdTRUE )\r
- { \r
- /* As we are in a critical section we can access the ready \r
- lists even if the scheduler is suspended. */\r
- vListRemove( &( pxTCB->xGenericListItem ) );\r
- prvAddTaskToReadyQueue( pxTCB );\r
-\r
- /* We may have just resumed a higher priority task. */\r
- if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
- {\r
- /* This yield may not cause the task just resumed to run, but\r
- will leave the lists in the correct state for the next yield. */\r
- taskYIELD();\r
- }\r
- }\r
+ xReturn = pdTRUE;\r
}\r
}\r
- taskEXIT_CRITICAL();\r
}\r
+\r
+ return xReturn;\r
}\r
\r
#endif\r
-\r
/*-----------------------------------------------------------*/\r
\r
-#if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )\r
+#if ( INCLUDE_vTaskSuspend == 1 )\r
\r
- portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume )\r
+ void vTaskResume( xTaskHandle pxTaskToResume )\r
{\r
- portBASE_TYPE xYieldRequired = pdFALSE;\r
tskTCB *pxTCB;\r
\r
- pxTCB = ( tskTCB * ) pxTaskToResume;\r
+ /* It does not make sense to resume the calling task. */\r
+ configASSERT( pxTaskToResume );\r
\r
- /* Is the task we are attempting to resume actually suspended? */\r
- if( listIS_CONTAINED_WITHIN( &xSuspendedTaskList, &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
+ /* Remove the task from whichever list it is currently in, and place\r
+ it in the ready list. */\r
+ pxTCB = ( tskTCB * ) pxTaskToResume;\r
+\r
+ /* The parameter cannot be NULL as it is impossible to resume the\r
+ currently executing task. */\r
+ if( ( pxTCB != NULL ) && ( pxTCB != pxCurrentTCB ) )\r
{\r
- /* Has the task already been resumed from within an ISR? */\r
- if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) != pdTRUE )\r
+ taskENTER_CRITICAL();\r
+ {\r
+ if( xTaskIsTaskSuspended( pxTCB ) == pdTRUE )\r
+ {\r
+ traceTASK_RESUME( pxTCB );\r
+\r
+ /* As we are in a critical section we can access the ready\r
+ lists even if the scheduler is suspended. */\r
+ vListRemove( &( pxTCB->xGenericListItem ) );\r
+ prvAddTaskToReadyQueue( pxTCB );\r
+\r
+ /* We may have just resumed a higher priority task. */\r
+ if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
+ {\r
+ /* This yield may not cause the task just resumed to run, but\r
+ will leave the lists in the correct state for the next yield. */\r
+ portYIELD_WITHIN_API();\r
+ }\r
+ }\r
+ }\r
+ taskEXIT_CRITICAL();\r
+ }\r
+ }\r
+\r
+#endif\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )\r
+\r
+ portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume )\r
+ {\r
+ portBASE_TYPE xYieldRequired = pdFALSE;\r
+ tskTCB *pxTCB;\r
+ unsigned portBASE_TYPE uxSavedInterruptStatus;\r
+\r
+ configASSERT( pxTaskToResume );\r
+\r
+ pxTCB = ( tskTCB * ) pxTaskToResume;\r
+\r
+ uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+ {\r
+ if( xTaskIsTaskSuspended( pxTCB ) == pdTRUE )\r
{\r
+ traceTASK_RESUME_FROM_ISR( pxTCB );\r
+\r
if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
{\r
xYieldRequired = ( pxTCB->uxPriority >= pxCurrentTCB->uxPriority );\r
- vListRemove( &( pxTCB->xGenericListItem ) ); \r
+ vListRemove( &( pxTCB->xGenericListItem ) );\r
prvAddTaskToReadyQueue( pxTCB );\r
}\r
else\r
{\r
/* We cannot access the delayed or ready lists, so will hold this\r
- task pending until the scheduler is resumed, at which point a \r
- yield will be preformed if necessary. */\r
+ task pending until the scheduler is resumed, at which point a\r
+ yield will be performed if necessary. */\r
vListInsertEnd( ( xList * ) &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\r
}\r
}\r
}\r
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
\r
return xYieldRequired;\r
}\r
portBASE_TYPE xReturn;\r
\r
/* Add the idle task at the lowest priority. */\r
- xReturn = xTaskCreate( prvIdleTask, ( signed portCHAR * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL );\r
+ #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\r
+ {\r
+ /* Create the idle task, storing its handle in xIdleTaskHandle so it can\r
+ be returned by the xTaskGetIdleTaskHandle() function. */\r
+ xReturn = xTaskCreate( prvIdleTask, ( signed char * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), &xIdleTaskHandle );\r
+ }\r
+ #else\r
+ {\r
+ /* Create the idle task without storing its handle. */\r
+ xReturn = xTaskCreate( prvIdleTask, ( signed char * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), NULL );\r
+ }\r
+ #endif\r
+\r
+ #if ( configUSE_TIMERS == 1 )\r
+ {\r
+ if( xReturn == pdPASS )\r
+ {\r
+ xReturn = xTimerCreateTimerTask();\r
+ }\r
+ }\r
+ #endif\r
\r
if( xReturn == pdPASS )\r
{\r
the created tasks contain a status word with interrupts switched on\r
so interrupts will automatically get re-enabled when the first task\r
starts to run.\r
- \r
+\r
STEPPING THROUGH HERE USING A DEBUGGER CAN CAUSE BIG PROBLEMS IF THE\r
DEBUGGER ALLOWS INTERRUPTS TO BE PROCESSED. */\r
portDISABLE_INTERRUPTS();\r
\r
xSchedulerRunning = pdTRUE;\r
- xTickCount = ( portTickType ) 0;\r
+ xTickCount = ( portTickType ) 0U;\r
\r
+ /* If configGENERATE_RUN_TIME_STATS is defined then the following\r
+ macro must be defined to configure the timer/counter used to generate\r
+ the run time counter time base. */\r
+ portCONFIGURE_TIMER_FOR_RUN_TIME_STATS();\r
+ \r
/* Setting up the timer tick is hardware specific and thus in the\r
portable interface. */\r
- if( xPortStartScheduler() )\r
+ if( xPortStartScheduler() != pdFALSE )\r
{\r
/* Should not reach here as if the scheduler is running the\r
function will not return. */\r
/* Should only reach here if a task calls xTaskEndScheduler(). */\r
}\r
}\r
+\r
+ /* This line will only be reached if the kernel could not be started. */\r
+ configASSERT( xReturn );\r
}\r
/*-----------------------------------------------------------*/\r
\r
\r
void vTaskSuspendAll( void )\r
{\r
- portENTER_CRITICAL();\r
- ++uxSchedulerSuspended;\r
- portEXIT_CRITICAL();\r
+ /* A critical section is not required as the variable is of type\r
+ portBASE_TYPE. */\r
+ ++uxSchedulerSuspended;\r
}\r
/*----------------------------------------------------------*/\r
\r
register tskTCB *pxTCB;\r
signed portBASE_TYPE xAlreadyYielded = pdFALSE;\r
\r
+ /* If uxSchedulerSuspended is zero then this function does not match a\r
+ previous call to vTaskSuspendAll(). */\r
+ configASSERT( uxSchedulerSuspended );\r
+\r
/* It is possible that an ISR caused a task to be removed from an event\r
list while the scheduler was suspended. If this was the case then the\r
removed task will have been added to the xPendingReadyList. Once the\r
scheduler has been resumed it is safe to move all the pending ready\r
tasks from this list into their appropriate ready list. */\r
- portENTER_CRITICAL();\r
+ taskENTER_CRITICAL();\r
{\r
--uxSchedulerSuspended;\r
\r
if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
- { \r
- if( uxCurrentNumberOfTasks > ( unsigned portBASE_TYPE ) 0 )\r
+ {\r
+ if( uxCurrentNumberOfTasks > ( unsigned portBASE_TYPE ) 0U )\r
{\r
portBASE_TYPE xYieldRequired = pdFALSE;\r
- \r
+\r
/* Move any readied tasks from the pending list into the\r
appropriate ready list. */\r
- while( ( pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xPendingReadyList ) ) ) != NULL )\r
+ while( listLIST_IS_EMPTY( ( xList * ) &xPendingReadyList ) == pdFALSE )\r
{\r
+ pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xPendingReadyList ) );\r
vListRemove( &( pxTCB->xEventListItem ) );\r
vListRemove( &( pxTCB->xGenericListItem ) );\r
prvAddTaskToReadyQueue( pxTCB );\r
- \r
+\r
/* If we have moved a task that has a priority higher than\r
the current task then we should yield. */\r
if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
/* If any ticks occurred while the scheduler was suspended then\r
they should be processed now. This ensures the tick count does not\r
slip, and that any delayed tasks are resumed at the correct time. */\r
- if( uxMissedTicks > ( unsigned portBASE_TYPE ) 0 )\r
+ if( uxMissedTicks > ( unsigned portBASE_TYPE ) 0U )\r
{\r
- while( uxMissedTicks > ( unsigned portBASE_TYPE ) 0 )\r
+ while( uxMissedTicks > ( unsigned portBASE_TYPE ) 0U )\r
{\r
vTaskIncrementTick();\r
--uxMissedTicks;\r
/* As we have processed some ticks it is appropriate to yield\r
to ensure the highest priority task that is ready to run is\r
the task actually running. */\r
- xYieldRequired = pdTRUE;\r
+ #if configUSE_PREEMPTION == 1\r
+ {\r
+ xYieldRequired = pdTRUE;\r
+ }\r
+ #endif\r
}\r
- \r
+\r
if( ( xYieldRequired == pdTRUE ) || ( xMissedYield == pdTRUE ) )\r
{\r
xAlreadyYielded = pdTRUE;\r
xMissedYield = pdFALSE;\r
- taskYIELD();\r
+ portYIELD_WITHIN_API();\r
}\r
}\r
}\r
}\r
- portEXIT_CRITICAL();\r
+ taskEXIT_CRITICAL();\r
\r
return xAlreadyYielded;\r
}\r
}\r
/*-----------------------------------------------------------*/\r
\r
-unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )\r
+portTickType xTaskGetTickCountFromISR( void )\r
{\r
-unsigned portBASE_TYPE uxNumberOfTasks;\r
+portTickType xReturn;\r
+unsigned portBASE_TYPE uxSavedInterruptStatus;\r
\r
- taskENTER_CRITICAL();\r
- uxNumberOfTasks = uxCurrentNumberOfTasks;\r
- taskEXIT_CRITICAL();\r
+ uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+ xReturn = xTickCount;\r
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
\r
- return uxNumberOfTasks;\r
+ return xReturn;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_vTaskDelete == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )\r
+unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )\r
+{\r
+ /* A critical section is not required because the variables are of type\r
+ portBASE_TYPE. */\r
+ return uxCurrentNumberOfTasks;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( INCLUDE_pcTaskGetTaskName == 1 )\r
+\r
+ signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery )\r
+ {\r
+ tskTCB *pxTCB;\r
+\r
+ /* If null is passed in here then the name of the calling task is being queried. */\r
+ pxTCB = prvGetTCBFromHandle( xTaskToQuery );\r
+ configASSERT( pxTCB );\r
+ return &( pxTCB->pcTaskName[ 0 ] );\r
+ }\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_TRACE_FACILITY == 1 )\r
\r
- void vTaskList( signed portCHAR *pcWriteBuffer )\r
+ void vTaskList( signed char *pcWriteBuffer )\r
{\r
unsigned portBASE_TYPE uxQueue;\r
\r
/* This is a VERY costly function that should be used for debug only.\r
It leaves interrupts disabled for a LONG time. */\r
\r
- vTaskSuspendAll();\r
+ vTaskSuspendAll();\r
{\r
/* Run through all the lists that could potentially contain a TCB and\r
report the task name, state and stack high water mark. */\r
\r
- pcWriteBuffer[ 0 ] = ( signed portCHAR ) 0x00;\r
- strcat( ( portCHAR * ) pcWriteBuffer, ( const portCHAR * ) "\r\n" );\r
+ *pcWriteBuffer = ( signed char ) 0x00;\r
+ strcat( ( char * ) pcWriteBuffer, ( const char * ) "\r\n" );\r
\r
- uxQueue = uxTopUsedPriority + 1;\r
+ uxQueue = uxTopUsedPriority + ( unsigned portBASE_TYPE ) 1U;\r
\r
do\r
{\r
uxQueue--;\r
\r
- if( !listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxQueue ] ) ) )\r
+ if( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxQueue ] ) ) == pdFALSE )\r
{\r
- prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) &( pxReadyTasksLists[ uxQueue ] ), tskREADY_CHAR ); \r
+ prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) &( pxReadyTasksLists[ uxQueue ] ), tskREADY_CHAR );\r
}\r
- }while( uxQueue > ( unsigned portSHORT ) tskIDLE_PRIORITY );\r
+ }while( uxQueue > ( unsigned short ) tskIDLE_PRIORITY );\r
\r
- if( !listLIST_IS_EMPTY( pxDelayedTaskList ) )\r
+ if( listLIST_IS_EMPTY( pxDelayedTaskList ) == pdFALSE )\r
{\r
prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) pxDelayedTaskList, tskBLOCKED_CHAR );\r
}\r
\r
- if( !listLIST_IS_EMPTY( pxOverflowDelayedTaskList ) )\r
+ if( listLIST_IS_EMPTY( pxOverflowDelayedTaskList ) == pdFALSE )\r
{\r
prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) pxOverflowDelayedTaskList, tskBLOCKED_CHAR );\r
}\r
\r
- if( !listLIST_IS_EMPTY( &xTasksWaitingTermination ) )\r
+ #if( INCLUDE_vTaskDelete == 1 )\r
{\r
- prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) &xTasksWaitingTermination, tskDELETED_CHAR );\r
+ if( listLIST_IS_EMPTY( &xTasksWaitingTermination ) == pdFALSE )\r
+ {\r
+ prvListTaskWithinSingleList( pcWriteBuffer, &xTasksWaitingTermination, tskDELETED_CHAR );\r
+ }\r
}\r
+ #endif\r
\r
- if( !listLIST_IS_EMPTY( &xSuspendedTaskList ) )\r
+ #if ( INCLUDE_vTaskSuspend == 1 )\r
{\r
- prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) &xSuspendedTaskList, tskSUSPENDED_CHAR );\r
+ if( listLIST_IS_EMPTY( &xSuspendedTaskList ) == pdFALSE )\r
+ {\r
+ prvListTaskWithinSingleList( pcWriteBuffer, &xSuspendedTaskList, tskSUSPENDED_CHAR );\r
+ }\r
}\r
+ #endif\r
}\r
- xTaskResumeAll();\r
+ xTaskResumeAll();\r
}\r
\r
#endif\r
/*----------------------------------------------------------*/\r
\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
+#if ( configGENERATE_RUN_TIME_STATS == 1 )\r
\r
- void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize )\r
+ void vTaskGetRunTimeStats( signed char *pcWriteBuffer )\r
{\r
- portENTER_CRITICAL();\r
+ unsigned portBASE_TYPE uxQueue;\r
+ unsigned long ulTotalRunTime;\r
+\r
+ /* This is a VERY costly function that should be used for debug only.\r
+ It leaves interrupts disabled for a LONG time. */\r
+\r
+ vTaskSuspendAll();\r
{\r
- pcTraceBuffer = ( volatile signed portCHAR * volatile )pcBuffer;\r
- pcTraceBufferStart = pcBuffer;\r
- pcTraceBufferEnd = pcBuffer + ( ulBufferSize - tskSIZE_OF_EACH_TRACE_LINE );\r
- xTracing = pdTRUE;\r
- }\r
- portEXIT_CRITICAL();\r
- }\r
+ #ifdef portALT_GET_RUN_TIME_COUNTER_VALUE\r
+ portALT_GET_RUN_TIME_COUNTER_VALUE( ulTotalRunTime );\r
+ #else\r
+ ulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
+ #endif\r
+\r
+ /* Divide ulTotalRunTime by 100 to make the percentage caluclations\r
+ simpler in the prvGenerateRunTimeStatsForTasksInList() function. */\r
+ ulTotalRunTime /= 100UL;\r
+ \r
+ /* Run through all the lists that could potentially contain a TCB,\r
+ generating a table of run timer percentages in the provided\r
+ buffer. */\r
\r
-#endif\r
-/*----------------------------------------------------------*/\r
+ *pcWriteBuffer = ( signed char ) 0x00;\r
+ strcat( ( char * ) pcWriteBuffer, ( const char * ) "\r\n" );\r
\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
+ uxQueue = uxTopUsedPriority + ( unsigned portBASE_TYPE ) 1U;\r
\r
- unsigned portLONG ulTaskEndTrace( void )\r
- {\r
- unsigned portLONG ulBufferLength;\r
+ do\r
+ {\r
+ uxQueue--;\r
+\r
+ if( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxQueue ] ) ) == pdFALSE )\r
+ {\r
+ prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) &( pxReadyTasksLists[ uxQueue ] ), ulTotalRunTime );\r
+ }\r
+ }while( uxQueue > ( unsigned short ) tskIDLE_PRIORITY );\r
+\r
+ if( listLIST_IS_EMPTY( pxDelayedTaskList ) == pdFALSE )\r
+ {\r
+ prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) pxDelayedTaskList, ulTotalRunTime );\r
+ }\r
\r
- portENTER_CRITICAL();\r
- xTracing = pdFALSE;\r
- portEXIT_CRITICAL();\r
+ if( listLIST_IS_EMPTY( pxOverflowDelayedTaskList ) == pdFALSE )\r
+ {\r
+ prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) pxOverflowDelayedTaskList, ulTotalRunTime );\r
+ }\r
\r
- ulBufferLength = ( unsigned portLONG ) ( pcTraceBuffer - pcTraceBufferStart );\r
+ #if ( INCLUDE_vTaskDelete == 1 )\r
+ {\r
+ if( listLIST_IS_EMPTY( &xTasksWaitingTermination ) == pdFALSE )\r
+ {\r
+ prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, &xTasksWaitingTermination, ulTotalRunTime );\r
+ }\r
+ }\r
+ #endif\r
\r
- return ulBufferLength;\r
+ #if ( INCLUDE_vTaskSuspend == 1 )\r
+ {\r
+ if( listLIST_IS_EMPTY( &xSuspendedTaskList ) == pdFALSE )\r
+ {\r
+ prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, &xSuspendedTaskList, ulTotalRunTime );\r
+ }\r
+ }\r
+ #endif\r
+ }\r
+ xTaskResumeAll();\r
}\r
\r
#endif\r
+/*----------------------------------------------------------*/\r
\r
+#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\r
\r
+ xTaskHandle xTaskGetIdleTaskHandle( void )\r
+ {\r
+ /* If xTaskGetIdleTaskHandle() is called before the scheduler has been\r
+ started, then xIdleTaskHandle will be NULL. */\r
+ configASSERT( ( xIdleTaskHandle != NULL ) );\r
+ return xIdleTaskHandle;\r
+ }\r
+ \r
+#endif\r
\r
/*-----------------------------------------------------------\r
* SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES\r
* documented in task.h\r
*----------------------------------------------------------*/\r
\r
-\r
-inline void vTaskIncrementTick( void )\r
+void vTaskIncrementTick( void )\r
{\r
+tskTCB * pxTCB;\r
+\r
/* Called by the portable layer each time a tick interrupt occurs.\r
Increments the tick then checks to see if the new tick value will cause any\r
tasks to be unblocked. */\r
if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
{\r
++xTickCount;\r
- if( xTickCount == ( portTickType ) 0 )\r
+ if( xTickCount == ( portTickType ) 0U )\r
{\r
xList *pxTemp;\r
\r
- /* Tick count has overflowed so we need to swap the delay lists. \r
- If there are any items in pxDelayedTaskList here then there is \r
+ /* Tick count has overflowed so we need to swap the delay lists.\r
+ If there are any items in pxDelayedTaskList here then there is\r
an error! */\r
+ configASSERT( ( listLIST_IS_EMPTY( pxDelayedTaskList ) ) );\r
+ \r
pxTemp = pxDelayedTaskList;\r
pxDelayedTaskList = pxOverflowDelayedTaskList;\r
pxOverflowDelayedTaskList = pxTemp;\r
- xNumOfOverflows++;\r
+ xNumOfOverflows++;\r
+ \r
+ if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
+ {\r
+ /* The new current delayed list is empty. Set\r
+ xNextTaskUnblockTime to the maximum possible value so it is\r
+ extremely unlikely that the \r
+ if( xTickCount >= xNextTaskUnblockTime ) test will pass until\r
+ there is an item in the delayed list. */\r
+ xNextTaskUnblockTime = portMAX_DELAY;\r
+ }\r
+ else\r
+ {\r
+ /* The new current delayed list is not empty, get the value of\r
+ the item at the head of the delayed list. This is the time at\r
+ which the task at the head of the delayed list should be removed\r
+ from the Blocked state. */\r
+ pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
+ xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );\r
+ }\r
}\r
\r
/* See if this tick has made a timeout expire. */\r
{\r
++uxMissedTicks;\r
\r
- /* The tick hook gets called at regular intervals, even if the \r
+ /* The tick hook gets called at regular intervals, even if the\r
scheduler is locked. */\r
#if ( configUSE_TICK_HOOK == 1 )\r
{\r
- extern void vApplicationTickHook( void );\r
-\r
vApplicationTickHook();\r
}\r
#endif\r
\r
#if ( configUSE_TICK_HOOK == 1 )\r
{\r
- extern void vApplicationTickHook( void );\r
-\r
/* Guard against the tick hook being called when the missed tick\r
count is being unwound (when the scheduler is being unlocked. */\r
- if( uxMissedTicks == 0 )\r
+ if( uxMissedTicks == ( unsigned portBASE_TYPE ) 0U )\r
{\r
vApplicationTickHook();\r
}\r
}\r
#endif\r
+\r
+ traceTASK_INCREMENT_TICK( xTickCount );\r
}\r
/*-----------------------------------------------------------*/\r
\r
-#if ( ( INCLUDE_vTaskCleanUpResources == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )\r
+#if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
\r
- void vTaskCleanUpResources( void )\r
+ void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction )\r
{\r
- unsigned portSHORT usQueue;\r
- volatile tskTCB *pxTCB;\r
+ tskTCB *xTCB;\r
\r
- usQueue = ( unsigned portSHORT ) uxTopUsedPriority + ( unsigned portSHORT ) 1;\r
-\r
- /* Remove any TCB's from the ready queues. */\r
- do\r
+ /* If xTask is NULL then we are setting our own task hook. */\r
+ if( xTask == NULL )\r
{\r
- usQueue--;\r
+ xTCB = ( tskTCB * ) pxCurrentTCB;\r
+ }\r
+ else\r
+ {\r
+ xTCB = ( tskTCB * ) xTask;\r
+ }\r
\r
- while( !listLIST_IS_EMPTY( &( pxReadyTasksLists[ usQueue ] ) ) )\r
- {\r
- listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &( pxReadyTasksLists[ usQueue ] ) );\r
- vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );\r
+ /* Save the hook function in the TCB. A critical section is required as\r
+ the value can be accessed from an interrupt. */\r
+ taskENTER_CRITICAL();\r
+ xTCB->pxTaskTag = pxHookFunction;\r
+ taskEXIT_CRITICAL();\r
+ }\r
\r
- prvDeleteTCB( ( tskTCB * ) pxTCB );\r
- }\r
- }while( usQueue > ( unsigned portSHORT ) tskIDLE_PRIORITY );\r
+#endif\r
+/*-----------------------------------------------------------*/\r
\r
- /* Remove any TCB's from the delayed queue. */\r
- while( !listLIST_IS_EMPTY( &xDelayedTaskList1 ) )\r
- {\r
- listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &xDelayedTaskList1 );\r
- vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );\r
+#if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
\r
- prvDeleteTCB( ( tskTCB * ) pxTCB );\r
- }\r
+ pdTASK_HOOK_CODE xTaskGetApplicationTaskTag( xTaskHandle xTask )\r
+ {\r
+ tskTCB *xTCB;\r
+ pdTASK_HOOK_CODE xReturn;\r
\r
- /* Remove any TCB's from the overflow delayed queue. */\r
- while( !listLIST_IS_EMPTY( &xDelayedTaskList2 ) )\r
+ /* If xTask is NULL then we are setting our own task hook. */\r
+ if( xTask == NULL )\r
{\r
- listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &xDelayedTaskList2 );\r
- vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );\r
-\r
- prvDeleteTCB( ( tskTCB * ) pxTCB );\r
+ xTCB = ( tskTCB * ) pxCurrentTCB;\r
}\r
-\r
- while( !listLIST_IS_EMPTY( &xSuspendedTaskList ) )\r
+ else\r
{\r
- listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &xSuspendedTaskList );\r
- vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );\r
+ xTCB = ( tskTCB * ) xTask;\r
+ }\r
\r
- prvDeleteTCB( ( tskTCB * ) pxTCB );\r
- } \r
+ /* Save the hook function in the TCB. A critical section is required as\r
+ the value can be accessed from an interrupt. */\r
+ taskENTER_CRITICAL();\r
+ xReturn = xTCB->pxTaskTag;\r
+ taskEXIT_CRITICAL();\r
\r
- while( !listLIST_IS_EMPTY( &xPendingReadyList ) )\r
+ return xReturn;\r
+ }\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
+\r
+ portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter )\r
+ {\r
+ tskTCB *xTCB;\r
+ portBASE_TYPE xReturn;\r
+\r
+ /* If xTask is NULL then we are calling our own task hook. */\r
+ if( xTask == NULL )\r
+ {\r
+ xTCB = ( tskTCB * ) pxCurrentTCB;\r
+ }\r
+ else\r
+ {\r
+ xTCB = ( tskTCB * ) xTask;\r
+ }\r
+\r
+ if( xTCB->pxTaskTag != NULL )\r
+ {\r
+ xReturn = xTCB->pxTaskTag( pvParameter );\r
+ }\r
+ else\r
{\r
- listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &xPendingReadyList );\r
- vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );\r
+ xReturn = pdFAIL;\r
+ }\r
\r
- prvDeleteTCB( ( tskTCB * ) pxTCB );\r
- } \r
+ return xReturn;\r
}\r
\r
#endif\r
/* The scheduler is currently suspended - do not allow a context\r
switch. */\r
xMissedYield = pdTRUE;\r
- return;\r
}\r
-\r
- /* Find the highest priority queue that contains ready tasks. */\r
- while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopReadyPriority ] ) ) )\r
+ else\r
{\r
- --uxTopReadyPriority;\r
+ traceTASK_SWITCHED_OUT();\r
+ \r
+ #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
+ {\r
+ unsigned long ulTempCounter;\r
+ \r
+ #ifdef portALT_GET_RUN_TIME_COUNTER_VALUE\r
+ portALT_GET_RUN_TIME_COUNTER_VALUE( ulTempCounter );\r
+ #else\r
+ ulTempCounter = portGET_RUN_TIME_COUNTER_VALUE();\r
+ #endif\r
+ \r
+ /* Add the amount of time the task has been running to the accumulated\r
+ time so far. The time the task started running was stored in\r
+ ulTaskSwitchedInTime. Note that there is no overflow protection here\r
+ so count values are only valid until the timer overflows. Generally\r
+ this will be about 1 hour assuming a 1uS timer increment. */\r
+ pxCurrentTCB->ulRunTimeCounter += ( ulTempCounter - ulTaskSwitchedInTime );\r
+ ulTaskSwitchedInTime = ulTempCounter;\r
+ }\r
+ #endif\r
+ \r
+ taskFIRST_CHECK_FOR_STACK_OVERFLOW();\r
+ taskSECOND_CHECK_FOR_STACK_OVERFLOW();\r
+ \r
+ /* Find the highest priority queue that contains ready tasks. */\r
+ while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopReadyPriority ] ) ) )\r
+ {\r
+ configASSERT( uxTopReadyPriority );\r
+ --uxTopReadyPriority;\r
+ }\r
+ \r
+ /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the tasks of the\r
+ same priority get an equal share of the processor time. */\r
+ listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) );\r
+ \r
+ traceTASK_SWITCHED_IN();\r
}\r
-\r
- /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the tasks of the\r
- same priority get an equal share of the processor time. */\r
- listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) );\r
- vWriteTraceToBuffer();\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vTaskPlaceOnEventList( xList *pxEventList, portTickType xTicksToWait )\r
+void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait )\r
{\r
portTickType xTimeToWake;\r
\r
+ configASSERT( pxEventList );\r
+\r
/* THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED OR THE\r
SCHEDULER SUSPENDED. */\r
\r
exclusive access to the ready lists as the scheduler is locked. */\r
vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
\r
- if( xTicksToWait == portMAX_DELAY )\r
- {\r
- /* Add ourselves to the suspended task list instead of a delayed task\r
- list to ensure we are not woken by a timing event. We will block\r
- indefinitely. */\r
- vListInsertEnd( ( xList * ) &xSuspendedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
- }\r
- else\r
+\r
+ #if ( INCLUDE_vTaskSuspend == 1 )\r
{\r
- /* Calculate the time at which the task should be woken if the event does\r
- not occur. This may overflow but this doesn't matter. */\r
- xTimeToWake = xTickCount + xTicksToWait;\r
- \r
- listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xGenericListItem ), xTimeToWake );\r
- \r
- if( xTimeToWake < xTickCount )\r
+ if( xTicksToWait == portMAX_DELAY )\r
{\r
- /* Wake time has overflowed. Place this item in the overflow list. */\r
- vListInsert( ( xList * ) pxOverflowDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
+ /* Add ourselves to the suspended task list instead of a delayed task\r
+ list to ensure we are not woken by a timing event. We will block\r
+ indefinitely. */\r
+ vListInsertEnd( ( xList * ) &xSuspendedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
}\r
else\r
{\r
- /* The wake time has not overflowed, so we can use the current block list. */\r
- vListInsert( ( xList * ) pxDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
+ /* Calculate the time at which the task should be woken if the event does\r
+ not occur. This may overflow but this doesn't matter. */\r
+ xTimeToWake = xTickCount + xTicksToWait;\r
+ prvAddCurrentTaskToDelayedList( xTimeToWake );\r
}\r
}\r
+ #else\r
+ {\r
+ /* Calculate the time at which the task should be woken if the event does\r
+ not occur. This may overflow but this doesn't matter. */\r
+ xTimeToWake = xTickCount + xTicksToWait;\r
+ prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+ }\r
+ #endif\r
}\r
/*-----------------------------------------------------------*/\r
\r
-signed portBASE_TYPE xTaskRemoveFromEventList( const xList *pxEventList )\r
+#if configUSE_TIMERS == 1\r
+\r
+ void vTaskPlaceOnEventListRestricted( const xList * const pxEventList, portTickType xTicksToWait )\r
+ {\r
+ portTickType xTimeToWake;\r
+\r
+ configASSERT( pxEventList );\r
+\r
+ /* This function should not be called by application code hence the\r
+ 'Restricted' in its name. It is not part of the public API. It is\r
+ designed for use by kernel code, and has special calling requirements -\r
+ it should be called from a critical section. */\r
+\r
+ \r
+ /* Place the event list item of the TCB in the appropriate event list.\r
+ In this case it is assume that this is the only task that is going to\r
+ be waiting on this event list, so the faster vListInsertEnd() function\r
+ can be used in place of vListInsert. */\r
+ vListInsertEnd( ( xList * ) pxEventList, ( xListItem * ) &( pxCurrentTCB->xEventListItem ) );\r
+\r
+ /* We must remove this task from the ready list before adding it to the\r
+ blocked list as the same list item is used for both lists. This\r
+ function is called form a critical section. */\r
+ vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
+\r
+ /* Calculate the time at which the task should be woken if the event does\r
+ not occur. This may overflow but this doesn't matter. */\r
+ xTimeToWake = xTickCount + xTicksToWait;\r
+ prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+ }\r
+ \r
+#endif /* configUSE_TIMERS */\r
+/*-----------------------------------------------------------*/\r
+\r
+signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList )\r
{\r
tskTCB *pxUnblockedTCB;\r
portBASE_TYPE xReturn;\r
/* The event list is sorted in priority order, so we can remove the\r
first in the list, remove the TCB from the delayed list, and add\r
it to the ready list.\r
- \r
+\r
If an event is for a queue that is locked then this function will never\r
get called - the lock count on the queue will get modified instead. This\r
- means we can always expect exclusive access to the event list here. */\r
+ means we can always expect exclusive access to the event list here.\r
+ \r
+ This function assumes that a check has already been made to ensure that\r
+ pxEventList is not empty. */\r
pxUnblockedTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );\r
+ configASSERT( pxUnblockedTCB );\r
vListRemove( &( pxUnblockedTCB->xEventListItem ) );\r
\r
if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vTaskSetTimeOutState( xTimeOutType *pxTimeOut )\r
+void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut )\r
{\r
- pxTimeOut->xOverflowCount = xNumOfOverflows;\r
- pxTimeOut->xTimeOnEntering = xTickCount;\r
+ configASSERT( pxTimeOut );\r
+ pxTimeOut->xOverflowCount = xNumOfOverflows;\r
+ pxTimeOut->xTimeOnEntering = xTickCount;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType *pxTimeOut, portTickType *pxTicksToWait )\r
+portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait )\r
{\r
portBASE_TYPE xReturn;\r
\r
- if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( xTickCount > pxTimeOut->xTimeOnEntering ) )\r
- {\r
- /* The tick count is greater than the time at which vTaskSetTimeout() \r
- was called, but has also overflowed since vTaskSetTimeOut() was called.\r
- It must have wrapped all the way around and gone past us again. This\r
- passed since vTaskSetTimeout() was called. */\r
- xReturn = pdTRUE;\r
- }\r
- else if( ( xTickCount - pxTimeOut->xTimeOnEntering ) < *pxTicksToWait )\r
- {\r
- /* Not a genuine timeout. Adjust parameters for time remaining. */\r
- *pxTicksToWait -= ( xTickCount - pxTimeOut->xTimeOnEntering );\r
- vTaskSetTimeOutState( pxTimeOut );\r
- xReturn = pdFALSE;\r
- }\r
- else\r
- {\r
- xReturn = pdTRUE;\r
- }\r
-\r
- return xReturn;\r
+ configASSERT( pxTimeOut );\r
+ configASSERT( pxTicksToWait );\r
+\r
+ taskENTER_CRITICAL();\r
+ {\r
+ #if ( INCLUDE_vTaskSuspend == 1 )\r
+ /* If INCLUDE_vTaskSuspend is set to 1 and the block time specified is\r
+ the maximum block time then the task should block indefinitely, and\r
+ therefore never time out. */\r
+ if( *pxTicksToWait == portMAX_DELAY )\r
+ {\r
+ xReturn = pdFALSE;\r
+ }\r
+ else /* We are not blocking indefinitely, perform the checks below. */\r
+ #endif\r
+\r
+ if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( ( portTickType ) xTickCount >= ( portTickType ) pxTimeOut->xTimeOnEntering ) )\r
+ {\r
+ /* The tick count is greater than the time at which vTaskSetTimeout()\r
+ was called, but has also overflowed since vTaskSetTimeOut() was called.\r
+ It must have wrapped all the way around and gone past us again. This\r
+ passed since vTaskSetTimeout() was called. */\r
+ xReturn = pdTRUE;\r
+ }\r
+ else if( ( ( portTickType ) ( ( portTickType ) xTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering ) ) < ( portTickType ) *pxTicksToWait )\r
+ {\r
+ /* Not a genuine timeout. Adjust parameters for time remaining. */\r
+ *pxTicksToWait -= ( ( portTickType ) xTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering );\r
+ vTaskSetTimeOutState( pxTimeOut );\r
+ xReturn = pdFALSE;\r
+ }\r
+ else\r
+ {\r
+ xReturn = pdTRUE;\r
+ }\r
+ }\r
+ taskEXIT_CRITICAL();\r
+\r
+ return xReturn;\r
}\r
/*-----------------------------------------------------------*/\r
\r
{\r
xMissedYield = pdTRUE;\r
}\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_TRACE_FACILITY == 1 )\r
+ unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask )\r
+ {\r
+ unsigned portBASE_TYPE uxReturn;\r
+ tskTCB *pxTCB;\r
+ \r
+ if( xTask != NULL )\r
+ {\r
+ pxTCB = ( tskTCB * ) xTask;\r
+ uxReturn = pxTCB->uxTaskNumber;\r
+ }\r
+ else\r
+ {\r
+ uxReturn = 0U;\r
+ }\r
+ \r
+ return uxReturn;\r
+ }\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_TRACE_FACILITY == 1 )\r
+ void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle )\r
+ {\r
+ tskTCB *pxTCB;\r
+ \r
+ if( xTask != NULL )\r
+ {\r
+ pxTCB = ( tskTCB * ) xTask;\r
+ pxTCB->uxTaskNumber = uxHandle;\r
+ }\r
+ }\r
+#endif\r
+\r
\r
/*\r
* -----------------------------------------------------------\r
see if any other task has become available. If we are using\r
preemption we don't need to do this as any task becoming available\r
will automatically get the processor anyway. */\r
- taskYIELD(); \r
+ taskYIELD();\r
}\r
#endif\r
\r
timesliced. If a task that is sharing the idle priority is ready\r
to run then the idle task should yield before the end of the\r
timeslice.\r
- \r
+\r
A critical region is not required here as we are just reading from\r
the list, and an occasional incorrect value will not matter. If\r
the ready list at the idle priority contains more than one task\r
\r
\r
\r
-static void prvInitialiseTCBVariables( tskTCB *pxTCB, unsigned portSHORT usStackDepth, const signed portCHAR * const pcName, unsigned portBASE_TYPE uxPriority )\r
+static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed char * const pcName, unsigned portBASE_TYPE uxPriority, const xMemoryRegion * const xRegions, unsigned short usStackDepth )\r
{\r
- pxTCB->usStackDepth = usStackDepth;\r
-\r
/* Store the function name in the TCB. */\r
- strncpy( ( char * ) pxTCB->pcTaskName, ( const char * ) pcName, ( unsigned portSHORT ) configMAX_TASK_NAME_LEN );\r
- pxTCB->pcTaskName[ ( unsigned portSHORT ) configMAX_TASK_NAME_LEN - ( unsigned portSHORT ) 1 ] = '\0';\r
+ #if configMAX_TASK_NAME_LEN > 1\r
+ {\r
+ /* Don't bring strncpy into the build unnecessarily. */\r
+ strncpy( ( char * ) pxTCB->pcTaskName, ( const char * ) pcName, ( unsigned short ) configMAX_TASK_NAME_LEN );\r
+ }\r
+ #endif\r
+ pxTCB->pcTaskName[ ( unsigned short ) configMAX_TASK_NAME_LEN - ( unsigned short ) 1 ] = ( signed char ) '\0';\r
\r
- /* This is used as an array index so must ensure it's not too large. */\r
+ /* This is used as an array index so must ensure it's not too large. First\r
+ remove the privilege bit if one is present. */\r
if( uxPriority >= configMAX_PRIORITIES )\r
{\r
- uxPriority = configMAX_PRIORITIES - 1;\r
+ uxPriority = configMAX_PRIORITIES - ( unsigned portBASE_TYPE ) 1U;\r
}\r
\r
pxTCB->uxPriority = uxPriority;\r
+ #if ( configUSE_MUTEXES == 1 )\r
+ {\r
+ pxTCB->uxBasePriority = uxPriority;\r
+ }\r
+ #endif\r
\r
vListInitialiseItem( &( pxTCB->xGenericListItem ) );\r
vListInitialiseItem( &( pxTCB->xEventListItem ) );\r
/* Event lists are always in priority order. */\r
listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority );\r
listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );\r
+\r
+ #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
+ {\r
+ pxTCB->uxCriticalNesting = ( unsigned portBASE_TYPE ) 0U;\r
+ }\r
+ #endif\r
+\r
+ #if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
+ {\r
+ pxTCB->pxTaskTag = NULL;\r
+ }\r
+ #endif\r
+\r
+ #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
+ {\r
+ pxTCB->ulRunTimeCounter = 0UL;\r
+ }\r
+ #endif\r
+\r
+ #if ( portUSING_MPU_WRAPPERS == 1 )\r
+ {\r
+ vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), xRegions, pxTCB->pxStack, usStackDepth );\r
+ }\r
+ #else\r
+ {\r
+ ( void ) xRegions;\r
+ ( void ) usStackDepth;\r
+ }\r
+ #endif\r
}\r
/*-----------------------------------------------------------*/\r
\r
+#if ( portUSING_MPU_WRAPPERS == 1 )\r
+\r
+ void vTaskAllocateMPURegions( xTaskHandle xTaskToModify, const xMemoryRegion * const xRegions )\r
+ {\r
+ tskTCB *pxTCB;\r
+ \r
+ if( xTaskToModify == pxCurrentTCB )\r
+ {\r
+ xTaskToModify = NULL;\r
+ }\r
+\r
+ /* If null is passed in here then we are deleting ourselves. */\r
+ pxTCB = prvGetTCBFromHandle( xTaskToModify );\r
+\r
+ vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), xRegions, NULL, 0 );\r
+ }\r
+ /*-----------------------------------------------------------*/\r
+#endif\r
+\r
static void prvInitialiseTaskLists( void )\r
{\r
unsigned portBASE_TYPE uxPriority;\r
\r
- for( uxPriority = 0; uxPriority < configMAX_PRIORITIES; uxPriority++ )\r
+ for( uxPriority = ( unsigned portBASE_TYPE ) 0U; uxPriority < configMAX_PRIORITIES; uxPriority++ )\r
{\r
vListInitialise( ( xList * ) &( pxReadyTasksLists[ uxPriority ] ) );\r
}\r
/*-----------------------------------------------------------*/\r
\r
static void prvCheckTasksWaitingTermination( void )\r
-{ \r
+{\r
#if ( INCLUDE_vTaskDelete == 1 )\r
- { \r
+ {\r
portBASE_TYPE xListIsEmpty;\r
\r
/* ucTasksDeleted is used to prevent vTaskSuspendAll() being called\r
too often in the idle task. */\r
- if( uxTasksDeleted > ( unsigned portBASE_TYPE ) 0 )\r
+ if( uxTasksDeleted > ( unsigned portBASE_TYPE ) 0U )\r
{\r
vTaskSuspendAll();\r
- xListIsEmpty = listLIST_IS_EMPTY( &xTasksWaitingTermination ); \r
+ xListIsEmpty = listLIST_IS_EMPTY( &xTasksWaitingTermination );\r
xTaskResumeAll();\r
\r
- if( !xListIsEmpty )\r
+ if( xListIsEmpty == pdFALSE )\r
{\r
tskTCB *pxTCB;\r
\r
- portENTER_CRITICAL();\r
- { \r
+ taskENTER_CRITICAL();\r
+ {\r
pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xTasksWaitingTermination ) );\r
vListRemove( &( pxTCB->xGenericListItem ) );\r
--uxCurrentNumberOfTasks;\r
--uxTasksDeleted;\r
}\r
- portEXIT_CRITICAL();\r
+ taskEXIT_CRITICAL();\r
\r
prvDeleteTCB( pxTCB );\r
}\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static tskTCB *prvAllocateTCBAndStack( unsigned portSHORT usStackDepth )\r
+static void prvAddCurrentTaskToDelayedList( portTickType xTimeToWake )\r
+{\r
+ /* The list item will be inserted in wake time order. */\r
+ listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xGenericListItem ), xTimeToWake );\r
+\r
+ if( xTimeToWake < xTickCount )\r
+ {\r
+ /* Wake time has overflowed. Place this item in the overflow list. */\r
+ vListInsert( ( xList * ) pxOverflowDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
+ }\r
+ else\r
+ {\r
+ /* The wake time has not overflowed, so we can use the current block list. */\r
+ vListInsert( ( xList * ) pxDelayedTaskList, ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
+\r
+ /* If the task entering the blocked state was placed at the head of the\r
+ list of blocked tasks then xNextTaskUnblockTime needs to be updated\r
+ too. */\r
+ if( xTimeToWake < xNextTaskUnblockTime )\r
+ {\r
+ xNextTaskUnblockTime = xTimeToWake;\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static tskTCB *prvAllocateTCBAndStack( unsigned short usStackDepth, portSTACK_TYPE *puxStackBuffer )\r
{\r
tskTCB *pxNewTCB;\r
\r
/* Allocate space for the stack used by the task being created.\r
The base of the stack memory stored in the TCB so the task can\r
be deleted later if required. */\r
- pxNewTCB->pxStack = ( portSTACK_TYPE * ) pvPortMalloc( ( ( size_t )usStackDepth ) * sizeof( portSTACK_TYPE ) );\r
+ pxNewTCB->pxStack = ( portSTACK_TYPE * ) pvPortMallocAligned( ( ( ( size_t )usStackDepth ) * sizeof( portSTACK_TYPE ) ), puxStackBuffer );\r
\r
if( pxNewTCB->pxStack == NULL )\r
{\r
/* Could not allocate the stack. Delete the allocated TCB. */\r
- vPortFree( pxNewTCB ); \r
- pxNewTCB = NULL; \r
- } \r
+ vPortFree( pxNewTCB );\r
+ pxNewTCB = NULL;\r
+ }\r
else\r
{\r
/* Just to help debugging. */\r
- memset( pxNewTCB->pxStack, tskSTACK_FILL_BYTE, usStackDepth * sizeof( portSTACK_TYPE ) );\r
+ memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) usStackDepth * sizeof( portSTACK_TYPE ) );\r
}\r
}\r
\r
\r
#if ( configUSE_TRACE_FACILITY == 1 )\r
\r
- static void prvListTaskWithinSingleList( signed portCHAR *pcWriteBuffer, xList *pxList, signed portCHAR cStatus )\r
+ static void prvListTaskWithinSingleList( const signed char *pcWriteBuffer, xList *pxList, signed char cStatus )\r
{\r
volatile tskTCB *pxNextTCB, *pxFirstTCB;\r
- static portCHAR pcStatusString[ 50 ];\r
- unsigned portSHORT usStackRemaining;\r
+ unsigned short usStackRemaining;\r
+ PRIVILEGED_DATA static char pcStatusString[ 50 ];\r
\r
/* Write the details of all the TCB's in pxList into the buffer. */\r
listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );\r
do\r
{\r
listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );\r
- usStackRemaining = usTaskCheckFreeStackSpace( ( unsigned portCHAR * ) pxNextTCB->pxStack );\r
- 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
- strcat( ( portCHAR * ) pcWriteBuffer, ( portCHAR * ) pcStatusString );\r
+ #if ( portSTACK_GROWTH > 0 )\r
+ {\r
+ usStackRemaining = usTaskCheckFreeStackSpace( ( unsigned char * ) pxNextTCB->pxEndOfStack );\r
+ }\r
+ #else\r
+ {\r
+ usStackRemaining = usTaskCheckFreeStackSpace( ( unsigned char * ) pxNextTCB->pxStack );\r
+ }\r
+ #endif \r
+ \r
+ sprintf( pcStatusString, ( char * ) "%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
+ strcat( ( char * ) pcWriteBuffer, ( char * ) pcStatusString );\r
\r
} while( pxNextTCB != pxFirstTCB );\r
}\r
#endif\r
/*-----------------------------------------------------------*/\r
\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
- unsigned portSHORT usTaskCheckFreeStackSpace( const unsigned portCHAR *pucStackByte )\r
+#if ( configGENERATE_RUN_TIME_STATS == 1 )\r
+\r
+ static void prvGenerateRunTimeStatsForTasksInList( const signed char *pcWriteBuffer, xList *pxList, unsigned long ulTotalRunTime )\r
+ {\r
+ volatile tskTCB *pxNextTCB, *pxFirstTCB;\r
+ unsigned long ulStatsAsPercentage;\r
+\r
+ /* Write the run time stats of all the TCB's in pxList into the buffer. */\r
+ listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );\r
+ do\r
+ {\r
+ /* Get next TCB in from the list. */\r
+ listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );\r
+\r
+ /* Divide by zero check. */\r
+ if( ulTotalRunTime > 0UL )\r
+ {\r
+ /* Has the task run at all? */\r
+ if( pxNextTCB->ulRunTimeCounter == 0UL )\r
+ {\r
+ /* The task has used no CPU time at all. */\r
+ sprintf( pcStatsString, ( char * ) "%s\t\t0\t\t0%%\r\n", pxNextTCB->pcTaskName );\r
+ }\r
+ else\r
+ {\r
+ /* What percentage of the total run time has the task used?\r
+ This will always be rounded down to the nearest integer.\r
+ ulTotalRunTime has already been divided by 100. */\r
+ ulStatsAsPercentage = pxNextTCB->ulRunTimeCounter / ulTotalRunTime;\r
+\r
+ if( ulStatsAsPercentage > 0UL )\r
+ {\r
+ #ifdef portLU_PRINTF_SPECIFIER_REQUIRED\r
+ {\r
+ sprintf( pcStatsString, ( char * ) "%s\t\t%lu\t\t%lu%%\r\n", pxNextTCB->pcTaskName, pxNextTCB->ulRunTimeCounter, ulStatsAsPercentage ); \r
+ }\r
+ #else\r
+ {\r
+ /* sizeof( int ) == sizeof( long ) so a smaller\r
+ printf() library can be used. */\r
+ sprintf( pcStatsString, ( char * ) "%s\t\t%u\t\t%u%%\r\n", pxNextTCB->pcTaskName, ( unsigned int ) pxNextTCB->ulRunTimeCounter, ( unsigned int ) ulStatsAsPercentage );\r
+ }\r
+ #endif\r
+ }\r
+ else\r
+ {\r
+ /* If the percentage is zero here then the task has\r
+ consumed less than 1% of the total run time. */\r
+ #ifdef portLU_PRINTF_SPECIFIER_REQUIRED\r
+ {\r
+ sprintf( pcStatsString, ( char * ) "%s\t\t%lu\t\t<1%%\r\n", pxNextTCB->pcTaskName, pxNextTCB->ulRunTimeCounter ); \r
+ }\r
+ #else\r
+ {\r
+ /* sizeof( int ) == sizeof( long ) so a smaller\r
+ printf() library can be used. */\r
+ sprintf( pcStatsString, ( char * ) "%s\t\t%u\t\t<1%%\r\n", pxNextTCB->pcTaskName, ( unsigned int ) pxNextTCB->ulRunTimeCounter );\r
+ }\r
+ #endif\r
+ }\r
+ }\r
+\r
+ strcat( ( char * ) pcWriteBuffer, ( char * ) pcStatsString );\r
+ }\r
+\r
+ } while( pxNextTCB != pxFirstTCB );\r
+ }\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
+\r
+ static unsigned short usTaskCheckFreeStackSpace( const unsigned char * pucStackByte )\r
{\r
- register unsigned portSHORT usCount = 0;\r
+ register unsigned short usCount = 0U;\r
\r
while( *pucStackByte == tskSTACK_FILL_BYTE )\r
{\r
\r
return usCount;\r
}\r
+\r
#endif\r
/*-----------------------------------------------------------*/\r
\r
+#if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )\r
\r
+ unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask )\r
+ {\r
+ tskTCB *pxTCB;\r
+ unsigned char *pcEndOfStack;\r
+ unsigned portBASE_TYPE uxReturn;\r
\r
-#if ( ( INCLUDE_vTaskDelete == 1 ) || ( INCLUDE_vTaskCleanUpResources == 1 ) )\r
+ pxTCB = prvGetTCBFromHandle( xTask );\r
+\r
+ #if portSTACK_GROWTH < 0\r
+ {\r
+ pcEndOfStack = ( unsigned char * ) pxTCB->pxStack;\r
+ }\r
+ #else\r
+ {\r
+ pcEndOfStack = ( unsigned char * ) pxTCB->pxEndOfStack;\r
+ }\r
+ #endif\r
+\r
+ uxReturn = ( unsigned portBASE_TYPE ) usTaskCheckFreeStackSpace( pcEndOfStack );\r
+\r
+ return uxReturn;\r
+ }\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( INCLUDE_vTaskDelete == 1 )\r
\r
static void prvDeleteTCB( tskTCB *pxTCB )\r
{\r
+ /* This call is required specifically for the TriCore port. It must be\r
+ above the vPortFree() calls. */\r
+ portCLEAN_UP_TCB( pxTCB );\r
+\r
/* Free up the memory allocated by the scheduler for the task. It is up to\r
the task to free any memory allocated at the application level. */\r
- vPortFree( pxTCB->pxStack );\r
+ vPortFreeAligned( pxTCB->pxStack );\r
vPortFree( pxTCB );\r
}\r
\r
\r
/*-----------------------------------------------------------*/\r
\r
-#if ( INCLUDE_xTaskGetCurrentTaskHandle == 1 )\r
+#if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) )\r
\r
xTaskHandle xTaskGetCurrentTaskHandle( void )\r
{\r
xTaskHandle xReturn;\r
\r
- portENTER_CRITICAL();\r
+ /* A critical section is not required as this is not called from\r
+ an interrupt and the current TCB will always be the same for any\r
+ individual execution thread. */\r
+ xReturn = pxCurrentTCB;\r
+\r
+ return xReturn;\r
+ }\r
+\r
+#endif\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
+\r
+ portBASE_TYPE xTaskGetSchedulerState( void )\r
+ {\r
+ portBASE_TYPE xReturn;\r
+\r
+ if( xSchedulerRunning == pdFALSE )\r
+ {\r
+ xReturn = taskSCHEDULER_NOT_STARTED;\r
+ }\r
+ else\r
{\r
- xReturn = ( xTaskHandle ) pxCurrentTCB;\r
+ if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
+ {\r
+ xReturn = taskSCHEDULER_RUNNING;\r
+ }\r
+ else\r
+ {\r
+ xReturn = taskSCHEDULER_SUSPENDED;\r
+ }\r
}\r
- portEXIT_CRITICAL();\r
\r
return xReturn;\r
}\r
\r
#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_MUTEXES == 1 )\r
+\r
+ void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder )\r
+ {\r
+ tskTCB * const pxTCB = ( tskTCB * ) pxMutexHolder;\r
+\r
+ configASSERT( pxMutexHolder );\r
+\r
+ if( pxTCB->uxPriority < pxCurrentTCB->uxPriority )\r
+ {\r
+ /* Adjust the mutex holder state to account for its new priority. */\r
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) pxCurrentTCB->uxPriority );\r
+\r
+ /* If the task being modified is in the ready state it will need to\r
+ be moved in to a new list. */\r
+ if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
+ {\r
+ vListRemove( &( pxTCB->xGenericListItem ) );\r
+\r
+ /* Inherit the priority before being moved into the new list. */\r
+ pxTCB->uxPriority = pxCurrentTCB->uxPriority;\r
+ prvAddTaskToReadyQueue( pxTCB );\r
+ }\r
+ else\r
+ {\r
+ /* Just inherit the priority. */\r
+ pxTCB->uxPriority = pxCurrentTCB->uxPriority;\r
+ }\r
+\r
+ traceTASK_PRIORITY_INHERIT( pxTCB, pxCurrentTCB->uxPriority );\r
+ }\r
+ }\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_MUTEXES == 1 )\r
\r
+ void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder )\r
+ {\r
+ tskTCB * const pxTCB = ( tskTCB * ) pxMutexHolder;\r
+\r
+ if( pxMutexHolder != NULL )\r
+ {\r
+ if( pxTCB->uxPriority != pxTCB->uxBasePriority )\r
+ {\r
+ /* We must be the running task to be able to give the mutex back.\r
+ Remove ourselves from the ready list we currently appear in. */\r
+ vListRemove( &( pxTCB->xGenericListItem ) );\r
+\r
+ /* Disinherit the priority before adding the task into the new\r
+ ready list. */\r
+ traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority );\r
+ pxTCB->uxPriority = pxTCB->uxBasePriority;\r
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) pxTCB->uxPriority );\r
+ prvAddTaskToReadyQueue( pxTCB );\r
+ }\r
+ }\r
+ }\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
+\r
+ void vTaskEnterCritical( void )\r
+ {\r
+ portDISABLE_INTERRUPTS();\r
+\r
+ if( xSchedulerRunning != pdFALSE )\r
+ {\r
+ ( pxCurrentTCB->uxCriticalNesting )++;\r
+ }\r
+ }\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
+\r
+void vTaskExitCritical( void )\r
+{\r
+ if( xSchedulerRunning != pdFALSE )\r
+ {\r
+ if( pxCurrentTCB->uxCriticalNesting > 0U )\r
+ {\r
+ ( pxCurrentTCB->uxCriticalNesting )--;\r
+\r
+ if( pxCurrentTCB->uxCriticalNesting == 0U )\r
+ {\r
+ portENABLE_INTERRUPTS();\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
\r
\r
\r