/*\r
- FreeRTOS.org V5.1.2 - Copyright (C) 2003-2009 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
+ FreeRTOS V6.0.1 - Copyright (C) 2009 Real Time Engineers Ltd.\r
\r
- ***************************************************************************\r
***************************************************************************\r
* *\r
- * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *\r
- * *\r
- * This is a concise, step by step, 'hands on' guide that describes both *\r
- * general multitasking concepts and FreeRTOS specifics. It presents and *\r
- * explains numerous examples that are written using the FreeRTOS API. *\r
- * Full source code for all the examples is provided in an accompanying *\r
- * .zip file. *\r
+ * If you are: *\r
+ * *\r
+ * + New to FreeRTOS, *\r
+ * + Wanting to learn FreeRTOS or multitasking in general quickly *\r
+ * + Looking for basic training, *\r
+ * + Wanting to improve your FreeRTOS skills and productivity *\r
+ * *\r
+ * then take a look at the FreeRTOS eBook *\r
+ * *\r
+ * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *\r
+ * http://www.FreeRTOS.org/Documentation *\r
+ * *\r
+ * A pdf reference manual is also available. Both are usually delivered *\r
+ * to your inbox within 20 minutes to two hours when purchased between 8am *\r
+ * and 8pm GMT (although please allow up to 24 hours in case of *\r
+ * exceptional circumstances). Thank you for your support! *\r
* *\r
***************************************************************************\r
- ***************************************************************************\r
-\r
- Please ensure to read the configuration and relevant port sections of the\r
- online documentation.\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
+ 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 exception to the GPL is included to allow you to distribute\r
+ a combined work that includes FreeRTOS without being obliged to provide the\r
+ source code for proprietary components outside of the FreeRTOS kernel.\r
+ FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+ 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 <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 "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
+#define tskIDLE_PRIORITY ( ( unsigned portBASE_TYPE ) 0 )\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
- signed portCHAR pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created. Facilitates debugging only. */\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 ( configUSE_TRACE_FACILITY == 1 )\r
- unsigned portBASE_TYPE uxTCBNumber; /*< This is used for tracing the scheduler and making debugging easier only. */\r
- #endif \r
- \r
+ unsigned portBASE_TYPE uxTCBNumber; /*< This is used for tracing the scheduler and making debugging easier only. */\r
+ #endif\r
+\r
#if ( configUSE_MUTEXES == 1 )\r
- unsigned portBASE_TYPE uxBasePriority;\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
+\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
+\r
/*\r
* Some kernel aware debuggers require data to be viewed to be global, rather\r
* than file scope.\r
#endif\r
\r
/*lint -e956 */\r
-\r
-tskTCB * volatile pxCurrentTCB = NULL; \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 volatile 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 ) 0;\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
/* 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
-static unsigned portBASE_TYPE uxTaskNumber = 0;\r
+PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxCurrentNumberOfTasks = ( unsigned portBASE_TYPE ) 0;\r
+PRIVILEGED_DATA static volatile portTickType xTickCount = ( portTickType ) 0;\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 ) 0;\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 uxTaskNumber = ( unsigned portBASE_TYPE ) 0;\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
* 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
+#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
* 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
+ #define tskSIZE_OF_EACH_TRACE_LINE ( ( unsigned long ) ( sizeof( unsigned long ) + sizeof( unsigned long ) ) )\r
+ PRIVILEGED_DATA static volatile signed char * volatile pcTraceBuffer;\r
+ PRIVILEGED_DATA static signed char *pcTraceBufferStart;\r
+ PRIVILEGED_DATA static signed char *pcTraceBufferEnd;\r
+ PRIVILEGED_DATA static signed portBASE_TYPE xTracing = pdFALSE;\r
static unsigned portBASE_TYPE uxPreviousTask = 255;\r
- static portCHAR pcStatusString[ 50 ];\r
+ PRIVILEGED_DATA static char pcStatusString[ 50 ];\r
+\r
#endif\r
\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
+ *( unsigned long * ) pcTraceBuffer = ( unsigned long ) xTickCount; \\r
+ pcTraceBuffer += sizeof( unsigned long ); \\r
+ *( unsigned long * ) pcTraceBuffer = ( unsigned long ) uxPreviousTask; \\r
+ pcTraceBuffer += sizeof( unsigned long ); \\r
} \\r
else \\r
{ \\r
} \\r
vListInsertEnd( ( xList * ) &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ); \\r
}\r
-/*-----------------------------------------------------------*/ \r
+/*-----------------------------------------------------------*/\r
\r
/*\r
* Macro that looks at the list of tasks that are currently delayed to see if\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, 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
* 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
+\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
* 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( const 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
*/\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
* 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
\r
- /* Allocate the memory required by the TCB and stack for the new task.\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, 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 ) != 0x00 )\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 + ( usStackDepth - 1 );\r
+ pxTopOfStack = ( portSTACK_TYPE * ) ( ( ( unsigned long ) pxTopOfStack ) & ( ( unsigned long ) ~portBYTE_ALIGNMENT_MASK ) );\r
}\r
#else\r
{\r
- pxTopOfStack = pxNewTCB->pxStack; \r
+ pxTopOfStack = pxNewTCB->pxStack;\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
}\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
/* 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
prvInitialiseTaskLists();\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
then it should run now. */\r
if( pxCurrentTCB->uxPriority < uxPriority )\r
{\r
- taskYIELD();\r
+ portYIELD_WITHIN_API();\r
}\r
}\r
}\r
{\r
tskTCB *pxTCB;\r
\r
- taskENTER_CRITICAL();\r
+ portENTER_CRITICAL();\r
{\r
/* Ensure a yield is performed if the current task is being\r
deleted. */\r
/* If null is passed in here then we are deleting ourselves. */\r
pxTCB = prvGetTCBFromHandle( pxTaskToDelete );\r
\r
- traceTASK_DELETE( pxTCB );\r
-\r
/* Remove task from the ready list and place in the termination list.\r
This will stop the task from be scheduled. The idle task will check\r
the termination list and free up any memory allocated by the\r
scheduler for the TCB and stack. */\r
vListRemove( &( pxTCB->xGenericListItem ) );\r
\r
- /* Is the task waiting on an event also? */ \r
+ /* Is the task waiting on an event also? */\r
if( pxTCB->xEventListItem.pvContainer )\r
{\r
vListRemove( &( pxTCB->xEventListItem ) );\r
++uxTasksDeleted;\r
\r
/* Increment the uxTaskNumberVariable also so kernel aware debuggers\r
- can detect that the task lists need re-generating. */ \r
+ can detect that the task lists need re-generating. */\r
uxTaskNumber++;\r
+\r
+ traceTASK_DELETE( pxTCB );\r
}\r
- taskEXIT_CRITICAL();\r
+ portEXIT_CRITICAL();\r
\r
/* Force a reschedule if we have just deleted the current task. */\r
if( xSchedulerRunning != pdFALSE )\r
{\r
if( ( void * ) pxTaskToDelete == NULL )\r
{\r
- taskYIELD();\r
+ portYIELD_WITHIN_API();\r
}\r
}\r
}\r
have put ourselves to sleep. */\r
if( !xAlreadyYielded )\r
{\r
- taskYIELD();\r
+ portYIELD_WITHIN_API();\r
}\r
- } \r
- \r
+ }\r
+\r
#endif\r
/*-----------------------------------------------------------*/\r
\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
}\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
{\r
- taskYIELD();\r
+ portYIELD_WITHIN_API();\r
}\r
}\r
- \r
+\r
#endif\r
/*-----------------------------------------------------------*/\r
\r
tskTCB *pxTCB;\r
unsigned portBASE_TYPE uxReturn;\r
\r
- taskENTER_CRITICAL();\r
+ portENTER_CRITICAL();\r
{\r
/* If null is passed in here then we are changing the\r
priority of the calling function. */\r
pxTCB = prvGetTCBFromHandle( pxTask );\r
uxReturn = pxTCB->uxPriority;\r
}\r
- taskEXIT_CRITICAL();\r
+ portEXIT_CRITICAL();\r
\r
return uxReturn;\r
}\r
uxNewPriority = configMAX_PRIORITIES - 1;\r
}\r
\r
- taskENTER_CRITICAL();\r
+ portENTER_CRITICAL();\r
{\r
if( pxTask == pxCurrentTCB )\r
{\r
/* If null is passed in here then we are changing the\r
priority of the calling function. */\r
pxTCB = prvGetTCBFromHandle( pxTask );\r
- \r
+\r
traceTASK_PRIORITY_SET( pxTask, uxNewPriority );\r
\r
#if ( configUSE_MUTEXES == 1 )\r
task of higher priority that is ready to execute. */\r
xYieldRequired = pdTRUE;\r
}\r
- \r
- \r
+\r
+\r
\r
#if ( configUSE_MUTEXES == 1 )\r
{\r
{\r
pxTCB->uxPriority = uxNewPriority;\r
}\r
- \r
+\r
/* The base priority gets set whatever. */\r
- pxTCB->uxBasePriority = uxNewPriority; \r
+ pxTCB->uxBasePriority = uxNewPriority;\r
}\r
#else\r
{\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
+ portEXIT_CRITICAL();\r
}\r
\r
#endif\r
{\r
tskTCB *pxTCB;\r
\r
- taskENTER_CRITICAL();\r
+ portENTER_CRITICAL();\r
{\r
/* Ensure a yield is performed if the current task is being\r
suspended. */\r
/* If null is passed in here then we are suspending ourselves. */\r
pxTCB = prvGetTCBFromHandle( pxTaskToSuspend );\r
\r
- traceTASK_SUSPEND( pxTaskToSuspend );\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
+ /* Is the task waiting on an event also? */\r
if( pxTCB->xEventListItem.pvContainer )\r
{\r
vListRemove( &( pxTCB->xEventListItem ) );\r
\r
vListInsertEnd( ( xList * ) &xSuspendedTaskList, &( pxTCB->xGenericListItem ) );\r
}\r
- taskEXIT_CRITICAL();\r
+ portEXIT_CRITICAL();\r
\r
/* We may have just suspended the current task. */\r
if( ( void * ) pxTaskToSuspend == NULL )\r
{\r
- taskYIELD();\r
+ portYIELD_WITHIN_API();\r
}\r
}\r
\r
{\r
/* Has the task already been resumed from within an ISR? */\r
if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) != pdTRUE )\r
- { \r
+ {\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
currently executing task. */\r
if( ( pxTCB != NULL ) && ( pxTCB != pxCurrentTCB ) )\r
{\r
- taskENTER_CRITICAL();\r
+ portENTER_CRITICAL();\r
{\r
if( xTaskIsTaskSuspended( pxTCB ) == pdTRUE )\r
{\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
+ portYIELD_WITHIN_API();\r
}\r
}\r
}\r
- taskEXIT_CRITICAL();\r
+ portEXIT_CRITICAL();\r
}\r
}\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
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
+ xReturn = xTaskCreate( prvIdleTask, ( signed char * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), ( xTaskHandle * ) NULL );\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
xSchedulerRunning = pdTRUE;\r
xTickCount = ( portTickType ) 0;\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
--uxSchedulerSuspended;\r
\r
if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
- { \r
+ {\r
if( uxCurrentNumberOfTasks > ( unsigned portBASE_TYPE ) 0 )\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
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
/* 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
- #if configUSE_PREEMPTION == 1\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
portTickType xTicks;\r
\r
/* Critical section required if running on a 16 bit processor. */\r
- taskENTER_CRITICAL();\r
+ portENTER_CRITICAL();\r
{\r
xTicks = xTickCount;\r
}\r
- taskEXIT_CRITICAL();\r
+ portEXIT_CRITICAL();\r
\r
return xTicks;\r
}\r
}\r
/*-----------------------------------------------------------*/\r
\r
-#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_vTaskDelete == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )\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[ 0 ] = ( signed char ) 0x00;\r
+ strcat( ( char * ) pcWriteBuffer, ( const char * ) "\r\n" );\r
\r
uxQueue = uxTopUsedPriority + 1;\r
\r
\r
if( !listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxQueue ] ) ) )\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
{\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 ) )\r
+ {\r
+ prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) &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 ) )\r
+ {\r
+ prvListTaskWithinSingleList( pcWriteBuffer, ( xList * ) &xSuspendedTaskList, tskSUSPENDED_CHAR );\r
+ }\r
}\r
+ #endif\r
}\r
- xTaskResumeAll();\r
+ xTaskResumeAll();\r
+ }\r
+\r
+#endif\r
+/*----------------------------------------------------------*/\r
+\r
+#if ( configGENERATE_RUN_TIME_STATS == 1 )\r
+\r
+ void vTaskGetRunTimeStats( signed char *pcWriteBuffer )\r
+ {\r
+ unsigned portBASE_TYPE uxQueue;\r
+ unsigned long ulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\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
+ /* 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
+ pcWriteBuffer[ 0 ] = ( signed char ) 0x00;\r
+ strcat( ( char * ) pcWriteBuffer, ( const char * ) "\r\n" );\r
+\r
+ uxQueue = uxTopUsedPriority + 1;\r
+\r
+ do\r
+ {\r
+ uxQueue--;\r
+\r
+ if( !listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxQueue ] ) ) )\r
+ {\r
+ prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) &( pxReadyTasksLists[ uxQueue ] ), ulTotalRunTime );\r
+ }\r
+ }while( uxQueue > ( unsigned short ) tskIDLE_PRIORITY );\r
+\r
+ if( !listLIST_IS_EMPTY( pxDelayedTaskList ) )\r
+ {\r
+ prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) pxDelayedTaskList, ulTotalRunTime );\r
+ }\r
+\r
+ if( !listLIST_IS_EMPTY( pxOverflowDelayedTaskList ) )\r
+ {\r
+ prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) pxOverflowDelayedTaskList, ulTotalRunTime );\r
+ }\r
+\r
+ #if ( INCLUDE_vTaskDelete == 1 )\r
+ {\r
+ if( !listLIST_IS_EMPTY( &xTasksWaitingTermination ) )\r
+ {\r
+ prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) &xTasksWaitingTermination, ulTotalRunTime );\r
+ }\r
+ }\r
+ #endif\r
+\r
+ #if ( INCLUDE_vTaskSuspend == 1 )\r
+ {\r
+ if( !listLIST_IS_EMPTY( &xSuspendedTaskList ) )\r
+ {\r
+ prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) &xSuspendedTaskList, ulTotalRunTime );\r
+ }\r
+ }\r
+ #endif\r
+ }\r
+ xTaskResumeAll();\r
}\r
\r
#endif\r
\r
#if ( configUSE_TRACE_FACILITY == 1 )\r
\r
- void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize )\r
+ void vTaskStartTrace( signed char * pcBuffer, unsigned long ulBufferSize )\r
{\r
portENTER_CRITICAL();\r
{\r
- pcTraceBuffer = ( signed portCHAR * )pcBuffer;\r
+ pcTraceBuffer = ( signed char * )pcBuffer;\r
pcTraceBufferStart = pcBuffer;\r
pcTraceBufferEnd = pcBuffer + ( ulBufferSize - tskSIZE_OF_EACH_TRACE_LINE );\r
xTracing = pdTRUE;\r
\r
#if ( configUSE_TRACE_FACILITY == 1 )\r
\r
- unsigned portLONG ulTaskEndTrace( void )\r
+ unsigned long ulTaskEndTrace( void )\r
{\r
- unsigned portLONG ulBufferLength;\r
+ unsigned long ulBufferLength;\r
\r
portENTER_CRITICAL();\r
xTracing = pdFALSE;\r
portEXIT_CRITICAL();\r
\r
- ulBufferLength = ( unsigned portLONG ) ( pcTraceBuffer - pcTraceBufferStart );\r
+ ulBufferLength = ( unsigned long ) ( pcTraceBuffer - pcTraceBufferStart );\r
\r
return ulBufferLength;\r
}\r
pxTemp = pxDelayedTaskList;\r
pxDelayedTaskList = pxOverflowDelayedTaskList;\r
pxOverflowDelayedTaskList = pxTemp;\r
- xNumOfOverflows++;\r
+ xNumOfOverflows++;\r
}\r
\r
/* See if this tick has made a timeout expire. */\r
\r
void vTaskCleanUpResources( void )\r
{\r
- unsigned portSHORT usQueue;\r
+ unsigned short usQueue;\r
volatile tskTCB *pxTCB;\r
\r
- usQueue = ( unsigned portSHORT ) uxTopUsedPriority + ( unsigned portSHORT ) 1;\r
+ usQueue = ( unsigned short ) uxTopUsedPriority + ( unsigned short ) 1;\r
\r
/* Remove any TCB's from the ready queues. */\r
do\r
\r
prvDeleteTCB( ( tskTCB * ) pxTCB );\r
}\r
- }while( usQueue > ( unsigned portSHORT ) tskIDLE_PRIORITY );\r
+ }while( usQueue > ( unsigned short ) tskIDLE_PRIORITY );\r
\r
/* Remove any TCB's from the delayed queue. */\r
while( !listLIST_IS_EMPTY( &xDelayedTaskList1 ) )\r
vListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) );\r
\r
prvDeleteTCB( ( tskTCB * ) pxTCB );\r
- } \r
+ }\r
}\r
\r
#endif\r
{\r
xTCB = ( tskTCB * ) xTask;\r
}\r
- \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
portENTER_CRITICAL();\r
xTCB->pxTaskTag = pxTagValue;\r
portEXIT_CRITICAL();\r
}\r
- \r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
+\r
+ pdTASK_HOOK_CODE xTaskGetApplicationTaskTag( xTaskHandle xTask )\r
+ {\r
+ tskTCB *xTCB;\r
+ pdTASK_HOOK_CODE xReturn;\r
+\r
+ /* If xTask is NULL then we are setting our own task hook. */\r
+ if( xTask == NULL )\r
+ {\r
+ xTCB = ( tskTCB * ) pxCurrentTCB;\r
+ }\r
+ else\r
+ {\r
+ xTCB = ( tskTCB * ) xTask;\r
+ }\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
+ portENTER_CRITICAL();\r
+ xReturn = xTCB->pxTaskTag;\r
+ portEXIT_CRITICAL();\r
+\r
+ return xReturn;\r
+ }\r
+\r
#endif\r
/*-----------------------------------------------------------*/\r
\r
\r
return xReturn;\r
}\r
- \r
+\r
#endif\r
/*-----------------------------------------------------------*/\r
\r
void vTaskSwitchContext( void )\r
{\r
- traceTASK_SWITCHED_OUT();\r
-\r
if( uxSchedulerSuspended != ( unsigned portBASE_TYPE ) pdFALSE )\r
{\r
/* The scheduler is currently suspended - do not allow a context\r
return;\r
}\r
\r
+ traceTASK_SWITCHED_OUT();\r
+\r
+ #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
+ {\r
+ unsigned long ulTempCounter = portGET_RUN_TIME_COUNTER_VALUE();\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
\r
\r
#if ( INCLUDE_vTaskSuspend == 1 )\r
- { \r
+ {\r
if( xTicksToWait == portMAX_DELAY )\r
{\r
/* Add ourselves to the suspended task list instead of a delayed task\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
+\r
listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xGenericListItem ), xTimeToWake );\r
- \r
+\r
if( xTimeToWake < xTickCount )\r
{\r
/* Wake time has overflowed. Place this item in the overflow list. */\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
+\r
listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xGenericListItem ), xTimeToWake );\r
- \r
+\r
if( xTimeToWake < xTickCount )\r
{\r
/* Wake time has overflowed. Place this item in the overflow list. */\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
\r
void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut )\r
{\r
- pxTimeOut->xOverflowCount = xNumOfOverflows;\r
- pxTimeOut->xTimeOnEntering = xTickCount;\r
+ pxTimeOut->xOverflowCount = xNumOfOverflows;\r
+ pxTimeOut->xTimeOnEntering = xTickCount;\r
}\r
/*-----------------------------------------------------------*/\r
\r
else /* We are not blocking indefinitely, perform the checks below. */\r
#endif\r
\r
- if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( xTickCount >= pxTimeOut->xTimeOnEntering ) )\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
passed since vTaskSetTimeout() was called. */\r
xReturn = pdTRUE;\r
}\r
- else if( ( xTickCount - pxTimeOut->xTimeOnEntering ) < *pxTicksToWait )\r
+ else if( ( ( portTickType ) ( ( portTickType ) xTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering ) ) < ( portTickType ) *pxTicksToWait )\r
{\r
/* Not a genuine timeout. Adjust parameters for time remaining. */\r
- *pxTicksToWait -= ( xTickCount - pxTimeOut->xTimeOnEntering );\r
+ *pxTicksToWait -= ( ( portTickType ) xTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering );\r
vTaskSetTimeOutState( pxTimeOut );\r
xReturn = pdFALSE;\r
}\r
}\r
portEXIT_CRITICAL();\r
\r
- return xReturn;\r
+ return xReturn;\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, 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
/* 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 ] = '\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
{\r
pxTCB->pxTaskTag = NULL;\r
}\r
- #endif \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
\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
if( uxTasksDeleted > ( unsigned portBASE_TYPE ) 0 )\r
{\r
vTaskSuspendAll();\r
- xListIsEmpty = listLIST_IS_EMPTY( &xTasksWaitingTermination ); \r
+ xListIsEmpty = listLIST_IS_EMPTY( &xTasksWaitingTermination );\r
xTaskResumeAll();\r
\r
if( !xListIsEmpty )\r
tskTCB *pxTCB;\r
\r
portENTER_CRITICAL();\r
- { \r
+ {\r
pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xTasksWaitingTermination ) );\r
vListRemove( &( pxTCB->xGenericListItem ) );\r
--uxCurrentNumberOfTasks;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static tskTCB *prvAllocateTCBAndStack( unsigned portSHORT usStackDepth )\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
\r
#if ( configUSE_TRACE_FACILITY == 1 )\r
\r
- static void prvListTaskWithinSingleList( const 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
- unsigned portSHORT usStackRemaining;\r
+ unsigned short usStackRemaining;\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
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\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 == 0 )\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 as the task used?\r
+ This will always be rounded down to the nearest integer. */\r
+ ulStatsAsPercentage = ( 100UL * pxNextTCB->ulRunTimeCounter ) / ulTotalRunTime;\r
+\r
+ if( ulStatsAsPercentage > 0UL )\r
+ {\r
+ sprintf( pcStatsString, ( char * ) "%s\t\t%u\t\t%u%%\r\n", pxNextTCB->pcTaskName, ( unsigned int ) pxNextTCB->ulRunTimeCounter, ( unsigned int ) ulStatsAsPercentage );\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
+ sprintf( pcStatsString, ( char * ) "%s\t\t%u\t\t<1%%\r\n", pxNextTCB->pcTaskName, ( unsigned int ) pxNextTCB->ulRunTimeCounter );\r
+ }\r
+ }\r
+\r
+ strcat( ( char * ) pcWriteBuffer, ( char * ) pcStatsString );\r
+ }\r
\r
} while( pxNextTCB != pxFirstTCB );\r
}\r
\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 )\r
{\r
- register unsigned portSHORT usCount = 0;\r
+ register unsigned short usCount = 0;\r
\r
while( *pucStackByte == tskSTACK_FILL_BYTE )\r
{\r
unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask )\r
{\r
tskTCB *pxTCB;\r
- unsigned portCHAR *pcEndOfStack;\r
+ unsigned char *pcEndOfStack;\r
+ unsigned portBASE_TYPE uxReturn;\r
\r
pxTCB = prvGetTCBFromHandle( xTask );\r
\r
#if portSTACK_GROWTH < 0\r
{\r
- pcEndOfStack = ( unsigned portCHAR * ) pxTCB->pxStack;\r
+ pcEndOfStack = ( unsigned char * ) pxTCB->pxStack;\r
}\r
#else\r
{\r
- pcEndOfStack = ( unsigned portCHAR * ) pxTCB->pxEndOfStack;\r
+ pcEndOfStack = ( unsigned char * ) pxTCB->pxEndOfStack;\r
}\r
#endif\r
\r
- return usTaskCheckFreeStackSpace( pcEndOfStack );\r
+ uxReturn = ( unsigned portBASE_TYPE ) usTaskCheckFreeStackSpace( pcEndOfStack );\r
+\r
+ return uxReturn;\r
}\r
\r
#endif\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
xTaskHandle xTaskGetCurrentTaskHandle( void )\r
{\r
+ xTaskHandle xReturn;\r
+\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
- return pxCurrentTCB;\r
+ xReturn = pxCurrentTCB;\r
+\r
+ return xReturn;\r
}\r
\r
#endif\r
portBASE_TYPE xTaskGetSchedulerState( void )\r
{\r
portBASE_TYPE xReturn;\r
- \r
+\r
if( xSchedulerRunning == pdFALSE )\r
{\r
xReturn = taskSCHEDULER_NOT_STARTED;\r
xReturn = taskSCHEDULER_SUSPENDED;\r
}\r
}\r
- \r
+\r
return xReturn;\r
}\r
\r
/*-----------------------------------------------------------*/\r
\r
#if ( configUSE_MUTEXES == 1 )\r
- \r
+\r
void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder )\r
{\r
tskTCB * const pxTCB = ( tskTCB * ) pxMutexHolder;\r
#endif\r
/*-----------------------------------------------------------*/\r
\r
-#if ( configUSE_MUTEXES == 1 ) \r
+#if ( configUSE_MUTEXES == 1 )\r
\r
void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder )\r
{\r
/*-----------------------------------------------------------*/\r
\r
\r
- \r
+\r
\r