/*\r
- FreeRTOS V8.0.0:rc1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
+ FreeRTOS V8.2.0rc1 - Copyright (C) 2014 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
\r
- >>! NOTE: The modification to the GPL is included to allow you to distribute\r
- >>! a combined work that includes FreeRTOS without being obliged to provide\r
- >>! the source code for proprietary components outside of the FreeRTOS\r
- >>! kernel.\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
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
* Having a problem? Start by reading the FAQ "My application does *\r
- * not run, what could be wrong?" *\r
+ * not run, what could be wrong?". Have you defined configASSERT()? *\r
* *\r
* http://www.FreeRTOS.org/FAQHelp.html *\r
* *\r
***************************************************************************\r
\r
+ ***************************************************************************\r
+ * *\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
+ * 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
+ ***************************************************************************\r
+ * *\r
+ * Investing in training allows your team to be as productive as *\r
+ * possible as early as possible, lowering your overall development *\r
+ * cost, and enabling you to bring a more robust product to market *\r
+ * earlier than would otherwise be possible. Richard Barry is both *\r
+ * the architect and key author of FreeRTOS, and so also the world's *\r
+ * leading authority on what is the world's most popular real time *\r
+ * kernel for deeply embedded MCU designs. Obtaining your training *\r
+ * from Richard ensures your team will gain directly from his in-depth *\r
+ * product knowledge and years of usage experience. Contact Real Time *\r
+ * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *\r
+ * by Richard Barry: http://www.FreeRTOS.org/contact\r
+ * *\r
+ ***************************************************************************\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * You are receiving this top quality software for free. Please play *\r
+ * fair and reciprocate by reporting any suspected issues and *\r
+ * participating in the community forum: *\r
+ * http://www.FreeRTOS.org/support *\r
+ * *\r
+ * Thank you! *\r
+ * *\r
+ ***************************************************************************\r
+\r
http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
license and Real Time Engineers Ltd. contact details.\r
\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.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 to sell under the OpenRTOS brand. Low cost OpenRTOS\r
- licenses offer ticketed support, indemnification and middleware.\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
#define taskYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API()\r
#endif\r
\r
+/* Value that can be assigned to the eNotifyState member of the TCB. */\r
+typedef enum\r
+{\r
+ eNotWaitingNotification = 0,\r
+ eWaitingNotification,\r
+ eNotified\r
+} eNotifyValue;\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
\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
+ BaseType_t xUsingStaticallyAllocatedStack; /* Set to pdTRUE if the stack is a statically allocated array, and pdFALSE if the stack is dynamically allocated. */\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
\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
struct _reent xNewLib_reent;\r
#endif\r
\r
-} TCB_t;\r
+ #if ( configUSE_TASK_NOTIFICATIONS == 1 )\r
+ volatile uint32_t ulNotifiedValue;\r
+ volatile eNotifyValue eNotifyState;\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
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 uxSchedulerSuspended = ( UBaseType_t ) 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 xGenericListItem of a TCB, or any of the\r
+lists the xGenericListItem 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
/* 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
*/\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
\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
+ static BaseType_t prvTaskIsTaskSuspended( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;\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 prvResetNextTaskUnblockTime( void );\r
\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )\r
+\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 );\r
+\r
+#endif\r
/*-----------------------------------------------------------*/\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
+StackType_t *pxTopOfStack;\r
\r
configASSERT( pxTaskCode );\r
configASSERT( ( ( uxPriority & ( ~portPRIVILEGE_BIT ) ) < configMAX_PRIORITIES ) );\r
\r
if( pxNewTCB != NULL )\r
{\r
- StackType_t *pxTopOfStack;\r
-\r
#if( portUSING_MPU_WRAPPERS == 1 )\r
/* Should the task be created in privileged mode? */\r
BaseType_t xRunPrivileged;\r
xRunPrivileged = pdFALSE;\r
}\r
uxPriority &= ~portPRIVILEGE_BIT;\r
+\r
+ if( puxStackBuffer != NULL )\r
+ {\r
+ /* The application provided its own stack. Note this so no\r
+ attempt is made to delete the stack should that task be\r
+ deleted. */\r
+ pxNewTCB->xUsingStaticallyAllocatedStack = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ /* The stack was allocated dynamically. Note this so it can be\r
+ deleted again if the task is deleted. */\r
+ pxNewTCB->xUsingStaticallyAllocatedStack = pdFALSE;\r
+ }\r
#endif /* portUSING_MPU_WRAPPERS == 1 */\r
\r
/* Calculate the top of stack address. This depends on whether the\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( ( ( ( uint32_t ) pxTopOfStack & ( uint32_t ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
+ configASSERT( ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack & ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
}\r
#else /* portSTACK_GROWTH */\r
{\r
pxTopOfStack = pxNewTCB->pxStack;\r
\r
/* Check the alignment of the stack buffer is correct. */\r
- configASSERT( ( ( ( uint32_t ) pxNewTCB->pxStack & ( uint32_t ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
+ configASSERT( ( ( ( portPOINTER_SIZE_TYPE ) pxNewTCB->pxStack & ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
\r
/* If we want to use stack checking on architectures that use\r
a positive stack growth direction then we also need to store the\r
{\r
/* Reset the next expected unblock time in case it referred to\r
the task that has just been deleted. */\r
- prvResetNextTaskUnblockTime();\r
+ taskENTER_CRITICAL();\r
+ {\r
+ prvResetNextTaskUnblockTime();\r
+ }\r
+ taskEXIT_CRITICAL();\r
}\r
}\r
}\r
{\r
traceTASK_DELAY_UNTIL();\r
\r
- /* We must remove ourselves from the ready list before adding\r
- ourselves to the blocked list as the same list item is used for\r
- both lists. */\r
+ /* 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
{\r
/* The current task must be in a ready list, so there is\r
}\r
#endif\r
\r
- else\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
}\r
\r
return eReturn;\r
- }\r
+ } /*lint !e818 xTask cannot be a pointer to const because it is a typedef. */\r
\r
#endif /* INCLUDE_eTaskGetState */\r
/*-----------------------------------------------------------*/\r
#endif /* INCLUDE_uxTaskPriorityGet */\r
/*-----------------------------------------------------------*/\r
\r
+#if ( INCLUDE_uxTaskPriorityGet == 1 )\r
+\r
+ UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask )\r
+ {\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
+ 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
+ uxSavedInterruptState = portSET_INTERRUPT_MASK_FROM_ISR();\r
+ {\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
+ 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
/* 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
- prvResetNextTaskUnblockTime();\r
+ taskENTER_CRITICAL();\r
+ {\r
+ prvResetNextTaskUnblockTime();\r
+ }\r
+ taskEXIT_CRITICAL();\r
}\r
else\r
{\r
\r
#if ( INCLUDE_vTaskSuspend == 1 )\r
\r
- BaseType_t xTaskIsTaskSuspended( const TaskHandle_t xTask )\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 we are attempting to resume actually in the\r
- suspended list? */\r
+ /* Is the task being resumed actually in the suspended list? */\r
if( listIS_CONTAINED_WITHIN( &xSuspendedTaskList, &( pxTCB->xGenericListItem ) ) != 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\r
- Suspended state? It is possible to be in the suspended\r
- list because it is blocked on a task with no timeout\r
- specified. */\r
+ /* 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
{\r
xReturn = pdTRUE;\r
{\r
taskENTER_CRITICAL();\r
{\r
- if( xTaskIsTaskSuspended( pxTCB ) == pdTRUE )\r
+ if( prvTaskIsTaskSuspended( pxTCB ) == pdTRUE )\r
{\r
traceTASK_RESUME( pxTCB );\r
\r
\r
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
{\r
- if( xTaskIsTaskSuspended( pxTCB ) == pdTRUE )\r
+ if( prvTaskIsTaskSuspended( pxTCB ) == pdTRUE )\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
- /* We cannot access the delayed or ready lists, so will hold this\r
- task pending until the scheduler is resumed, at which point a\r
- yield will be performed if necessary. */\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
( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
prvAddTaskToReadyList( pxTCB );\r
\r
- /* If we have moved a task that has a priority higher than\r
- the current task then we should yield. */\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
TickType_t xTicks;\r
\r
/* Critical section required if running on a 16 bit processor. */\r
- taskENTER_CRITICAL();\r
+ portTICK_TYPE_ENTER_CRITICAL();\r
{\r
xTicks = xTickCount;\r
}\r
- taskEXIT_CRITICAL();\r
+ portTICK_TYPE_EXIT_CRITICAL();\r
\r
return xTicks;\r
}\r
link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
\r
- uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
- xReturn = xTickCount;\r
- portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+ uxSavedInterruptStatus = portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR();\r
+ {\r
+ xReturn = xTickCount;\r
+ }\r
+ portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
\r
return xReturn;\r
}\r
\r
#if ( INCLUDE_pcTaskGetTaskName == 1 )\r
\r
- char *pcTaskGetTaskName( TaskHandle_t xTaskToQuery )\r
+ char *pcTaskGetTaskName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
{\r
TCB_t *pxTCB;\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
+ look any further down the list. */\r
if( xConstTickCount >= xNextTaskUnblockTime )\r
{\r
for( ;; )\r
}\r
#endif /* configGENERATE_RUN_TIME_STATS */\r
\r
+ /* Check for stack overflow, if configured. */\r
taskFIRST_CHECK_FOR_STACK_OVERFLOW();\r
taskSECOND_CHECK_FOR_STACK_OVERFLOW();\r
\r
+ /* Select a new task to run using either the generic C or port\r
+ optimised asm code. */\r
taskSELECT_HIGHEST_PRIORITY_TASK();\r
-\r
traceTASK_SWITCHED_IN();\r
\r
#if ( configUSE_NEWLIB_REENTRANT == 1 )\r
\r
configASSERT( pxEventList );\r
\r
- /* THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED OR THE\r
- SCHEDULER SUSPENDED. */\r
+ /* THIS FUNCTION MUST BE CALLED WITH EITHER INTERRUPTS DISABLED OR THE\r
+ SCHEDULER SUSPENDED AND THE QUEUE BEING ACCESSED LOCKED. */\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. */\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
- /* We must remove ourselves from the ready list before adding ourselves\r
- to the blocked list as the same list item is used for both lists. We have\r
- exclusive access to the ready lists as the scheduler is locked. */\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
{\r
if( xTicksToWait == portMAX_DELAY )\r
{\r
- /* Add ourselves to the suspended task list instead of a delayed task\r
- list to ensure we are not woken by a timing event. We will block\r
- indefinitely. */\r
+ /* 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
}\r
else\r
{\r
- /* Calculate the time at which the task should be woken if the event does\r
- not occur. This may overflow but this doesn't matter. */\r
+ /* 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
}\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. */\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
\r
configASSERT( pxEventList );\r
\r
- /* THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED OR THE\r
- SCHEDULER SUSPENDED. */\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. */\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. */\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
/* The task must be removed from the ready list before it is added to the\r
}\r
else\r
{\r
- /* Calculate the time at which the task should be woken if the event does\r
- not occur. This may overflow but this doesn't matter. */\r
+ /* 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
}\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. */\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
TCB_t *pxUnblockedTCB;\r
BaseType_t xReturn;\r
\r
- /* THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED OR THE\r
- SCHEDULER SUSPENDED. It can also be called from within an ISR. */\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
- /* The event list is sorted in priority order, so we can remove the\r
- first in the list, remove the TCB from the delayed list, and add\r
- it to the ready list.\r
+ /* 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
If an event is for a queue that is locked then this function will never\r
get called - the lock count on the queue will get modified instead. This\r
- means we can always expect exclusive access to the event list here.\r
+ means exclusive access to the event list is guaranteed here.\r
\r
This function assumes that a check has already been made to ensure that\r
pxEventList is not empty. */\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
+ /* 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
xReturn = pdFALSE;\r
}\r
\r
+ #if( configUSE_TICKLESS_IDLE == 1 )\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 get 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\r
+\r
return xReturn;\r
}\r
/*-----------------------------------------------------------*/\r
TCB_t *pxUnblockedTCB;\r
BaseType_t xReturn;\r
\r
- /* THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED OR THE\r
- SCHEDULER SUSPENDED. It can also be called from within an ISR. */\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
/* Store the new item value in the event list. */\r
listSET_LIST_ITEM_VALUE( pxEventListItem, xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );\r
\r
- /* Remove the TCB from the delayed list, and add it to the ready list. */\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
\r
- if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )\r
- {\r
- ( void ) uxListRemove( &( pxUnblockedTCB->xGenericListItem ) );\r
- prvAddTaskToReadyList( pxUnblockedTCB );\r
- }\r
- else\r
- {\r
- /* Cannot access the delayed or ready lists, so will hold this task\r
- pending until the scheduler is resumed. */\r
- vListInsertEnd( &( xPendingReadyList ), 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->xGenericListItem ) );\r
+ prvAddTaskToReadyList( pxUnblockedTCB );\r
\r
if( pxUnblockedTCB->uxPriority > pxCurrentTCB->uxPriority )\r
{\r
#if ( configUSE_MUTEXES == 1 )\r
{\r
pxTCB->uxBasePriority = uxPriority;\r
+ pxTCB->uxMutexesHeld = 0;\r
}\r
#endif /* configUSE_MUTEXES */\r
\r
}\r
#endif /* portUSING_MPU_WRAPPERS */\r
\r
+ #if ( configUSE_TASK_NOTIFICATIONS == 1 )\r
+ {\r
+ pxTCB->ulNotifiedValue = 0;\r
+ pxTCB->eNotifyState = eNotWaitingNotification;\r
+ }\r
+ #endif\r
+\r
#if ( configUSE_NEWLIB_REENTRANT == 1 )\r
{\r
/* Initialise this task's Newlib reent structure. */\r
while( uxTasksDeleted > ( UBaseType_t ) 0U )\r
{\r
vTaskSuspendAll();\r
+ {\r
xListIsEmpty = listLIST_IS_EMPTY( &xTasksWaitingTermination );\r
+ }\r
( void ) xTaskResumeAll();\r
\r
if( xListIsEmpty == pdFALSE )\r
{\r
TCB_t *pxNewTCB;\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
-\r
- if( pxNewTCB != NULL )\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
- /* 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
+ /* 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
\r
- if( pxNewTCB->pxStack == NULL )\r
+ if( pxNewTCB != NULL )\r
{\r
- /* Could not allocate the stack. Delete the allocated TCB. */\r
- vPortFree( pxNewTCB );\r
- pxNewTCB = NULL;\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
+\r
+ if( pxNewTCB->pxStack == NULL )\r
+ {\r
+ /* Could not allocate the stack. Delete the allocated TCB. */\r
+ vPortFree( pxNewTCB );\r
+ pxNewTCB = NULL;\r
+ }\r
}\r
- else\r
+ }\r
+ #else /* portSTACK_GROWTH */\r
+ {\r
+ StackType_t *pxStack;\r
+\r
+ /* Allocate space for the stack used by the task being created. */\r
+ 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
+\r
+ if( pxStack != NULL )\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
+ /* Allocate space for the TCB. Where the memory comes from depends\r
+ on the implementation of the port malloc function. */\r
+ pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );\r
+\r
+ if( pxNewTCB != NULL )\r
{\r
- /* Just to help debugging. */\r
- ( void ) memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) usStackDepth * sizeof( StackType_t ) );\r
+ /* Store the stack location in the TCB. */\r
+ pxNewTCB->pxStack = pxStack;\r
}\r
- #endif /* ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) ) */\r
+ else\r
+ {\r
+ /* The stack cannot be used as the TCB was not created. Free it\r
+ again. */\r
+ vPortFree( pxStack );\r
+ }\r
+ }\r
+ else\r
+ {\r
+ pxNewTCB = NULL;\r
+ }\r
+ }\r
+ #endif /* portSTACK_GROWTH */\r
+\r
+ if( pxNewTCB != NULL )\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
return pxNewTCB;\r
pxTaskStatusArray[ uxTask ].eCurrentState = eState;\r
pxTaskStatusArray[ uxTask ].uxCurrentPriority = pxNextTCB->uxPriority;\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
+\r
#if ( configUSE_MUTEXES == 1 )\r
{\r
pxTaskStatusArray[ uxTask ].uxBasePriority = pxNextTCB->uxBasePriority;\r
{\r
uint32_t ulCount = 0U;\r
\r
- while( *pucStackByte == tskSTACK_FILL_BYTE )\r
+ while( *pucStackByte == ( uint8_t ) tskSTACK_FILL_BYTE )\r
{\r
pucStackByte -= portSTACK_GROWTH;\r
ulCount++;\r
}\r
\r
- ulCount /= ( uint32_t ) sizeof( StackType_t );\r
+ ulCount /= ( uint32_t ) sizeof( StackType_t ); /*lint !e961 Casting is not redundant on smaller architectures. */\r
\r
return ( uint16_t ) ulCount;\r
}\r
want to allocate and clean RAM statically. */\r
portCLEAN_UP_TCB( pxTCB );\r
\r
- /* Free up the memory allocated by the scheduler for the task. It is up to\r
- the task to free any memory allocated at the application level. */\r
- vPortFreeAligned( pxTCB->pxStack );\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
+ _reclaim_reent( &( pxTCB->xNewLib_reent ) );\r
+ }\r
+ #endif /* configUSE_NEWLIB_REENTRANT */\r
+\r
+ #if( portUSING_MPU_WRAPPERS == 1 )\r
+ {\r
+ /* Only free the stack if it was allocated dynamically in the first\r
+ place. */\r
+ if( pxTCB->xUsingStaticallyAllocatedStack == pdFALSE )\r
+ {\r
+ vPortFreeAligned( pxTCB->pxStack );\r
+ }\r
+ }\r
+ #else\r
+ {\r
+ vPortFreeAligned( pxTCB->pxStack );\r
+ }\r
+ #endif\r
+\r
vPortFree( pxTCB );\r
}\r
\r
\r
#if ( configUSE_MUTEXES == 1 )\r
\r
- void vTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder )\r
+ BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder )\r
{\r
TCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder;\r
+ BaseType_t xReturn = pdFALSE;\r
\r
if( pxMutexHolder != NULL )\r
{\r
+ configASSERT( pxTCB->uxMutexesHeld );\r
+ ( pxTCB->uxMutexesHeld )--;\r
+\r
if( pxTCB->uxPriority != pxTCB->uxBasePriority )\r
{\r
- /* We must be the running task to be able to give the mutex back.\r
- Remove ourselves from the ready list we currently appear in. */\r
- if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
- {\r
- taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
- }\r
- else\r
+ /* Only disinherit if no other mutexes are held. */\r
+ if( pxTCB->uxMutexesHeld == ( UBaseType_t ) 0 )\r
{\r
- mtCOVERAGE_TEST_MARKER();\r
- }\r
+ /* A task can only have an inhertied 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->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
+ {\r
+ taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\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
+ /* 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
- /* 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
+ /* 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
+ /* 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
- prvAddTaskToReadyList( pxTCB );\r
}\r
else\r
{\r
{\r
mtCOVERAGE_TEST_MARKER();\r
}\r
+\r
+ return xReturn;\r
}\r
\r
#endif /* configUSE_MUTEXES */\r
if( xSchedulerRunning != pdFALSE )\r
{\r
( pxCurrentTCB->uxCriticalNesting )++;\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
+ {\r
+ portASSERT_IF_IN_ISR();\r
+ }\r
+\r
}\r
else\r
{\r
#endif /* portCRITICAL_NESTING_IN_TCB */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) )\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )\r
+\r
+ static char *prvWriteNameToBuffer( char *pcBuffer, const char *pcTaskName )\r
+ {\r
+ BaseType_t x;\r
+\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 < ( configMAX_TASK_NAME_LEN - 1 ); x++ )\r
+ {\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
+#endif /* ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )\r
\r
void vTaskList( char * pcWriteBuffer )\r
{\r
{\r
switch( pxTaskStatusArray[ x ].eCurrentState )\r
{\r
- case eReady: cStatus = tskREADY_CHAR;\r
- break;\r
+ case eReady: cStatus = tskREADY_CHAR;\r
+ break;\r
\r
- case eBlocked: cStatus = tskBLOCKED_CHAR;\r
- break;\r
+ case eBlocked: cStatus = tskBLOCKED_CHAR;\r
+ break;\r
\r
- case eSuspended: cStatus = tskSUSPENDED_CHAR;\r
- break;\r
+ case eSuspended: cStatus = tskSUSPENDED_CHAR;\r
+ break;\r
\r
- case eDeleted: cStatus = tskDELETED_CHAR;\r
- break;\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
+ default: /* Should not get here, but it is included\r
+ to prevent static checking errors. */\r
+ cStatus = 0x00;\r
+ break;\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
+ /* 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
+ /* 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
}\r
}\r
\r
-#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) ) */\r
+#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) */\r
/*----------------------------------------------------------*/\r
\r
-#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) )\r
+#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )\r
\r
void vTaskGetRunTimeStats( char *pcWriteBuffer )\r
{\r
volatile UBaseType_t uxArraySize, x;\r
uint32_t ulTotalTime, ulStatsAsPercentage;\r
\r
+ #if( configUSE_TRACE_FACILITY != 1 )\r
+ {\r
+ #error configUSE_TRACE_FACILITY must also be set to 1 in FreeRTOSConfig.h to use vTaskGetRunTimeStats().\r
+ }\r
+ #endif\r
+\r
/*\r
* PLEASE NOTE:\r
*\r
ulTotalRunTimeDiv100 has already been divided by 100. */\r
ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalTime;\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( 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
+ 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, "%s\t\t%u\t\t%u%%\r\n", pxTaskStatusArray[ x ].pcTaskName, ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter, ( unsigned int ) ulStatsAsPercentage );\r
+ sprintf( pcWriteBuffer, "\t%u\t\t%u%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter, ( unsigned int ) ulStatsAsPercentage );\r
}\r
#endif\r
}\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
+ 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, "%s\t\t%u\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter );\r
+ sprintf( pcWriteBuffer, "\t%u\t\t<1%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter );\r
}\r
#endif\r
}\r
}\r
}\r
\r
-#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) ) */\r
+#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) */\r
/*-----------------------------------------------------------*/\r
\r
TickType_t uxTaskResetEventItemValue( void )\r
}\r
/*-----------------------------------------------------------*/\r
\r
+#if ( configUSE_MUTEXES == 1 )\r
+\r
+ void *pvTaskIncrementMutexHeldCount( void )\r
+ {\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 pxCurrentTCB;\r
+ }\r
+\r
+#endif /* configUSE_MUTEXES */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+\r
+ uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait )\r
+ {\r
+ TickType_t xTimeToWake;\r
+ uint32_t ulReturn;\r
+\r
+ taskENTER_CRITICAL();\r
+ {\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->eNotifyState = eWaitingNotification;\r
+\r
+ if( xTicksToWait > ( TickType_t ) 0 )\r
+ {\r
+ /* The task is going to block. First it must be removed\r
+ from the ready list. */\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
+\r
+ #if ( INCLUDE_vTaskSuspend == 1 )\r
+ {\r
+ if( xTicksToWait == portMAX_DELAY )\r
+ {\r
+ /* Add the task to the suspended task list instead\r
+ of a delayed task list to ensure the task is not\r
+ woken by a timing event. It will block\r
+ indefinitely. */\r
+ vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xGenericListItem ) );\r
+ }\r
+ else\r
+ {\r
+ /* Calculate the time at which the task should be\r
+ woken if no notification events occur. This may\r
+ overflow but this doesn't matter, the scheduler will\r
+ handle it. */\r
+ xTimeToWake = xTickCount + xTicksToWait;\r
+ prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+ }\r
+ }\r
+ #else /* INCLUDE_vTaskSuspend */\r
+ {\r
+ /* Calculate the time at which the task should be\r
+ woken if the event does not occur. This may\r
+ overflow but this doesn't matter, the scheduler will\r
+ handle it. */\r
+ xTimeToWake = xTickCount + xTicksToWait;\r
+ prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+ }\r
+ #endif /* INCLUDE_vTaskSuspend */\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
+ taskENTER_CRITICAL();\r
+ {\r
+ ulReturn = pxCurrentTCB->ulNotifiedValue;\r
+\r
+ if( ulReturn != 0UL )\r
+ {\r
+ if( xClearCountOnExit != pdFALSE )\r
+ {\r
+ pxCurrentTCB->ulNotifiedValue = 0UL;\r
+ }\r
+ else\r
+ {\r
+ ( pxCurrentTCB->ulNotifiedValue )--;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ pxCurrentTCB->eNotifyState = eNotWaitingNotification;\r
+ }\r
+ taskEXIT_CRITICAL();\r
+\r
+ return ulReturn;\r
+ }\r
+\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+\r
+ BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait )\r
+ {\r
+ TickType_t xTimeToWake;\r
+ BaseType_t xReturn;\r
+\r
+ taskENTER_CRITICAL();\r
+ {\r
+ /* Only block if a notification is not already pending. */\r
+ if( pxCurrentTCB->eNotifyState != eNotified )\r
+ {\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->eNotifyState = eWaitingNotification;\r
+\r
+ if( xTicksToWait > ( TickType_t ) 0 )\r
+ {\r
+ /* The task is going to block. First it must be removed\r
+ from the ready list. */\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
+\r
+ #if ( INCLUDE_vTaskSuspend == 1 )\r
+ {\r
+ if( xTicksToWait == portMAX_DELAY )\r
+ {\r
+ /* Add the task to the suspended task list instead\r
+ of a delayed task list to ensure the task is not\r
+ woken by a timing event. It will block\r
+ indefinitely. */\r
+ vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xGenericListItem ) );\r
+ }\r
+ else\r
+ {\r
+ /* Calculate the time at which the task should be\r
+ woken if no notification events occur. This may\r
+ overflow but this doesn't matter, the scheduler will\r
+ handle it. */\r
+ xTimeToWake = xTickCount + xTicksToWait;\r
+ prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+ }\r
+ }\r
+ #else /* INCLUDE_vTaskSuspend */\r
+ {\r
+ /* Calculate the time at which the task should be\r
+ woken if the event does not occur. This may\r
+ overflow but this doesn't matter, the scheduler will\r
+ handle it. */\r
+ xTimeToWake = xTickCount + xTicksToWait;\r
+ prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+ }\r
+ #endif /* INCLUDE_vTaskSuspend */\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
+ taskENTER_CRITICAL();\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 eNotifyValue 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->eNotifyState == eWaitingNotification )\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->eNotifyState = eNotWaitingNotification;\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 xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction )\r
+ {\r
+ TCB_t * pxTCB;\r
+ eNotifyValue eOriginalNotifyState;\r
+ BaseType_t xReturn = pdPASS;\r
+\r
+ configASSERT( xTaskToNotify );\r
+ pxTCB = ( TCB_t * ) xTaskToNotify;\r
+\r
+ taskENTER_CRITICAL();\r
+ {\r
+ eOriginalNotifyState = pxTCB->eNotifyState;\r
+\r
+ pxTCB->eNotifyState = eNotified;\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( eOriginalNotifyState != eNotified )\r
+ {\r
+ pxTCB->ulNotifiedValue = ulValue;\r
+ }\r
+ else\r
+ {\r
+ /* The value could not be written to the task. */\r
+ xReturn = pdFAIL;\r
+ }\r
+ break;\r
+\r
+ case eNoAction:\r
+ /* The task is being notified without its notify value being\r
+ updated. */\r
+ break;\r
+ }\r
+\r
+\r
+ /* If the task is in the blocked state specifically to wait for a\r
+ notification then unblock it now. */\r
+ if( eOriginalNotifyState == eWaitingNotification )\r
+ {\r
+ ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\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( pxTCB->uxPriority > pxCurrentTCB->uxPriority )\r
+ {\r
+ /* The notified task has a priority above the currently\r
+ executing task so a yield is required. */\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
+ return xReturn;\r
+ }\r
+\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+\r
+ BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken )\r
+ {\r
+ TCB_t * pxTCB;\r
+ eNotifyValue eOriginalNotifyState;\r
+ BaseType_t xReturn = pdPASS;\r
+ UBaseType_t uxSavedInterruptStatus;\r
+\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
+ eOriginalNotifyState = pxTCB->eNotifyState;\r
+\r
+ pxTCB->eNotifyState = eNotified;\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( eOriginalNotifyState != eNotified )\r
+ {\r
+ pxTCB->ulNotifiedValue = ulValue;\r
+ }\r
+ else\r
+ {\r
+ /* The value could not be written to the task. */\r
+ xReturn = pdFAIL;\r
+ }\r
+ break;\r
+\r
+ case eNoAction :\r
+ /* The task is being notified without its notify value being\r
+ updated. */\r
+ break;\r
+ }\r
+\r
+\r
+ /* If the task is in the blocked state specifically to wait for a\r
+ notification then unblock it now. */\r
+ if( eOriginalNotifyState == eWaitingNotification )\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->xGenericListItem ) );\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
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ }\r
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+\r
+ return xReturn;\r
+ }\r
+\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+\r
+ void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken )\r
+ {\r
+ TCB_t * pxTCB;\r
+ eNotifyValue eOriginalNotifyState;\r
+ UBaseType_t uxSavedInterruptStatus;\r
+\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
+ eOriginalNotifyState = pxTCB->eNotifyState;\r
+ pxTCB->eNotifyState = eNotified;\r
+\r
+ /* 'Giving' is equivalent to incrementing a count in a counting\r
+ semaphore. */\r
+ ( pxTCB->ulNotifiedValue )++;\r
+\r
+ /* If the task is in the blocked state specifically to wait for a\r
+ notification then unblock it now. */\r
+ if( eOriginalNotifyState == eWaitingNotification )\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->xGenericListItem ) );\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
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ }\r
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+ }\r
+\r
+#endif /* configUSE_TASK_NOTIFICATIONS */\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+\r
#ifdef FREERTOS_MODULE_TEST\r
#include "tasks_test_access_functions.h"\r
#endif\r