/*\r
- FreeRTOS V8.0.1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
+ FreeRTOS V9.0.1 - Copyright (C) 2017 Real Time Engineers Ltd.\r
All rights reserved\r
\r
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
\r
- ***************************************************************************\r
- * *\r
- * FreeRTOS provides completely free yet professionally developed, *\r
- * robust, strictly quality controlled, supported, and cross *\r
- * platform software that has become a de facto standard. *\r
- * *\r
- * Help yourself get started quickly and support the FreeRTOS *\r
- * project by purchasing a FreeRTOS tutorial book, reference *\r
- * manual, or both from: http://www.FreeRTOS.org/Documentation *\r
- * *\r
- * Thank you! *\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
+ Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
\r
+ ***************************************************************************\r
>>! NOTE: The modification to the GPL is included to allow you to !<<\r
>>! distribute a combined work that includes FreeRTOS without being !<<\r
>>! obliged to provide the source code for proprietary components !<<\r
>>! outside of the FreeRTOS kernel. !<<\r
+ ***************************************************************************\r
\r
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
- FOR A PARTICULAR PURPOSE. Full license text is available from the following\r
+ FOR A PARTICULAR PURPOSE. Full license text is available on the following\r
link: http://www.freertos.org/a00114.html\r
\r
- 1 tab == 4 spaces!\r
-\r
***************************************************************************\r
* *\r
- * Having a problem? Start by reading the FAQ "My application does *\r
- * not run, what could be wrong?" *\r
+ * FreeRTOS provides completely free yet professionally developed, *\r
+ * robust, strictly quality controlled, supported, and cross *\r
+ * platform software that is more than just the market leader, it *\r
+ * is the industry's de facto standard. *\r
* *\r
- * http://www.FreeRTOS.org/FAQHelp.html *\r
+ * Help yourself get started quickly while simultaneously helping *\r
+ * to support the FreeRTOS project by purchasing a FreeRTOS *\r
+ * tutorial book, reference manual, or both: *\r
+ * http://www.FreeRTOS.org/Documentation *\r
* *\r
***************************************************************************\r
\r
- http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
- license and Real Time Engineers Ltd. contact details.\r
+ http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading\r
+ the FAQ page "My application does not run, what could be wrong?". Have you\r
+ defined configASSERT()?\r
+\r
+ http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+ embedded software for free we request you assist our global community by\r
+ participating in the support forum.\r
+\r
+ http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+ be as productive as possible as early as possible. Now you can receive\r
+ FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+ Ltd, and the world's leading authority on the world's leading RTOS.\r
\r
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
\r
- http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
- Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS\r
- licenses offer ticketed support, indemnification and middleware.\r
+ http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+ Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+\r
+ http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+ Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS\r
+ licenses offer ticketed support, indemnification and commercial middleware.\r
\r
http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
engineered and independently SIL3 certified version for use in safety and\r
privileged Vs unprivileged linkage and placement. */\r
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */\r
\r
+/* Set configUSE_STATS_FORMATTING_FUNCTIONS to 2 to include the stats formatting\r
+functions but without including stdio.h here. */\r
#if ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 )\r
/* At the bottom of this file are two optional functions that can be used\r
to generate human readable text from the raw data generated by the\r
#include <stdio.h>\r
#endif /* configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) */\r
\r
-/* Sanity check the configuration. */\r
-#if configUSE_TICKLESS_IDLE != 0\r
- #if INCLUDE_vTaskSuspend != 1\r
- #error INCLUDE_vTaskSuspend must be set to 1 if configUSE_TICKLESS_IDLE is not set to 0\r
- #endif /* INCLUDE_vTaskSuspend */\r
-#endif /* configUSE_TICKLESS_IDLE */\r
-\r
-/*\r
- * Defines the size, in words, of the stack allocated to the idle task.\r
- */\r
-#define tskIDLE_STACK_SIZE configMINIMAL_STACK_SIZE\r
-\r
#if( configUSE_PREEMPTION == 0 )\r
/* If the cooperative scheduler is being used then a yield should not be\r
performed just because a higher priority task has been woken. */\r
#define taskYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API()\r
#endif\r
\r
-/*\r
- * Task control block. A task control block (TCB) is allocated for each task,\r
- * and stores task state information, including a pointer to the task's context\r
- * (the task's run time environment, including register values)\r
- */\r
-typedef struct tskTaskControlBlock\r
-{\r
- volatile StackType_t *pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE TCB 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 TCB STRUCT. */\r
- #endif\r
-\r
- ListItem_t xGenericListItem; /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */\r
- ListItem_t xEventListItem; /*< Used to reference a task from an event list. */\r
- UBaseType_t uxPriority; /*< The priority of the task. 0 is the lowest priority. */\r
- StackType_t *pxStack; /*< Points to the start of the stack. */\r
- char pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created. Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
-\r
- #if ( portSTACK_GROWTH > 0 )\r
- StackType_t *pxEndOfStack; /*< Points to the end of the stack on architectures where the stack grows up from low memory. */\r
- #endif\r
-\r
- #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
- UBaseType_t uxCriticalNesting; /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */\r
- #endif\r
-\r
- #if ( configUSE_TRACE_FACILITY == 1 )\r
- UBaseType_t uxTCBNumber; /*< 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
- UBaseType_t uxTaskNumber; /*< Stores a number specifically for use by third party trace code. */\r
- #endif\r
-\r
- #if ( configUSE_MUTEXES == 1 )\r
- UBaseType_t uxBasePriority; /*< The priority last assigned to the task - used by the priority inheritance mechanism. */\r
- UBaseType_t uxMutexesHeld;\r
- #endif\r
-\r
- #if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
- TaskHookFunction_t pxTaskTag;\r
- #endif\r
-\r
- #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
- uint32_t ulRunTimeCounter; /*< Stores the amount of time the task has spent in the Running state. */\r
- #endif\r
-\r
- #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
- /* Allocate a Newlib reent structure that is specific to this task.\r
- Note Newlib support has been included by popular demand, but is not\r
- used by the FreeRTOS maintainers themselves. FreeRTOS is not\r
- responsible for resulting newlib operation. User must be familiar with\r
- newlib and must provide system-wide implementations of the necessary\r
- stubs. Be warned that (at the time of writing) the current newlib design\r
- implements a system-wide malloc() that must be provided with locks. */\r
- struct _reent xNewLib_reent;\r
- #endif\r
-\r
-} tskTCB;\r
-\r
-/* The old tskTCB name is maintained above then typedefed to the new TCB_t name\r
-below to enable the use of older kernel aware debuggers. */\r
-typedef tskTCB TCB_t;\r
-\r
-/*\r
- * Some kernel aware debuggers require the data the debugger needs access to to\r
- * be global, rather than file scope.\r
- */\r
-#ifdef portREMOVE_STATIC_QUALIFIER\r
- #define static\r
-#endif\r
-\r
-/*lint -e956 A manual analysis and inspection has been used to determine which\r
-static variables must be declared volatile. */\r
-\r
-PRIVILEGED_DATA TCB_t * volatile pxCurrentTCB = NULL;\r
-\r
-/* Lists for ready and blocked tasks. --------------------*/\r
-PRIVILEGED_DATA static List_t pxReadyTasksLists[ configMAX_PRIORITIES ];/*< Prioritised ready tasks. */\r
-PRIVILEGED_DATA static List_t xDelayedTaskList1; /*< Delayed tasks. */\r
-PRIVILEGED_DATA static List_t xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */\r
-PRIVILEGED_DATA static List_t * volatile pxDelayedTaskList; /*< Points to the delayed task list currently being used. */\r
-PRIVILEGED_DATA static List_t * 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 List_t xPendingReadyList; /*< Tasks that have been readied while the scheduler was suspended. They will be moved to the ready list when the scheduler is resumed. */\r
-\r
-#if ( INCLUDE_vTaskDelete == 1 )\r
-\r
- PRIVILEGED_DATA static List_t xTasksWaitingTermination; /*< Tasks that have been deleted - but their memory not yet freed. */\r
- PRIVILEGED_DATA static volatile UBaseType_t uxTasksDeleted = ( UBaseType_t ) 0U;\r
-\r
-#endif\r
-\r
-#if ( INCLUDE_vTaskSuspend == 1 )\r
-\r
- PRIVILEGED_DATA static List_t xSuspendedTaskList; /*< Tasks that are currently suspended. */\r
-\r
-#endif\r
-\r
-#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\r
-\r
- PRIVILEGED_DATA static TaskHandle_t xIdleTaskHandle = NULL; /*< Holds the handle of the idle task. The idle task is created automatically when the scheduler is started. */\r
-\r
-#endif\r
-\r
-/* Other file private variables. --------------------------------*/\r
-PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;\r
-PRIVILEGED_DATA static volatile TickType_t xTickCount = ( TickType_t ) 0U;\r
-PRIVILEGED_DATA static volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY;\r
-PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning = pdFALSE;\r
-PRIVILEGED_DATA static volatile UBaseType_t uxPendedTicks = ( UBaseType_t ) 0U;\r
-PRIVILEGED_DATA static volatile BaseType_t xYieldPending = pdFALSE;\r
-PRIVILEGED_DATA static volatile BaseType_t xNumOfOverflows = ( BaseType_t ) 0;\r
-PRIVILEGED_DATA static UBaseType_t uxTaskNumber = ( UBaseType_t ) 0U;\r
-PRIVILEGED_DATA static volatile TickType_t xNextTaskUnblockTime = portMAX_DELAY;\r
-\r
-/* Context switches are held pending while the scheduler is suspended. Also,\r
-interrupts must not manipulate the xStateListItem of a TCB, or any of the\r
-lists the xStateListItem can be referenced from, if the scheduler is suspended.\r
-If an interrupt needs to unblock a task while the scheduler is suspended then it\r
-moves the task's event list item into the xPendingReadyList, ready for the\r
-kernel to move the task from the pending ready list into the real ready list\r
-when the scheduler is unsuspended. The pending ready list itself can only be\r
-accessed from a critical section. */\r
-PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended = ( UBaseType_t ) pdFALSE;\r
-\r
-#if ( configGENERATE_RUN_TIME_STATS == 1 )\r
-\r
- PRIVILEGED_DATA static uint32_t ulTaskSwitchedInTime = 0UL; /*< Holds the value of a timer/counter the last time a task was switched in. */\r
- PRIVILEGED_DATA static uint32_t ulTotalRunTime = 0UL; /*< Holds the total amount of execution time as defined by the run time counter clock. */\r
-\r
-#endif\r
-\r
-/*lint +e956 */\r
-\r
-/* Debugging and trace facilities private variables and macros. ------------*/\r
+/* Values that can be assigned to the ucNotifyState member of the TCB. */\r
+#define taskNOT_WAITING_NOTIFICATION ( ( uint8_t ) 0 )\r
+#define taskWAITING_NOTIFICATION ( ( uint8_t ) 1 )\r
+#define taskNOTIFICATION_RECEIVED ( ( uint8_t ) 2 )\r
\r
/*\r
* The value used to fill the stack of a task when the task is created. This\r
*/\r
#define tskSTACK_FILL_BYTE ( 0xa5U )\r
\r
+/* Sometimes the FreeRTOSConfig.h settings only allow a task to be created using\r
+dynamically allocated RAM, in which case when any task is deleted it is known\r
+that both the task's stack and TCB need to be freed. Sometimes the\r
+FreeRTOSConfig.h settings only allow a task to be created using statically\r
+allocated RAM, in which case when any task is deleted it is known that neither\r
+the task's stack or TCB should be freed. Sometimes the FreeRTOSConfig.h\r
+settings allow a task to be created using either statically or dynamically\r
+allocated RAM, in which case a member of the TCB is used to record whether the\r
+stack and/or TCB were allocated statically or dynamically, so when a task is\r
+deleted the RAM that was allocated dynamically is freed again and no attempt is\r
+made to free the RAM that was allocated statically.\r
+tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is only true if it is possible for a\r
+task to be created using either statically or dynamically allocated RAM. Note\r
+that if portUSING_MPU_WRAPPERS is 1 then a protected task can be created with\r
+a statically allocated stack and a dynamically allocated TCB.\r
+!!!NOTE!!! If the definition of tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is\r
+changed then the definition of StaticTask_t must also be updated. */\r
+#define tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
+#define tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB ( ( uint8_t ) 0 )\r
+#define tskSTATICALLY_ALLOCATED_STACK_ONLY ( ( uint8_t ) 1 )\r
+#define tskSTATICALLY_ALLOCATED_STACK_AND_TCB ( ( uint8_t ) 2 )\r
+\r
+/* If any of the following are set then task stacks are filled with a known\r
+value so the high water mark can be determined. If none of the following are\r
+set then don't fill the stack so there is no unnecessary dependency on memset. */\r
+#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
+ #define tskSET_NEW_STACKS_TO_KNOWN_VALUE 1\r
+#else\r
+ #define tskSET_NEW_STACKS_TO_KNOWN_VALUE 0\r
+#endif\r
+\r
/*\r
* Macros used by vListTask to indicate which state a task is in.\r
*/\r
#define tskDELETED_CHAR ( 'D' )\r
#define tskSUSPENDED_CHAR ( 'S' )\r
\r
-/*-----------------------------------------------------------*/\r
+/*\r
+ * Some kernel aware debuggers require the data the debugger needs access to be\r
+ * global, rather than file scope.\r
+ */\r
+#ifdef portREMOVE_STATIC_QUALIFIER\r
+ #define static\r
+#endif\r
+\r
+/* The name allocated to the Idle task. This can be overridden by defining\r
+configIDLE_TASK_NAME in FreeRTOSConfig.h. */\r
+#ifndef configIDLE_TASK_NAME\r
+ #define configIDLE_TASK_NAME "IDLE"\r
+#endif\r
\r
#if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 )\r
\r
\r
#define taskSELECT_HIGHEST_PRIORITY_TASK() \\r
{ \\r
+ UBaseType_t uxTopPriority = uxTopReadyPriority; \\r
+ \\r
/* Find the highest priority queue that contains ready tasks. */ \\r
- while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopReadyPriority ] ) ) ) \\r
+ while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopPriority ] ) ) ) \\r
{ \\r
- configASSERT( uxTopReadyPriority ); \\r
- --uxTopReadyPriority; \\r
+ configASSERT( uxTopPriority ); \\r
+ --uxTopPriority; \\r
} \\r
\\r
/* listGET_OWNER_OF_NEXT_ENTRY indexes through the list, so the tasks of \\r
the same priority get an equal share of the processor time. */ \\r
- listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) ); \\r
+ listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) ); \\r
+ uxTopReadyPriority = uxTopPriority; \\r
} /* taskSELECT_HIGHEST_PRIORITY_TASK */\r
\r
/*-----------------------------------------------------------*/\r
{ \\r
UBaseType_t uxTopPriority; \\r
\\r
- /* Find the highest priority queue that contains ready tasks. */ \\r
+ /* Find the highest priority list that contains ready tasks. */ \\r
portGET_HIGHEST_PRIORITY( uxTopPriority, uxTopReadyPriority ); \\r
configASSERT( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ uxTopPriority ] ) ) > 0 ); \\r
listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) ); \\r
/* A port optimised version is provided, call it only if the TCB being reset\r
is being referenced from a ready list. If it is referenced from a delayed\r
or suspended list then it won't be in a ready list. */\r
- #define taskRESET_READY_PRIORITY( uxPriority ) \\r
- { \\r
- if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ ( uxPriority ) ] ) ) == 0 ) \\r
- { \\r
- portRESET_READY_PRIORITY( ( uxPriority ), ( uxTopReadyPriority ) ); \\r
- } \\r
+ #define taskRESET_READY_PRIORITY( uxPriority ) \\r
+ { \\r
+ if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ ( uxPriority ) ] ) ) == ( UBaseType_t ) 0 ) \\r
+ { \\r
+ portRESET_READY_PRIORITY( ( uxPriority ), ( uxTopReadyPriority ) ); \\r
+ } \\r
}\r
\r
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
* the task. It is inserted at the end of the list.\r
*/\r
#define prvAddTaskToReadyList( pxTCB ) \\r
- traceMOVED_TASK_TO_READY_STATE( pxTCB ) \\r
+ traceMOVED_TASK_TO_READY_STATE( pxTCB ); \\r
taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \\r
- vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xGenericListItem ) )\r
+ vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \\r
+ tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB )\r
/*-----------------------------------------------------------*/\r
\r
/*\r
the scheduler that the value should not be changed - in which case it is the\r
responsibility of whichever module is using the value to ensure it gets set back\r
to its original value when it is released. */\r
-#if configUSE_16_BIT_TICKS == 1\r
+#if( configUSE_16_BIT_TICKS == 1 )\r
#define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x8000U\r
#else\r
#define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x80000000UL\r
#endif\r
\r
-/* Callback function prototypes. --------------------------*/\r
-#if configCHECK_FOR_STACK_OVERFLOW > 0\r
- extern void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName );\r
-#endif\r
-\r
-#if configUSE_TICK_HOOK > 0\r
- extern void vApplicationTickHook( void );\r
-#endif\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
+ * Task control block. A task control block (TCB) is allocated for each task,\r
+ * and stores task state information, including a pointer to the task's context\r
+ * (the task's run time environment, including register values)\r
*/\r
-static void prvInitialiseTCBVariables( TCB_t * const pxTCB, const char * const pcName, UBaseType_t uxPriority, const MemoryRegion_t * const xRegions, const uint16_t usStackDepth ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+typedef struct tskTaskControlBlock\r
+{\r
+ volatile StackType_t *pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */\r
\r
-/**\r
- * Utility task that simply returns pdTRUE if the task referenced by xTask is\r
- * currently in the Suspended state, or pdFALSE if the task referenced by xTask\r
- * is in any other state.\r
- */\r
-static BaseType_t prvTaskIsTaskSuspended( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;\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 TCB STRUCT. */\r
+ #endif\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 ) PRIVILEGED_FUNCTION;\r
+ ListItem_t xStateListItem; /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */\r
+ ListItem_t xEventListItem; /*< Used to reference a task from an event list. */\r
+ UBaseType_t uxPriority; /*< The priority of the task. 0 is the lowest priority. */\r
+ StackType_t *pxStack; /*< Points to the start of the stack. */\r
+ char pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created. Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
\r
-/*\r
- * The idle task, which as all tasks is implemented as a never ending loop.\r
- * The idle task is automatically created and added to the ready lists upon\r
- * creation of the first user task.\r
- *\r
- * The portTASK_FUNCTION_PROTO() macro is used to allow port/compiler specific\r
- * language extensions. The equivalent prototype for this function is:\r
- *\r
- * void prvIdleTask( void *pvParameters );\r
- *\r
- */\r
-static portTASK_FUNCTION_PROTO( prvIdleTask, pvParameters );\r
+ #if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )\r
+ StackType_t *pxEndOfStack; /*< Points to the highest valid address for the stack. */\r
+ #endif\r
\r
-/*\r
- * Utility to free all memory allocated by the scheduler to hold a TCB,\r
- * including the stack pointed to by the TCB.\r
- *\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 )\r
+ #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
+ UBaseType_t uxCriticalNesting; /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */\r
+ #endif\r
\r
- static void prvDeleteTCB( TCB_t *pxTCB ) PRIVILEGED_FUNCTION;\r
+ #if ( configUSE_TRACE_FACILITY == 1 )\r
+ UBaseType_t uxTCBNumber; /*< 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
+ UBaseType_t uxTaskNumber; /*< Stores a number specifically for use by third party trace code. */\r
+ #endif\r
\r
-#endif\r
+ #if ( configUSE_MUTEXES == 1 )\r
+ UBaseType_t uxBasePriority; /*< The priority last assigned to the task - used by the priority inheritance mechanism. */\r
+ UBaseType_t uxMutexesHeld;\r
+ #endif\r
\r
-/*\r
- * Used only by the idle task. This checks to see if anything has been placed\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 ) PRIVILEGED_FUNCTION;\r
+ #if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
+ TaskHookFunction_t pxTaskTag;\r
+ #endif\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( const TickType_t xTimeToWake ) PRIVILEGED_FUNCTION;\r
+ #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )\r
+ void *pvThreadLocalStoragePointers[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ];\r
+ #endif\r
\r
-/*\r
- * Allocates memory from the heap for a TCB and associated stack. Checks the\r
- * allocation was successful.\r
- */\r
-static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t * const puxStackBuffer ) PRIVILEGED_FUNCTION;\r
+ #if( configGENERATE_RUN_TIME_STATS == 1 )\r
+ uint32_t ulRunTimeCounter; /*< Stores the amount of time the task has spent in the Running state. */\r
+ #endif\r
\r
-/*\r
- * Fills an TaskStatus_t structure with information on each task that is\r
- * referenced from the pxList list (which may be a ready list, a delayed list,\r
- * a suspended list, etc.).\r
- *\r
- * THIS FUNCTION IS INTENDED FOR DEBUGGING ONLY, AND SHOULD NOT BE CALLED FROM\r
- * NORMAL APPLICATION CODE.\r
- */\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
+ #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
+ /* Allocate a Newlib reent structure that is specific to this task.\r
+ Note Newlib support has been included by popular demand, but is not\r
+ used by the FreeRTOS maintainers themselves. FreeRTOS is not\r
+ responsible for resulting newlib operation. User must be familiar with\r
+ newlib and must provide system-wide implementations of the necessary\r
+ stubs. Be warned that (at the time of writing) the current newlib design\r
+ implements a system-wide malloc() that must be provided with locks. */\r
+ struct _reent xNewLib_reent;\r
+ #endif\r
\r
- static UBaseType_t prvListTaskWithinSingleList( TaskStatus_t *pxTaskStatusArray, List_t *pxList, eTaskState eState ) PRIVILEGED_FUNCTION;\r
+ #if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+ volatile uint32_t ulNotifiedValue;\r
+ volatile uint8_t ucNotifyState;\r
+ #endif\r
\r
-#endif\r
+ /* See the comments above the definition of\r
+ tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE. */\r
+ #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */\r
+ uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */\r
+ #endif\r
+\r
+ #if( INCLUDE_xTaskAbortDelay == 1 )\r
+ uint8_t ucDelayAborted;\r
+ #endif\r
+\r
+} tskTCB;\r
+\r
+/* The old tskTCB name is maintained above then typedefed to the new TCB_t name\r
+below to enable the use of older kernel aware debuggers. */\r
+typedef tskTCB TCB_t;\r
+\r
+/*lint -save -e956 A manual analysis and inspection has been used to determine\r
+which static variables must be declared volatile. */\r
+\r
+PRIVILEGED_DATA TCB_t * volatile pxCurrentTCB = NULL;\r
+\r
+/* Lists for ready and blocked tasks. --------------------*/\r
+PRIVILEGED_DATA static List_t pxReadyTasksLists[ configMAX_PRIORITIES ];/*< Prioritised ready tasks. */\r
+PRIVILEGED_DATA static List_t xDelayedTaskList1; /*< Delayed tasks. */\r
+PRIVILEGED_DATA static List_t xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */\r
+PRIVILEGED_DATA static List_t * volatile pxDelayedTaskList; /*< Points to the delayed task list currently being used. */\r
+PRIVILEGED_DATA static List_t * 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 List_t xPendingReadyList; /*< Tasks that have been readied while the scheduler was suspended. They will be moved to the ready list when the scheduler is resumed. */\r
+\r
+#if( INCLUDE_vTaskDelete == 1 )\r
+\r
+ PRIVILEGED_DATA static List_t xTasksWaitingTermination; /*< Tasks that have been deleted - but their memory not yet freed. */\r
+ PRIVILEGED_DATA static volatile UBaseType_t uxDeletedTasksWaitingCleanUp = ( UBaseType_t ) 0U;\r
+\r
+#endif\r
+\r
+#if ( INCLUDE_vTaskSuspend == 1 )\r
+\r
+ PRIVILEGED_DATA static List_t xSuspendedTaskList; /*< Tasks that are currently suspended. */\r
+\r
+#endif\r
+\r
+/* Other file private variables. --------------------------------*/\r
+PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;\r
+PRIVILEGED_DATA static volatile TickType_t xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT;\r
+PRIVILEGED_DATA static volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY;\r
+PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning = pdFALSE;\r
+PRIVILEGED_DATA static volatile UBaseType_t uxPendedTicks = ( UBaseType_t ) 0U;\r
+PRIVILEGED_DATA static volatile BaseType_t xYieldPending = pdFALSE;\r
+PRIVILEGED_DATA static volatile BaseType_t xNumOfOverflows = ( BaseType_t ) 0;\r
+PRIVILEGED_DATA static UBaseType_t uxTaskNumber = ( UBaseType_t ) 0U;\r
+PRIVILEGED_DATA static volatile TickType_t xNextTaskUnblockTime = ( TickType_t ) 0U; /* Initialised to portMAX_DELAY before the scheduler starts. */\r
+PRIVILEGED_DATA static TaskHandle_t xIdleTaskHandle = NULL; /*< Holds the handle of the idle task. The idle task is created automatically when the scheduler is started. */\r
+\r
+/* Context switches are held pending while the scheduler is suspended. Also,\r
+interrupts must not manipulate the xStateListItem of a TCB, or any of the\r
+lists the xStateListItem can be referenced from, if the scheduler is suspended.\r
+If an interrupt needs to unblock a task while the scheduler is suspended then it\r
+moves the task's event list item into the xPendingReadyList, ready for the\r
+kernel to move the task from the pending ready list into the real ready list\r
+when the scheduler is unsuspended. The pending ready list itself can only be\r
+accessed from a critical section. */\r
+PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended = ( UBaseType_t ) pdFALSE;\r
+\r
+#if ( configGENERATE_RUN_TIME_STATS == 1 )\r
+\r
+ PRIVILEGED_DATA static uint32_t ulTaskSwitchedInTime = 0UL; /*< Holds the value of a timer/counter the last time a task was switched in. */\r
+ PRIVILEGED_DATA static uint32_t ulTotalRunTime = 0UL; /*< Holds the total amount of execution time as defined by the run time counter clock. */\r
+\r
+#endif\r
+\r
+/*lint -restore */\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Callback function prototypes. --------------------------*/\r
+#if( configCHECK_FOR_STACK_OVERFLOW > 0 )\r
+\r
+ extern void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName );\r
+\r
+#endif\r
+\r
+#if( configUSE_TICK_HOOK > 0 )\r
+\r
+ extern void vApplicationTickHook( void );\r
+\r
+#endif\r
+\r
+#if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+\r
+ extern void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );\r
+\r
+#endif\r
+\r
+/* File private functions. --------------------------------*/\r
+\r
+/**\r
+ * Utility task that simply returns pdTRUE if the task referenced by xTask is\r
+ * currently in the Suspended state, or pdFALSE if the task referenced by xTask\r
+ * is in any other state.\r
+ */\r
+#if ( INCLUDE_vTaskSuspend == 1 )\r
+\r
+ static BaseType_t prvTaskIsTaskSuspended( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;\r
+\r
+#endif /* INCLUDE_vTaskSuspend */\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 ) PRIVILEGED_FUNCTION;\r
+\r
+/*\r
+ * The idle task, which as all tasks is implemented as a never ending loop.\r
+ * The idle task is automatically created and added to the ready lists upon\r
+ * creation of the first user task.\r
+ *\r
+ * The portTASK_FUNCTION_PROTO() macro is used to allow port/compiler specific\r
+ * language extensions. The equivalent prototype for this function is:\r
+ *\r
+ * void prvIdleTask( void *pvParameters );\r
+ *\r
+ */\r
+static portTASK_FUNCTION_PROTO( prvIdleTask, pvParameters );\r
+\r
+/*\r
+ * Utility to free all memory allocated by the scheduler to hold a TCB,\r
+ * including the stack pointed to by the TCB.\r
+ *\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 )\r
+\r
+ static void prvDeleteTCB( TCB_t *pxTCB ) PRIVILEGED_FUNCTION;\r
+\r
+#endif\r
+\r
+/*\r
+ * Used only by the idle task. This checks to see if anything has been placed\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 ) 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( TickType_t xTicksToWait, const BaseType_t xCanBlockIndefinitely ) PRIVILEGED_FUNCTION;\r
+\r
+/*\r
+ * Fills an TaskStatus_t structure with information on each task that is\r
+ * referenced from the pxList list (which may be a ready list, a delayed list,\r
+ * a suspended list, etc.).\r
+ *\r
+ * THIS FUNCTION IS INTENDED FOR DEBUGGING ONLY, AND SHOULD NOT BE CALLED FROM\r
+ * NORMAL APPLICATION CODE.\r
+ */\r
+#if ( configUSE_TRACE_FACILITY == 1 )\r
+\r
+ static UBaseType_t prvListTasksWithinSingleList( TaskStatus_t *pxTaskStatusArray, List_t *pxList, eTaskState eState ) PRIVILEGED_FUNCTION;\r
+\r
+#endif\r
+\r
+/*\r
+ * Searches pxList for a task with name pcNameToQuery - returning a handle to\r
+ * the task if it is found, or NULL if the task is not found.\r
+ */\r
+#if ( INCLUDE_xTaskGetHandle == 1 )\r
+\r
+ static TCB_t *prvSearchForNameWithinSingleList( List_t *pxList, const char pcNameToQuery[] ) PRIVILEGED_FUNCTION;\r
+\r
+#endif\r
\r
/*\r
* When a task is created, the stack of the task is filled with a known value.\r
*/\r
static void prvResetNextTaskUnblockTime( void );\r
\r
-/*-----------------------------------------------------------*/\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )\r
\r
-BaseType_t xTaskGenericCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask, StackType_t * const puxStackBuffer, const MemoryRegion_t * const xRegions ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
-{\r
-BaseType_t xReturn;\r
-TCB_t * pxNewTCB;\r
+ /*\r
+ * Helper function used to pad task names with spaces when printing out\r
+ * human readable tables of task information.\r
+ */\r
+ static char *prvWriteNameToBuffer( char *pcBuffer, const char *pcTaskName ) PRIVILEGED_FUNCTION;\r
\r
- configASSERT( pxTaskCode );\r
- configASSERT( ( ( uxPriority & ( ~portPRIVILEGE_BIT ) ) < configMAX_PRIORITIES ) );\r
+#endif\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, puxStackBuffer );\r
+/*\r
+ * Called after a Task_t structure has been allocated either statically or\r
+ * dynamically to fill in the structure's members.\r
+ */\r
+static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,\r
+ const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+ const uint32_t ulStackDepth,\r
+ void * const pvParameters,\r
+ UBaseType_t uxPriority,\r
+ TaskHandle_t * const pxCreatedTask,\r
+ TCB_t *pxNewTCB,\r
+ const MemoryRegion_t * const xRegions ) PRIVILEGED_FUNCTION;\r
\r
- if( pxNewTCB != NULL )\r
- {\r
- StackType_t *pxTopOfStack;\r
+/*\r
+ * Called after a new task has been created and initialised to place the task\r
+ * under the control of the scheduler.\r
+ */\r
+static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;\r
\r
- #if( portUSING_MPU_WRAPPERS == 1 )\r
- /* Should the task be created in privileged mode? */\r
- BaseType_t 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
+ * freertos_tasks_c_additions_init() should only be called if the user definable\r
+ * macro FREERTOS_TASKS_C_ADDITIONS_INIT() is defined, as that is the only macro\r
+ * called by the function.\r
+ */\r
+#ifdef FREERTOS_TASKS_C_ADDITIONS_INIT\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 vice 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
- {\r
- pxTopOfStack = pxNewTCB->pxStack + ( usStackDepth - ( uint16_t ) 1 );\r
- pxTopOfStack = ( StackType_t * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ( portPOINTER_SIZE_TYPE ) ~portBYTE_ALIGNMENT_MASK ) ); /*lint !e923 MISRA exception. Avoiding casts between pointers and integers is not practical. Size differences accounted for using portPOINTER_SIZE_TYPE type. */\r
+ static void freertos_tasks_c_additions_init( void ) PRIVILEGED_FUNCTION;\r
\r
- /* Check the alignment of the calculated top of stack is correct. */\r
- configASSERT( ( ( ( uint32_t ) pxTopOfStack & ( uint32_t ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
- }\r
- #else /* portSTACK_GROWTH */\r
- {\r
- pxTopOfStack = pxNewTCB->pxStack;\r
+#endif\r
\r
- /* Check the alignment of the stack buffer is correct. */\r
- configASSERT( ( ( ( uint32_t ) pxNewTCB->pxStack & ( uint32_t ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
+/*-----------------------------------------------------------*/\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 /* portSTACK_GROWTH */\r
+#if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
\r
- /* Setup the newly allocated TCB with the initial state of the task. */\r
- prvInitialiseTCBVariables( pxNewTCB, pcName, uxPriority, xRegions, usStackDepth );\r
+ TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,\r
+ const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+ const uint32_t ulStackDepth,\r
+ void * const pvParameters,\r
+ UBaseType_t uxPriority,\r
+ StackType_t * const puxStackBuffer,\r
+ StaticTask_t * const pxTaskBuffer )\r
+ {\r
+ TCB_t *pxNewTCB;\r
+ TaskHandle_t xReturn;\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
- #if( portUSING_MPU_WRAPPERS == 1 )\r
- {\r
- pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters, xRunPrivileged );\r
- }\r
- #else /* portUSING_MPU_WRAPPERS */\r
+ configASSERT( puxStackBuffer != NULL );\r
+ configASSERT( pxTaskBuffer != NULL );\r
+\r
+ #if( configASSERT_DEFINED == 1 )\r
{\r
- pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters );\r
+ /* Sanity check that the size of the structure used to declare a\r
+ variable of type StaticTask_t equals the size of the real task\r
+ structure. */\r
+ volatile size_t xSize = sizeof( StaticTask_t );\r
+ configASSERT( xSize == sizeof( TCB_t ) );\r
}\r
- #endif /* portUSING_MPU_WRAPPERS */\r
+ #endif /* configASSERT_DEFINED */\r
\r
- if( ( void * ) pxCreatedTask != NULL )\r
+\r
+ if( ( pxTaskBuffer != NULL ) && ( puxStackBuffer != 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 = ( TaskHandle_t ) pxNewTCB;\r
+ /* The memory used for the task's TCB and stack are passed into this\r
+ function - use them. */\r
+ pxNewTCB = ( TCB_t * ) pxTaskBuffer; /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */\r
+ pxNewTCB->pxStack = ( StackType_t * ) puxStackBuffer;\r
+\r
+ #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */\r
+ {\r
+ /* Tasks can be created statically or dynamically, so note this\r
+ task was created statically in case the task is later deleted. */\r
+ pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB;\r
+ }\r
+ #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
+\r
+ prvInitialiseNewTask( pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, &xReturn, pxNewTCB, NULL );\r
+ prvAddNewTaskToReadyList( pxNewTCB );\r
}\r
else\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ xReturn = NULL;\r
}\r
\r
- /* Ensure interrupts don't access the task lists while they are being\r
- updated. */\r
- taskENTER_CRITICAL();\r
- {\r
- uxCurrentNumberOfTasks++;\r
- if( pxCurrentTCB == NULL )\r
- {\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
+ return xReturn;\r
+ }\r
\r
- if( uxCurrentNumberOfTasks == ( UBaseType_t ) 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
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- }\r
- else\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
- if( xSchedulerRunning == pdFALSE )\r
- {\r
- if( pxCurrentTCB->uxPriority <= uxPriority )\r
- {\r
- pxCurrentTCB = pxNewTCB;\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- }\r
+#endif /* SUPPORT_STATIC_ALLOCATION */\r
+/*-----------------------------------------------------------*/\r
\r
- uxTaskNumber++;\r
+#if( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )\r
+\r
+ BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask )\r
+ {\r
+ TCB_t *pxNewTCB;\r
+ BaseType_t xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;\r
+\r
+ configASSERT( pxTaskDefinition->puxStackBuffer != NULL );\r
+ configASSERT( pxTaskDefinition->pxTaskBuffer != NULL );\r
\r
- #if ( configUSE_TRACE_FACILITY == 1 )\r
+ if( ( pxTaskDefinition->puxStackBuffer != NULL ) && ( pxTaskDefinition->pxTaskBuffer != NULL ) )\r
+ {\r
+ /* Allocate space for the TCB. Where the memory comes from depends\r
+ on the implementation of the port malloc function and whether or\r
+ not static allocation is being used. */\r
+ pxNewTCB = ( TCB_t * ) pxTaskDefinition->pxTaskBuffer;\r
+\r
+ /* Store the stack location in the TCB. */\r
+ pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer;\r
+\r
+ #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 )\r
{\r
- /* Add a counter into the TCB for tracing only. */\r
- pxNewTCB->uxTCBNumber = uxTaskNumber;\r
+ /* Tasks can be created statically or dynamically, so note this\r
+ task was created statically in case the task is later deleted. */\r
+ pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB;\r
}\r
- #endif /* configUSE_TRACE_FACILITY */\r
- traceTASK_CREATE( pxNewTCB );\r
+ #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
\r
- prvAddTaskToReadyList( pxNewTCB );\r
+ prvInitialiseNewTask( pxTaskDefinition->pvTaskCode,\r
+ pxTaskDefinition->pcName,\r
+ ( uint32_t ) pxTaskDefinition->usStackDepth,\r
+ pxTaskDefinition->pvParameters,\r
+ pxTaskDefinition->uxPriority,\r
+ pxCreatedTask, pxNewTCB,\r
+ pxTaskDefinition->xRegions );\r
\r
+ prvAddNewTaskToReadyList( pxNewTCB );\r
xReturn = pdPASS;\r
- portSETUP_TCB( pxNewTCB );\r
}\r
- taskEXIT_CRITICAL();\r
- }\r
- else\r
- {\r
- xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;\r
- traceTASK_CREATE_FAILED();\r
+\r
+ return xReturn;\r
}\r
\r
- if( xReturn == pdPASS )\r
+#endif /* ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( ( portUSING_MPU_WRAPPERS == 1 ) && ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) )\r
+\r
+ BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask )\r
{\r
- if( xSchedulerRunning != pdFALSE )\r
+ TCB_t *pxNewTCB;\r
+ BaseType_t xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;\r
+\r
+ configASSERT( pxTaskDefinition->puxStackBuffer );\r
+\r
+ if( pxTaskDefinition->puxStackBuffer != NULL )\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_IF_USING_PREEMPTION();\r
- }\r
- else\r
+ /* Allocate space for the TCB. Where the memory comes from depends\r
+ on the implementation of the port malloc function and whether or\r
+ not static allocation is being used. */\r
+ pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );\r
+\r
+ if( pxNewTCB != NULL )\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ /* Store the stack location in the TCB. */\r
+ pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer;\r
+\r
+ /* Tasks can be created statically or dynamically, so note\r
+ this task had a statically allocated stack in case it is\r
+ later deleted. The TCB was allocated dynamically. */\r
+ pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_ONLY;\r
+\r
+ prvInitialiseNewTask( pxTaskDefinition->pvTaskCode,\r
+ pxTaskDefinition->pcName,\r
+ ( uint32_t ) pxTaskDefinition->usStackDepth,\r
+ pxTaskDefinition->pvParameters,\r
+ pxTaskDefinition->uxPriority,\r
+ pxCreatedTask, pxNewTCB,\r
+ pxTaskDefinition->xRegions );\r
+\r
+ prvAddNewTaskToReadyList( pxNewTCB );\r
+ xReturn = pdPASS;\r
}\r
}\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+\r
+ return xReturn;\r
}\r
\r
- return xReturn;\r
-}\r
+#endif /* portUSING_MPU_WRAPPERS */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( INCLUDE_vTaskDelete == 1 )\r
+#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\r
\r
- void vTaskDelete( TaskHandle_t xTaskToDelete )\r
+ BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,\r
+ const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+ const configSTACK_DEPTH_TYPE usStackDepth,\r
+ void * const pvParameters,\r
+ UBaseType_t uxPriority,\r
+ TaskHandle_t * const pxCreatedTask )\r
{\r
- TCB_t *pxTCB;\r
+ TCB_t *pxNewTCB;\r
+ BaseType_t xReturn;\r
\r
- taskENTER_CRITICAL();\r
+ /* If the stack grows down then allocate the stack then the TCB so the stack\r
+ does not grow into the TCB. Likewise if the stack grows up then allocate\r
+ the TCB then the stack. */\r
+ #if( portSTACK_GROWTH > 0 )\r
{\r
- /* If null is passed in here then it is the calling task that is\r
- being deleted. */\r
- pxTCB = prvGetTCBFromHandle( xTaskToDelete );\r
+ /* Allocate space for the TCB. Where the memory comes from depends on\r
+ the implementation of the port malloc function and whether or not static\r
+ allocation is being used. */\r
+ pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );\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
- if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
+ if( pxNewTCB != NULL )\r
{\r
- taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
-\r
- /* Is the task waiting on an event also? */\r
- if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
- {\r
- ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
-\r
- vListInsertEnd( &xTasksWaitingTermination, &( pxTCB->xGenericListItem ) );\r
-\r
- /* Increment the ucTasksDeleted variable so the idle task knows\r
- there is a task that has been deleted and that it should therefore\r
- check the xTasksWaitingTermination list. */\r
- ++uxTasksDeleted;\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 = ( StackType_t * ) pvPortMalloc( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
\r
- /* Increment the uxTaskNumberVariable also so kernel aware debuggers\r
- can detect that the task lists need re-generating. */\r
- uxTaskNumber++;\r
-\r
- traceTASK_DELETE( pxTCB );\r
- }\r
- taskEXIT_CRITICAL();\r
-\r
- /* Force a reschedule if it is the currently running task that has just\r
- been deleted. */\r
- if( xSchedulerRunning != pdFALSE )\r
- {\r
- if( pxTCB == pxCurrentTCB )\r
- {\r
- configASSERT( uxSchedulerSuspended == 0 );\r
-\r
- /* The pre-delete hook is primarily for the Windows simulator,\r
- in which Windows specific clean up operations are performed,\r
- after which it is not possible to yield away from this task -\r
- hence xYieldPending is used to latch that a context switch is\r
- required. */\r
- portPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPending );\r
- portYIELD_WITHIN_API();\r
- }\r
- else\r
- {\r
- /* Reset the next expected unblock time in case it referred to\r
- the task that has just been deleted. */\r
- taskENTER_CRITICAL();\r
+ if( pxNewTCB->pxStack == NULL )\r
{\r
- prvResetNextTaskUnblockTime();\r
+ /* Could not allocate the stack. Delete the allocated TCB. */\r
+ vPortFree( pxNewTCB );\r
+ pxNewTCB = NULL;\r
}\r
- taskEXIT_CRITICAL();\r
}\r
}\r
- }\r
-\r
-#endif /* INCLUDE_vTaskDelete */\r
-/*-----------------------------------------------------------*/\r
-\r
-#if ( INCLUDE_vTaskDelayUntil == 1 )\r
-\r
- void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement )\r
- {\r
- TickType_t xTimeToWake;\r
- BaseType_t xAlreadyYielded, xShouldDelay = pdFALSE;\r
-\r
- configASSERT( pxPreviousWakeTime );\r
- configASSERT( ( xTimeIncrement > 0U ) );\r
- configASSERT( uxSchedulerSuspended == 0 );\r
-\r
- vTaskSuspendAll();\r
+ #else /* portSTACK_GROWTH */\r
{\r
- /* Minor optimisation. The tick count cannot change in this\r
- block. */\r
- const TickType_t xConstTickCount = xTickCount;\r
-\r
- /* Generate the tick time at which the task wants to wake. */\r
- xTimeToWake = *pxPreviousWakeTime + xTimeIncrement;\r
-\r
- if( xConstTickCount < *pxPreviousWakeTime )\r
- {\r
- /* The tick count has overflowed since this function was\r
- lasted called. In this case the only time we should ever\r
- actually delay is if the wake time has also overflowed,\r
- and the wake time is greater than the tick time. When this\r
- is the case it is as if neither time had overflowed. */\r
- if( ( xTimeToWake < *pxPreviousWakeTime ) && ( xTimeToWake > xConstTickCount ) )\r
- {\r
- xShouldDelay = pdTRUE;\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- }\r
- else\r
- {\r
- /* The tick time has not overflowed. In this case we will\r
- delay if either the wake time has overflowed, and/or the\r
- tick time is less than the wake time. */\r
- if( ( xTimeToWake < *pxPreviousWakeTime ) || ( xTimeToWake > xConstTickCount ) )\r
- {\r
- xShouldDelay = pdTRUE;\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- }\r
+ StackType_t *pxStack;\r
\r
- /* Update the wake time ready for the next call. */\r
- *pxPreviousWakeTime = xTimeToWake;\r
+ /* Allocate space for the stack used by the task being created. */\r
+ pxStack = ( StackType_t * ) pvPortMalloc( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
\r
- if( xShouldDelay != pdFALSE )\r
+ if( pxStack != NULL )\r
{\r
- traceTASK_DELAY_UNTIL();\r
+ /* Allocate space for the TCB. */\r
+ pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) ); /*lint !e961 MISRA exception as the casts are only redundant for some paths. */\r
\r
- /* Remove the task from the ready list before adding it to the\r
- blocked list as the same list item is used for both lists. */\r
- if( uxListRemove( &( pxCurrentTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
+ if( pxNewTCB != NULL )\r
{\r
- /* The current task must be in a ready list, so there is\r
- no need to check, and the port reset macro can be called\r
- directly. */\r
- portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
+ /* Store the stack location in the TCB. */\r
+ pxNewTCB->pxStack = pxStack;\r
}\r
else\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ /* The stack cannot be used as the TCB was not created. Free\r
+ it again. */\r
+ vPortFree( pxStack );\r
}\r
-\r
- prvAddCurrentTaskToDelayedList( xTimeToWake );\r
}\r
else\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ pxNewTCB = NULL;\r
}\r
}\r
- xAlreadyYielded = xTaskResumeAll();\r
+ #endif /* portSTACK_GROWTH */\r
\r
- /* Force a reschedule if xTaskResumeAll has not already done so, we may\r
- have put ourselves to sleep. */\r
- if( xAlreadyYielded == pdFALSE )\r
+ if( pxNewTCB != NULL )\r
{\r
- portYIELD_WITHIN_API();\r
+ #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */\r
+ {\r
+ /* Tasks can be created statically or dynamically, so note this\r
+ task was created dynamically in case it is later deleted. */\r
+ pxNewTCB->ucStaticallyAllocated = tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB;\r
+ }\r
+ #endif /* configSUPPORT_STATIC_ALLOCATION */\r
+\r
+ prvInitialiseNewTask( pxTaskCode, pcName, ( uint32_t ) usStackDepth, pvParameters, uxPriority, pxCreatedTask, pxNewTCB, NULL );\r
+ prvAddNewTaskToReadyList( pxNewTCB );\r
+ xReturn = pdPASS;\r
}\r
else\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;\r
}\r
+\r
+ return xReturn;\r
}\r
\r
-#endif /* INCLUDE_vTaskDelayUntil */\r
+#endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( INCLUDE_vTaskDelay == 1 )\r
-\r
- void vTaskDelay( const TickType_t xTicksToDelay )\r
- {\r
- TickType_t xTimeToWake;\r
- BaseType_t xAlreadyYielded = pdFALSE;\r
-\r
+static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,\r
+ const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+ const uint32_t ulStackDepth,\r
+ void * const pvParameters,\r
+ UBaseType_t uxPriority,\r
+ TaskHandle_t * const pxCreatedTask,\r
+ TCB_t *pxNewTCB,\r
+ const MemoryRegion_t * const xRegions )\r
+{\r
+StackType_t *pxTopOfStack;\r
+UBaseType_t x;\r
\r
- /* A delay time of zero just forces a reschedule. */\r
- if( xTicksToDelay > ( TickType_t ) 0U )\r
+ #if( portUSING_MPU_WRAPPERS == 1 )\r
+ /* Should the task be created in privileged mode? */\r
+ BaseType_t xRunPrivileged;\r
+ if( ( uxPriority & portPRIVILEGE_BIT ) != 0U )\r
{\r
- configASSERT( uxSchedulerSuspended == 0 );\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
- This task cannot be in an event list as it is the currently\r
- executing task. */\r
-\r
- /* Calculate the time to wake - this may overflow but this is\r
- not a problem. */\r
- xTimeToWake = xTickCount + xTicksToDelay;\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
- if( uxListRemove( &( pxCurrentTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
- {\r
- /* The current task must be in a ready list, so there is\r
- no need to check, and the port reset macro can be called\r
- directly. */\r
- portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- prvAddCurrentTaskToDelayedList( xTimeToWake );\r
- }\r
- xAlreadyYielded = xTaskResumeAll();\r
+ xRunPrivileged = pdTRUE;\r
}\r
else\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ xRunPrivileged = pdFALSE;\r
}\r
+ uxPriority &= ~portPRIVILEGE_BIT;\r
+ #endif /* portUSING_MPU_WRAPPERS == 1 */\r
\r
- /* Force a reschedule if xTaskResumeAll has not already done so, we may\r
- have put ourselves to sleep. */\r
- if( xAlreadyYielded == pdFALSE )\r
- {\r
- portYIELD_WITHIN_API();\r
- }\r
- else\r
+ /* Avoid dependency on memset() if it is not required. */\r
+ #if( tskSET_NEW_STACKS_TO_KNOWN_VALUE == 1 )\r
+ {\r
+ /* Fill the stack with a known value to assist debugging. */\r
+ ( void ) memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) ulStackDepth * sizeof( StackType_t ) );\r
+ }\r
+ #endif /* tskSET_NEW_STACKS_TO_KNOWN_VALUE */\r
+\r
+ /* Calculate the top of stack address. This depends on whether the stack\r
+ grows from high memory to low (as per the 80x86) or vice versa.\r
+ portSTACK_GROWTH is used to make the result positive or negative as required\r
+ by the port. */\r
+ #if( portSTACK_GROWTH < 0 )\r
+ {\r
+ pxTopOfStack = pxNewTCB->pxStack + ( ulStackDepth - ( uint32_t ) 1 );\r
+ pxTopOfStack = ( StackType_t * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); /*lint !e923 MISRA exception. Avoiding casts between pointers and integers is not practical. Size differences accounted for using portPOINTER_SIZE_TYPE type. */\r
+\r
+ /* Check the alignment of the calculated top of stack is correct. */\r
+ configASSERT( ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack & ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
+\r
+ #if( configRECORD_STACK_HIGH_ADDRESS == 1 )\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ /* Also record the stack's high address, which may assist\r
+ debugging. */\r
+ pxNewTCB->pxEndOfStack = pxTopOfStack;\r
}\r
+ #endif /* configRECORD_STACK_HIGH_ADDRESS */\r
}\r
+ #else /* portSTACK_GROWTH */\r
+ {\r
+ pxTopOfStack = pxNewTCB->pxStack;\r
\r
-#endif /* INCLUDE_vTaskDelay */\r
-/*-----------------------------------------------------------*/\r
+ /* Check the alignment of the stack buffer is correct. */\r
+ configASSERT( ( ( ( portPOINTER_SIZE_TYPE ) pxNewTCB->pxStack & ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
\r
-#if ( INCLUDE_eTaskGetState == 1 )\r
+ /* The other extreme of the stack space is required if stack checking is\r
+ performed. */\r
+ pxNewTCB->pxEndOfStack = pxNewTCB->pxStack + ( ulStackDepth - ( uint32_t ) 1 );\r
+ }\r
+ #endif /* portSTACK_GROWTH */\r
\r
- eTaskState eTaskGetState( TaskHandle_t xTask )\r
+ /* Store the task name in the TCB. */\r
+ for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ )\r
{\r
- eTaskState eReturn;\r
- List_t *pxStateList;\r
- const TCB_t * const pxTCB = ( TCB_t * ) xTask;\r
-\r
- configASSERT( pxTCB );\r
+ pxNewTCB->pcTaskName[ x ] = pcName[ x ];\r
\r
- if( pxTCB == pxCurrentTCB )\r
+ /* Don't copy all configMAX_TASK_NAME_LEN if the string is shorter than\r
+ configMAX_TASK_NAME_LEN characters just in case the memory after the\r
+ string is not accessible (extremely unlikely). */\r
+ if( pcName[ x ] == 0x00 )\r
{\r
- /* The task calling this function is querying its own state. */\r
- eReturn = eRunning;\r
+ break;\r
}\r
else\r
{\r
- taskENTER_CRITICAL();\r
- {\r
- pxStateList = ( List_t * ) listLIST_ITEM_CONTAINER( &( pxTCB->xGenericListItem ) );\r
- }\r
- taskEXIT_CRITICAL();\r
-\r
- if( ( pxStateList == pxDelayedTaskList ) || ( pxStateList == pxOverflowDelayedTaskList ) )\r
- {\r
- /* The task being queried is referenced from one of the Blocked\r
- lists. */\r
- eReturn = eBlocked;\r
- }\r
-\r
- #if ( INCLUDE_vTaskSuspend == 1 )\r
- else if( pxStateList == &xSuspendedTaskList )\r
- {\r
- /* The task being queried is referenced from the suspended\r
- list. Is it genuinely suspended or is it block\r
- indefinitely? */\r
- if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL )\r
- {\r
- eReturn = eSuspended;\r
- }\r
- else\r
- {\r
- eReturn = eBlocked;\r
- }\r
- }\r
- #endif\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
\r
- #if ( INCLUDE_vTaskDelete == 1 )\r
- else if( pxStateList == &xTasksWaitingTermination )\r
- {\r
- /* The task being queried is referenced from the deleted\r
- tasks list. */\r
- eReturn = eDeleted;\r
- }\r
- #endif\r
+ /* Ensure the name string is terminated in the case that the string length\r
+ was greater or equal to configMAX_TASK_NAME_LEN. */\r
+ pxNewTCB->pcTaskName[ configMAX_TASK_NAME_LEN - 1 ] = '\0';\r
\r
- else\r
- {\r
- /* If the task is not in any other state, it must be in the\r
- Ready (including pending ready) state. */\r
- eReturn = eReady;\r
- }\r
- }\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 >= ( UBaseType_t ) configMAX_PRIORITIES )\r
+ {\r
+ uxPriority = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) 1U;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
\r
- return eReturn;\r
+ pxNewTCB->uxPriority = uxPriority;\r
+ #if ( configUSE_MUTEXES == 1 )\r
+ {\r
+ pxNewTCB->uxBasePriority = uxPriority;\r
+ pxNewTCB->uxMutexesHeld = 0;\r
}\r
+ #endif /* configUSE_MUTEXES */\r
\r
-#endif /* INCLUDE_eTaskGetState */\r
-/*-----------------------------------------------------------*/\r
+ vListInitialiseItem( &( pxNewTCB->xStateListItem ) );\r
+ vListInitialiseItem( &( pxNewTCB->xEventListItem ) );\r
\r
-#if ( INCLUDE_uxTaskPriorityGet == 1 )\r
+ /* Set the pxNewTCB as a link back from the ListItem_t. This is so we can get\r
+ back to the containing TCB from a generic item in a list. */\r
+ listSET_LIST_ITEM_OWNER( &( pxNewTCB->xStateListItem ), pxNewTCB );\r
\r
- UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask )\r
+ /* Event lists are always in priority order. */\r
+ listSET_LIST_ITEM_VALUE( &( pxNewTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ listSET_LIST_ITEM_OWNER( &( pxNewTCB->xEventListItem ), pxNewTCB );\r
+\r
+ #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
{\r
- TCB_t *pxTCB;\r
- UBaseType_t uxReturn;\r
+ pxNewTCB->uxCriticalNesting = ( UBaseType_t ) 0U;\r
+ }\r
+ #endif /* portCRITICAL_NESTING_IN_TCB */\r
\r
- taskENTER_CRITICAL();\r
+ #if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
+ {\r
+ pxNewTCB->pxTaskTag = NULL;\r
+ }\r
+ #endif /* configUSE_APPLICATION_TASK_TAG */\r
+\r
+ #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
+ {\r
+ pxNewTCB->ulRunTimeCounter = 0UL;\r
+ }\r
+ #endif /* configGENERATE_RUN_TIME_STATS */\r
+\r
+ #if ( portUSING_MPU_WRAPPERS == 1 )\r
+ {\r
+ vPortStoreTaskMPUSettings( &( pxNewTCB->xMPUSettings ), xRegions, pxNewTCB->pxStack, ulStackDepth );\r
+ }\r
+ #else\r
+ {\r
+ /* Avoid compiler warning about unreferenced parameter. */\r
+ ( void ) xRegions;\r
+ }\r
+ #endif\r
+\r
+ #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )\r
+ {\r
+ for( x = 0; x < ( UBaseType_t ) configNUM_THREAD_LOCAL_STORAGE_POINTERS; x++ )\r
{\r
- /* If null is passed in here then we are changing the\r
- priority of the calling function. */\r
- pxTCB = prvGetTCBFromHandle( xTask );\r
- uxReturn = pxTCB->uxPriority;\r
+ pxNewTCB->pvThreadLocalStoragePointers[ x ] = NULL;\r
}\r
- taskEXIT_CRITICAL();\r
-\r
- return uxReturn;\r
}\r
+ #endif\r
\r
-#endif /* INCLUDE_uxTaskPriorityGet */\r
-/*-----------------------------------------------------------*/\r
+ #if ( configUSE_TASK_NOTIFICATIONS == 1 )\r
+ {\r
+ pxNewTCB->ulNotifiedValue = 0;\r
+ pxNewTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION;\r
+ }\r
+ #endif\r
\r
-#if ( INCLUDE_vTaskPrioritySet == 1 )\r
+ #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
+ {\r
+ /* Initialise this task's Newlib reent structure. */\r
+ _REENT_INIT_PTR( ( &( pxNewTCB->xNewLib_reent ) ) );\r
+ }\r
+ #endif\r
\r
- void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority )\r
+ #if( INCLUDE_xTaskAbortDelay == 1 )\r
{\r
- TCB_t *pxTCB;\r
- UBaseType_t uxCurrentBasePriority, uxPriorityUsedOnEntry;\r
- BaseType_t xYieldRequired = pdFALSE;\r
+ pxNewTCB->ucDelayAborted = pdFALSE;\r
+ }\r
+ #endif\r
\r
- configASSERT( ( uxNewPriority < configMAX_PRIORITIES ) );\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
+ #if( portUSING_MPU_WRAPPERS == 1 )\r
+ {\r
+ pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters, xRunPrivileged );\r
+ }\r
+ #else /* portUSING_MPU_WRAPPERS */\r
+ {\r
+ pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters );\r
+ }\r
+ #endif /* portUSING_MPU_WRAPPERS */\r
\r
- /* Ensure the new priority is valid. */\r
- if( uxNewPriority >= ( UBaseType_t ) configMAX_PRIORITIES )\r
- {\r
- uxNewPriority = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) 1U;\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ if( ( void * ) pxCreatedTask != NULL )\r
+ {\r
+ /* Pass the handle out in an anonymous way. The handle can be used to\r
+ change the created task's priority, delete the created task, etc.*/\r
+ *pxCreatedTask = ( TaskHandle_t ) pxNewTCB;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
\r
- taskENTER_CRITICAL();\r
+static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )\r
+{\r
+ /* Ensure interrupts don't access the task lists while the lists are being\r
+ updated. */\r
+ taskENTER_CRITICAL();\r
+ {\r
+ uxCurrentNumberOfTasks++;\r
+ if( pxCurrentTCB == NULL )\r
{\r
- /* If null is passed in here then it is the priority of the calling\r
- task that is being changed. */\r
- pxTCB = prvGetTCBFromHandle( xTask );\r
-\r
- traceTASK_PRIORITY_SET( pxTCB, uxNewPriority );\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
- #if ( configUSE_MUTEXES == 1 )\r
+ if( uxCurrentNumberOfTasks == ( UBaseType_t ) 1 )\r
{\r
- uxCurrentBasePriority = pxTCB->uxBasePriority;\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
- #else\r
+ else\r
{\r
- uxCurrentBasePriority = pxTCB->uxPriority;\r
+ mtCOVERAGE_TEST_MARKER();\r
}\r
- #endif\r
-\r
- if( uxCurrentBasePriority != uxNewPriority )\r
+ }\r
+ else\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
+ if( xSchedulerRunning == pdFALSE )\r
{\r
- /* The priority change may have readied a task of higher\r
- priority than the calling task. */\r
- if( uxNewPriority > uxCurrentBasePriority )\r
+ if( pxCurrentTCB->uxPriority <= pxNewTCB->uxPriority )\r
{\r
- if( pxTCB != pxCurrentTCB )\r
- {\r
- /* The priority of a task other than the currently\r
- running task is being raised. Is the priority being\r
- raised above that of the running task? */\r
- if( uxNewPriority >= pxCurrentTCB->uxPriority )\r
- {\r
- xYieldRequired = pdTRUE;\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- }\r
- else\r
- {\r
- /* The priority of the running task is being raised,\r
- but the running task must already be the highest\r
- priority task able to run so no yield is required. */\r
- }\r
- }\r
- else if( pxTCB == pxCurrentTCB )\r
- {\r
- /* Setting the priority of the running task down means\r
- there may now be another task of higher priority that\r
- is ready to execute. */\r
- xYieldRequired = pdTRUE;\r
+ pxCurrentTCB = pxNewTCB;\r
}\r
else\r
{\r
- /* Setting the priority of any other task down does not\r
- require a yield as the running task must be above the\r
- new priority of the task being modified. */\r
+ mtCOVERAGE_TEST_MARKER();\r
}\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
\r
- /* Remember the ready list the task might be referenced from\r
- before its uxPriority member is changed so the\r
- taskRESET_READY_PRIORITY() macro can function correctly. */\r
- uxPriorityUsedOnEntry = pxTCB->uxPriority;\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
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\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
+ uxTaskNumber++;\r
\r
- /* Only reset the event list item value if the value is not\r
- being used for anything else. */\r
- if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL )\r
- {\r
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) uxNewPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ #if ( configUSE_TRACE_FACILITY == 1 )\r
+ {\r
+ /* Add a counter into the TCB for tracing only. */\r
+ pxNewTCB->uxTCBNumber = uxTaskNumber;\r
+ }\r
+ #endif /* configUSE_TRACE_FACILITY */\r
+ traceTASK_CREATE( pxNewTCB );\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
- the task is in a ready list it needs to be removed and placed\r
- in the list appropriate to its new priority. */\r
- if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxPriorityUsedOnEntry ] ), &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
- {\r
- /* The task is currently in its ready list - remove before adding\r
- it to it's new ready list. As we are in a critical section we\r
- can do this even if the scheduler is suspended. */\r
- if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
- {\r
- /* It is known that the task is in its ready list so\r
- there is no need to check again and the port level\r
- reset macro can be called directly. */\r
- portRESET_READY_PRIORITY( uxPriorityUsedOnEntry, uxTopReadyPriority );\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- prvAddTaskToReadyList( pxTCB );\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ prvAddTaskToReadyList( pxNewTCB );\r
\r
- if( xYieldRequired == pdTRUE )\r
- {\r
- taskYIELD_IF_USING_PREEMPTION();\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ portSETUP_TCB( pxNewTCB );\r
+ }\r
+ taskEXIT_CRITICAL();\r
\r
- /* Remove compiler warning about unused variables when the port\r
- optimised task selection is not being used. */\r
- ( void ) uxPriorityUsedOnEntry;\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 < pxNewTCB->uxPriority )\r
+ {\r
+ taskYIELD_IF_USING_PREEMPTION();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
}\r
- taskEXIT_CRITICAL();\r
}\r
-\r
-#endif /* INCLUDE_vTaskPrioritySet */\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+}\r
/*-----------------------------------------------------------*/\r
\r
-#if ( INCLUDE_vTaskSuspend == 1 )\r
+#if ( INCLUDE_vTaskDelete == 1 )\r
\r
- void vTaskSuspend( TaskHandle_t xTaskToSuspend )\r
+ void vTaskDelete( TaskHandle_t xTaskToDelete )\r
{\r
TCB_t *pxTCB;\r
\r
taskENTER_CRITICAL();\r
{\r
- /* If null is passed in here then it is the running task that is\r
- being suspended. */\r
- pxTCB = prvGetTCBFromHandle( xTaskToSuspend );\r
-\r
- traceTASK_SUSPEND( pxTCB );\r
+ /* If null is passed in here then it is the calling task that is\r
+ being deleted. */\r
+ pxTCB = prvGetTCBFromHandle( xTaskToDelete );\r
\r
- /* Remove task from the ready/delayed list and place in the\r
- suspended list. */\r
- if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
+ /* Remove task from the ready list. */\r
+ if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
{\r
taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
}\r
mtCOVERAGE_TEST_MARKER();\r
}\r
\r
- vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xGenericListItem ) );\r
- }\r
- taskEXIT_CRITICAL();\r
+ /* Increment the uxTaskNumber also so kernel aware debuggers can\r
+ detect that the task lists need re-generating. This is done before\r
+ portPRE_TASK_DELETE_HOOK() as in the Windows port that macro will\r
+ not return. */\r
+ uxTaskNumber++;\r
\r
- if( pxTCB == pxCurrentTCB )\r
- {\r
- if( xSchedulerRunning != pdFALSE )\r
+ if( pxTCB == pxCurrentTCB )\r
{\r
- /* The current task has just been suspended. */\r
- configASSERT( uxSchedulerSuspended == 0 );\r
- portYIELD_WITHIN_API();\r
+ /* A task is deleting itself. This cannot complete within the\r
+ task itself, as a context switch to another task is required.\r
+ Place the task in the termination list. The idle task will\r
+ check the termination list and free up any memory allocated by\r
+ the scheduler for the TCB and stack of the deleted task. */\r
+ vListInsertEnd( &xTasksWaitingTermination, &( pxTCB->xStateListItem ) );\r
+\r
+ /* Increment the ucTasksDeleted variable so the idle task knows\r
+ there is a task that has been deleted and that it should therefore\r
+ check the xTasksWaitingTermination list. */\r
+ ++uxDeletedTasksWaitingCleanUp;\r
+\r
+ /* The pre-delete hook is primarily for the Windows simulator,\r
+ in which Windows specific clean up operations are performed,\r
+ after which it is not possible to yield away from this task -\r
+ hence xYieldPending is used to latch that a context switch is\r
+ required. */\r
+ portPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPending );\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
+ --uxCurrentNumberOfTasks;\r
+ prvDeleteTCB( pxTCB );\r
+\r
+ /* Reset the next expected unblock time in case it referred to\r
+ the task that has just been deleted. */\r
+ prvResetNextTaskUnblockTime();\r
}\r
+\r
+ traceTASK_DELETE( pxTCB );\r
}\r
- else\r
+ taskEXIT_CRITICAL();\r
+\r
+ /* Force a reschedule if it is the currently running task that has just\r
+ been deleted. */\r
+ if( xSchedulerRunning != pdFALSE )\r
{\r
- if( xSchedulerRunning != pdFALSE )\r
+ if( pxTCB == pxCurrentTCB )\r
{\r
- /* A task other than the currently running task was suspended,\r
- reset the next expected unblock time in case it referred to the\r
- task that is now in the Suspended state. */\r
- taskENTER_CRITICAL();\r
- {\r
- prvResetNextTaskUnblockTime();\r
- }\r
- taskEXIT_CRITICAL();\r
+ configASSERT( uxSchedulerSuspended == 0 );\r
+ portYIELD_WITHIN_API();\r
}\r
else\r
{\r
}\r
}\r
\r
-#endif /* INCLUDE_vTaskSuspend */\r
+#endif /* INCLUDE_vTaskDelete */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( INCLUDE_vTaskSuspend == 1 )\r
+#if ( INCLUDE_vTaskDelayUntil == 1 )\r
\r
- static BaseType_t prvTaskIsTaskSuspended( const TaskHandle_t xTask )\r
+ void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement )\r
{\r
- BaseType_t xReturn = pdFALSE;\r
- const TCB_t * const pxTCB = ( TCB_t * ) xTask;\r
-\r
- /* Accesses xPendingReadyList so must be called from a critical\r
- section. */\r
+ TickType_t xTimeToWake;\r
+ BaseType_t xAlreadyYielded, xShouldDelay = pdFALSE;\r
\r
- /* It does not make sense to check if the calling task is suspended. */\r
- configASSERT( xTask );\r
+ configASSERT( pxPreviousWakeTime );\r
+ configASSERT( ( xTimeIncrement > 0U ) );\r
+ configASSERT( uxSchedulerSuspended == 0 );\r
\r
- /* Is the task being resumed actually in the suspended list? */\r
- if( listIS_CONTAINED_WITHIN( &xSuspendedTaskList, &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
+ vTaskSuspendAll();\r
{\r
- /* Has the task already been resumed from within an ISR? */\r
- if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) == pdFALSE )\r
+ /* Minor optimisation. The tick count cannot change in this\r
+ block. */\r
+ const TickType_t xConstTickCount = xTickCount;\r
+\r
+ /* Generate the tick time at which the task wants to wake. */\r
+ xTimeToWake = *pxPreviousWakeTime + xTimeIncrement;\r
+\r
+ if( xConstTickCount < *pxPreviousWakeTime )\r
{\r
- /* Is it in the suspended list because it is in the Suspended\r
- state, or because is is blocked with no timeout? */\r
- if( listIS_CONTAINED_WITHIN( NULL, &( pxTCB->xEventListItem ) ) != pdFALSE )\r
+ /* The tick count has overflowed since this function was\r
+ lasted called. In this case the only time we should ever\r
+ actually delay is if the wake time has also overflowed,\r
+ and the wake time is greater than the tick time. When this\r
+ is the case it is as if neither time had overflowed. */\r
+ if( ( xTimeToWake < *pxPreviousWakeTime ) && ( xTimeToWake > xConstTickCount ) )\r
{\r
- xReturn = pdTRUE;\r
+ xShouldDelay = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* The tick time has not overflowed. In this case we will\r
+ delay if either the wake time has overflowed, and/or the\r
+ tick time is less than the wake time. */\r
+ if( ( xTimeToWake < *pxPreviousWakeTime ) || ( xTimeToWake > xConstTickCount ) )\r
+ {\r
+ xShouldDelay = pdTRUE;\r
}\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
}\r
+\r
+ /* Update the wake time ready for the next call. */\r
+ *pxPreviousWakeTime = xTimeToWake;\r
+\r
+ if( xShouldDelay != pdFALSE )\r
+ {\r
+ traceTASK_DELAY_UNTIL( xTimeToWake );\r
+\r
+ /* prvAddCurrentTaskToDelayedList() needs the block time, not\r
+ the time to wake, so subtract the current tick count. */\r
+ prvAddCurrentTaskToDelayedList( xTimeToWake - xConstTickCount, pdFALSE );\r
+ }\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\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 == pdFALSE )\r
+ {\r
+ portYIELD_WITHIN_API();\r
+ }\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
+ }\r
\r
- return xReturn;\r
- } /*lint !e818 xTask cannot be a pointer to const because it is a typedef. */\r
+#endif /* INCLUDE_vTaskDelayUntil */\r
+/*-----------------------------------------------------------*/\r
\r
-#endif /* INCLUDE_vTaskSuspend */\r
+#if ( INCLUDE_vTaskDelay == 1 )\r
+\r
+ void vTaskDelay( const TickType_t xTicksToDelay )\r
+ {\r
+ BaseType_t xAlreadyYielded = pdFALSE;\r
+\r
+ /* A delay time of zero just forces a reschedule. */\r
+ if( xTicksToDelay > ( TickType_t ) 0U )\r
+ {\r
+ configASSERT( uxSchedulerSuspended == 0 );\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
+ This task cannot be in an event list as it is the currently\r
+ executing task. */\r
+ prvAddCurrentTaskToDelayedList( xTicksToDelay, pdFALSE );\r
+ }\r
+ xAlreadyYielded = xTaskResumeAll();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ /* Force a reschedule if xTaskResumeAll has not already done so, we may\r
+ have put ourselves to sleep. */\r
+ if( xAlreadyYielded == pdFALSE )\r
+ {\r
+ portYIELD_WITHIN_API();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+\r
+#endif /* INCLUDE_vTaskDelay */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( INCLUDE_vTaskSuspend == 1 )\r
+#if( ( INCLUDE_eTaskGetState == 1 ) || ( configUSE_TRACE_FACILITY == 1 ) )\r
\r
- void vTaskResume( TaskHandle_t xTaskToResume )\r
+ eTaskState eTaskGetState( TaskHandle_t xTask )\r
{\r
- TCB_t * const pxTCB = ( TCB_t * ) xTaskToResume;\r
+ eTaskState eReturn;\r
+ List_t *pxStateList;\r
+ const TCB_t * const pxTCB = ( TCB_t * ) xTask;\r
\r
- /* It does not make sense to resume the calling task. */\r
- configASSERT( xTaskToResume );\r
+ configASSERT( pxTCB );\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
+ if( pxTCB == pxCurrentTCB )\r
+ {\r
+ /* The task calling this function is querying its own state. */\r
+ eReturn = eRunning;\r
+ }\r
+ else\r
{\r
taskENTER_CRITICAL();\r
{\r
- if( prvTaskIsTaskSuspended( pxTCB ) == pdTRUE )\r
- {\r
- traceTASK_RESUME( pxTCB );\r
+ pxStateList = ( List_t * ) listLIST_ITEM_CONTAINER( &( pxTCB->xStateListItem ) );\r
+ }\r
+ taskEXIT_CRITICAL();\r
\r
- /* As we are in a critical section we can access the ready\r
- lists even if the scheduler is suspended. */\r
- ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
- prvAddTaskToReadyList( pxTCB );\r
+ if( ( pxStateList == pxDelayedTaskList ) || ( pxStateList == pxOverflowDelayedTaskList ) )\r
+ {\r
+ /* The task being queried is referenced from one of the Blocked\r
+ lists. */\r
+ eReturn = eBlocked;\r
+ }\r
\r
- /* We may have just resumed a higher priority task. */\r
- if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
+ #if ( INCLUDE_vTaskSuspend == 1 )\r
+ else if( pxStateList == &xSuspendedTaskList )\r
+ {\r
+ /* The task being queried is referenced from the suspended\r
+ list. Is it genuinely suspended or is it block\r
+ indefinitely? */\r
+ if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL )\r
{\r
- /* This yield may not cause the task just resumed to run,\r
- but will leave the lists in the correct state for the\r
- next yield. */\r
- taskYIELD_IF_USING_PREEMPTION();\r
+ eReturn = eSuspended;\r
}\r
else\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ eReturn = eBlocked;\r
}\r
}\r
- else\r
+ #endif\r
+\r
+ #if ( INCLUDE_vTaskDelete == 1 )\r
+ else if( ( pxStateList == &xTasksWaitingTermination ) || ( pxStateList == NULL ) )\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ /* The task being queried is referenced from the deleted\r
+ tasks list, or it is not referenced from any lists at\r
+ all. */\r
+ eReturn = eDeleted;\r
}\r
+ #endif\r
+\r
+ else /*lint !e525 Negative indentation is intended to make use of pre-processor clearer. */\r
+ {\r
+ /* If the task is not in any other state, it must be in the\r
+ Ready (including pending ready) state. */\r
+ eReturn = eReady;\r
}\r
- taskEXIT_CRITICAL();\r
}\r
- else\r
+\r
+ return eReturn;\r
+ } /*lint !e818 xTask cannot be a pointer to const because it is a typedef. */\r
+\r
+#endif /* INCLUDE_eTaskGetState */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( INCLUDE_uxTaskPriorityGet == 1 )\r
+\r
+ UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask )\r
+ {\r
+ TCB_t *pxTCB;\r
+ UBaseType_t uxReturn;\r
+\r
+ taskENTER_CRITICAL();\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ /* If null is passed in here then it is the priority of the that\r
+ called uxTaskPriorityGet() that is being queried. */\r
+ pxTCB = prvGetTCBFromHandle( xTask );\r
+ uxReturn = pxTCB->uxPriority;\r
}\r
- }\r
+ taskEXIT_CRITICAL();\r
\r
-#endif /* INCLUDE_vTaskSuspend */\r
+ return uxReturn;\r
+ }\r
\r
+#endif /* INCLUDE_uxTaskPriorityGet */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )\r
+#if ( INCLUDE_uxTaskPriorityGet == 1 )\r
\r
- BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume )\r
+ UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask )\r
{\r
- BaseType_t xYieldRequired = pdFALSE;\r
- TCB_t * const pxTCB = ( TCB_t * ) xTaskToResume;\r
- UBaseType_t uxSavedInterruptStatus;\r
-\r
- configASSERT( xTaskToResume );\r
+ TCB_t *pxTCB;\r
+ UBaseType_t uxReturn, uxSavedInterruptState;\r
\r
/* RTOS ports that support interrupt nesting have the concept of a\r
maximum system call (or maximum API call) interrupt priority.\r
http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
\r
- uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+ uxSavedInterruptState = portSET_INTERRUPT_MASK_FROM_ISR();\r
{\r
- if( prvTaskIsTaskSuspended( pxTCB ) == pdTRUE )\r
- {\r
- traceTASK_RESUME_FROM_ISR( pxTCB );\r
+ /* If null is passed in here then it is the priority of the calling\r
+ task that is being queried. */\r
+ pxTCB = prvGetTCBFromHandle( xTask );\r
+ uxReturn = pxTCB->uxPriority;\r
+ }\r
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptState );\r
\r
- /* Check the ready lists can be accessed. */\r
- if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
- {\r
- /* Ready lists can be accessed so move the task from the\r
- suspended list to the ready list directly. */\r
- if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
- {\r
- xYieldRequired = pdTRUE;\r
- }\r
+ return uxReturn;\r
+ }\r
+\r
+#endif /* INCLUDE_uxTaskPriorityGet */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( INCLUDE_vTaskPrioritySet == 1 )\r
+\r
+ void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority )\r
+ {\r
+ TCB_t *pxTCB;\r
+ UBaseType_t uxCurrentBasePriority, uxPriorityUsedOnEntry;\r
+ BaseType_t xYieldRequired = pdFALSE;\r
+\r
+ configASSERT( ( uxNewPriority < configMAX_PRIORITIES ) );\r
+\r
+ /* Ensure the new priority is valid. */\r
+ if( uxNewPriority >= ( UBaseType_t ) configMAX_PRIORITIES )\r
+ {\r
+ uxNewPriority = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) 1U;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ taskENTER_CRITICAL();\r
+ {\r
+ /* If null is passed in here then it is the priority of the calling\r
+ task that is being changed. */\r
+ pxTCB = prvGetTCBFromHandle( xTask );\r
+\r
+ traceTASK_PRIORITY_SET( pxTCB, uxNewPriority );\r
+\r
+ #if ( configUSE_MUTEXES == 1 )\r
+ {\r
+ uxCurrentBasePriority = pxTCB->uxBasePriority;\r
+ }\r
+ #else\r
+ {\r
+ uxCurrentBasePriority = pxTCB->uxPriority;\r
+ }\r
+ #endif\r
+\r
+ if( uxCurrentBasePriority != uxNewPriority )\r
+ {\r
+ /* The priority change may have readied a task of higher\r
+ priority than the calling task. */\r
+ if( uxNewPriority > uxCurrentBasePriority )\r
+ {\r
+ if( pxTCB != pxCurrentTCB )\r
+ {\r
+ /* The priority of a task other than the currently\r
+ running task is being raised. Is the priority being\r
+ raised above that of the running task? */\r
+ if( uxNewPriority >= pxCurrentTCB->uxPriority )\r
+ {\r
+ xYieldRequired = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* The priority of the running task is being raised,\r
+ but the running task must already be the highest\r
+ priority task able to run so no yield is required. */\r
+ }\r
+ }\r
+ else if( pxTCB == pxCurrentTCB )\r
+ {\r
+ /* Setting the priority of the running task down means\r
+ there may now be another task of higher priority that\r
+ is ready to execute. */\r
+ xYieldRequired = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ /* Setting the priority of any other task down does not\r
+ require a yield as the running task must be above the\r
+ new priority of the task being modified. */\r
+ }\r
+\r
+ /* Remember the ready list the task might be referenced from\r
+ before its uxPriority member is changed so the\r
+ taskRESET_READY_PRIORITY() macro can function correctly. */\r
+ uxPriorityUsedOnEntry = pxTCB->uxPriority;\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
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\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
+ /* Only reset the event list item value if the value is not\r
+ being used for anything else. */\r
+ if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL )\r
+ {\r
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) uxNewPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ /* If the task is in the blocked or suspended list we need do\r
+ nothing more than change its priority variable. However, if\r
+ the task is in a ready list it needs to be removed and placed\r
+ in the list appropriate to its new priority. */\r
+ if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxPriorityUsedOnEntry ] ), &( pxTCB->xStateListItem ) ) != pdFALSE )\r
+ {\r
+ /* The task is currently in its ready list - remove before\r
+ adding it to it's new ready list. As we are in a critical\r
+ section we can do this even if the scheduler is suspended. */\r
+ if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
+ {\r
+ /* It is known that the task is in its ready list so\r
+ there is no need to check again and the port level\r
+ reset macro can be called directly. */\r
+ portRESET_READY_PRIORITY( uxPriorityUsedOnEntry, uxTopReadyPriority );\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ prvAddTaskToReadyList( pxTCB );\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ if( xYieldRequired != pdFALSE )\r
+ {\r
+ taskYIELD_IF_USING_PREEMPTION();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ /* Remove compiler warning about unused variables when the port\r
+ optimised task selection is not being used. */\r
+ ( void ) uxPriorityUsedOnEntry;\r
+ }\r
+ }\r
+ taskEXIT_CRITICAL();\r
+ }\r
+\r
+#endif /* INCLUDE_vTaskPrioritySet */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( INCLUDE_vTaskSuspend == 1 )\r
+\r
+ void vTaskSuspend( TaskHandle_t xTaskToSuspend )\r
+ {\r
+ TCB_t *pxTCB;\r
+\r
+ taskENTER_CRITICAL();\r
+ {\r
+ /* If null is passed in here then it is the running task that is\r
+ being suspended. */\r
+ pxTCB = prvGetTCBFromHandle( xTaskToSuspend );\r
+\r
+ traceTASK_SUSPEND( pxTCB );\r
+\r
+ /* Remove task from the ready/delayed list and place in the\r
+ suspended list. */\r
+ if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
+ {\r
+ taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ /* Is the task waiting on an event also? */\r
+ if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
+ {\r
+ ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xStateListItem ) );\r
+\r
+ #if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+ {\r
+ if( pxTCB->ucNotifyState == taskWAITING_NOTIFICATION )\r
+ {\r
+ /* The task was blocked to wait for a notification, but is\r
+ now suspended, so no notification was received. */\r
+ pxTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION;\r
+ }\r
+ }\r
+ #endif\r
+ }\r
+ taskEXIT_CRITICAL();\r
+\r
+ if( xSchedulerRunning != pdFALSE )\r
+ {\r
+ /* Reset the next expected unblock time in case it referred to the\r
+ task that is now in the Suspended state. */\r
+ taskENTER_CRITICAL();\r
+ {\r
+ prvResetNextTaskUnblockTime();\r
+ }\r
+ taskEXIT_CRITICAL();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ if( pxTCB == pxCurrentTCB )\r
+ {\r
+ if( xSchedulerRunning != pdFALSE )\r
+ {\r
+ /* The current task has just been suspended. */\r
+ configASSERT( uxSchedulerSuspended == 0 );\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
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+\r
+#endif /* INCLUDE_vTaskSuspend */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( INCLUDE_vTaskSuspend == 1 )\r
+\r
+ static BaseType_t prvTaskIsTaskSuspended( const TaskHandle_t xTask )\r
+ {\r
+ BaseType_t xReturn = pdFALSE;\r
+ const TCB_t * const pxTCB = ( TCB_t * ) xTask;\r
+\r
+ /* Accesses xPendingReadyList so must be called from a critical\r
+ section. */\r
+\r
+ /* It does not make sense to check if the calling task is suspended. */\r
+ configASSERT( xTask );\r
+\r
+ /* Is the task being resumed actually in the suspended list? */\r
+ if( listIS_CONTAINED_WITHIN( &xSuspendedTaskList, &( pxTCB->xStateListItem ) ) != pdFALSE )\r
+ {\r
+ /* Has the task already been resumed from within an ISR? */\r
+ if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) == pdFALSE )\r
+ {\r
+ /* Is it in the suspended list because it is in the Suspended\r
+ state, or because is is blocked with no timeout? */\r
+ if( listIS_CONTAINED_WITHIN( NULL, &( pxTCB->xEventListItem ) ) != pdFALSE ) /*lint !e961. The cast is only redundant when NULL is used. */\r
+ {\r
+ xReturn = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ return xReturn;\r
+ } /*lint !e818 xTask cannot be a pointer to const because it is a typedef. */\r
+\r
+#endif /* INCLUDE_vTaskSuspend */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( INCLUDE_vTaskSuspend == 1 )\r
+\r
+ void vTaskResume( TaskHandle_t xTaskToResume )\r
+ {\r
+ TCB_t * const pxTCB = ( TCB_t * ) xTaskToResume;\r
+\r
+ /* It does not make sense to resume the calling task. */\r
+ configASSERT( xTaskToResume );\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
+ taskENTER_CRITICAL();\r
+ {\r
+ if( prvTaskIsTaskSuspended( pxTCB ) != pdFALSE )\r
+ {\r
+ traceTASK_RESUME( pxTCB );\r
+\r
+ /* The ready list can be accessed even if the scheduler is\r
+ suspended because this is inside a critical section. */\r
+ ( void ) uxListRemove( &( pxTCB->xStateListItem ) );\r
+ prvAddTaskToReadyList( pxTCB );\r
+\r
+ /* A higher priority task may have just been resumed. */\r
+ if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
+ {\r
+ /* This yield may not cause the task just resumed to run,\r
+ but will leave the lists in the correct state for the\r
+ next yield. */\r
+ taskYIELD_IF_USING_PREEMPTION();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ taskEXIT_CRITICAL();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+\r
+#endif /* INCLUDE_vTaskSuspend */\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )\r
+\r
+ BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume )\r
+ {\r
+ BaseType_t xYieldRequired = pdFALSE;\r
+ TCB_t * const pxTCB = ( TCB_t * ) xTaskToResume;\r
+ UBaseType_t uxSavedInterruptStatus;\r
+\r
+ configASSERT( xTaskToResume );\r
+\r
+ /* RTOS ports that support interrupt nesting have the concept of a\r
+ maximum system call (or maximum API call) interrupt priority.\r
+ Interrupts that are above the maximum system call priority are keep\r
+ permanently enabled, even when the RTOS kernel is in a critical section,\r
+ but cannot make any calls to FreeRTOS API functions. If configASSERT()\r
+ is defined in FreeRTOSConfig.h then\r
+ portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+ failure if a FreeRTOS API function is called from an interrupt that has\r
+ been assigned a priority above the configured maximum system call\r
+ priority. Only FreeRTOS functions that end in FromISR can be called\r
+ from interrupts that have been assigned a priority at or (logically)\r
+ below the maximum system call interrupt priority. FreeRTOS maintains a\r
+ separate interrupt safe API to ensure interrupt entry is as fast and as\r
+ simple as possible. More information (albeit Cortex-M specific) is\r
+ provided on the following link:\r
+ http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+ portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+\r
+ uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+ {\r
+ if( prvTaskIsTaskSuspended( pxTCB ) != pdFALSE )\r
+ {\r
+ traceTASK_RESUME_FROM_ISR( pxTCB );\r
+\r
+ /* Check the ready lists can be accessed. */\r
+ if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
+ {\r
+ /* Ready lists can be accessed so move the task from the\r
+ suspended list to the ready list directly. */\r
+ if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
+ {\r
+ xYieldRequired = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ ( void ) uxListRemove( &( pxTCB->xStateListItem ) );\r
+ prvAddTaskToReadyList( pxTCB );\r
+ }\r
+ else\r
+ {\r
+ /* The delayed or ready lists cannot be accessed so the task\r
+ is held in the pending ready list until the scheduler is\r
+ unsuspended. */\r
+ vListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+\r
+ return xYieldRequired;\r
+ }\r
+\r
+#endif /* ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) */\r
+/*-----------------------------------------------------------*/\r
+\r
+void vTaskStartScheduler( void )\r
+{\r
+BaseType_t xReturn;\r
+\r
+ /* Add the idle task at the lowest priority. */\r
+ #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+ {\r
+ StaticTask_t *pxIdleTaskTCBBuffer = NULL;\r
+ StackType_t *pxIdleTaskStackBuffer = NULL;\r
+ uint32_t ulIdleTaskStackSize;\r
+\r
+ /* The Idle task is created using user provided RAM - obtain the\r
+ address of the RAM then create the idle task. */\r
+ vApplicationGetIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &ulIdleTaskStackSize );\r
+ xIdleTaskHandle = xTaskCreateStatic( prvIdleTask,\r
+ configIDLE_TASK_NAME,\r
+ ulIdleTaskStackSize,\r
+ ( void * ) NULL, /*lint !e961. The cast is not redundant for all compilers. */\r
+ ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ),\r
+ pxIdleTaskStackBuffer,\r
+ pxIdleTaskTCBBuffer ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
+\r
+ if( xIdleTaskHandle != NULL )\r
+ {\r
+ xReturn = pdPASS;\r
+ }\r
+ else\r
+ {\r
+ xReturn = pdFAIL;\r
+ }\r
+ }\r
+ #else\r
+ {\r
+ /* The Idle task is being created using dynamically allocated RAM. */\r
+ xReturn = xTaskCreate( prvIdleTask,\r
+ configIDLE_TASK_NAME,\r
+ configMINIMAL_STACK_SIZE,\r
+ ( void * ) NULL,\r
+ ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ),\r
+ &xIdleTaskHandle ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
+ }\r
+ #endif /* configSUPPORT_STATIC_ALLOCATION */\r
+\r
+ #if ( configUSE_TIMERS == 1 )\r
+ {\r
+ if( xReturn == pdPASS )\r
+ {\r
+ xReturn = xTimerCreateTimerTask();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ #endif /* configUSE_TIMERS */\r
+\r
+ if( xReturn == pdPASS )\r
+ {\r
+ /* freertos_tasks_c_additions_init() should only be called if the user\r
+ definable macro FREERTOS_TASKS_C_ADDITIONS_INIT() is defined, as that is\r
+ the only macro called by the function. */\r
+ #ifdef FREERTOS_TASKS_C_ADDITIONS_INIT\r
+ {\r
+ freertos_tasks_c_additions_init();\r
+ }\r
+ #endif\r
+\r
+ /* Interrupts are turned off here, to ensure a tick does not occur\r
+ before or during the call to xPortStartScheduler(). The stacks of\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
+ portDISABLE_INTERRUPTS();\r
+\r
+ #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
+ {\r
+ /* Switch Newlib's _impure_ptr variable to point to the _reent\r
+ structure specific to the task that will run first. */\r
+ _impure_ptr = &( pxCurrentTCB->xNewLib_reent );\r
+ }\r
+ #endif /* configUSE_NEWLIB_REENTRANT */\r
+\r
+ xNextTaskUnblockTime = portMAX_DELAY;\r
+ xSchedulerRunning = pdTRUE;\r
+ xTickCount = ( TickType_t ) 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. NOTE: If configGENERATE_RUN_TIME_STATS\r
+ is set to 0 and the following line fails to build then ensure you do not\r
+ have portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() defined in your\r
+ FreeRTOSConfig.h file. */\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() != pdFALSE )\r
+ {\r
+ /* Should not reach here as if the scheduler is running the\r
+ function will not return. */\r
+ }\r
+ else\r
+ {\r
+ /* Should only reach here if a task calls xTaskEndScheduler(). */\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* This line will only be reached if the kernel could not be started,\r
+ because there was not enough FreeRTOS heap to create the idle task\r
+ or the timer task. */\r
+ configASSERT( xReturn != errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY );\r
+ }\r
+\r
+ /* Prevent compiler warnings if INCLUDE_xTaskGetIdleTaskHandle is set to 0,\r
+ meaning xIdleTaskHandle is not used anywhere else. */\r
+ ( void ) xIdleTaskHandle;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vTaskEndScheduler( void )\r
+{\r
+ /* Stop the scheduler interrupts and call the portable scheduler end\r
+ routine so the original ISRs can be restored if necessary. The port\r
+ layer must ensure interrupts enable bit is left in the correct state. */\r
+ portDISABLE_INTERRUPTS();\r
+ xSchedulerRunning = pdFALSE;\r
+ vPortEndScheduler();\r
+}\r
+/*----------------------------------------------------------*/\r
+\r
+void vTaskSuspendAll( void )\r
+{\r
+ /* A critical section is not required as the variable is of type\r
+ BaseType_t. Please read Richard Barry's reply in the following link to a\r
+ post in the FreeRTOS support forum before reporting this as a bug! -\r
+ http://goo.gl/wu4acr */\r
+ ++uxSchedulerSuspended;\r
+}\r
+/*----------------------------------------------------------*/\r
+\r
+#if ( configUSE_TICKLESS_IDLE != 0 )\r
+\r
+ static TickType_t prvGetExpectedIdleTime( void )\r
+ {\r
+ TickType_t xReturn;\r
+ UBaseType_t uxHigherPriorityReadyTasks = pdFALSE;\r
+\r
+ /* uxHigherPriorityReadyTasks takes care of the case where\r
+ configUSE_PREEMPTION is 0, so there may be tasks above the idle priority\r
+ task that are in the Ready state, even though the idle task is\r
+ running. */\r
+ #if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 )\r
+ {\r
+ if( uxTopReadyPriority > tskIDLE_PRIORITY )\r
+ {\r
+ uxHigherPriorityReadyTasks = pdTRUE;\r
+ }\r
+ }\r
+ #else\r
+ {\r
+ const UBaseType_t uxLeastSignificantBit = ( UBaseType_t ) 0x01;\r
+\r
+ /* When port optimised task selection is used the uxTopReadyPriority\r
+ variable is used as a bit map. If bits other than the least\r
+ significant bit are set then there are tasks that have a priority\r
+ above the idle priority that are in the Ready state. This takes\r
+ care of the case where the co-operative scheduler is in use. */\r
+ if( uxTopReadyPriority > uxLeastSignificantBit )\r
+ {\r
+ uxHigherPriorityReadyTasks = pdTRUE;\r
+ }\r
+ }\r
+ #endif\r
+\r
+ if( pxCurrentTCB->uxPriority > tskIDLE_PRIORITY )\r
+ {\r
+ xReturn = 0;\r
+ }\r
+ else if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > 1 )\r
+ {\r
+ /* There are other idle priority tasks in the ready state. If\r
+ time slicing is used then the very next tick interrupt must be\r
+ processed. */\r
+ xReturn = 0;\r
+ }\r
+ else if( uxHigherPriorityReadyTasks != pdFALSE )\r
+ {\r
+ /* There are tasks in the Ready state that have a priority above the\r
+ idle priority. This path can only be reached if\r
+ configUSE_PREEMPTION is 0. */\r
+ xReturn = 0;\r
+ }\r
+ else\r
+ {\r
+ xReturn = xNextTaskUnblockTime - xTickCount;\r
+ }\r
+\r
+ return xReturn;\r
+ }\r
+\r
+#endif /* configUSE_TICKLESS_IDLE */\r
+/*----------------------------------------------------------*/\r
+\r
+BaseType_t xTaskResumeAll( void )\r
+{\r
+TCB_t *pxTCB = NULL;\r
+BaseType_t 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
+ taskENTER_CRITICAL();\r
+ {\r
+ --uxSchedulerSuspended;\r
+\r
+ if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
+ {\r
+ if( uxCurrentNumberOfTasks > ( UBaseType_t ) 0U )\r
+ {\r
+ /* Move any readied tasks from the pending list into the\r
+ appropriate ready list. */\r
+ while( listLIST_IS_EMPTY( &xPendingReadyList ) == pdFALSE )\r
+ {\r
+ pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xPendingReadyList ) );\r
+ ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
+ ( void ) uxListRemove( &( pxTCB->xStateListItem ) );\r
+ prvAddTaskToReadyList( pxTCB );\r
+\r
+ /* If the moved task has a priority higher than the current\r
+ task then a yield must be performed. */\r
+ if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
+ {\r
+ xYieldPending = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+\r
+ if( pxTCB != NULL )\r
+ {\r
+ /* A task was unblocked while the scheduler was suspended,\r
+ which may have prevented the next unblock time from being\r
+ re-calculated, in which case re-calculate it now. Mainly\r
+ important for low power tickless implementations, where\r
+ this can prevent an unnecessary exit from low power\r
+ state. */\r
+ prvResetNextTaskUnblockTime();\r
+ }\r
+\r
+ /* If any ticks occurred while the scheduler was suspended then\r
+ they should be processed now. This ensures the tick count does\r
+ not slip, and that any delayed tasks are resumed at the correct\r
+ time. */\r
+ {\r
+ UBaseType_t uxPendedCounts = uxPendedTicks; /* Non-volatile copy. */\r
+\r
+ if( uxPendedCounts > ( UBaseType_t ) 0U )\r
+ {\r
+ do\r
+ {\r
+ if( xTaskIncrementTick() != pdFALSE )\r
+ {\r
+ xYieldPending = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ --uxPendedCounts;\r
+ } while( uxPendedCounts > ( UBaseType_t ) 0U );\r
+\r
+ uxPendedTicks = 0;\r
+ }\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
+ }\r
\r
- ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
- prvAddTaskToReadyList( pxTCB );\r
+ if( xYieldPending != pdFALSE )\r
+ {\r
+ #if( configUSE_PREEMPTION != 0 )\r
+ {\r
+ xAlreadyYielded = pdTRUE;\r
+ }\r
+ #endif\r
+ taskYIELD_IF_USING_PREEMPTION();\r
}\r
else\r
{\r
- /* The delayed or ready lists cannot be accessed so the task\r
- is held in the pending ready list until the scheduler is\r
- unsuspended. */\r
- vListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\r
+ mtCOVERAGE_TEST_MARKER();\r
}\r
}\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
}\r
- portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
-\r
- return xYieldRequired;\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
}\r
+ taskEXIT_CRITICAL();\r
\r
-#endif /* ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) */\r
+ return xAlreadyYielded;\r
+}\r
/*-----------------------------------------------------------*/\r
\r
-void vTaskStartScheduler( void )\r
+TickType_t xTaskGetTickCount( void )\r
{\r
-BaseType_t xReturn;\r
+TickType_t xTicks;\r
\r
- /* Add the idle task at the lowest priority. */\r
- #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\r
+ /* Critical section required if running on a 16 bit processor. */\r
+ portTICK_TYPE_ENTER_CRITICAL();\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, "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), &xIdleTaskHandle ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
+ xTicks = xTickCount;\r
}\r
- #else\r
+ portTICK_TYPE_EXIT_CRITICAL();\r
+\r
+ return xTicks;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+TickType_t xTaskGetTickCountFromISR( void )\r
+{\r
+TickType_t xReturn;\r
+UBaseType_t uxSavedInterruptStatus;\r
+\r
+ /* RTOS ports that support interrupt nesting have the concept of a maximum\r
+ system call (or maximum API call) interrupt priority. Interrupts that are\r
+ above the maximum system call priority are kept permanently enabled, even\r
+ when the RTOS kernel is in a critical section, but cannot make any calls to\r
+ FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h\r
+ then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+ failure if a FreeRTOS API function is called from an interrupt that has been\r
+ assigned a priority above the configured maximum system call priority.\r
+ Only FreeRTOS functions that end in FromISR can be called from interrupts\r
+ that have been assigned a priority at or (logically) below the maximum\r
+ system call interrupt priority. FreeRTOS maintains a separate interrupt\r
+ safe API to ensure interrupt entry is as fast and as simple as possible.\r
+ More information (albeit Cortex-M specific) is provided on the following\r
+ link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+ portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+\r
+ uxSavedInterruptStatus = portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR();\r
{\r
- /* Create the idle task without storing its handle. */\r
- xReturn = xTaskCreate( prvIdleTask, "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), NULL ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
+ xReturn = xTickCount;\r
}\r
- #endif /* INCLUDE_xTaskGetIdleTaskHandle */\r
+ portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
\r
- #if ( configUSE_TIMERS == 1 )\r
+ return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+UBaseType_t uxTaskGetNumberOfTasks( void )\r
+{\r
+ /* A critical section is not required because the variables are of type\r
+ BaseType_t. */\r
+ return uxCurrentNumberOfTasks;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+char *pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+{\r
+TCB_t *pxTCB;\r
+\r
+ /* If null is passed in here then the name of the calling task is being\r
+ queried. */\r
+ pxTCB = prvGetTCBFromHandle( xTaskToQuery );\r
+ configASSERT( pxTCB );\r
+ return &( pxTCB->pcTaskName[ 0 ] );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( INCLUDE_xTaskGetHandle == 1 )\r
+\r
+ static TCB_t *prvSearchForNameWithinSingleList( List_t *pxList, const char pcNameToQuery[] )\r
{\r
- if( xReturn == pdPASS )\r
+ TCB_t *pxNextTCB, *pxFirstTCB, *pxReturn = NULL;\r
+ UBaseType_t x;\r
+ char cNextChar;\r
+\r
+ /* This function is called with the scheduler suspended. */\r
+\r
+ if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 )\r
{\r
- xReturn = xTimerCreateTimerTask();\r
+ listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );\r
+\r
+ do\r
+ {\r
+ listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );\r
+\r
+ /* Check each character in the name looking for a match or\r
+ mismatch. */\r
+ for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ )\r
+ {\r
+ cNextChar = pxNextTCB->pcTaskName[ x ];\r
+\r
+ if( cNextChar != pcNameToQuery[ x ] )\r
+ {\r
+ /* Characters didn't match. */\r
+ break;\r
+ }\r
+ else if( cNextChar == 0x00 )\r
+ {\r
+ /* Both strings terminated, a match must have been\r
+ found. */\r
+ pxReturn = pxNextTCB;\r
+ break;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+\r
+ if( pxReturn != NULL )\r
+ {\r
+ /* The handle has been found. */\r
+ break;\r
+ }\r
+\r
+ } while( pxNextTCB != pxFirstTCB );\r
}\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
+\r
+ return pxReturn;\r
}\r
- #endif /* configUSE_TIMERS */\r
\r
- if( xReturn == pdPASS )\r
+#endif /* INCLUDE_xTaskGetHandle */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( INCLUDE_xTaskGetHandle == 1 )\r
+\r
+ TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
{\r
- /* Interrupts are turned off here, to ensure a tick does not occur\r
- before or during the call to xPortStartScheduler(). The stacks of\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
- portDISABLE_INTERRUPTS();\r
+ UBaseType_t uxQueue = configMAX_PRIORITIES;\r
+ TCB_t* pxTCB;\r
\r
- #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
+ /* Task names will be truncated to configMAX_TASK_NAME_LEN - 1 bytes. */\r
+ configASSERT( strlen( pcNameToQuery ) < configMAX_TASK_NAME_LEN );\r
+\r
+ vTaskSuspendAll();\r
{\r
- /* Switch Newlib's _impure_ptr variable to point to the _reent\r
- structure specific to the task that will run first. */\r
- _impure_ptr = &( pxCurrentTCB->xNewLib_reent );\r
- }\r
- #endif /* configUSE_NEWLIB_REENTRANT */\r
+ /* Search the ready lists. */\r
+ do\r
+ {\r
+ uxQueue--;\r
+ pxTCB = prvSearchForNameWithinSingleList( ( List_t * ) &( pxReadyTasksLists[ uxQueue ] ), pcNameToQuery );\r
\r
- xSchedulerRunning = pdTRUE;\r
- xTickCount = ( TickType_t ) 0U;\r
+ if( pxTCB != NULL )\r
+ {\r
+ /* Found the handle. */\r
+ break;\r
+ }\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
+ } while( uxQueue > ( UBaseType_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
\r
- /* Setting up the timer tick is hardware specific and thus in the\r
- portable interface. */\r
- if( xPortStartScheduler() != pdFALSE )\r
- {\r
- /* Should not reach here as if the scheduler is running the\r
- function will not return. */\r
+ /* Search the delayed lists. */\r
+ if( pxTCB == NULL )\r
+ {\r
+ pxTCB = prvSearchForNameWithinSingleList( ( List_t * ) pxDelayedTaskList, pcNameToQuery );\r
+ }\r
+\r
+ if( pxTCB == NULL )\r
+ {\r
+ pxTCB = prvSearchForNameWithinSingleList( ( List_t * ) pxOverflowDelayedTaskList, pcNameToQuery );\r
+ }\r
+\r
+ #if ( INCLUDE_vTaskSuspend == 1 )\r
+ {\r
+ if( pxTCB == NULL )\r
+ {\r
+ /* Search the suspended list. */\r
+ pxTCB = prvSearchForNameWithinSingleList( &xSuspendedTaskList, pcNameToQuery );\r
+ }\r
+ }\r
+ #endif\r
+\r
+ #if( INCLUDE_vTaskDelete == 1 )\r
+ {\r
+ if( pxTCB == NULL )\r
+ {\r
+ /* Search the deleted list. */\r
+ pxTCB = prvSearchForNameWithinSingleList( &xTasksWaitingTermination, pcNameToQuery );\r
+ }\r
+ }\r
+ #endif\r
}\r
- else\r
+ ( void ) xTaskResumeAll();\r
+\r
+ return ( TaskHandle_t ) pxTCB;\r
+ }\r
+\r
+#endif /* INCLUDE_xTaskGetHandle */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_TRACE_FACILITY == 1 )\r
+\r
+ UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime )\r
+ {\r
+ UBaseType_t uxTask = 0, uxQueue = configMAX_PRIORITIES;\r
+\r
+ vTaskSuspendAll();\r
{\r
- /* Should only reach here if a task calls xTaskEndScheduler(). */\r
+ /* Is there a space in the array for each task in the system? */\r
+ if( uxArraySize >= uxCurrentNumberOfTasks )\r
+ {\r
+ /* Fill in an TaskStatus_t structure with information on each\r
+ task in the Ready state. */\r
+ do\r
+ {\r
+ uxQueue--;\r
+ uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &( pxReadyTasksLists[ uxQueue ] ), eReady );\r
+\r
+ } while( uxQueue > ( UBaseType_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+\r
+ /* Fill in an TaskStatus_t structure with information on each\r
+ task in the Blocked state. */\r
+ uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxDelayedTaskList, eBlocked );\r
+ uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxOverflowDelayedTaskList, eBlocked );\r
+\r
+ #if( INCLUDE_vTaskDelete == 1 )\r
+ {\r
+ /* Fill in an TaskStatus_t structure with information on\r
+ each task that has been deleted but not yet cleaned up. */\r
+ uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xTasksWaitingTermination, eDeleted );\r
+ }\r
+ #endif\r
+\r
+ #if ( INCLUDE_vTaskSuspend == 1 )\r
+ {\r
+ /* Fill in an TaskStatus_t structure with information on\r
+ each task in the Suspended state. */\r
+ uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xSuspendedTaskList, eSuspended );\r
+ }\r
+ #endif\r
+\r
+ #if ( configGENERATE_RUN_TIME_STATS == 1)\r
+ {\r
+ if( pulTotalRunTime != NULL )\r
+ {\r
+ #ifdef portALT_GET_RUN_TIME_COUNTER_VALUE\r
+ portALT_GET_RUN_TIME_COUNTER_VALUE( ( *pulTotalRunTime ) );\r
+ #else\r
+ *pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
+ #endif\r
+ }\r
+ }\r
+ #else\r
+ {\r
+ if( pulTotalRunTime != NULL )\r
+ {\r
+ *pulTotalRunTime = 0;\r
+ }\r
+ }\r
+ #endif\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
}\r
+ ( void ) xTaskResumeAll();\r
+\r
+ return uxTask;\r
}\r
- else\r
+\r
+#endif /* configUSE_TRACE_FACILITY */\r
+/*----------------------------------------------------------*/\r
+\r
+#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\r
+\r
+ TaskHandle_t xTaskGetIdleTaskHandle( void )\r
{\r
- /* This line will only be reached if the kernel could not be started,\r
- because there was not enough FreeRTOS heap to create the idle task\r
- or the timer task. */\r
- configASSERT( xReturn );\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
-/*-----------------------------------------------------------*/\r
\r
-void vTaskEndScheduler( void )\r
-{\r
- /* Stop the scheduler interrupts and call the portable scheduler end\r
- routine so the original ISRs can be restored if necessary. The port\r
- layer must ensure interrupts enable bit is left in the correct state. */\r
- portDISABLE_INTERRUPTS();\r
- xSchedulerRunning = pdFALSE;\r
- vPortEndScheduler();\r
-}\r
+#endif /* INCLUDE_xTaskGetIdleTaskHandle */\r
/*----------------------------------------------------------*/\r
\r
-void vTaskSuspendAll( void )\r
-{\r
- /* A critical section is not required as the variable is of type\r
- BaseType_t. Please read Richard Barry's reply in the following link to a\r
- post in the FreeRTOS support forum before reporting this as a bug! -\r
- http://goo.gl/wu4acr */\r
- ++uxSchedulerSuspended;\r
-}\r
+/* This conditional compilation should use inequality to 0, not equality to 1.\r
+This is to ensure vTaskStepTick() is available when user defined low power mode\r
+implementations require configUSE_TICKLESS_IDLE to be set to a value other than\r
+1. */\r
+#if ( configUSE_TICKLESS_IDLE != 0 )\r
+\r
+ void vTaskStepTick( const TickType_t xTicksToJump )\r
+ {\r
+ /* Correct the tick count value after a period during which the tick\r
+ was suppressed. Note this does *not* call the tick hook function for\r
+ each stepped tick. */\r
+ configASSERT( ( xTickCount + xTicksToJump ) <= xNextTaskUnblockTime );\r
+ xTickCount += xTicksToJump;\r
+ traceINCREASE_TICK_COUNT( xTicksToJump );\r
+ }\r
+\r
+#endif /* configUSE_TICKLESS_IDLE */\r
/*----------------------------------------------------------*/\r
\r
-#if ( configUSE_TICKLESS_IDLE != 0 )\r
+#if ( INCLUDE_xTaskAbortDelay == 1 )\r
\r
- static TickType_t prvGetExpectedIdleTime( void )\r
+ BaseType_t xTaskAbortDelay( TaskHandle_t xTask )\r
{\r
- TickType_t xReturn;\r
+ TCB_t *pxTCB = ( TCB_t * ) xTask;\r
+ BaseType_t xReturn;\r
\r
- if( pxCurrentTCB->uxPriority > tskIDLE_PRIORITY )\r
- {\r
- xReturn = 0;\r
- }\r
- else if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > 1 )\r
- {\r
- /* There are other idle priority tasks in the ready state. If\r
- time slicing is used then the very next tick interrupt must be\r
- processed. */\r
- xReturn = 0;\r
- }\r
- else\r
+ configASSERT( pxTCB );\r
+\r
+ vTaskSuspendAll();\r
{\r
- xReturn = xNextTaskUnblockTime - xTickCount;\r
+ /* A task can only be prematurely removed from the Blocked state if\r
+ it is actually in the Blocked state. */\r
+ if( eTaskGetState( xTask ) == eBlocked )\r
+ {\r
+ xReturn = pdPASS;\r
+\r
+ /* Remove the reference to the task from the blocked list. An\r
+ interrupt won't touch the xStateListItem because the\r
+ scheduler is suspended. */\r
+ ( void ) uxListRemove( &( pxTCB->xStateListItem ) );\r
+\r
+ /* Is the task waiting on an event also? If so remove it from\r
+ the event list too. Interrupts can touch the event list item,\r
+ even though the scheduler is suspended, so a critical section\r
+ is used. */\r
+ taskENTER_CRITICAL();\r
+ {\r
+ if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
+ {\r
+ ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
+ pxTCB->ucDelayAborted = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ taskEXIT_CRITICAL();\r
+\r
+ /* Place the unblocked task into the appropriate ready list. */\r
+ prvAddTaskToReadyList( pxTCB );\r
+\r
+ /* A task being unblocked cannot cause an immediate context\r
+ switch if preemption is turned off. */\r
+ #if ( configUSE_PREEMPTION == 1 )\r
+ {\r
+ /* Preemption is on, but a context switch should only be\r
+ performed if the unblocked task has a priority that is\r
+ equal to or higher than the currently executing task. */\r
+ if( pxTCB->uxPriority > pxCurrentTCB->uxPriority )\r
+ {\r
+ /* Pend the yield to be performed when the scheduler\r
+ is unsuspended. */\r
+ xYieldPending = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ #endif /* configUSE_PREEMPTION */\r
+ }\r
+ else\r
+ {\r
+ xReturn = pdFAIL;\r
+ }\r
}\r
+ ( void ) xTaskResumeAll();\r
\r
return xReturn;\r
}\r
\r
-#endif /* configUSE_TICKLESS_IDLE */\r
+#endif /* INCLUDE_xTaskAbortDelay */\r
/*----------------------------------------------------------*/\r
\r
-BaseType_t xTaskResumeAll( void )\r
+BaseType_t xTaskIncrementTick( void )\r
{\r
-TCB_t *pxTCB;\r
-BaseType_t xAlreadyYielded = pdFALSE;\r
-\r
- /* If uxSchedulerSuspended is zero then this function does not match a\r
- previous call to vTaskSuspendAll(). */\r
- configASSERT( uxSchedulerSuspended );\r
+TCB_t * pxTCB;\r
+TickType_t xItemValue;\r
+BaseType_t xSwitchRequired = pdFALSE;\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
- taskENTER_CRITICAL();\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
+ traceTASK_INCREMENT_TICK( xTickCount );\r
+ if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
{\r
- --uxSchedulerSuspended;\r
+ /* Minor optimisation. The tick count cannot change in this\r
+ block. */\r
+ const TickType_t xConstTickCount = xTickCount + ( TickType_t ) 1;\r
\r
- if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
+ /* Increment the RTOS tick, switching the delayed and overflowed\r
+ delayed lists if it wraps to 0. */\r
+ xTickCount = xConstTickCount;\r
+\r
+ if( xConstTickCount == ( TickType_t ) 0U ) /*lint !e774 'if' does not always evaluate to false as it is looking for an overflow. */\r
{\r
- if( uxCurrentNumberOfTasks > ( UBaseType_t ) 0U )\r
+ taskSWITCH_DELAYED_LISTS();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ /* See if this tick has made a timeout expire. Tasks are stored in\r
+ the queue in the order of their wake time - meaning once one task\r
+ has been found whose block time has not expired there is no need to\r
+ look any further down the list. */\r
+ if( xConstTickCount >= xNextTaskUnblockTime )\r
+ {\r
+ for( ;; )\r
{\r
- /* Move any readied tasks from the pending list into the\r
- appropriate ready list. */\r
- while( listLIST_IS_EMPTY( &xPendingReadyList ) == pdFALSE )\r
+ if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
{\r
- pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xPendingReadyList ) );\r
- ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
- ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
- prvAddTaskToReadyList( pxTCB );\r
+ /* The delayed list is empty. Set xNextTaskUnblockTime\r
+ to the maximum possible value so it is extremely\r
+ unlikely that the\r
+ if( xTickCount >= xNextTaskUnblockTime ) test will pass\r
+ next time through. */\r
+ xNextTaskUnblockTime = portMAX_DELAY; /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ break;\r
+ }\r
+ else\r
+ {\r
+ /* The delayed list is not empty, get the value of the\r
+ item at the head of the delayed list. This is the time\r
+ at which the task at the head of the delayed list must\r
+ be removed from the Blocked state. */\r
+ pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
+ xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ) );\r
+\r
+ if( xConstTickCount < xItemValue )\r
+ {\r
+ /* It is not time to unblock this item yet, but the\r
+ item value is the time at which the task at the head\r
+ of the blocked list must be removed from the Blocked\r
+ state - so record the item value in\r
+ xNextTaskUnblockTime. */\r
+ xNextTaskUnblockTime = xItemValue;\r
+ break;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\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
+ /* It is time to remove the item from the Blocked state. */\r
+ ( void ) uxListRemove( &( pxTCB->xStateListItem ) );\r
+\r
+ /* Is the task waiting on an event also? If so remove\r
+ it from the event list. */\r
+ if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
{\r
- xYieldPending = pdTRUE;\r
+ ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
}\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
- }\r
\r
- /* If any ticks occurred while the scheduler was suspended then\r
- they should be processed now. This ensures the tick count does\r
- not slip, and that any delayed tasks are resumed at the correct\r
- time. */\r
- if( uxPendedTicks > ( UBaseType_t ) 0U )\r
- {\r
- while( uxPendedTicks > ( UBaseType_t ) 0U )\r
+ /* Place the unblocked task into the appropriate ready\r
+ list. */\r
+ prvAddTaskToReadyList( pxTCB );\r
+\r
+ /* A task being unblocked cannot cause an immediate\r
+ context switch if preemption is turned off. */\r
+ #if ( configUSE_PREEMPTION == 1 )\r
{\r
- if( xTaskIncrementTick() != pdFALSE )\r
+ /* Preemption is on, but a context switch should\r
+ only be performed if the unblocked task has a\r
+ priority that is equal to or higher than the\r
+ currently executing task. */\r
+ if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
{\r
- xYieldPending = pdTRUE;\r
+ xSwitchRequired = pdTRUE;\r
}\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
- --uxPendedTicks;\r
}\r
+ #endif /* configUSE_PREEMPTION */\r
}\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ }\r
+ }\r
\r
- if( xYieldPending == pdTRUE )\r
- {\r
- #if( configUSE_PREEMPTION != 0 )\r
- {\r
- xAlreadyYielded = pdTRUE;\r
- }\r
- #endif\r
- taskYIELD_IF_USING_PREEMPTION();\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ /* Tasks of equal priority to the currently running task will share\r
+ processing time (time slice) if preemption is on, and the application\r
+ writer has not explicitly turned time slicing off. */\r
+ #if ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) )\r
+ {\r
+ if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ pxCurrentTCB->uxPriority ] ) ) > ( UBaseType_t ) 1 )\r
+ {\r
+ xSwitchRequired = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
}\r
}\r
- else\r
+ #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) */\r
+\r
+ #if ( configUSE_TICK_HOOK == 1 )\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ /* Guard against the tick hook being called when the pended tick\r
+ count is being unwound (when the scheduler is being unlocked). */\r
+ if( uxPendedTicks == ( UBaseType_t ) 0U )\r
+ {\r
+ vApplicationTickHook();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
}\r
+ #endif /* configUSE_TICK_HOOK */\r
}\r
- taskEXIT_CRITICAL();\r
-\r
- return xAlreadyYielded;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-TickType_t xTaskGetTickCount( void )\r
-{\r
-TickType_t xTicks;\r
-\r
- /* Critical section required if running on a 16 bit processor. */\r
- taskENTER_CRITICAL();\r
+ else\r
{\r
- xTicks = xTickCount;\r
- }\r
- taskEXIT_CRITICAL();\r
-\r
- return xTicks;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-TickType_t xTaskGetTickCountFromISR( void )\r
-{\r
-TickType_t xReturn;\r
-UBaseType_t uxSavedInterruptStatus;\r
+ ++uxPendedTicks;\r
\r
- /* RTOS ports that support interrupt nesting have the concept of a maximum\r
- system call (or maximum API call) interrupt priority. Interrupts that are\r
- above the maximum system call priority are kept permanently enabled, even\r
- when the RTOS kernel is in a critical section, but cannot make any calls to\r
- FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h\r
- then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
- failure if a FreeRTOS API function is called from an interrupt that has been\r
- assigned a priority above the configured maximum system call priority.\r
- Only FreeRTOS functions that end in FromISR can be called from interrupts\r
- that have been assigned a priority at or (logically) below the maximum\r
- system call interrupt priority. FreeRTOS maintains a separate interrupt\r
- safe API to ensure interrupt entry is as fast and as simple as possible.\r
- More information (albeit Cortex-M specific) is provided on the following\r
- link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
- portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+ /* The tick hook gets called at regular intervals, even if the\r
+ scheduler is locked. */\r
+ #if ( configUSE_TICK_HOOK == 1 )\r
+ {\r
+ vApplicationTickHook();\r
+ }\r
+ #endif\r
+ }\r
\r
- uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+ #if ( configUSE_PREEMPTION == 1 )\r
{\r
- xReturn = xTickCount;\r
+ if( xYieldPending != pdFALSE )\r
+ {\r
+ xSwitchRequired = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
}\r
- portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+ #endif /* configUSE_PREEMPTION */\r
\r
- return xReturn;\r
+ return xSwitchRequired;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-UBaseType_t uxTaskGetNumberOfTasks( void )\r
-{\r
- /* A critical section is not required because the variables are of type\r
- BaseType_t. */\r
- return uxCurrentNumberOfTasks;\r
-}\r
+#if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
+\r
+ void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction )\r
+ {\r
+ TCB_t *xTCB;\r
+\r
+ /* If xTask is NULL then it is the task hook of the calling task that is\r
+ getting set. */\r
+ if( xTask == NULL )\r
+ {\r
+ xTCB = ( TCB_t * ) pxCurrentTCB;\r
+ }\r
+ else\r
+ {\r
+ xTCB = ( TCB_t * ) 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
+ taskENTER_CRITICAL();\r
+ xTCB->pxTaskTag = pxHookFunction;\r
+ taskEXIT_CRITICAL();\r
+ }\r
+\r
+#endif /* configUSE_APPLICATION_TASK_TAG */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( INCLUDE_pcTaskGetTaskName == 1 )\r
+#if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
\r
- char *pcTaskGetTaskName( TaskHandle_t xTaskToQuery )\r
+ TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask )\r
{\r
- TCB_t *pxTCB;\r
+ TCB_t *xTCB;\r
+ TaskHookFunction_t xReturn;\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
+ /* If xTask is NULL then we are setting our own task hook. */\r
+ if( xTask == NULL )\r
+ {\r
+ xTCB = ( TCB_t * ) pxCurrentTCB;\r
+ }\r
+ else\r
+ {\r
+ xTCB = ( TCB_t * ) 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
+ taskENTER_CRITICAL();\r
+ {\r
+ xReturn = xTCB->pxTaskTag;\r
+ }\r
+ taskEXIT_CRITICAL();\r
+\r
+ return xReturn;\r
}\r
\r
-#endif /* INCLUDE_pcTaskGetTaskName */\r
+#endif /* configUSE_APPLICATION_TASK_TAG */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
+#if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
\r
- UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime )\r
+ BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter )\r
{\r
- UBaseType_t uxTask = 0, uxQueue = configMAX_PRIORITIES;\r
+ TCB_t *xTCB;\r
+ BaseType_t xReturn;\r
\r
- vTaskSuspendAll();\r
+ /* If xTask is NULL then we are calling our own task hook. */\r
+ if( xTask == NULL )\r
{\r
- /* Is there a space in the array for each task in the system? */\r
- if( uxArraySize >= uxCurrentNumberOfTasks )\r
- {\r
- /* Fill in an TaskStatus_t structure with information on each\r
- task in the Ready state. */\r
- do\r
- {\r
- uxQueue--;\r
- uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &( pxReadyTasksLists[ uxQueue ] ), eReady );\r
+ xTCB = ( TCB_t * ) pxCurrentTCB;\r
+ }\r
+ else\r
+ {\r
+ xTCB = ( TCB_t * ) xTask;\r
+ }\r
\r
- } while( uxQueue > ( UBaseType_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ if( xTCB->pxTaskTag != NULL )\r
+ {\r
+ xReturn = xTCB->pxTaskTag( pvParameter );\r
+ }\r
+ else\r
+ {\r
+ xReturn = pdFAIL;\r
+ }\r
\r
- /* Fill in an TaskStatus_t structure with information on each\r
- task in the Blocked state. */\r
- uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxDelayedTaskList, eBlocked );\r
- uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxOverflowDelayedTaskList, eBlocked );\r
+ return xReturn;\r
+ }\r
\r
- #if( INCLUDE_vTaskDelete == 1 )\r
- {\r
- /* Fill in an TaskStatus_t structure with information on\r
- each task that has been deleted but not yet cleaned up. */\r
- uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xTasksWaitingTermination, eDeleted );\r
- }\r
- #endif\r
+#endif /* configUSE_APPLICATION_TASK_TAG */\r
+/*-----------------------------------------------------------*/\r
\r
- #if ( INCLUDE_vTaskSuspend == 1 )\r
- {\r
- /* Fill in an TaskStatus_t structure with information on\r
- each task in the Suspended state. */\r
- uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xSuspendedTaskList, eSuspended );\r
- }\r
+void vTaskSwitchContext( void )\r
+{\r
+ if( uxSchedulerSuspended != ( UBaseType_t ) pdFALSE )\r
+ {\r
+ /* The scheduler is currently suspended - do not allow a context\r
+ switch. */\r
+ xYieldPending = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ xYieldPending = pdFALSE;\r
+ traceTASK_SWITCHED_OUT();\r
+\r
+ #if ( configGENERATE_RUN_TIME_STATS == 1 )\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
- #if ( configGENERATE_RUN_TIME_STATS == 1)\r
+ /* Add the amount of time the task has been running to the\r
+ accumulated time so far. The time the task started running was\r
+ stored in ulTaskSwitchedInTime. Note that there is no overflow\r
+ protection here so count values are only valid until the timer\r
+ overflows. The guard against negative values is to protect\r
+ against suspect run time stat counter implementations - which\r
+ are provided by the application, not the kernel. */\r
+ if( ulTotalRunTime > ulTaskSwitchedInTime )\r
{\r
- if( pulTotalRunTime != NULL )\r
- {\r
- #ifdef portALT_GET_RUN_TIME_COUNTER_VALUE\r
- portALT_GET_RUN_TIME_COUNTER_VALUE( ( *pulTotalRunTime ) );\r
- #else\r
- *pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
- #endif\r
- }\r
+ pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime );\r
}\r
- #else\r
+ else\r
{\r
- if( pulTotalRunTime != NULL )\r
- {\r
- *pulTotalRunTime = 0;\r
- }\r
+ mtCOVERAGE_TEST_MARKER();\r
}\r
- #endif\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ ulTaskSwitchedInTime = ulTotalRunTime;\r
}\r
- ( void ) xTaskResumeAll();\r
-\r
- return uxTask;\r
- }\r
+ #endif /* configGENERATE_RUN_TIME_STATS */\r
\r
-#endif /* configUSE_TRACE_FACILITY */\r
-/*----------------------------------------------------------*/\r
+ /* Check for stack overflow, if configured. */\r
+ taskCHECK_FOR_STACK_OVERFLOW();\r
\r
-#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\r
+ /* Select a new task to run using either the generic C or port\r
+ optimised asm code. */\r
+ taskSELECT_HIGHEST_PRIORITY_TASK();\r
+ traceTASK_SWITCHED_IN();\r
\r
- TaskHandle_t 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
+ #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
+ {\r
+ /* Switch Newlib's _impure_ptr variable to point to the _reent\r
+ structure specific to this task. */\r
+ _impure_ptr = &( pxCurrentTCB->xNewLib_reent );\r
+ }\r
+ #endif /* configUSE_NEWLIB_REENTRANT */\r
}\r
+}\r
+/*-----------------------------------------------------------*/\r
\r
-#endif /* INCLUDE_xTaskGetIdleTaskHandle */\r
-/*----------------------------------------------------------*/\r
+void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait )\r
+{\r
+ configASSERT( pxEventList );\r
\r
-/* This conditional compilation should use inequality to 0, not equality to 1.\r
-This is to ensure vTaskStepTick() is available when user defined low power mode\r
-implementations require configUSE_TICKLESS_IDLE to be set to a value other than\r
-1. */\r
-#if ( configUSE_TICKLESS_IDLE != 0 )\r
+ /* THIS FUNCTION MUST BE CALLED WITH EITHER INTERRUPTS DISABLED OR THE\r
+ SCHEDULER SUSPENDED AND THE QUEUE BEING ACCESSED LOCKED. */\r
\r
- void vTaskStepTick( const TickType_t xTicksToJump )\r
- {\r
- /* Correct the tick count value after a period during which the tick\r
- was suppressed. Note this does *not* call the tick hook function for\r
- each stepped tick. */\r
- configASSERT( ( xTickCount + xTicksToJump ) <= xNextTaskUnblockTime );\r
- xTickCount += xTicksToJump;\r
- traceINCREASE_TICK_COUNT( xTicksToJump );\r
- }\r
+ /* Place the event list item of the TCB in the appropriate event list.\r
+ This is placed in the list in priority order so the highest priority task\r
+ is the first to be woken by the event. The queue that contains the event\r
+ list is locked, preventing simultaneous access from interrupts. */\r
+ vListInsert( pxEventList, &( pxCurrentTCB->xEventListItem ) );\r
\r
-#endif /* configUSE_TICKLESS_IDLE */\r
-/*----------------------------------------------------------*/\r
+ prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );\r
+}\r
+/*-----------------------------------------------------------*/\r
\r
-BaseType_t xTaskIncrementTick( void )\r
+void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait )\r
{\r
-TCB_t * pxTCB;\r
-TickType_t xItemValue;\r
-BaseType_t xSwitchRequired = pdFALSE;\r
+ configASSERT( pxEventList );\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
- traceTASK_INCREMENT_TICK( xTickCount );\r
- if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
+ /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by\r
+ the event groups implementation. */\r
+ configASSERT( uxSchedulerSuspended != 0 );\r
+\r
+ /* Store the item value in the event list item. It is safe to access the\r
+ event list item here as interrupts won't access the event list item of a\r
+ task that is not in the Blocked state. */\r
+ listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );\r
+\r
+ /* Place the event list item of the TCB at the end of the appropriate event\r
+ list. It is safe to access the event list here because it is part of an\r
+ event group implementation - and interrupts don't access event groups\r
+ directly (instead they access them indirectly by pending function calls to\r
+ the task level). */\r
+ vListInsertEnd( pxEventList, &( pxCurrentTCB->xEventListItem ) );\r
+\r
+ prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( configUSE_TIMERS == 1 )\r
+\r
+ void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely )\r
{\r
- /* Increment the RTOS tick, switching the delayed and overflowed\r
- delayed lists if it wraps to 0. */\r
- ++xTickCount;\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 with the scheduler suspended. */\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( pxEventList, &( pxCurrentTCB->xEventListItem ) );\r
\r
+ /* If the task should block indefinitely then set the block time to a\r
+ value that will be recognised as an indefinite delay inside the\r
+ prvAddCurrentTaskToDelayedList() function. */\r
+ if( xWaitIndefinitely != pdFALSE )\r
{\r
- /* Minor optimisation. The tick count cannot change in this\r
- block. */\r
- const TickType_t xConstTickCount = xTickCount;\r
+ xTicksToWait = portMAX_DELAY;\r
+ }\r
\r
- if( xConstTickCount == ( TickType_t ) 0U )\r
- {\r
- taskSWITCH_DELAYED_LISTS();\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ traceTASK_DELAY_UNTIL( ( xTickCount + xTicksToWait ) );\r
+ prvAddCurrentTaskToDelayedList( xTicksToWait, xWaitIndefinitely );\r
+ }\r
\r
- /* See if this tick has made a timeout expire. Tasks are stored in\r
- the queue in the order of their wake time - meaning once one task\r
- has been found whose block time has not expired there is no need to\r
- look any further down the list. */\r
- if( xConstTickCount >= xNextTaskUnblockTime )\r
- {\r
- for( ;; )\r
- {\r
- if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
- {\r
- /* The delayed list is empty. Set xNextTaskUnblockTime\r
- to the maximum possible value so it is extremely\r
- unlikely that the\r
- if( xTickCount >= xNextTaskUnblockTime ) test will pass\r
- next time through. */\r
- xNextTaskUnblockTime = portMAX_DELAY;\r
- break;\r
- }\r
- else\r
- {\r
- /* The delayed list is not empty, get the value of the\r
- item at the head of the delayed list. This is the time\r
- at which the task at the head of the delayed list must\r
- be removed from the Blocked state. */\r
- pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
- xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );\r
-\r
- if( xConstTickCount < xItemValue )\r
- {\r
- /* It is not time to unblock this item yet, but the\r
- item value is the time at which the task at the head\r
- of the blocked list must be removed from the Blocked\r
- state - so record the item value in\r
- xNextTaskUnblockTime. */\r
- xNextTaskUnblockTime = xItemValue;\r
- break;\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+#endif /* configUSE_TIMERS */\r
+/*-----------------------------------------------------------*/\r
\r
- /* It is time to remove the item from the Blocked state. */\r
- ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
+BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList )\r
+{\r
+TCB_t *pxUnblockedTCB;\r
+BaseType_t xReturn;\r
\r
- /* Is the task waiting on an event also? If so remove\r
- it from the event list. */\r
- if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
- {\r
- ( void ) uxListRemove( &( pxTCB->xEventListItem ) );\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ /* THIS FUNCTION MUST BE CALLED FROM A CRITICAL SECTION. It can also be\r
+ called from a critical section within an ISR. */\r
\r
- /* Place the unblocked task into the appropriate ready\r
- list. */\r
- prvAddTaskToReadyList( pxTCB );\r
+ /* The event list is sorted in priority order, so the first in the list can\r
+ be removed as it is known to be the highest priority. Remove the TCB from\r
+ the delayed list, and add it to the ready list.\r
\r
- /* A task being unblocked cannot cause an immediate\r
- context switch if preemption is turned off. */\r
- #if ( configUSE_PREEMPTION == 1 )\r
- {\r
- /* Preemption is on, but a context switch should\r
- only be performed if the unblocked task has a\r
- priority that is equal to or higher than the\r
- currently executing task. */\r
- if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
- {\r
- xSwitchRequired = pdTRUE;\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- }\r
- #endif /* configUSE_PREEMPTION */\r
- }\r
- }\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 exclusive access to the event list is guaranteed here.\r
\r
- /* Tasks of equal priority to the currently running task will share\r
- processing time (time slice) if preemption is on, and the application\r
- writer has not explicitly turned time slicing off. */\r
- #if ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) )\r
- {\r
- if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ pxCurrentTCB->uxPriority ] ) ) > ( UBaseType_t ) 1 )\r
- {\r
- xSwitchRequired = pdTRUE;\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- }\r
- #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) */\r
+ This function assumes that a check has already been made to ensure that\r
+ pxEventList is not empty. */\r
+ pxUnblockedTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );\r
+ configASSERT( pxUnblockedTCB );\r
+ ( void ) uxListRemove( &( pxUnblockedTCB->xEventListItem ) );\r
\r
- #if ( configUSE_TICK_HOOK == 1 )\r
- {\r
- /* Guard against the tick hook being called when the pended tick\r
- count is being unwound (when the scheduler is being unlocked). */\r
- if( uxPendedTicks == ( UBaseType_t ) 0U )\r
- {\r
- vApplicationTickHook();\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- }\r
- #endif /* configUSE_TICK_HOOK */\r
+ if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
+ {\r
+ ( void ) uxListRemove( &( pxUnblockedTCB->xStateListItem ) );\r
+ prvAddTaskToReadyList( pxUnblockedTCB );\r
}\r
else\r
{\r
- ++uxPendedTicks;\r
+ /* The delayed and ready lists cannot be accessed, so hold this task\r
+ pending until the scheduler is resumed. */\r
+ vListInsertEnd( &( xPendingReadyList ), &( pxUnblockedTCB->xEventListItem ) );\r
+ }\r
\r
- /* The tick hook gets called at regular intervals, even if the\r
- scheduler is locked. */\r
- #if ( configUSE_TICK_HOOK == 1 )\r
- {\r
- vApplicationTickHook();\r
- }\r
- #endif\r
+ if( pxUnblockedTCB->uxPriority > pxCurrentTCB->uxPriority )\r
+ {\r
+ /* Return true if the task removed from the event list has a higher\r
+ priority than the calling task. This allows the calling task to know if\r
+ it should force a context switch now. */\r
+ xReturn = pdTRUE;\r
+\r
+ /* Mark that a yield is pending in case the user is not using the\r
+ "xHigherPriorityTaskWoken" parameter to an ISR safe FreeRTOS function. */\r
+ xYieldPending = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ xReturn = pdFALSE;\r
}\r
\r
- #if ( configUSE_PREEMPTION == 1 )\r
+ #if( configUSE_TICKLESS_IDLE != 0 )\r
{\r
- if( xYieldPending != pdFALSE )\r
- {\r
- xSwitchRequired = pdTRUE;\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ /* If a task is blocked on a kernel object then xNextTaskUnblockTime\r
+ might be set to the blocked task's time out time. If the task is\r
+ unblocked for a reason other than a timeout xNextTaskUnblockTime is\r
+ normally left unchanged, because it is automatically reset to a new\r
+ value when the tick count equals xNextTaskUnblockTime. However if\r
+ tickless idling is used it might be more important to enter sleep mode\r
+ at the earliest possible time - so reset xNextTaskUnblockTime here to\r
+ ensure it is updated at the earliest possible time. */\r
+ prvResetNextTaskUnblockTime();\r
}\r
- #endif /* configUSE_PREEMPTION */\r
+ #endif\r
\r
- return xSwitchRequired;\r
+ return xReturn;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-#if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
+void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue )\r
+{\r
+TCB_t *pxUnblockedTCB;\r
\r
- void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction )\r
- {\r
- TCB_t *xTCB;\r
+ /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by\r
+ the event flags implementation. */\r
+ configASSERT( uxSchedulerSuspended != pdFALSE );\r
\r
- /* If xTask is NULL then it is the task hook of the calling task that is\r
- getting set. */\r
- if( xTask == NULL )\r
- {\r
- xTCB = ( TCB_t * ) pxCurrentTCB;\r
- }\r
- else\r
- {\r
- xTCB = ( TCB_t * ) xTask;\r
- }\r
+ /* Store the new item value in the event list. */\r
+ listSET_LIST_ITEM_VALUE( pxEventListItem, xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );\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
- xTCB->pxTaskTag = pxHookFunction;\r
- taskEXIT_CRITICAL();\r
+ /* Remove the event list form the event flag. Interrupts do not access\r
+ event flags. */\r
+ pxUnblockedTCB = ( TCB_t * ) listGET_LIST_ITEM_OWNER( pxEventListItem );\r
+ configASSERT( pxUnblockedTCB );\r
+ ( void ) uxListRemove( pxEventListItem );\r
+\r
+ /* Remove the task from the delayed list and add it to the ready list. The\r
+ scheduler is suspended so interrupts will not be accessing the ready\r
+ lists. */\r
+ ( void ) uxListRemove( &( pxUnblockedTCB->xStateListItem ) );\r
+ prvAddTaskToReadyList( pxUnblockedTCB );\r
+\r
+ if( pxUnblockedTCB->uxPriority > pxCurrentTCB->uxPriority )\r
+ {\r
+ /* The unblocked task has a priority above that of the calling task, so\r
+ a context switch is required. This function is called with the\r
+ scheduler suspended so xYieldPending is set so the context switch\r
+ occurs immediately that the scheduler is resumed (unsuspended). */\r
+ xYieldPending = pdTRUE;\r
}\r
+}\r
+/*-----------------------------------------------------------*/\r
\r
-#endif /* configUSE_APPLICATION_TASK_TAG */\r
+void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut )\r
+{\r
+ configASSERT( pxTimeOut );\r
+ pxTimeOut->xOverflowCount = xNumOfOverflows;\r
+ pxTimeOut->xTimeOnEntering = xTickCount;\r
+}\r
/*-----------------------------------------------------------*/\r
\r
-#if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
+BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait )\r
+{\r
+BaseType_t xReturn;\r
\r
- TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask )\r
+ configASSERT( pxTimeOut );\r
+ configASSERT( pxTicksToWait );\r
+\r
+ taskENTER_CRITICAL();\r
{\r
- TCB_t *xTCB;\r
- TaskHookFunction_t xReturn;\r
+ /* Minor optimisation. The tick count cannot change in this block. */\r
+ const TickType_t xConstTickCount = xTickCount;\r
+ const TickType_t xElapsedTime = xConstTickCount - pxTimeOut->xTimeOnEntering;\r
\r
- /* If xTask is NULL then we are setting our own task hook. */\r
- if( xTask == NULL )\r
+ #if( INCLUDE_xTaskAbortDelay == 1 )\r
+ if( pxCurrentTCB->ucDelayAborted != pdFALSE )\r
+ {\r
+ /* The delay was aborted, which is not the same as a time out,\r
+ but has the same result. */\r
+ pxCurrentTCB->ucDelayAborted = pdFALSE;\r
+ xReturn = pdTRUE;\r
+ }\r
+ else\r
+ #endif\r
+\r
+ #if ( INCLUDE_vTaskSuspend == 1 )\r
+ if( *pxTicksToWait == portMAX_DELAY )\r
+ {\r
+ /* If INCLUDE_vTaskSuspend is set to 1 and the block time\r
+ specified is the maximum block time then the task should block\r
+ indefinitely, and therefore never time out. */\r
+ xReturn = pdFALSE;\r
+ }\r
+ else\r
+ #endif\r
+\r
+ if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( xConstTickCount >= pxTimeOut->xTimeOnEntering ) ) /*lint !e525 Indentation preferred as is to make code within pre-processor directives clearer. */\r
{\r
- xTCB = ( TCB_t * ) pxCurrentTCB;\r
+ /* The tick count is greater than the time at which\r
+ vTaskSetTimeout() was called, but has also overflowed since\r
+ vTaskSetTimeOut() was called. It must have wrapped all the way\r
+ around and gone past again. This passed since vTaskSetTimeout()\r
+ was called. */\r
+ xReturn = pdTRUE;\r
}\r
- else\r
+ else if( xElapsedTime < *pxTicksToWait ) /*lint !e961 Explicit casting is only redundant with some compilers, whereas others require it to prevent integer conversion errors. */\r
{\r
- xTCB = ( TCB_t * ) xTask;\r
+ /* Not a genuine timeout. Adjust parameters for time remaining. */\r
+ *pxTicksToWait -= xElapsedTime;\r
+ vTaskSetTimeOutState( pxTimeOut );\r
+ xReturn = pdFALSE;\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
- taskENTER_CRITICAL();\r
+ else\r
{\r
- xReturn = xTCB->pxTaskTag;\r
+ xReturn = pdTRUE;\r
}\r
- taskEXIT_CRITICAL();\r
-\r
- return xReturn;\r
}\r
+ taskEXIT_CRITICAL();\r
\r
-#endif /* configUSE_APPLICATION_TASK_TAG */\r
+ return xReturn;\r
+}\r
/*-----------------------------------------------------------*/\r
\r
-#if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
+void vTaskMissedYield( void )\r
+{\r
+ xYieldPending = pdTRUE;\r
+}\r
+/*-----------------------------------------------------------*/\r
\r
- BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter )\r
- {\r
- TCB_t *xTCB;\r
- BaseType_t xReturn;\r
+#if ( configUSE_TRACE_FACILITY == 1 )\r
\r
- /* If xTask is NULL then we are calling our own task hook. */\r
- if( xTask == NULL )\r
- {\r
- xTCB = ( TCB_t * ) pxCurrentTCB;\r
- }\r
- else\r
- {\r
- xTCB = ( TCB_t * ) xTask;\r
- }\r
+ UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask )\r
+ {\r
+ UBaseType_t uxReturn;\r
+ TCB_t *pxTCB;\r
\r
- if( xTCB->pxTaskTag != NULL )\r
+ if( xTask != NULL )\r
{\r
- xReturn = xTCB->pxTaskTag( pvParameter );\r
+ pxTCB = ( TCB_t * ) xTask;\r
+ uxReturn = pxTCB->uxTaskNumber;\r
}\r
else\r
{\r
- xReturn = pdFAIL;\r
+ uxReturn = 0U;\r
}\r
\r
- return xReturn;\r
+ return uxReturn;\r
}\r
\r
-#endif /* configUSE_APPLICATION_TASK_TAG */\r
+#endif /* configUSE_TRACE_FACILITY */\r
/*-----------------------------------------------------------*/\r
\r
-void vTaskSwitchContext( void )\r
-{\r
- if( uxSchedulerSuspended != ( UBaseType_t ) pdFALSE )\r
- {\r
- /* The scheduler is currently suspended - do not allow a context\r
- switch. */\r
- xYieldPending = pdTRUE;\r
- }\r
- else\r
- {\r
- xYieldPending = pdFALSE;\r
- traceTASK_SWITCHED_OUT();\r
-\r
- #if ( configGENERATE_RUN_TIME_STATS == 1 )\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
- /* Add the amount of time the task has been running to the\r
- accumulated time so far. The time the task started running was\r
- stored in ulTaskSwitchedInTime. Note that there is no overflow\r
- protection here so count values are only valid until the timer\r
- overflows. The guard against negative values is to protect\r
- against suspect run time stat counter implementations - which\r
- are provided by the application, not the kernel. */\r
- if( ulTotalRunTime > ulTaskSwitchedInTime )\r
- {\r
- pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime );\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- ulTaskSwitchedInTime = ulTotalRunTime;\r
- }\r
- #endif /* configGENERATE_RUN_TIME_STATS */\r
-\r
- taskFIRST_CHECK_FOR_STACK_OVERFLOW();\r
- taskSECOND_CHECK_FOR_STACK_OVERFLOW();\r
-\r
- taskSELECT_HIGHEST_PRIORITY_TASK();\r
+#if ( configUSE_TRACE_FACILITY == 1 )\r
\r
- traceTASK_SWITCHED_IN();\r
+ void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle )\r
+ {\r
+ TCB_t *pxTCB;\r
\r
- #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
+ if( xTask != NULL )\r
{\r
- /* Switch Newlib's _impure_ptr variable to point to the _reent\r
- structure specific to this task. */\r
- _impure_ptr = &( pxCurrentTCB->xNewLib_reent );\r
+ pxTCB = ( TCB_t * ) xTask;\r
+ pxTCB->uxTaskNumber = uxHandle;\r
}\r
- #endif /* configUSE_NEWLIB_REENTRANT */\r
}\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait )\r
-{\r
-TickType_t xTimeToWake;\r
\r
- configASSERT( pxEventList );\r
+#endif /* configUSE_TRACE_FACILITY */\r
\r
- /* THIS FUNCTION MUST BE CALLED WITH EITHER INTERRUPTS DISABLED OR THE\r
- SCHEDULER SUSPENDED AND THE QUEUE BEING ACCESSED LOCKED. */\r
+/*\r
+ * -----------------------------------------------------------\r
+ * The Idle task.\r
+ * ----------------------------------------------------------\r
+ *\r
+ * The portTASK_FUNCTION() macro is used to allow port/compiler specific\r
+ * language extensions. The equivalent prototype for this function is:\r
+ *\r
+ * void prvIdleTask( void *pvParameters );\r
+ *\r
+ */\r
+static portTASK_FUNCTION( prvIdleTask, pvParameters )\r
+{\r
+ /* Stop warnings. */\r
+ ( void ) pvParameters;\r
\r
- /* Place the event list item of the TCB in the appropriate event list.\r
- This is placed in the list in priority order so the highest priority task\r
- is the first to be woken by the event. The queue that contains the event\r
- list is locked, preventing simultaneous access from interrupts. */\r
- vListInsert( pxEventList, &( pxCurrentTCB->xEventListItem ) );\r
+ /** THIS IS THE RTOS IDLE TASK - WHICH IS CREATED AUTOMATICALLY WHEN THE\r
+ SCHEDULER IS STARTED. **/\r
\r
- /* The task must be removed from from the ready list before it is added to\r
- the blocked list as the same list item is used for both lists. Exclusive\r
- access to the ready lists guaranteed because the scheduler is locked. */\r
- if( uxListRemove( &( pxCurrentTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
- {\r
- /* The current task must be in a ready list, so there is no need to\r
- check, and the port reset macro can be called directly. */\r
- portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
- }\r
- else\r
+ for( ;; )\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ /* See if any tasks have deleted themselves - if so then the idle task\r
+ is responsible for freeing the deleted task's TCB and stack. */\r
+ prvCheckTasksWaitingTermination();\r
\r
- #if ( INCLUDE_vTaskSuspend == 1 )\r
- {\r
- if( xTicksToWait == portMAX_DELAY )\r
+ #if ( configUSE_PREEMPTION == 0 )\r
{\r
- /* Add the task to the suspended task list instead of a delayed task\r
- list to ensure the task is not woken by a timing event. It will\r
- block indefinitely. */\r
- vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xGenericListItem ) );\r
+ /* If we are not using preemption we keep forcing a task switch to\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
}\r
- else\r
+ #endif /* configUSE_PREEMPTION */\r
+\r
+ #if ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) )\r
{\r
- /* Calculate the time at which the task should be woken if the event\r
- does not occur. This may overflow but this doesn't matter, the\r
- scheduler will handle it. */\r
- xTimeToWake = xTickCount + xTicksToWait;\r
- prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+ /* When using preemption tasks of equal priority will be\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
+ 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
+ then a task other than the idle task is ready to execute. */\r
+ if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > ( UBaseType_t ) 1 )\r
+ {\r
+ taskYIELD();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
}\r
- }\r
- #else /* INCLUDE_vTaskSuspend */\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, the scheduler\r
- will handle it. */\r
- xTimeToWake = xTickCount + xTicksToWait;\r
- prvAddCurrentTaskToDelayedList( xTimeToWake );\r
- }\r
- #endif /* INCLUDE_vTaskSuspend */\r
-}\r
-/*-----------------------------------------------------------*/\r
+ #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) ) */\r
\r
-void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait )\r
-{\r
-TickType_t xTimeToWake;\r
+ #if ( configUSE_IDLE_HOOK == 1 )\r
+ {\r
+ extern void vApplicationIdleHook( void );\r
\r
- configASSERT( pxEventList );\r
+ /* Call the user defined function from within the idle task. This\r
+ allows the application designer to add background functionality\r
+ without the overhead of a separate task.\r
+ NOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES,\r
+ CALL A FUNCTION THAT MIGHT BLOCK. */\r
+ vApplicationIdleHook();\r
+ }\r
+ #endif /* configUSE_IDLE_HOOK */\r
\r
- /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by\r
- the event groups implementation. */\r
- configASSERT( uxSchedulerSuspended != 0 );\r
+ /* This conditional compilation should use inequality to 0, not equality\r
+ to 1. This is to ensure portSUPPRESS_TICKS_AND_SLEEP() is called when\r
+ user defined low power mode implementations require\r
+ configUSE_TICKLESS_IDLE to be set to a value other than 1. */\r
+ #if ( configUSE_TICKLESS_IDLE != 0 )\r
+ {\r
+ TickType_t xExpectedIdleTime;\r
\r
- /* Store the item value in the event list item. It is safe to access the\r
- event list item here as interrupts won't access the event list item of a\r
- task that is not in the Blocked state. */\r
- listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );\r
+ /* It is not desirable to suspend then resume the scheduler on\r
+ each iteration of the idle task. Therefore, a preliminary\r
+ test of the expected idle time is performed without the\r
+ scheduler suspended. The result here is not necessarily\r
+ valid. */\r
+ xExpectedIdleTime = prvGetExpectedIdleTime();\r
\r
- /* Place the event list item of the TCB at the end of the appropriate event\r
- list. It is safe to access the event list here because it is part of an\r
- event group implementation - and interrupts don't access event groups\r
- directly (instead they access them indirectly by pending function calls to\r
- the task level). */\r
- vListInsertEnd( pxEventList, &( pxCurrentTCB->xEventListItem ) );\r
+ if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )\r
+ {\r
+ vTaskSuspendAll();\r
+ {\r
+ /* Now the scheduler is suspended, the expected idle\r
+ time can be sampled again, and this time its value can\r
+ be used. */\r
+ configASSERT( xNextTaskUnblockTime >= xTickCount );\r
+ xExpectedIdleTime = prvGetExpectedIdleTime();\r
\r
- /* The task must be removed from the ready list before it is added to the\r
- blocked list. Exclusive access can be assured to the ready list as the\r
- scheduler is locked. */\r
- if( uxListRemove( &( pxCurrentTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
- {\r
- /* The current task must be in a ready list, so there is no need to\r
- check, and the port reset macro can be called directly. */\r
- portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
+ /* Define the following macro to set xExpectedIdleTime to 0\r
+ if the application does not want\r
+ portSUPPRESS_TICKS_AND_SLEEP() to be called. */\r
+ configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING( xExpectedIdleTime );\r
+\r
+ if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )\r
+ {\r
+ traceLOW_POWER_IDLE_BEGIN();\r
+ portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime );\r
+ traceLOW_POWER_IDLE_END();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ ( void ) xTaskResumeAll();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ #endif /* configUSE_TICKLESS_IDLE */\r
}\r
+}\r
+/*-----------------------------------------------------------*/\r
\r
- #if ( INCLUDE_vTaskSuspend == 1 )\r
+#if( configUSE_TICKLESS_IDLE != 0 )\r
+\r
+ eSleepModeStatus eTaskConfirmSleepModeStatus( void )\r
{\r
- if( xTicksToWait == portMAX_DELAY )\r
+ /* The idle task exists in addition to the application tasks. */\r
+ const UBaseType_t uxNonApplicationTasks = 1;\r
+ eSleepModeStatus eReturn = eStandardSleep;\r
+\r
+ if( listCURRENT_LIST_LENGTH( &xPendingReadyList ) != 0 )\r
{\r
- /* Add the task to the suspended task list instead of a delayed task\r
- list to ensure it is not woken by a timing event. It will block\r
- indefinitely. */\r
- vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xGenericListItem ) );\r
+ /* A task was made ready while the scheduler was suspended. */\r
+ eReturn = eAbortSleep;\r
+ }\r
+ else if( xYieldPending != pdFALSE )\r
+ {\r
+ /* A yield was pended while the scheduler was suspended. */\r
+ eReturn = eAbortSleep;\r
}\r
else\r
{\r
- /* Calculate the time at which the task should be woken if the event\r
- does not occur. This may overflow but this doesn't matter, the\r
- kernel will manage it correctly. */\r
- xTimeToWake = xTickCount + xTicksToWait;\r
- prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+ /* If all the tasks are in the suspended list (which might mean they\r
+ have an infinite block time rather than actually being suspended)\r
+ then it is safe to turn all clocks off and just wait for external\r
+ interrupts. */\r
+ if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == ( uxCurrentNumberOfTasks - uxNonApplicationTasks ) )\r
+ {\r
+ eReturn = eNoTasksWaitingTimeout;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
}\r
+\r
+ return eReturn;\r
}\r
- #else /* INCLUDE_vTaskSuspend */\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, the kernel\r
- will manage it correctly. */\r
- xTimeToWake = xTickCount + xTicksToWait;\r
- prvAddCurrentTaskToDelayedList( xTimeToWake );\r
- }\r
- #endif /* INCLUDE_vTaskSuspend */\r
-}\r
+\r
+#endif /* configUSE_TICKLESS_IDLE */\r
/*-----------------------------------------------------------*/\r
\r
-#if configUSE_TIMERS == 1\r
+#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )\r
\r
- void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, const TickType_t xTicksToWait )\r
+ void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue )\r
{\r
- TickType_t xTimeToWake;\r
+ TCB_t *pxTCB;\r
\r
- configASSERT( pxEventList );\r
+ if( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS )\r
+ {\r
+ pxTCB = prvGetTCBFromHandle( xTaskToSet );\r
+ pxTCB->pvThreadLocalStoragePointers[ xIndex ] = pvValue;\r
+ }\r
+ }\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
+#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */\r
+/*-----------------------------------------------------------*/\r
\r
+#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )\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( pxEventList, &( pxCurrentTCB->xEventListItem ) );\r
+ void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex )\r
+ {\r
+ void *pvReturn = NULL;\r
+ TCB_t *pxTCB;\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
- if( uxListRemove( &( pxCurrentTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
+ if( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS )\r
{\r
- /* The current task must be in a ready list, so there is no need to\r
- check, and the port reset macro can be called directly. */\r
- portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
+ pxTCB = prvGetTCBFromHandle( xTaskToQuery );\r
+ pvReturn = pxTCB->pvThreadLocalStoragePointers[ xIndex ];\r
}\r
else\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ pvReturn = NULL;\r
}\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
- traceTASK_DELAY_UNTIL();\r
- prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+ return pvReturn;\r
}\r
\r
-#endif /* configUSE_TIMERS */\r
+#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */\r
/*-----------------------------------------------------------*/\r
\r
-BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList )\r
-{\r
-TCB_t *pxUnblockedTCB;\r
-BaseType_t xReturn;\r
+#if ( portUSING_MPU_WRAPPERS == 1 )\r
\r
- /* THIS FUNCTION MUST BE CALLED FROM A CRITICAL SECTION. It can also be\r
- called from a critical section within an ISR. */\r
+ void vTaskAllocateMPURegions( TaskHandle_t xTaskToModify, const MemoryRegion_t * const xRegions )\r
+ {\r
+ TCB_t *pxTCB;\r
\r
- /* The event list is sorted in priority order, so the first in the list can\r
- be removed as it is known to be the highest priority. Remove the TCB from\r
- the delayed list, and add it to the ready list.\r
+ /* If null is passed in here then we are modifying the MPU settings of\r
+ the calling task. */\r
+ pxTCB = prvGetTCBFromHandle( xTaskToModify );\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 exclusive access to the event list is guaranteed here.\r
+ vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), xRegions, NULL, 0 );\r
+ }\r
\r
- This function assumes that a check has already been made to ensure that\r
- pxEventList is not empty. */\r
- pxUnblockedTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );\r
- configASSERT( pxUnblockedTCB );\r
- ( void ) uxListRemove( &( pxUnblockedTCB->xEventListItem ) );\r
+#endif /* portUSING_MPU_WRAPPERS */\r
+/*-----------------------------------------------------------*/\r
\r
- if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
- {\r
- ( void ) uxListRemove( &( pxUnblockedTCB->xGenericListItem ) );\r
- prvAddTaskToReadyList( pxUnblockedTCB );\r
- }\r
- else\r
+static void prvInitialiseTaskLists( void )\r
+{\r
+UBaseType_t uxPriority;\r
+\r
+ for( uxPriority = ( UBaseType_t ) 0U; uxPriority < ( UBaseType_t ) configMAX_PRIORITIES; uxPriority++ )\r
{\r
- /* The delayed and ready lists cannot be accessed, so hold this task\r
- pending until the scheduler is resumed. */\r
- vListInsertEnd( &( xPendingReadyList ), &( pxUnblockedTCB->xEventListItem ) );\r
+ vListInitialise( &( pxReadyTasksLists[ uxPriority ] ) );\r
}\r
\r
- if( pxUnblockedTCB->uxPriority > pxCurrentTCB->uxPriority )\r
- {\r
- /* Return true if the task removed from the event list has a higher\r
- priority than the calling task. This allows the calling task to know if\r
- it should force a context switch now. */\r
- xReturn = pdTRUE;\r
+ vListInitialise( &xDelayedTaskList1 );\r
+ vListInitialise( &xDelayedTaskList2 );\r
+ vListInitialise( &xPendingReadyList );\r
\r
- /* Mark that a yield is pending in case the user is not using the\r
- "xHigherPriorityTaskWoken" parameter to an ISR safe FreeRTOS function. */\r
- xYieldPending = pdTRUE;\r
+ #if ( INCLUDE_vTaskDelete == 1 )\r
+ {\r
+ vListInitialise( &xTasksWaitingTermination );\r
}\r
- else\r
+ #endif /* INCLUDE_vTaskDelete */\r
+\r
+ #if ( INCLUDE_vTaskSuspend == 1 )\r
{\r
- xReturn = pdFALSE;\r
+ vListInitialise( &xSuspendedTaskList );\r
}\r
+ #endif /* INCLUDE_vTaskSuspend */\r
\r
- return xReturn;\r
+ /* Start with pxDelayedTaskList using list1 and the pxOverflowDelayedTaskList\r
+ using list2. */\r
+ pxDelayedTaskList = &xDelayedTaskList1;\r
+ pxOverflowDelayedTaskList = &xDelayedTaskList2;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-BaseType_t xTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue )\r
+static void prvCheckTasksWaitingTermination( void )\r
{\r
-TCB_t *pxUnblockedTCB;\r
-BaseType_t xReturn;\r
\r
- /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by\r
- the event flags implementation. */\r
- configASSERT( uxSchedulerSuspended != pdFALSE );\r
+ /** THIS FUNCTION IS CALLED FROM THE RTOS IDLE TASK **/\r
\r
- /* Store the new item value in the event list. */\r
- listSET_LIST_ITEM_VALUE( pxEventListItem, xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );\r
+ #if ( INCLUDE_vTaskDelete == 1 )\r
+ {\r
+ BaseType_t xListIsEmpty;\r
\r
- /* Remove the event list form the event flag. Interrupts do not access\r
- event flags. */\r
- pxUnblockedTCB = ( TCB_t * ) listGET_LIST_ITEM_OWNER( pxEventListItem );\r
- configASSERT( pxUnblockedTCB );\r
- ( void ) uxListRemove( pxEventListItem );\r
+ /* ucTasksDeleted is used to prevent vTaskSuspendAll() being called\r
+ too often in the idle task. */\r
+ while( uxDeletedTasksWaitingCleanUp > ( UBaseType_t ) 0U )\r
+ {\r
+ vTaskSuspendAll();\r
+ {\r
+ xListIsEmpty = listLIST_IS_EMPTY( &xTasksWaitingTermination );\r
+ }\r
+ ( void ) xTaskResumeAll();\r
\r
- /* Remove the task from the delayed list and add it to the ready list. The\r
- scheduler is suspended so interrupts will not be accessing the ready\r
- lists. */\r
- ( void ) uxListRemove( &( pxUnblockedTCB->xGenericListItem ) );\r
- prvAddTaskToReadyList( pxUnblockedTCB );\r
+ if( xListIsEmpty == pdFALSE )\r
+ {\r
+ TCB_t *pxTCB;\r
\r
- if( pxUnblockedTCB->uxPriority > pxCurrentTCB->uxPriority )\r
- {\r
- /* Return true if the task removed from the event list has\r
- a higher priority than the calling task. This allows\r
- the calling task to know if it should force a context\r
- switch now. */\r
- xReturn = pdTRUE;\r
+ taskENTER_CRITICAL();\r
+ {\r
+ pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xTasksWaitingTermination ) );\r
+ ( void ) uxListRemove( &( pxTCB->xStateListItem ) );\r
+ --uxCurrentNumberOfTasks;\r
+ --uxDeletedTasksWaitingCleanUp;\r
+ }\r
+ taskEXIT_CRITICAL();\r
\r
- /* Mark that a yield is pending in case the user is not using the\r
- "xHigherPriorityTaskWoken" parameter to an ISR safe FreeRTOS function. */\r
- xYieldPending = pdTRUE;\r
- }\r
- else\r
- {\r
- xReturn = pdFALSE;\r
+ prvDeleteTCB( pxTCB );\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
}\r
-\r
- return xReturn;\r
+ #endif /* INCLUDE_vTaskDelete */\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut )\r
-{\r
- configASSERT( pxTimeOut );\r
- pxTimeOut->xOverflowCount = xNumOfOverflows;\r
- pxTimeOut->xTimeOnEntering = xTickCount;\r
-}\r
-/*-----------------------------------------------------------*/\r
+#if( configUSE_TRACE_FACILITY == 1 )\r
\r
-BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait )\r
-{\r
-BaseType_t xReturn;\r
+ void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState )\r
+ {\r
+ TCB_t *pxTCB;\r
\r
- configASSERT( pxTimeOut );\r
- configASSERT( pxTicksToWait );\r
+ /* xTask is NULL then get the state of the calling task. */\r
+ pxTCB = prvGetTCBFromHandle( xTask );\r
\r
- taskENTER_CRITICAL();\r
- {\r
- /* Minor optimisation. The tick count cannot change in this block. */\r
- const TickType_t xConstTickCount = xTickCount;\r
+ pxTaskStatus->xHandle = ( TaskHandle_t ) pxTCB;\r
+ pxTaskStatus->pcTaskName = ( const char * ) &( pxTCB->pcTaskName [ 0 ] );\r
+ pxTaskStatus->uxCurrentPriority = pxTCB->uxPriority;\r
+ pxTaskStatus->pxStackBase = pxTCB->pxStack;\r
+ pxTaskStatus->xTaskNumber = pxTCB->uxTCBNumber;\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
+ /* If the task is in the suspended list then there is a chance it is\r
+ actually just blocked indefinitely - so really it should be reported as\r
+ being in the Blocked state. */\r
+ if( pxTaskStatus->eCurrentState == eSuspended )\r
{\r
- xReturn = pdFALSE;\r
+ vTaskSuspendAll();\r
+ {\r
+ if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
+ {\r
+ pxTaskStatus->eCurrentState = eBlocked;\r
+ }\r
+ }\r
+ ( void ) xTaskResumeAll();\r
}\r
- else /* We are not blocking indefinitely, perform the checks below. */\r
+ }\r
+ #endif /* INCLUDE_vTaskSuspend */\r
+\r
+ #if ( configUSE_MUTEXES == 1 )\r
+ {\r
+ pxTaskStatus->uxBasePriority = pxTCB->uxBasePriority;\r
+ }\r
+ #else\r
+ {\r
+ pxTaskStatus->uxBasePriority = 0;\r
+ }\r
#endif\r
\r
- if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( xConstTickCount >= pxTimeOut->xTimeOnEntering ) ) /*lint !e525 Indentation preferred as is to make code within pre-processor directives clearer. */\r
+ #if ( configGENERATE_RUN_TIME_STATS == 1 )\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
+ pxTaskStatus->ulRunTimeCounter = pxTCB->ulRunTimeCounter;\r
}\r
- else if( ( xConstTickCount - pxTimeOut->xTimeOnEntering ) < *pxTicksToWait )\r
+ #else\r
{\r
- /* Not a genuine timeout. Adjust parameters for time remaining. */\r
- *pxTicksToWait -= ( xConstTickCount - pxTimeOut->xTimeOnEntering );\r
- vTaskSetTimeOutState( pxTimeOut );\r
- xReturn = pdFALSE;\r
+ pxTaskStatus->ulRunTimeCounter = 0;\r
+ }\r
+ #endif\r
+\r
+ /* Obtaining the task state is a little fiddly, so is only done if the value\r
+ of eState passed into this function is eInvalid - otherwise the state is\r
+ just set to whatever is passed in. */\r
+ if( eState != eInvalid )\r
+ {\r
+ pxTaskStatus->eCurrentState = eState;\r
}\r
else\r
{\r
- xReturn = pdTRUE;\r
+ pxTaskStatus->eCurrentState = eTaskGetState( xTask );\r
+ }\r
+\r
+ /* Obtaining the stack space takes some time, so the xGetFreeStackSpace\r
+ parameter is provided to allow it to be skipped. */\r
+ if( xGetFreeStackSpace != pdFALSE )\r
+ {\r
+ #if ( portSTACK_GROWTH > 0 )\r
+ {\r
+ pxTaskStatus->usStackHighWaterMark = prvTaskCheckFreeStackSpace( ( uint8_t * ) pxTCB->pxEndOfStack );\r
+ }\r
+ #else\r
+ {\r
+ pxTaskStatus->usStackHighWaterMark = prvTaskCheckFreeStackSpace( ( uint8_t * ) pxTCB->pxStack );\r
+ }\r
+ #endif\r
+ }\r
+ else\r
+ {\r
+ pxTaskStatus->usStackHighWaterMark = 0;\r
}\r
}\r
- taskEXIT_CRITICAL();\r
\r
- return xReturn;\r
-}\r
+#endif /* configUSE_TRACE_FACILITY */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_TRACE_FACILITY == 1 )\r
+\r
+ static UBaseType_t prvListTasksWithinSingleList( TaskStatus_t *pxTaskStatusArray, List_t *pxList, eTaskState eState )\r
+ {\r
+ configLIST_VOLATILE TCB_t *pxNextTCB, *pxFirstTCB;\r
+ UBaseType_t uxTask = 0;\r
+\r
+ if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 )\r
+ {\r
+ listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );\r
+\r
+ /* Populate an TaskStatus_t structure within the\r
+ pxTaskStatusArray array for each task that is referenced from\r
+ pxList. See the definition of TaskStatus_t in task.h for the\r
+ meaning of each TaskStatus_t structure member. */\r
+ do\r
+ {\r
+ listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );\r
+ vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState );\r
+ uxTask++;\r
+ } while( pxNextTCB != pxFirstTCB );\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ return uxTask;\r
+ }\r
+\r
+#endif /* configUSE_TRACE_FACILITY */\r
/*-----------------------------------------------------------*/\r
\r
-void vTaskMissedYield( void )\r
-{\r
- xYieldPending = pdTRUE;\r
-}\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
+\r
+ static uint16_t prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte )\r
+ {\r
+ uint32_t ulCount = 0U;\r
+\r
+ while( *pucStackByte == ( uint8_t ) tskSTACK_FILL_BYTE )\r
+ {\r
+ pucStackByte -= portSTACK_GROWTH;\r
+ ulCount++;\r
+ }\r
+\r
+ ulCount /= ( uint32_t ) sizeof( StackType_t ); /*lint !e961 Casting is not redundant on smaller architectures. */\r
+\r
+ return ( uint16_t ) ulCount;\r
+ }\r
+\r
+#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
+#if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )\r
\r
- UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask )\r
+ UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask )\r
{\r
- UBaseType_t uxReturn;\r
TCB_t *pxTCB;\r
+ uint8_t *pucEndOfStack;\r
+ UBaseType_t uxReturn;\r
\r
- if( xTask != NULL )\r
+ pxTCB = prvGetTCBFromHandle( xTask );\r
+\r
+ #if portSTACK_GROWTH < 0\r
{\r
- pxTCB = ( TCB_t * ) xTask;\r
- uxReturn = pxTCB->uxTaskNumber;\r
+ pucEndOfStack = ( uint8_t * ) pxTCB->pxStack;\r
}\r
- else\r
+ #else\r
{\r
- uxReturn = 0U;\r
+ pucEndOfStack = ( uint8_t * ) pxTCB->pxEndOfStack;\r
}\r
+ #endif\r
+\r
+ uxReturn = ( UBaseType_t ) prvTaskCheckFreeStackSpace( pucEndOfStack );\r
\r
return uxReturn;\r
}\r
\r
-#endif /* configUSE_TRACE_FACILITY */\r
+#endif /* INCLUDE_uxTaskGetStackHighWaterMark */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
+#if ( INCLUDE_vTaskDelete == 1 )\r
\r
- void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle )\r
+ static void prvDeleteTCB( TCB_t *pxTCB )\r
{\r
- TCB_t *pxTCB;\r
+ /* This call is required specifically for the TriCore port. It must be\r
+ above the vPortFree() calls. The call is also used by ports/demos that\r
+ want to allocate and clean RAM statically. */\r
+ portCLEAN_UP_TCB( pxTCB );\r
\r
- if( xTask != NULL )\r
+ /* Free up the memory allocated by the scheduler for the task. It is up\r
+ to the task to free any memory allocated at the application level. */\r
+ #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
{\r
- pxTCB = ( TCB_t * ) xTask;\r
- pxTCB->uxTaskNumber = uxHandle;\r
+ _reclaim_reent( &( pxTCB->xNewLib_reent ) );\r
}\r
- }\r
-\r
-#endif /* configUSE_TRACE_FACILITY */\r
-\r
-/*\r
- * -----------------------------------------------------------\r
- * The Idle task.\r
- * ----------------------------------------------------------\r
- *\r
- * The portTASK_FUNCTION() macro is used to allow port/compiler specific\r
- * language extensions. The equivalent prototype for this function is:\r
- *\r
- * void prvIdleTask( void *pvParameters );\r
- *\r
- */\r
-static portTASK_FUNCTION( prvIdleTask, pvParameters )\r
-{\r
- /* Stop warnings. */\r
- ( void ) pvParameters;\r
-\r
- for( ;; )\r
- {\r
- /* See if any tasks have been deleted. */\r
- prvCheckTasksWaitingTermination();\r
+ #endif /* configUSE_NEWLIB_REENTRANT */\r
\r
- #if ( configUSE_PREEMPTION == 0 )\r
+ #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) && ( portUSING_MPU_WRAPPERS == 0 ) )\r
{\r
- /* If we are not using preemption we keep forcing a task switch to\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
+ /* The task can only have been allocated dynamically - free both\r
+ the stack and TCB. */\r
+ vPortFree( pxTCB->pxStack );\r
+ vPortFree( pxTCB );\r
}\r
- #endif /* configUSE_PREEMPTION */\r
-\r
- #if ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) )\r
+ #elif( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */\r
{\r
- /* When using preemption tasks of equal priority will be\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
- 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
- then a task other than the idle task is ready to execute. */\r
- if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > ( UBaseType_t ) 1 )\r
+ /* The task could have been allocated statically or dynamically, so\r
+ check what was statically allocated before trying to free the\r
+ memory. */\r
+ if( pxTCB->ucStaticallyAllocated == tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB )\r
{\r
- taskYIELD();\r
+ /* Both the stack and TCB were allocated dynamically, so both\r
+ must be freed. */\r
+ vPortFree( pxTCB->pxStack );\r
+ vPortFree( pxTCB );\r
+ }\r
+ else if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_ONLY )\r
+ {\r
+ /* Only the stack was statically allocated, so the TCB is the\r
+ only memory that must be freed. */\r
+ vPortFree( pxTCB );\r
}\r
else\r
{\r
+ /* Neither the stack nor the TCB were allocated dynamically, so\r
+ nothing needs to be freed. */\r
+ configASSERT( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB )\r
mtCOVERAGE_TEST_MARKER();\r
}\r
}\r
- #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) ) */\r
+ #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
+ }\r
\r
- #if ( configUSE_IDLE_HOOK == 1 )\r
- {\r
- extern void vApplicationIdleHook( void );\r
+#endif /* INCLUDE_vTaskDelete */\r
+/*-----------------------------------------------------------*/\r
\r
- /* Call the user defined function from within the idle task. This\r
- allows the application designer to add background functionality\r
- without the overhead of a separate task.\r
- NOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES,\r
- CALL A FUNCTION THAT MIGHT BLOCK. */\r
- vApplicationIdleHook();\r
- }\r
- #endif /* configUSE_IDLE_HOOK */\r
+static void prvResetNextTaskUnblockTime( void )\r
+{\r
+TCB_t *pxTCB;\r
\r
- /* This conditional compilation should use inequality to 0, not equality\r
- to 1. This is to ensure portSUPPRESS_TICKS_AND_SLEEP() is called when\r
- user defined low power mode implementations require\r
- configUSE_TICKLESS_IDLE to be set to a value other than 1. */\r
- #if ( configUSE_TICKLESS_IDLE != 0 )\r
- {\r
- TickType_t xExpectedIdleTime;\r
+ if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
+ {\r
+ /* The new current delayed list is empty. Set xNextTaskUnblockTime to\r
+ the maximum possible value so it is 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 ) = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
+ xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( ( pxTCB )->xStateListItem ) );\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
\r
- /* It is not desirable to suspend then resume the scheduler on\r
- each iteration of the idle task. Therefore, a preliminary\r
- test of the expected idle time is performed without the\r
- scheduler suspended. The result here is not necessarily\r
- valid. */\r
- xExpectedIdleTime = prvGetExpectedIdleTime();\r
+#if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) )\r
\r
- if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )\r
- {\r
- vTaskSuspendAll();\r
- {\r
- /* Now the scheduler is suspended, the expected idle\r
- time can be sampled again, and this time its value can\r
- be used. */\r
- configASSERT( xNextTaskUnblockTime >= xTickCount );\r
- xExpectedIdleTime = prvGetExpectedIdleTime();\r
+ TaskHandle_t xTaskGetCurrentTaskHandle( void )\r
+ {\r
+ TaskHandle_t xReturn;\r
\r
- if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )\r
- {\r
- traceLOW_POWER_IDLE_BEGIN();\r
- portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime );\r
- traceLOW_POWER_IDLE_END();\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- }\r
- ( void ) xTaskResumeAll();\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 /* ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
+\r
+ BaseType_t xTaskGetSchedulerState( void )\r
+ {\r
+ BaseType_t xReturn;\r
+\r
+ if( xSchedulerRunning == pdFALSE )\r
+ {\r
+ xReturn = taskSCHEDULER_NOT_STARTED;\r
+ }\r
+ else\r
+ {\r
+ if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
+ {\r
+ xReturn = taskSCHEDULER_RUNNING;\r
}\r
else\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ xReturn = taskSCHEDULER_SUSPENDED;\r
}\r
}\r
- #endif /* configUSE_TICKLESS_IDLE */\r
+\r
+ return xReturn;\r
}\r
-}\r
+\r
+#endif /* ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) */\r
/*-----------------------------------------------------------*/\r
\r
-#if configUSE_TICKLESS_IDLE != 0\r
+#if ( configUSE_MUTEXES == 1 )\r
\r
- eSleepModeStatus eTaskConfirmSleepModeStatus( void )\r
+ BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder )\r
{\r
- eSleepModeStatus eReturn = eStandardSleep;\r
+ TCB_t * const pxMutexHolderTCB = ( TCB_t * ) pxMutexHolder;\r
+ BaseType_t xReturn = pdFALSE;\r
\r
- if( listCURRENT_LIST_LENGTH( &xPendingReadyList ) != 0 )\r
- {\r
- /* A task was made ready while the scheduler was suspended. */\r
- eReturn = eAbortSleep;\r
- }\r
- else if( xYieldPending != pdFALSE )\r
- {\r
- /* A yield was pended while the scheduler was suspended. */\r
- eReturn = eAbortSleep;\r
- }\r
- else\r
+ /* If the mutex was given back by an interrupt while the queue was\r
+ locked then the mutex holder might now be NULL. _RB_ Is this still\r
+ needed as interrupts can no longer use mutexes? */\r
+ if( pxMutexHolder != NULL )\r
{\r
- #if configUSE_TIMERS == 0\r
+ /* If the holder of the mutex has a priority below the priority of\r
+ the task attempting to obtain the mutex then it will temporarily\r
+ inherit the priority of the task attempting to obtain the mutex. */\r
+ if( pxMutexHolderTCB->uxPriority < pxCurrentTCB->uxPriority )\r
{\r
- /* The idle task exists in addition to the application tasks. */\r
- const UBaseType_t uxNonApplicationTasks = 1;\r
-\r
- /* If timers are not being used and all the tasks are in the\r
- suspended list (which might mean they have an infinite block\r
- time rather than actually being suspended) then it is safe to\r
- turn all clocks off and just wait for external interrupts. */\r
- if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == ( uxCurrentNumberOfTasks - uxNonApplicationTasks ) )\r
+ /* Adjust the mutex holder state to account for its new\r
+ priority. Only reset the event list item value if the value is\r
+ not being used for anything else. */\r
+ if( ( listGET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL )\r
{\r
- eReturn = eNoTasksWaitingTimeout;\r
+ listSET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxCurrentTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
}\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
- }\r
- #endif /* configUSE_TIMERS */\r
- }\r
\r
- return eReturn;\r
- }\r
-#endif /* configUSE_TICKLESS_IDLE */\r
-/*-----------------------------------------------------------*/\r
+ /* If the task being modified is in the ready state it will need\r
+ to be moved into a new list. */\r
+ if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxMutexHolderTCB->uxPriority ] ), &( pxMutexHolderTCB->xStateListItem ) ) != pdFALSE )\r
+ {\r
+ if( uxListRemove( &( pxMutexHolderTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
+ {\r
+ taskRESET_READY_PRIORITY( pxMutexHolderTCB->uxPriority );\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
\r
-static void prvInitialiseTCBVariables( TCB_t * const pxTCB, const char * const pcName, UBaseType_t uxPriority, const MemoryRegion_t * const xRegions, const uint16_t usStackDepth ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
-{\r
-UBaseType_t x;\r
+ /* Inherit the priority before being moved into the new list. */\r
+ pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority;\r
+ prvAddTaskToReadyList( pxMutexHolderTCB );\r
+ }\r
+ else\r
+ {\r
+ /* Just inherit the priority. */\r
+ pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority;\r
+ }\r
\r
- /* Store the task name in the TCB. */\r
- for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ )\r
- {\r
- pxTCB->pcTaskName[ x ] = pcName[ x ];\r
+ traceTASK_PRIORITY_INHERIT( pxMutexHolderTCB, pxCurrentTCB->uxPriority );\r
\r
- /* Don't copy all configMAX_TASK_NAME_LEN if the string is shorter than\r
- configMAX_TASK_NAME_LEN characters just in case the memory after the\r
- string is not accessible (extremely unlikely). */\r
- if( pcName[ x ] == 0x00 )\r
- {\r
- break;\r
+ /* Inheritance occurred. */\r
+ xReturn = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ if( pxMutexHolderTCB->uxBasePriority < pxCurrentTCB->uxPriority )\r
+ {\r
+ /* The base priority of the mutex holder is lower than the\r
+ priority of the task attempting to take the mutex, but the\r
+ current priority of the mutex holder is not lower than the\r
+ priority of the task attempting to take the mutex.\r
+ Therefore the mutex holder must have already inherited a\r
+ priority, but inheritance would have occurred if that had\r
+ not been the case. */\r
+ xReturn = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
}\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
+\r
+ return xReturn;\r
}\r
\r
- /* Ensure the name string is terminated in the case that the string length\r
- was greater or equal to configMAX_TASK_NAME_LEN. */\r
- pxTCB->pcTaskName[ configMAX_TASK_NAME_LEN - 1 ] = '\0';\r
+#endif /* configUSE_MUTEXES */\r
+/*-----------------------------------------------------------*/\r
\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 >= ( UBaseType_t ) configMAX_PRIORITIES )\r
- {\r
- uxPriority = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) 1U;\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+#if ( configUSE_MUTEXES == 1 )\r
\r
- pxTCB->uxPriority = uxPriority;\r
- #if ( configUSE_MUTEXES == 1 )\r
+ BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder )\r
{\r
- pxTCB->uxBasePriority = uxPriority;\r
- pxTCB->uxMutexesHeld = 0;\r
- }\r
- #endif /* configUSE_MUTEXES */\r
+ TCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder;\r
+ BaseType_t xReturn = pdFALSE;\r
\r
- vListInitialiseItem( &( pxTCB->xGenericListItem ) );\r
- vListInitialiseItem( &( pxTCB->xEventListItem ) );\r
+ if( pxMutexHolder != NULL )\r
+ {\r
+ /* A task can only have an inherited priority if it holds the mutex.\r
+ If the mutex is held by a task then it cannot be given from an\r
+ interrupt, and if a mutex is given by the holding task then it must\r
+ be the running state task. */\r
+ configASSERT( pxTCB == pxCurrentTCB );\r
+ configASSERT( pxTCB->uxMutexesHeld );\r
+ ( pxTCB->uxMutexesHeld )--;\r
+\r
+ /* Has the holder of the mutex inherited the priority of another\r
+ task? */\r
+ if( pxTCB->uxPriority != pxTCB->uxBasePriority )\r
+ {\r
+ /* Only disinherit if no other mutexes are held. */\r
+ if( pxTCB->uxMutexesHeld == ( UBaseType_t ) 0 )\r
+ {\r
+ /* A task can only have an inherited priority if it holds\r
+ the mutex. If the mutex is held by a task then it cannot be\r
+ given from an interrupt, and if a mutex is given by the\r
+ holding task then it must be the running state task. Remove\r
+ the holding task from the ready list. */\r
+ if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
+ {\r
+ taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
\r
- /* Set the pxTCB as a link back from the ListItem_t. This is so we can get\r
- back to the containing TCB from a generic item in a list. */\r
- listSET_LIST_ITEM_OWNER( &( pxTCB->xGenericListItem ), pxTCB );\r
+ /* Disinherit the priority before adding the task into the\r
+ new ready list. */\r
+ traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority );\r
+ pxTCB->uxPriority = pxTCB->uxBasePriority;\r
\r
- /* Event lists are always in priority order. */\r
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
- listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );\r
+ /* Reset the event list item value. It cannot be in use for\r
+ any other purpose if this task is running, and it must be\r
+ running to give back the mutex. */\r
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ prvAddTaskToReadyList( pxTCB );\r
\r
- #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
- {\r
- pxTCB->uxCriticalNesting = ( UBaseType_t ) 0U;\r
- }\r
- #endif /* portCRITICAL_NESTING_IN_TCB */\r
+ /* Return true to indicate that a context switch is required.\r
+ This is only actually required in the corner case whereby\r
+ multiple mutexes were held and the mutexes were given back\r
+ in an order different to that in which they were taken.\r
+ If a context switch did not occur when the first mutex was\r
+ returned, even if a task was waiting on it, then a context\r
+ switch should occur when the last mutex is returned whether\r
+ a task is waiting on it or not. */\r
+ xReturn = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
\r
- #if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
- {\r
- pxTCB->pxTaskTag = NULL;\r
+ return xReturn;\r
}\r
- #endif /* configUSE_APPLICATION_TASK_TAG */\r
\r
- #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
- {\r
- pxTCB->ulRunTimeCounter = 0UL;\r
- }\r
- #endif /* configGENERATE_RUN_TIME_STATS */\r
+#endif /* configUSE_MUTEXES */\r
+/*-----------------------------------------------------------*/\r
\r
- #if ( portUSING_MPU_WRAPPERS == 1 )\r
- {\r
- vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), xRegions, pxTCB->pxStack, usStackDepth );\r
- }\r
- #else /* portUSING_MPU_WRAPPERS */\r
- {\r
- ( void ) xRegions;\r
- ( void ) usStackDepth;\r
- }\r
- #endif /* portUSING_MPU_WRAPPERS */\r
+#if ( configUSE_MUTEXES == 1 )\r
\r
- #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
+ void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, UBaseType_t uxHighestPriorityWaitingTask )\r
{\r
- /* Initialise this task's Newlib reent structure. */\r
- _REENT_INIT_PTR( ( &( pxTCB->xNewLib_reent ) ) );\r
- }\r
- #endif /* configUSE_NEWLIB_REENTRANT */\r
-}\r
-/*-----------------------------------------------------------*/\r
+ TCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder;\r
+ UBaseType_t uxPriorityUsedOnEntry, uxPriorityToUse;\r
+ const UBaseType_t uxOnlyOneMutexHeld = ( UBaseType_t ) 1;\r
\r
-#if ( portUSING_MPU_WRAPPERS == 1 )\r
+ if( pxMutexHolder != NULL )\r
+ {\r
+ /* If pxMutexHolder is not NULL then the holder must hold at least\r
+ one mutex. */\r
+ configASSERT( pxTCB->uxMutexesHeld );\r
+\r
+ /* Determine the priority to which the priority of the task that\r
+ holds the mutex should be set. This will be the greater of the\r
+ holding task's base priority and the priority of the highest\r
+ priority task that is waiting to obtain the mutex. */\r
+ if( pxTCB->uxBasePriority < uxHighestPriorityWaitingTask )\r
+ {\r
+ uxPriorityToUse = uxHighestPriorityWaitingTask;\r
+ }\r
+ else\r
+ {\r
+ uxPriorityToUse = pxTCB->uxBasePriority;\r
+ }\r
\r
- void vTaskAllocateMPURegions( TaskHandle_t xTaskToModify, const MemoryRegion_t * const xRegions )\r
- {\r
- TCB_t *pxTCB;\r
+ /* Does the priority need to change? */\r
+ if( pxTCB->uxPriority != uxPriorityToUse )\r
+ {\r
+ /* Only disinherit if no other mutexes are held. This is a\r
+ simplification in the priority inheritance implementation. If\r
+ the task that holds the mutex is also holding other mutexes then\r
+ the other mutexes may have caused the priority inheritance. */\r
+ if( pxTCB->uxMutexesHeld == uxOnlyOneMutexHeld )\r
+ {\r
+ /* If a task has timed out because it already holds the\r
+ mutex it was trying to obtain then it cannot of inherited\r
+ its own priority. */\r
+ configASSERT( pxTCB != pxCurrentTCB );\r
+\r
+ /* Disinherit the priority, remembering the previous\r
+ priority to facilitate determining the subject task's\r
+ state. */\r
+ traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority );\r
+ uxPriorityUsedOnEntry = pxTCB->uxPriority;\r
+ pxTCB->uxPriority = uxPriorityToUse;\r
\r
- /* If null is passed in here then we are deleting ourselves. */\r
- pxTCB = prvGetTCBFromHandle( xTaskToModify );\r
+ /* Only reset the event list item value if the value is not\r
+ being used for anything else. */\r
+ if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL )\r
+ {\r
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) uxPriorityToUse ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ /* If the running task is not the task that holds the mutex\r
+ then the task that holds the mutex could be in either the\r
+ Ready, Blocked or Suspended states. Only remove the task\r
+ from its current state list if it is in the Ready state as\r
+ the task's priority is going to change and there is one\r
+ Ready list per priority. */\r
+ if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxPriorityUsedOnEntry ] ), &( pxTCB->xStateListItem ) ) != pdFALSE )\r
+ {\r
+ if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
+ {\r
+ taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
\r
- vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), xRegions, NULL, 0 );\r
+ prvAddTaskToReadyList( pxTCB );\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
}\r
\r
-#endif /* portUSING_MPU_WRAPPERS */\r
+#endif /* configUSE_MUTEXES */\r
/*-----------------------------------------------------------*/\r
\r
-static void prvInitialiseTaskLists( void )\r
-{\r
-UBaseType_t uxPriority;\r
+#if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
\r
- for( uxPriority = ( UBaseType_t ) 0U; uxPriority < ( UBaseType_t ) configMAX_PRIORITIES; uxPriority++ )\r
+ void vTaskEnterCritical( void )\r
{\r
- vListInitialise( &( pxReadyTasksLists[ uxPriority ] ) );\r
- }\r
-\r
- vListInitialise( &xDelayedTaskList1 );\r
- vListInitialise( &xDelayedTaskList2 );\r
- vListInitialise( &xPendingReadyList );\r
+ portDISABLE_INTERRUPTS();\r
\r
- #if ( INCLUDE_vTaskDelete == 1 )\r
- {\r
- vListInitialise( &xTasksWaitingTermination );\r
- }\r
- #endif /* INCLUDE_vTaskDelete */\r
+ if( xSchedulerRunning != pdFALSE )\r
+ {\r
+ ( pxCurrentTCB->uxCriticalNesting )++;\r
\r
- #if ( INCLUDE_vTaskSuspend == 1 )\r
- {\r
- vListInitialise( &xSuspendedTaskList );\r
+ /* This is not the interrupt safe version of the enter critical\r
+ function so assert() if it is being called from an interrupt\r
+ context. Only API functions that end in "FromISR" can be used in an\r
+ interrupt. Only assert if the critical nesting count is 1 to\r
+ protect against recursive calls if the assert function also uses a\r
+ critical section. */\r
+ if( pxCurrentTCB->uxCriticalNesting == 1 )\r
+ {\r
+ portASSERT_IF_IN_ISR();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
}\r
- #endif /* INCLUDE_vTaskSuspend */\r
\r
- /* Start with pxDelayedTaskList using list1 and the pxOverflowDelayedTaskList\r
- using list2. */\r
- pxDelayedTaskList = &xDelayedTaskList1;\r
- pxOverflowDelayedTaskList = &xDelayedTaskList2;\r
-}\r
+#endif /* portCRITICAL_NESTING_IN_TCB */\r
/*-----------------------------------------------------------*/\r
\r
-static void prvCheckTasksWaitingTermination( void )\r
-{\r
- #if ( INCLUDE_vTaskDelete == 1 )\r
- {\r
- BaseType_t xListIsEmpty;\r
+#if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
\r
- /* ucTasksDeleted is used to prevent vTaskSuspendAll() being called\r
- too often in the idle task. */\r
- while( uxTasksDeleted > ( UBaseType_t ) 0U )\r
+ void vTaskExitCritical( void )\r
+ {\r
+ if( xSchedulerRunning != pdFALSE )\r
{\r
- vTaskSuspendAll();\r
- {\r
- xListIsEmpty = listLIST_IS_EMPTY( &xTasksWaitingTermination );\r
- }\r
- ( void ) xTaskResumeAll();\r
-\r
- if( xListIsEmpty == pdFALSE )\r
+ if( pxCurrentTCB->uxCriticalNesting > 0U )\r
{\r
- TCB_t *pxTCB;\r
+ ( pxCurrentTCB->uxCriticalNesting )--;\r
\r
- taskENTER_CRITICAL();\r
+ if( pxCurrentTCB->uxCriticalNesting == 0U )\r
{\r
- pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xTasksWaitingTermination ) );\r
- ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
- --uxCurrentNumberOfTasks;\r
- --uxTasksDeleted;\r
+ portENABLE_INTERRUPTS();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
}\r
- taskEXIT_CRITICAL();\r
-\r
- prvDeleteTCB( pxTCB );\r
}\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
}\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
}\r
- #endif /* vTaskDelete */\r
-}\r
+\r
+#endif /* portCRITICAL_NESTING_IN_TCB */\r
/*-----------------------------------------------------------*/\r
\r
-static void prvAddCurrentTaskToDelayedList( const TickType_t xTimeToWake )\r
-{\r
- /* The list item will be inserted in wake time order. */\r
- listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xGenericListItem ), xTimeToWake );\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )\r
\r
- if( xTimeToWake < xTickCount )\r
+ static char *prvWriteNameToBuffer( char *pcBuffer, const char *pcTaskName )\r
{\r
- /* Wake time has overflowed. Place this item in the overflow list. */\r
- vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xGenericListItem ) );\r
- }\r
- else\r
- {\r
- /* The wake time has not overflowed, so the current block list is used. */\r
- vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xGenericListItem ) );\r
+ size_t x;\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
- else\r
+ /* Start by copying the entire string. */\r
+ strcpy( pcBuffer, pcTaskName );\r
+\r
+ /* Pad the end of the string with spaces to ensure columns line up when\r
+ printed out. */\r
+ for( x = strlen( pcBuffer ); x < ( size_t ) ( configMAX_TASK_NAME_LEN - 1 ); x++ )\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ pcBuffer[ x ] = ' ';\r
}\r
+\r
+ /* Terminate. */\r
+ pcBuffer[ x ] = 0x00;\r
+\r
+ /* Return the new end of string. */\r
+ return &( pcBuffer[ x ] );\r
}\r
-}\r
-/*-----------------------------------------------------------*/\r
\r
-static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t * const puxStackBuffer )\r
-{\r
-TCB_t *pxNewTCB;\r
+#endif /* ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) */\r
+/*-----------------------------------------------------------*/\r
\r
- /* Allocate space for the TCB. Where the memory comes from depends on\r
- the implementation of the port malloc function. */\r
- pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
\r
- if( pxNewTCB != NULL )\r
+ void vTaskList( char * pcWriteBuffer )\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 = ( StackType_t * ) pvPortMallocAligned( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ), puxStackBuffer ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ TaskStatus_t *pxTaskStatusArray;\r
+ volatile UBaseType_t uxArraySize, x;\r
+ char cStatus;\r
+\r
+ /*\r
+ * PLEASE NOTE:\r
+ *\r
+ * This function is provided for convenience only, and is used by many\r
+ * of the demo applications. Do not consider it to be part of the\r
+ * scheduler.\r
+ *\r
+ * vTaskList() calls uxTaskGetSystemState(), then formats part of the\r
+ * uxTaskGetSystemState() output into a human readable table that\r
+ * displays task names, states and stack usage.\r
+ *\r
+ * vTaskList() has a dependency on the sprintf() C library function that\r
+ * might bloat the code size, use a lot of stack, and provide different\r
+ * results on different platforms. An alternative, tiny, third party,\r
+ * and limited functionality implementation of sprintf() is provided in\r
+ * many of the FreeRTOS/Demo sub-directories in a file called\r
+ * printf-stdarg.c (note printf-stdarg.c does not provide a full\r
+ * snprintf() implementation!).\r
+ *\r
+ * It is recommended that production systems call uxTaskGetSystemState()\r
+ * directly to get access to raw stats data, rather than indirectly\r
+ * through a call to vTaskList().\r
+ */\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
- else\r
- {\r
- /* Avoid dependency on memset() if it is not required. */\r
- #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
- {\r
- /* Just to help debugging. */\r
- ( void ) memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) usStackDepth * sizeof( StackType_t ) );\r
- }\r
- #endif /* ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) ) */\r
- }\r
- }\r
\r
- return pxNewTCB;\r
-}\r
-/*-----------------------------------------------------------*/\r
+ /* Make sure the write buffer does not contain a string. */\r
+ *pcWriteBuffer = 0x00;\r
\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
+ /* Take a snapshot of the number of tasks in case it changes while this\r
+ function is executing. */\r
+ uxArraySize = uxCurrentNumberOfTasks;\r
\r
- static UBaseType_t prvListTaskWithinSingleList( TaskStatus_t *pxTaskStatusArray, List_t *pxList, eTaskState eState )\r
- {\r
- volatile TCB_t *pxNextTCB, *pxFirstTCB;\r
- UBaseType_t uxTask = 0;\r
+ /* Allocate an array index for each task. NOTE! if\r
+ configSUPPORT_DYNAMIC_ALLOCATION is set to 0 then pvPortMalloc() will\r
+ equate to NULL. */\r
+ pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) );\r
\r
- if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 )\r
+ if( pxTaskStatusArray != NULL )\r
{\r
- listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );\r
+ /* Generate the (binary) data. */\r
+ uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL );\r
\r
- /* Populate an TaskStatus_t structure within the\r
- pxTaskStatusArray array for each task that is referenced from\r
- pxList. See the definition of TaskStatus_t in task.h for the\r
- meaning of each TaskStatus_t structure member. */\r
- do\r
+ /* Create a human readable table from the binary data. */\r
+ for( x = 0; x < uxArraySize; x++ )\r
{\r
- listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );\r
+ switch( pxTaskStatusArray[ x ].eCurrentState )\r
+ {\r
+ case eReady: cStatus = tskREADY_CHAR;\r
+ break;\r
\r
- pxTaskStatusArray[ uxTask ].xHandle = ( TaskHandle_t ) pxNextTCB;\r
- pxTaskStatusArray[ uxTask ].pcTaskName = ( const char * ) &( pxNextTCB->pcTaskName [ 0 ] );\r
- pxTaskStatusArray[ uxTask ].xTaskNumber = pxNextTCB->uxTCBNumber;\r
- pxTaskStatusArray[ uxTask ].eCurrentState = eState;\r
- pxTaskStatusArray[ uxTask ].uxCurrentPriority = pxNextTCB->uxPriority;\r
+ case eBlocked: cStatus = tskBLOCKED_CHAR;\r
+ break;\r
\r
- #if ( INCLUDE_vTaskSuspend == 1 )\r
- {\r
- /* If the task is in the suspended list then there is a chance\r
- it is actually just blocked indefinitely - so really it should\r
- be reported as being in the Blocked state. */\r
- if( eState == eSuspended )\r
- {\r
- if( listLIST_ITEM_CONTAINER( &( pxNextTCB->xEventListItem ) ) != NULL )\r
- {\r
- pxTaskStatusArray[ uxTask ].eCurrentState = eBlocked;\r
- }\r
- }\r
- }\r
- #endif /* INCLUDE_vTaskSuspend */\r
+ case eSuspended: cStatus = tskSUSPENDED_CHAR;\r
+ break;\r
\r
- #if ( configUSE_MUTEXES == 1 )\r
- {\r
- pxTaskStatusArray[ uxTask ].uxBasePriority = pxNextTCB->uxBasePriority;\r
- }\r
- #else\r
- {\r
- pxTaskStatusArray[ uxTask ].uxBasePriority = 0;\r
- }\r
- #endif\r
+ case eDeleted: cStatus = tskDELETED_CHAR;\r
+ break;\r
\r
- #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
- {\r
- pxTaskStatusArray[ uxTask ].ulRunTimeCounter = pxNextTCB->ulRunTimeCounter;\r
- }\r
- #else\r
- {\r
- pxTaskStatusArray[ uxTask ].ulRunTimeCounter = 0;\r
+ default: /* Should not get here, but it is included\r
+ to prevent static checking errors. */\r
+ cStatus = 0x00;\r
+ break;\r
}\r
- #endif\r
\r
- #if ( portSTACK_GROWTH > 0 )\r
- {\r
- pxTaskStatusArray[ uxTask ].usStackHighWaterMark = prvTaskCheckFreeStackSpace( ( uint8_t * ) pxNextTCB->pxEndOfStack );\r
- }\r
- #else\r
- {\r
- pxTaskStatusArray[ uxTask ].usStackHighWaterMark = prvTaskCheckFreeStackSpace( ( uint8_t * ) pxNextTCB->pxStack );\r
- }\r
- #endif\r
+ /* Write the task name to the string, padding with spaces so it\r
+ can be printed in tabular form more easily. */\r
+ pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName );\r
\r
- uxTask++;\r
+ /* Write the rest of the string. */\r
+ sprintf( pcWriteBuffer, "\t%c\t%u\t%u\t%u\r\n", cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber );\r
+ pcWriteBuffer += strlen( pcWriteBuffer );\r
+ }\r
\r
- } while( pxNextTCB != pxFirstTCB );\r
+ /* Free the array again. NOTE! If configSUPPORT_DYNAMIC_ALLOCATION\r
+ is 0 then vPortFree() will be #defined to nothing. */\r
+ vPortFree( pxTaskStatusArray );\r
}\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
-\r
- return uxTask;\r
}\r
\r
-#endif /* configUSE_TRACE_FACILITY */\r
-/*-----------------------------------------------------------*/\r
+#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */\r
+/*----------------------------------------------------------*/\r
\r
-#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\r
+#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
\r
- static uint16_t prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte )\r
+ void vTaskGetRunTimeStats( char *pcWriteBuffer )\r
{\r
- uint32_t ulCount = 0U;\r
+ TaskStatus_t *pxTaskStatusArray;\r
+ volatile UBaseType_t uxArraySize, x;\r
+ uint32_t ulTotalTime, ulStatsAsPercentage;\r
\r
- while( *pucStackByte == tskSTACK_FILL_BYTE )\r
+ #if( configUSE_TRACE_FACILITY != 1 )\r
{\r
- pucStackByte -= portSTACK_GROWTH;\r
- ulCount++;\r
+ #error configUSE_TRACE_FACILITY must also be set to 1 in FreeRTOSConfig.h to use vTaskGetRunTimeStats().\r
}\r
+ #endif\r
\r
- ulCount /= ( uint32_t ) sizeof( StackType_t );\r
-\r
- return ( uint16_t ) ulCount;\r
- }\r
-\r
-#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) */\r
-/*-----------------------------------------------------------*/\r
+ /*\r
+ * PLEASE NOTE:\r
+ *\r
+ * This function is provided for convenience only, and is used by many\r
+ * of the demo applications. Do not consider it to be part of the\r
+ * scheduler.\r
+ *\r
+ * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part\r
+ * of the uxTaskGetSystemState() output into a human readable table that\r
+ * displays the amount of time each task has spent in the Running state\r
+ * in both absolute and percentage terms.\r
+ *\r
+ * vTaskGetRunTimeStats() has a dependency on the sprintf() C library\r
+ * function that might bloat the code size, use a lot of stack, and\r
+ * provide different results on different platforms. An alternative,\r
+ * tiny, third party, and limited functionality implementation of\r
+ * sprintf() is provided in many of the FreeRTOS/Demo sub-directories in\r
+ * a file called printf-stdarg.c (note printf-stdarg.c does not provide\r
+ * a full snprintf() implementation!).\r
+ *\r
+ * It is recommended that production systems call uxTaskGetSystemState()\r
+ * directly to get access to raw stats data, rather than indirectly\r
+ * through a call to vTaskGetRunTimeStats().\r
+ */\r
\r
-#if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )\r
+ /* Make sure the write buffer does not contain a string. */\r
+ *pcWriteBuffer = 0x00;\r
\r
- UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask )\r
- {\r
- TCB_t *pxTCB;\r
- uint8_t *pucEndOfStack;\r
- UBaseType_t uxReturn;\r
+ /* Take a snapshot of the number of tasks in case it changes while this\r
+ function is executing. */\r
+ uxArraySize = uxCurrentNumberOfTasks;\r
\r
- pxTCB = prvGetTCBFromHandle( xTask );\r
+ /* Allocate an array index for each task. NOTE! If\r
+ configSUPPORT_DYNAMIC_ALLOCATION is set to 0 then pvPortMalloc() will\r
+ equate to NULL. */\r
+ pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) );\r
\r
- #if portSTACK_GROWTH < 0\r
- {\r
- pucEndOfStack = ( uint8_t * ) pxTCB->pxStack;\r
- }\r
- #else\r
+ if( pxTaskStatusArray != NULL )\r
{\r
- pucEndOfStack = ( uint8_t * ) pxTCB->pxEndOfStack;\r
- }\r
- #endif\r
+ /* Generate the (binary) data. */\r
+ uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalTime );\r
\r
- uxReturn = ( UBaseType_t ) prvTaskCheckFreeStackSpace( pucEndOfStack );\r
+ /* For percentage calculations. */\r
+ ulTotalTime /= 100UL;\r
\r
- return uxReturn;\r
- }\r
+ /* Avoid divide by zero errors. */\r
+ if( ulTotalTime > 0 )\r
+ {\r
+ /* Create a human readable table from the binary data. */\r
+ for( x = 0; x < uxArraySize; x++ )\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
+ ulTotalRunTimeDiv100 has already been divided by 100. */\r
+ ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalTime;\r
\r
-#endif /* INCLUDE_uxTaskGetStackHighWaterMark */\r
-/*-----------------------------------------------------------*/\r
+ /* Write the task name to the string, padding with\r
+ spaces so it can be printed in tabular form more\r
+ easily. */\r
+ pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName );\r
\r
-#if ( INCLUDE_vTaskDelete == 1 )\r
+ if( ulStatsAsPercentage > 0UL )\r
+ {\r
+ #ifdef portLU_PRINTF_SPECIFIER_REQUIRED\r
+ {\r
+ sprintf( pcWriteBuffer, "\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );\r
+ }\r
+ #else\r
+ {\r
+ /* sizeof( int ) == sizeof( long ) so a smaller\r
+ printf() library can be used. */\r
+ sprintf( pcWriteBuffer, "\t%u\t\t%u%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].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( pcWriteBuffer, "\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].ulRunTimeCounter );\r
+ }\r
+ #else\r
+ {\r
+ /* sizeof( int ) == sizeof( long ) so a smaller\r
+ printf() library can be used. */\r
+ sprintf( pcWriteBuffer, "\t%u\t\t<1%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter );\r
+ }\r
+ #endif\r
+ }\r
\r
- static void prvDeleteTCB( TCB_t *pxTCB )\r
- {\r
- /* This call is required specifically for the TriCore port. It must be\r
- above the vPortFree() calls. The call is also used by ports/demos that\r
- want to allocate and clean RAM statically. */\r
- portCLEAN_UP_TCB( pxTCB );\r
+ pcWriteBuffer += strlen( pcWriteBuffer );\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
\r
- /* Free up the memory allocated by the scheduler for the task. It is up\r
- to the task to free any memory allocated at the application level. */\r
- #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
+ /* Free the array again. NOTE! If configSUPPORT_DYNAMIC_ALLOCATION\r
+ is 0 then vPortFree() will be #defined to nothing. */\r
+ vPortFree( pxTaskStatusArray );\r
+ }\r
+ else\r
{\r
- _reclaim_reent( &( pxTCB->xNewLib_reent ) );\r
+ mtCOVERAGE_TEST_MARKER();\r
}\r
- #endif /* configUSE_NEWLIB_REENTRANT */\r
- vPortFreeAligned( pxTCB->pxStack );\r
- vPortFree( pxTCB );\r
}\r
\r
-#endif /* INCLUDE_vTaskDelete */\r
+#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) */\r
/*-----------------------------------------------------------*/\r
\r
-static void prvResetNextTaskUnblockTime( void )\r
+TickType_t uxTaskResetEventItemValue( void )\r
{\r
-TCB_t *pxTCB;\r
+TickType_t uxReturn;\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 ) = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
- xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( ( pxTCB )->xGenericListItem ) );\r
- }\r
+ uxReturn = listGET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ) );\r
+\r
+ /* Reset the event list item to its normal value - so it can be used with\r
+ queues and semaphores. */\r
+ listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), ( ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxCurrentTCB->uxPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+\r
+ return uxReturn;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-#if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) )\r
+#if ( configUSE_MUTEXES == 1 )\r
\r
- TaskHandle_t xTaskGetCurrentTaskHandle( void )\r
+ void *pvTaskIncrementMutexHeldCount( void )\r
{\r
- TaskHandle_t 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
- xReturn = pxCurrentTCB;\r
+ /* If xSemaphoreCreateMutex() is called before any tasks have been created\r
+ then pxCurrentTCB will be NULL. */\r
+ if( pxCurrentTCB != NULL )\r
+ {\r
+ ( pxCurrentTCB->uxMutexesHeld )++;\r
+ }\r
\r
- return xReturn;\r
+ return pxCurrentTCB;\r
}\r
\r
-#endif /* ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) */\r
+#endif /* configUSE_MUTEXES */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
\r
- BaseType_t xTaskGetSchedulerState( void )\r
+ uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait )\r
{\r
- BaseType_t xReturn;\r
+ uint32_t ulReturn;\r
\r
- if( xSchedulerRunning == pdFALSE )\r
+ taskENTER_CRITICAL();\r
{\r
- xReturn = taskSCHEDULER_NOT_STARTED;\r
+ /* Only block if the notification count is not already non-zero. */\r
+ if( pxCurrentTCB->ulNotifiedValue == 0UL )\r
+ {\r
+ /* Mark this task as waiting for a notification. */\r
+ pxCurrentTCB->ucNotifyState = taskWAITING_NOTIFICATION;\r
+\r
+ if( xTicksToWait > ( TickType_t ) 0 )\r
+ {\r
+ prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );\r
+ traceTASK_NOTIFY_TAKE_BLOCK();\r
+\r
+ /* All ports are written to allow a yield in a critical\r
+ section (some will yield immediately, others wait until the\r
+ critical section exits) - but it is not something that\r
+ application code should ever do. */\r
+ portYIELD_WITHIN_API();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
}\r
- else\r
+ taskEXIT_CRITICAL();\r
+\r
+ taskENTER_CRITICAL();\r
{\r
- if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
+ traceTASK_NOTIFY_TAKE();\r
+ ulReturn = pxCurrentTCB->ulNotifiedValue;\r
+\r
+ if( ulReturn != 0UL )\r
{\r
- xReturn = taskSCHEDULER_RUNNING;\r
+ if( xClearCountOnExit != pdFALSE )\r
+ {\r
+ pxCurrentTCB->ulNotifiedValue = 0UL;\r
+ }\r
+ else\r
+ {\r
+ pxCurrentTCB->ulNotifiedValue = ulReturn - ( uint32_t ) 1;\r
+ }\r
}\r
else\r
{\r
- xReturn = taskSCHEDULER_SUSPENDED;\r
+ mtCOVERAGE_TEST_MARKER();\r
}\r
+\r
+ pxCurrentTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION;\r
}\r
+ taskEXIT_CRITICAL();\r
\r
- return xReturn;\r
+ return ulReturn;\r
}\r
\r
-#endif /* ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) */\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( configUSE_MUTEXES == 1 )\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
\r
- void vTaskPriorityInherit( TaskHandle_t const pxMutexHolder )\r
+ BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait )\r
{\r
- TCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder;\r
+ BaseType_t xReturn;\r
\r
- /* If the mutex was given back by an interrupt while the queue was\r
- locked then the mutex holder might now be NULL. */\r
- if( pxMutexHolder != NULL )\r
+ taskENTER_CRITICAL();\r
{\r
- if( pxTCB->uxPriority < pxCurrentTCB->uxPriority )\r
+ /* Only block if a notification is not already pending. */\r
+ if( pxCurrentTCB->ucNotifyState != taskNOTIFICATION_RECEIVED )\r
{\r
- /* Adjust the mutex holder state to account for its new\r
- priority. Only reset the event list item value if the value is\r
- not being used for anything else. */\r
- if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL )\r
+ /* Clear bits in the task's notification value as bits may get\r
+ set by the notifying task or interrupt. This can be used to\r
+ clear the value to zero. */\r
+ pxCurrentTCB->ulNotifiedValue &= ~ulBitsToClearOnEntry;\r
+\r
+ /* Mark this task as waiting for a notification. */\r
+ pxCurrentTCB->ucNotifyState = taskWAITING_NOTIFICATION;\r
+\r
+ if( xTicksToWait > ( TickType_t ) 0 )\r
{\r
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxCurrentTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );\r
+ traceTASK_NOTIFY_WAIT_BLOCK();\r
+\r
+ /* All ports are written to allow a yield in a critical\r
+ section (some will yield immediately, others wait until the\r
+ critical section exits) - but it is not something that\r
+ application code should ever do. */\r
+ portYIELD_WITHIN_API();\r
}\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ taskEXIT_CRITICAL();\r
\r
- /* If the task being modified is in the ready state it will need to\r
- be moved into a new list. */\r
- if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
- {\r
- if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
+ taskENTER_CRITICAL();\r
+ {\r
+ traceTASK_NOTIFY_WAIT();\r
+\r
+ if( pulNotificationValue != NULL )\r
+ {\r
+ /* Output the current notification value, which may or may not\r
+ have changed. */\r
+ *pulNotificationValue = pxCurrentTCB->ulNotifiedValue;\r
+ }\r
+\r
+ /* If ucNotifyValue is set then either the task never entered the\r
+ blocked state (because a notification was already pending) or the\r
+ task unblocked because of a notification. Otherwise the task\r
+ unblocked because of a timeout. */\r
+ if( pxCurrentTCB->ucNotifyState != taskNOTIFICATION_RECEIVED )\r
+ {\r
+ /* A notification was not received. */\r
+ xReturn = pdFALSE;\r
+ }\r
+ else\r
+ {\r
+ /* A notification was already pending or a notification was\r
+ received while the task was waiting. */\r
+ pxCurrentTCB->ulNotifiedValue &= ~ulBitsToClearOnExit;\r
+ xReturn = pdTRUE;\r
+ }\r
+\r
+ pxCurrentTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION;\r
+ }\r
+ taskEXIT_CRITICAL();\r
+\r
+ return xReturn;\r
+ }\r
+\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+\r
+ BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue )\r
+ {\r
+ TCB_t * pxTCB;\r
+ BaseType_t xReturn = pdPASS;\r
+ uint8_t ucOriginalNotifyState;\r
+\r
+ configASSERT( xTaskToNotify );\r
+ pxTCB = ( TCB_t * ) xTaskToNotify;\r
+\r
+ taskENTER_CRITICAL();\r
+ {\r
+ if( pulPreviousNotificationValue != NULL )\r
+ {\r
+ *pulPreviousNotificationValue = pxTCB->ulNotifiedValue;\r
+ }\r
+\r
+ ucOriginalNotifyState = pxTCB->ucNotifyState;\r
+\r
+ pxTCB->ucNotifyState = taskNOTIFICATION_RECEIVED;\r
+\r
+ switch( eAction )\r
+ {\r
+ case eSetBits :\r
+ pxTCB->ulNotifiedValue |= ulValue;\r
+ break;\r
+\r
+ case eIncrement :\r
+ ( pxTCB->ulNotifiedValue )++;\r
+ break;\r
+\r
+ case eSetValueWithOverwrite :\r
+ pxTCB->ulNotifiedValue = ulValue;\r
+ break;\r
+\r
+ case eSetValueWithoutOverwrite :\r
+ if( ucOriginalNotifyState != taskNOTIFICATION_RECEIVED )\r
{\r
- taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
+ pxTCB->ulNotifiedValue = ulValue;\r
}\r
else\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ /* The value could not be written to the task. */\r
+ xReturn = pdFAIL;\r
}\r
+ break;\r
\r
- /* Inherit the priority before being moved into the new list. */\r
- pxTCB->uxPriority = pxCurrentTCB->uxPriority;\r
- prvAddTaskToReadyList( pxTCB );\r
+ case eNoAction:\r
+ /* The task is being notified without its notify value being\r
+ updated. */\r
+ break;\r
+ }\r
+\r
+ traceTASK_NOTIFY();\r
+\r
+ /* If the task is in the blocked state specifically to wait for a\r
+ notification then unblock it now. */\r
+ if( ucOriginalNotifyState == taskWAITING_NOTIFICATION )\r
+ {\r
+ ( void ) uxListRemove( &( pxTCB->xStateListItem ) );\r
+ prvAddTaskToReadyList( pxTCB );\r
+\r
+ /* The task should not have been on an event list. */\r
+ configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL );\r
+\r
+ #if( configUSE_TICKLESS_IDLE != 0 )\r
+ {\r
+ /* If a task is blocked waiting for a notification then\r
+ xNextTaskUnblockTime might be set to the blocked task's time\r
+ out time. If the task is unblocked for a reason other than\r
+ a timeout xNextTaskUnblockTime is normally left unchanged,\r
+ because it will automatically get reset to a new value when\r
+ the tick count equals xNextTaskUnblockTime. However if\r
+ tickless idling is used it might be more important to enter\r
+ sleep mode at the earliest possible time - so reset\r
+ xNextTaskUnblockTime here to ensure it is updated at the\r
+ earliest possible time. */\r
+ prvResetNextTaskUnblockTime();\r
+ }\r
+ #endif\r
+\r
+ if( pxTCB->uxPriority > pxCurrentTCB->uxPriority )\r
+ {\r
+ /* The notified task has a priority above the currently\r
+ executing task so a yield is required. */\r
+ taskYIELD_IF_USING_PREEMPTION();\r
}\r
else\r
{\r
- /* Just inherit the priority. */\r
- pxTCB->uxPriority = pxCurrentTCB->uxPriority;\r
+ mtCOVERAGE_TEST_MARKER();\r
}\r
-\r
- traceTASK_PRIORITY_INHERIT( pxTCB, pxCurrentTCB->uxPriority );\r
}\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
}\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ taskEXIT_CRITICAL();\r
+\r
+ return xReturn;\r
}\r
\r
-#endif /* configUSE_MUTEXES */\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( configUSE_MUTEXES == 1 )\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
\r
- BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder )\r
+ BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken )\r
{\r
- TCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder;\r
- BaseType_t xReturn = pdFALSE;\r
+ TCB_t * pxTCB;\r
+ uint8_t ucOriginalNotifyState;\r
+ BaseType_t xReturn = pdPASS;\r
+ UBaseType_t uxSavedInterruptStatus;\r
\r
- if( pxMutexHolder != NULL )\r
+ configASSERT( xTaskToNotify );\r
+\r
+ /* RTOS ports that support interrupt nesting have the concept of a\r
+ maximum system call (or maximum API call) interrupt priority.\r
+ Interrupts that are above the maximum system call priority are keep\r
+ permanently enabled, even when the RTOS kernel is in a critical section,\r
+ but cannot make any calls to FreeRTOS API functions. If configASSERT()\r
+ is defined in FreeRTOSConfig.h then\r
+ portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+ failure if a FreeRTOS API function is called from an interrupt that has\r
+ been assigned a priority above the configured maximum system call\r
+ priority. Only FreeRTOS functions that end in FromISR can be called\r
+ from interrupts that have been assigned a priority at or (logically)\r
+ below the maximum system call interrupt priority. FreeRTOS maintains a\r
+ separate interrupt safe API to ensure interrupt entry is as fast and as\r
+ simple as possible. More information (albeit Cortex-M specific) is\r
+ provided on the following link:\r
+ http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+ portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+\r
+ pxTCB = ( TCB_t * ) xTaskToNotify;\r
+\r
+ uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
{\r
- if( pxTCB->uxPriority != pxTCB->uxBasePriority )\r
+ if( pulPreviousNotificationValue != NULL )\r
{\r
- /* Only disinherit if no other mutexes are held. */\r
- if( pxTCB->uxMutexesHeld == 0 )\r
- {\r
- /* The holding task must be the running task to be able to give\r
- the mutex back. Remove the holding task from the ready list. */\r
- if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
+ *pulPreviousNotificationValue = pxTCB->ulNotifiedValue;\r
+ }\r
+\r
+ ucOriginalNotifyState = pxTCB->ucNotifyState;\r
+ pxTCB->ucNotifyState = taskNOTIFICATION_RECEIVED;\r
+\r
+ switch( eAction )\r
+ {\r
+ case eSetBits :\r
+ pxTCB->ulNotifiedValue |= ulValue;\r
+ break;\r
+\r
+ case eIncrement :\r
+ ( pxTCB->ulNotifiedValue )++;\r
+ break;\r
+\r
+ case eSetValueWithOverwrite :\r
+ pxTCB->ulNotifiedValue = ulValue;\r
+ break;\r
+\r
+ case eSetValueWithoutOverwrite :\r
+ if( ucOriginalNotifyState != taskNOTIFICATION_RECEIVED )\r
{\r
- taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
+ pxTCB->ulNotifiedValue = ulValue;\r
}\r
else\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ /* The value could not be written to the task. */\r
+ xReturn = pdFAIL;\r
}\r
+ break;\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
+ case eNoAction :\r
+ /* The task is being notified without its notify value being\r
+ updated. */\r
+ break;\r
+ }\r
\r
- /* Only reset the event list item value if the value is not\r
- being used for anything else. */\r
- if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL )\r
+ traceTASK_NOTIFY_FROM_ISR();\r
+\r
+ /* If the task is in the blocked state specifically to wait for a\r
+ notification then unblock it now. */\r
+ if( ucOriginalNotifyState == taskWAITING_NOTIFICATION )\r
+ {\r
+ /* The task should not have been on an event list. */\r
+ configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL );\r
+\r
+ if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
+ {\r
+ ( void ) uxListRemove( &( pxTCB->xStateListItem ) );\r
+ prvAddTaskToReadyList( pxTCB );\r
+ }\r
+ else\r
+ {\r
+ /* The delayed and ready lists cannot be accessed, so hold\r
+ this task pending until the scheduler is resumed. */\r
+ vListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\r
+ }\r
+\r
+ if( pxTCB->uxPriority > pxCurrentTCB->uxPriority )\r
+ {\r
+ /* The notified task has a priority above the currently\r
+ executing task so a yield is required. */\r
+ if( pxHigherPriorityTaskWoken != NULL )\r
{\r
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ *pxHigherPriorityTaskWoken = pdTRUE;\r
}\r
else\r
{\r
-#warning Is it possible to come through here?\r
- mtCOVERAGE_TEST_MARKER();\r
+ /* Mark that a yield is pending in case the user is not\r
+ using the "xHigherPriorityTaskWoken" parameter to an ISR\r
+ safe FreeRTOS function. */\r
+ xYieldPending = pdTRUE;\r
}\r
- prvAddTaskToReadyList( pxTCB );\r
-\r
- /* Return true to indicate that a context switch is required.\r
- This is only actually required in the corner case whereby\r
- multiple mutexes were held and the mutexes were given back\r
- in an order different to that in which they were taken. */\r
- xReturn = pdTRUE;\r
}\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
}\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
}\r
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
\r
return xReturn;\r
}\r
\r
-#endif /* configUSE_MUTEXES */\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
\r
- void vTaskEnterCritical( void )\r
+ void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken )\r
{\r
- portDISABLE_INTERRUPTS();\r
+ TCB_t * pxTCB;\r
+ uint8_t ucOriginalNotifyState;\r
+ UBaseType_t uxSavedInterruptStatus;\r
\r
- if( xSchedulerRunning != pdFALSE )\r
+ configASSERT( xTaskToNotify );\r
+\r
+ /* RTOS ports that support interrupt nesting have the concept of a\r
+ maximum system call (or maximum API call) interrupt priority.\r
+ Interrupts that are above the maximum system call priority are keep\r
+ permanently enabled, even when the RTOS kernel is in a critical section,\r
+ but cannot make any calls to FreeRTOS API functions. If configASSERT()\r
+ is defined in FreeRTOSConfig.h then\r
+ portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+ failure if a FreeRTOS API function is called from an interrupt that has\r
+ been assigned a priority above the configured maximum system call\r
+ priority. Only FreeRTOS functions that end in FromISR can be called\r
+ from interrupts that have been assigned a priority at or (logically)\r
+ below the maximum system call interrupt priority. FreeRTOS maintains a\r
+ separate interrupt safe API to ensure interrupt entry is as fast and as\r
+ simple as possible. More information (albeit Cortex-M specific) is\r
+ provided on the following link:\r
+ http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+ portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+\r
+ pxTCB = ( TCB_t * ) xTaskToNotify;\r
+\r
+ uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
{\r
- ( pxCurrentTCB->uxCriticalNesting )++;\r
+ ucOriginalNotifyState = pxTCB->ucNotifyState;\r
+ pxTCB->ucNotifyState = taskNOTIFICATION_RECEIVED;\r
\r
- /* This is not the interrupt safe version of the enter critical\r
- function so assert() if it is being called from an interrupt\r
- context. Only API functions that end in "FromISR" can be used in an\r
- interrupt. Only assert if the critical nesting count is 1 to\r
- protect against recursive calls if the assert function also uses a\r
- critical section. */\r
- if( pxCurrentTCB->uxCriticalNesting == 1 )\r
+ /* 'Giving' is equivalent to incrementing a count in a counting\r
+ semaphore. */\r
+ ( pxTCB->ulNotifiedValue )++;\r
+\r
+ traceTASK_NOTIFY_GIVE_FROM_ISR();\r
+\r
+ /* If the task is in the blocked state specifically to wait for a\r
+ notification then unblock it now. */\r
+ if( ucOriginalNotifyState == taskWAITING_NOTIFICATION )\r
{\r
- portASSERT_IF_IN_ISR();\r
+ /* The task should not have been on an event list. */\r
+ configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL );\r
+\r
+ if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
+ {\r
+ ( void ) uxListRemove( &( pxTCB->xStateListItem ) );\r
+ prvAddTaskToReadyList( pxTCB );\r
+ }\r
+ else\r
+ {\r
+ /* The delayed and ready lists cannot be accessed, so hold\r
+ this task pending until the scheduler is resumed. */\r
+ vListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\r
+ }\r
+\r
+ if( pxTCB->uxPriority > pxCurrentTCB->uxPriority )\r
+ {\r
+ /* The notified task has a priority above the currently\r
+ executing task so a yield is required. */\r
+ if( pxHigherPriorityTaskWoken != NULL )\r
+ {\r
+ *pxHigherPriorityTaskWoken = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ /* Mark that a yield is pending in case the user is not\r
+ using the "xHigherPriorityTaskWoken" parameter in an ISR\r
+ safe FreeRTOS function. */\r
+ xYieldPending = pdTRUE;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
}\r
-\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
}\r
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
}\r
\r
-#endif /* portCRITICAL_NESTING_IN_TCB */\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
+\r
/*-----------------------------------------------------------*/\r
\r
-#if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
\r
- void vTaskExitCritical( void )\r
+ BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask )\r
{\r
- if( xSchedulerRunning != pdFALSE )\r
+ TCB_t *pxTCB;\r
+ BaseType_t xReturn;\r
+\r
+ /* If null is passed in here then it is the calling task that is having\r
+ its notification state cleared. */\r
+ pxTCB = prvGetTCBFromHandle( xTask );\r
+\r
+ taskENTER_CRITICAL();\r
{\r
- if( pxCurrentTCB->uxCriticalNesting > 0U )\r
+ if( pxTCB->ucNotifyState == taskNOTIFICATION_RECEIVED )\r
{\r
- ( pxCurrentTCB->uxCriticalNesting )--;\r
-\r
- if( pxCurrentTCB->uxCriticalNesting == 0U )\r
- {\r
- portENABLE_INTERRUPTS();\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ pxTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION;\r
+ xReturn = pdPASS;\r
}\r
else\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
+ xReturn = pdFAIL;\r
}\r
}\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ taskEXIT_CRITICAL();\r
+\r
+ return xReturn;\r
}\r
\r
-#endif /* portCRITICAL_NESTING_IN_TCB */\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) )\r
-\r
- void vTaskList( char * pcWriteBuffer )\r
- {\r
- TaskStatus_t *pxTaskStatusArray;\r
- volatile UBaseType_t uxArraySize, x;\r
- char cStatus;\r
-\r
- /*\r
- * PLEASE NOTE:\r
- *\r
- * This function is provided for convenience only, and is used by many\r
- * of the demo applications. Do not consider it to be part of the\r
- * scheduler.\r
- *\r
- * vTaskList() calls uxTaskGetSystemState(), then formats part of the\r
- * uxTaskGetSystemState() output into a human readable table that\r
- * displays task names, states and stack usage.\r
- *\r
- * vTaskList() has a dependency on the sprintf() C library function that\r
- * might bloat the code size, use a lot of stack, and provide different\r
- * results on different platforms. An alternative, tiny, third party,\r
- * and limited functionality implementation of sprintf() is provided in\r
- * many of the FreeRTOS/Demo sub-directories in a file called\r
- * printf-stdarg.c (note printf-stdarg.c does not provide a full\r
- * snprintf() implementation!).\r
- *\r
- * It is recommended that production systems call uxTaskGetSystemState()\r
- * directly to get access to raw stats data, rather than indirectly\r
- * through a call to vTaskList().\r
- */\r
-\r
\r
- /* Make sure the write buffer does not contain a string. */\r
- *pcWriteBuffer = 0x00;\r
+static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, const BaseType_t xCanBlockIndefinitely )\r
+{\r
+TickType_t xTimeToWake;\r
+const TickType_t xConstTickCount = xTickCount;\r
\r
- /* Take a snapshot of the number of tasks in case it changes while this\r
- function is executing. */\r
- uxArraySize = uxCurrentNumberOfTasks;\r
+ #if( INCLUDE_xTaskAbortDelay == 1 )\r
+ {\r
+ /* About to enter a delayed list, so ensure the ucDelayAborted flag is\r
+ reset to pdFALSE so it can be detected as having been set to pdTRUE\r
+ when the task leaves the Blocked state. */\r
+ pxCurrentTCB->ucDelayAborted = pdFALSE;\r
+ }\r
+ #endif\r
\r
- /* Allocate an array index for each task. */\r
- pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) );\r
+ /* Remove the task from the ready list before adding it to the blocked list\r
+ as the same list item is used for both lists. */\r
+ if( uxListRemove( &( pxCurrentTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )\r
+ {\r
+ /* The current task must be in a ready list, so there is no need to\r
+ check, and the port reset macro can be called directly. */\r
+ portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
\r
- if( pxTaskStatusArray != NULL )\r
+ #if ( INCLUDE_vTaskSuspend == 1 )\r
+ {\r
+ if( ( xTicksToWait == portMAX_DELAY ) && ( xCanBlockIndefinitely != pdFALSE ) )\r
{\r
- /* Generate the (binary) data. */\r
- uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL );\r
+ /* Add the task to the suspended task list instead of a delayed task\r
+ list to ensure it is not woken by a timing event. It will block\r
+ indefinitely. */\r
+ vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xStateListItem ) );\r
+ }\r
+ else\r
+ {\r
+ /* Calculate the time at which the task should be woken if the event\r
+ does not occur. This may overflow but this doesn't matter, the\r
+ kernel will manage it correctly. */\r
+ xTimeToWake = xConstTickCount + xTicksToWait;\r
\r
- /* Create a human readable table from the binary data. */\r
- for( x = 0; x < uxArraySize; x++ )\r
+ /* The list item will be inserted in wake time order. */\r
+ listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xStateListItem ), xTimeToWake );\r
+\r
+ if( xTimeToWake < xConstTickCount )\r
{\r
- switch( pxTaskStatusArray[ x ].eCurrentState )\r
+ /* Wake time has overflowed. Place this item in the overflow\r
+ list. */\r
+ vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );\r
+ }\r
+ else\r
+ {\r
+ /* The wake time has not overflowed, so the current block list\r
+ is used. */\r
+ vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );\r
+\r
+ /* If the task entering the blocked state was placed at the\r
+ head of the list of blocked tasks then xNextTaskUnblockTime\r
+ needs to be updated too. */\r
+ if( xTimeToWake < xNextTaskUnblockTime )\r
{\r
- case eReady: cStatus = tskREADY_CHAR;\r
- break;\r
-\r
- case eBlocked: cStatus = tskBLOCKED_CHAR;\r
- break;\r
-\r
- case eSuspended: cStatus = tskSUSPENDED_CHAR;\r
- break;\r
-\r
- case eDeleted: cStatus = tskDELETED_CHAR;\r
- break;\r
-\r
- default: /* Should not get here, but it is included\r
- to prevent static checking errors. */\r
- cStatus = 0x00;\r
- break;\r
+ xNextTaskUnblockTime = xTimeToWake;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
}\r
-\r
- sprintf( pcWriteBuffer, "%s\t\t%c\t%u\t%u\t%u\r\n", pxTaskStatusArray[ x ].pcTaskName, cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber );\r
- pcWriteBuffer += strlen( pcWriteBuffer );\r
}\r
-\r
- /* Free the array again. */\r
- vPortFree( pxTaskStatusArray );\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
}\r
}\r
-\r
-#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) ) */\r
-/*----------------------------------------------------------*/\r
-\r
-#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) )\r
-\r
- void vTaskGetRunTimeStats( char *pcWriteBuffer )\r
+ #else /* INCLUDE_vTaskSuspend */\r
{\r
- TaskStatus_t *pxTaskStatusArray;\r
- volatile UBaseType_t uxArraySize, x;\r
- uint32_t ulTotalTime, ulStatsAsPercentage;\r
+ /* Calculate the time at which the task should be woken if the event\r
+ does not occur. This may overflow but this doesn't matter, the kernel\r
+ will manage it correctly. */\r
+ xTimeToWake = xConstTickCount + xTicksToWait;\r
\r
- #if( configUSE_TRACE_FACILITY != 1 )\r
+ /* The list item will be inserted in wake time order. */\r
+ listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xStateListItem ), xTimeToWake );\r
+\r
+ if( xTimeToWake < xConstTickCount )\r
{\r
- #error configUSE_TRACE_FACILITY must also be set to 1 in FreeRTOSConfig.h to use vTaskGetRunTimeStats().\r
+ /* Wake time has overflowed. Place this item in the overflow list. */\r
+ vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );\r
}\r
- #endif\r
-\r
- /*\r
- * PLEASE NOTE:\r
- *\r
- * This function is provided for convenience only, and is used by many\r
- * of the demo applications. Do not consider it to be part of the\r
- * scheduler.\r
- *\r
- * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part\r
- * of the uxTaskGetSystemState() output into a human readable table that\r
- * displays the amount of time each task has spent in the Running state\r
- * in both absolute and percentage terms.\r
- *\r
- * vTaskGetRunTimeStats() has a dependency on the sprintf() C library\r
- * function that might bloat the code size, use a lot of stack, and\r
- * provide different results on different platforms. An alternative,\r
- * tiny, third party, and limited functionality implementation of\r
- * sprintf() is provided in many of the FreeRTOS/Demo sub-directories in\r
- * a file called printf-stdarg.c (note printf-stdarg.c does not provide\r
- * a full snprintf() implementation!).\r
- *\r
- * It is recommended that production systems call uxTaskGetSystemState()\r
- * directly to get access to raw stats data, rather than indirectly\r
- * through a call to vTaskGetRunTimeStats().\r
- */\r
-\r
- /* Make sure the write buffer does not contain a string. */\r
- *pcWriteBuffer = 0x00;\r
-\r
- /* Take a snapshot of the number of tasks in case it changes while this\r
- function is executing. */\r
- uxArraySize = uxCurrentNumberOfTasks;\r
-\r
- /* Allocate an array index for each task. */\r
- pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) );\r
-\r
- if( pxTaskStatusArray != NULL )\r
+ else\r
{\r
- /* Generate the (binary) data. */\r
- uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalTime );\r
-\r
- /* For percentage calculations. */\r
- ulTotalTime /= 100UL;\r
+ /* The wake time has not overflowed, so the current block list is used. */\r
+ vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );\r
\r
- /* Avoid divide by zero errors. */\r
- if( ulTotalTime > 0 )\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
- /* Create a human readable table from the binary data. */\r
- for( x = 0; x < uxArraySize; x++ )\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
- ulTotalRunTimeDiv100 has already been divided by 100. */\r
- ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalTime;\r
-\r
- if( ulStatsAsPercentage > 0UL )\r
- {\r
- #ifdef portLU_PRINTF_SPECIFIER_REQUIRED\r
- {\r
- sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );\r
- }\r
- #else\r
- {\r
- /* sizeof( int ) == sizeof( long ) so a smaller\r
- printf() library can be used. */\r
- sprintf( pcWriteBuffer, "%s\t\t%u\t\t%u%%\r\n", pxTaskStatusArray[ x ].pcTaskName, ( unsigned int ) pxTaskStatusArray[ x ].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( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );\r
- }\r
- #else\r
- {\r
- /* sizeof( int ) == sizeof( long ) so a smaller\r
- printf() library can be used. */\r
- sprintf( pcWriteBuffer, "%s\t\t%u\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter );\r
- }\r
- #endif\r
- }\r
-\r
- pcWriteBuffer += strlen( pcWriteBuffer );\r
- }\r
+ xNextTaskUnblockTime = xTimeToWake;\r
}\r
else\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
-\r
- /* Free the array again. */\r
- vPortFree( pxTaskStatusArray );\r
- }\r
- else\r
- {\r
- mtCOVERAGE_TEST_MARKER();\r
}\r
- }\r
\r
-#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) ) */\r
-/*-----------------------------------------------------------*/\r
+ /* Avoid compiler warning when INCLUDE_vTaskSuspend is not 1. */\r
+ ( void ) xCanBlockIndefinitely;\r
+ }\r
+ #endif /* INCLUDE_vTaskSuspend */\r
+}\r
\r
-TickType_t uxTaskResetEventItemValue( void )\r
-{\r
-TickType_t uxReturn;\r
+/* Code below here allows additional code to be inserted into this source file,\r
+especially where access to file scope functions and data is needed (for example\r
+when performing module tests). */\r
\r
- uxReturn = listGET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ) );\r
+#ifdef FREERTOS_MODULE_TEST\r
+ #include "tasks_test_access_functions.h"\r
+#endif\r
\r
- /* Reset the event list item to its normal value - so it can be used with\r
- queues and semaphores. */\r
- listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), ( ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxCurrentTCB->uxPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
\r
- return uxReturn;\r
-}\r
-/*-----------------------------------------------------------*/\r
+#if( configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H == 1 )\r
\r
-void vTaskIncrementMutexHeldCount( void )\r
-{\r
- ( pxCurrentTCB->uxMutexesHeld )++;\r
-}\r
-/*-----------------------------------------------------------*/\r
+ #include "freertos_tasks_c_additions.h"\r
\r
-void vTaskDecrementMutexHeldCount( void )\r
-{\r
- configASSERT( pxCurrentTCB->uxMutexesHeld );\r
- ( pxCurrentTCB->uxMutexesHeld )--;\r
-}\r
+ static void freertos_tasks_c_additions_init( void )\r
+ {\r
+ #ifdef FREERTOS_TASKS_C_ADDITIONS_INIT\r
+ FREERTOS_TASKS_C_ADDITIONS_INIT();\r
+ #endif\r
+ }\r
\r
-#ifdef FREERTOS_MODULE_TEST\r
- #include "tasks_test_access_functions.h"\r
#endif\r
\r
+\r