mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-08-19 09:38:32 -04:00
Changes to the FreeRTOS code:
+ Introduced xTaskCreateStatic() to allow tasks to be created without any dynamic memory allocation. + When a task notification is used to unblock a task from an ISR, but the xHigherPriorityTaskWoken parameter is not used, then pend a context switch to occur during the next tick interrupt. Demo application changes: + Updated TaskNotify.c to test the case where a task is unblocked by an ISR, but does not use its xHigherPriorityTaskWoken parameter. + Updated the Win32 MSVC project to test statically allocated tasks being created and deleted. + Introduced StaticAllocation.c standard demo task.
This commit is contained in:
parent
7d6609f8db
commit
ea95020ffd
15 changed files with 839 additions and 115 deletions
|
@ -681,7 +681,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#ifndef pvPortMallocAligned
|
||||
#define pvPortMallocAligned( x, puxStackBuffer ) ( ( ( puxStackBuffer ) == NULL ) ? ( pvPortMalloc( ( x ) ) ) : ( puxStackBuffer ) )
|
||||
#define pvPortMallocAligned( x, puxPreallocatedBuffer ) ( ( ( puxPreallocatedBuffer ) == NULL ) ? ( pvPortMalloc( ( x ) ) ) : ( puxPreallocatedBuffer ) )
|
||||
#endif
|
||||
|
||||
#ifndef vPortFreeAligned
|
||||
|
@ -772,6 +772,10 @@ extern "C" {
|
|||
#define portTICK_TYPE_IS_ATOMIC 0
|
||||
#endif
|
||||
|
||||
#ifndef configSUPPORT_STATIC_ALLOCATION
|
||||
#define configSUPPORT_STATIC_ALLOCATION 0
|
||||
#endif
|
||||
|
||||
#if( portTICK_TYPE_IS_ATOMIC == 0 )
|
||||
/* Either variables of tick type cannot be read atomically, or
|
||||
portTICK_TYPE_IS_ATOMIC was not set - map the critical sections used when
|
||||
|
|
|
@ -128,6 +128,12 @@ typedef enum
|
|||
eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */
|
||||
} eNotifyAction;
|
||||
|
||||
/* For data hiding purposes. */
|
||||
typedef enum
|
||||
{
|
||||
eNothing = 0
|
||||
} eDummy;
|
||||
|
||||
/*
|
||||
* Used internally only.
|
||||
*/
|
||||
|
@ -183,6 +189,65 @@ typedef enum
|
|||
eNoTasksWaitingTimeout /* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */
|
||||
} eSleepModeStatus;
|
||||
|
||||
/* Value that can be assigned to the eNotifyState member of the TCB. */
|
||||
typedef enum
|
||||
{
|
||||
eNotWaitingNotification = 0,
|
||||
eWaitingNotification,
|
||||
eNotified
|
||||
} eNotifyValue;
|
||||
|
||||
/*
|
||||
* FreeRTOS implements a strict data hiding policy, so the real task control
|
||||
* block (TCB) structure is not accessible to the application code. However, if
|
||||
* the application writer wants to statically allocate a TCB then the size of
|
||||
* the TCB needs to be know. The dummy TCB structure below is used for this
|
||||
* purpose. Its size will allows match the size of the real TCB, no matter what
|
||||
* the FreeRTOSConfig.h settings.
|
||||
*/
|
||||
typedef struct xDUMMY_TCB
|
||||
{
|
||||
void *pxDummy1;
|
||||
#if ( portUSING_MPU_WRAPPERS == 1 )
|
||||
xMPU_SETTINGS xDummy2;
|
||||
#endif
|
||||
ListItem_t xDummy3[ 2 ];
|
||||
UBaseType_t uxDummy5;
|
||||
void *pxDummy6;
|
||||
uint8_t ucDummy7[ configMAX_TASK_NAME_LEN ];
|
||||
#if ( portSTACK_GROWTH > 0 )
|
||||
void *pxDummy8;
|
||||
#endif
|
||||
#if ( portCRITICAL_NESTING_IN_TCB == 1 )
|
||||
UBaseType_t uxDummy9;
|
||||
#endif
|
||||
#if ( configUSE_TRACE_FACILITY == 1 )
|
||||
UBaseType_t uxDummy10[ 2 ];
|
||||
#endif
|
||||
#if ( configUSE_MUTEXES == 1 )
|
||||
UBaseType_t uxDummy12[ 2 ];
|
||||
#endif
|
||||
#if ( configUSE_APPLICATION_TASK_TAG == 1 )
|
||||
void *pxDummy14;
|
||||
#endif
|
||||
#if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
|
||||
void pvDummy15[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ];
|
||||
#endif
|
||||
#if ( configGENERATE_RUN_TIME_STATS == 1 )
|
||||
uint32_t ulDummy16;
|
||||
#endif
|
||||
#if ( configUSE_NEWLIB_REENTRANT == 1 )
|
||||
struct _reent xDummy17;
|
||||
#endif
|
||||
#if ( configUSE_TASK_NOTIFICATIONS == 1 )
|
||||
uint32_t ulDummy18;
|
||||
eDummy eDummy19;
|
||||
#endif
|
||||
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
UBaseType_t uxDummy20;
|
||||
#endif
|
||||
|
||||
} DummyTCB_t;
|
||||
|
||||
/**
|
||||
* Defines the priority used by the idle task. This must not be modified.
|
||||
|
@ -342,7 +407,112 @@ is used in assert() statements. */
|
|||
* \defgroup xTaskCreate xTaskCreate
|
||||
* \ingroup Tasks
|
||||
*/
|
||||
#define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ) )
|
||||
#define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ), ( NULL ) )
|
||||
|
||||
/**
|
||||
* task. h
|
||||
*<pre>
|
||||
BaseType_t xTaskCreateStatic(
|
||||
TaskFunction_t pvTaskCode,
|
||||
const char * const pcName,
|
||||
uint16_t usStackDepth,
|
||||
void *pvParameters,
|
||||
UBaseType_t uxPriority,
|
||||
TaskHandle_t *pvCreatedTask,
|
||||
StackType_t *pxStackBuffer,
|
||||
DummyTCB_t *pxTCBBuffer
|
||||
);</pre>
|
||||
*
|
||||
* Create a new task and add it to the list of tasks that are ready to run.
|
||||
* If a task is created using xTaskCreate() then the stack and task control
|
||||
* block (TCB) used by the task are allocated dynamically. If a task is created
|
||||
* using xTaskCreateStatic() then the application writer can optionally provide
|
||||
* the buffers that will hold the task stack and TCB respectively.
|
||||
* xTaskCreateStatic() therefore allows tasks to be created without any dynamic
|
||||
* memory allocation.
|
||||
*
|
||||
* @param pvTaskCode Pointer to the task entry function. Tasks
|
||||
* must be implemented to never return (i.e. continuous loop).
|
||||
*
|
||||
* @param pcName A descriptive name for the task. This is mainly used to
|
||||
* facilitate debugging. The maximum length of the string is defined by
|
||||
* configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
|
||||
*
|
||||
* @param usStackDepth The size of the task stack specified as the number of
|
||||
* variables the stack can hold - not the number of bytes. For example, if
|
||||
* the stack is 32-bits wide and usStackDepth is defined as 100 then 400 bytes
|
||||
* will be allocated for stack storage.
|
||||
*
|
||||
* @param pvParameters Pointer that will be used as the parameter for the task
|
||||
* being created.
|
||||
*
|
||||
* @param uxPriority The priority at which the task will run.
|
||||
*
|
||||
* @param pvCreatedTask Used to pass back a handle by which the created task
|
||||
* can be referenced. Pass as NULL if the handle is not required.
|
||||
*
|
||||
* @param pxStackBuffer If pxStackBuffer is NULL then the stack used by the
|
||||
* task will be allocated dynamically, just as if the task was created using
|
||||
* xTaskCreate(). if pxStackBuffer is not NULL then it must point to a
|
||||
* StackType_t array that has at least usStackDepth indexes - the array will
|
||||
* then be used as the task's stack.
|
||||
*
|
||||
* @param pxTCBBuffer If pxTCBBuffer is NULL then the TCB (which is the
|
||||
* structures used internally within FreeRTOS to hold information on the task)
|
||||
* will be allocated dynamically, just as when xTaskCreate() is used. If
|
||||
* pxTCBBuffer is not NULL then it must point to a variable of type DummyTCB_T,
|
||||
* which will then be used as the TCB of the task being created.
|
||||
*
|
||||
* @return pdPASS if the task was successfully created and added to a ready
|
||||
* list, otherwise an error code defined in the file projdefs.h
|
||||
*
|
||||
* Example usage:
|
||||
<pre>
|
||||
|
||||
// Dimensions the buffer that the task being created will use as its stack.
|
||||
// NOTE: This is the number of words the stack will hold, not the number of
|
||||
// bytes. For example, if each stack item is 32-bits, and this is set to 100,
|
||||
// then 400 bytes (100 * 32-bits) will be allocated.
|
||||
#define STACK_SIZE 200
|
||||
|
||||
// Structure that will hold the TCB of the task being created.
|
||||
DummyTCB_t xTCB;
|
||||
|
||||
// Buffer that the task being created will use as its stack.
|
||||
StackType_t xStack[ STACK_SIZE ];
|
||||
|
||||
// Task to be created.
|
||||
void vTaskCode( void * pvParameters )
|
||||
{
|
||||
for( ;; )
|
||||
{
|
||||
// Task code goes here.
|
||||
}
|
||||
}
|
||||
|
||||
// Function that creates a task.
|
||||
void vOtherFunction( void )
|
||||
{
|
||||
static uint8_t ucParameterToPass;
|
||||
TaskHandle_t xHandle = NULL;
|
||||
|
||||
// Create the task without using any dynamic memory allocation.
|
||||
xTaskCreate( vTaskCode, // As per xTaskCreate() parameter.
|
||||
"NAME", // As per xTaskCreate() parameter.
|
||||
STACK_SIZE, // As per xTaskCreate() parameter.
|
||||
&ucParameterToPass, // As per xTaskCreate() parameter.
|
||||
tskIDLE_PRIORITY, // As per xTaskCreate() parameter.
|
||||
&xHandle, // As per xTaskCreate() parameter.
|
||||
xStack, // Pointer to the buffer that the task being created will use as its stack.
|
||||
&xTCB ); // Pointer to a structure in which the TCB of the task being created will be stored.
|
||||
}
|
||||
</pre>
|
||||
* \defgroup xTaskCreateStatic xTaskCreateStatic
|
||||
* \ingroup Tasks
|
||||
*/
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
#define xTaskCreateStatic( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask, puxStackBuffer, pxDummyTCB ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( puxStackBuffer ), ( pxDummyTCB ), ( NULL ) )
|
||||
#endif
|
||||
|
||||
/**
|
||||
* task. h
|
||||
|
@ -411,7 +581,7 @@ TaskHandle_t xHandle;
|
|||
* \defgroup xTaskCreateRestricted xTaskCreateRestricted
|
||||
* \ingroup Tasks
|
||||
*/
|
||||
#define xTaskCreateRestricted( x, pxCreatedTask ) xTaskGenericCreate( ((x)->pvTaskCode), ((x)->pcName), ((x)->usStackDepth), ((x)->pvParameters), ((x)->uxPriority), (pxCreatedTask), ((x)->puxStackBuffer), ((x)->xRegions) )
|
||||
#define xTaskCreateRestricted( x, pxCreatedTask ) xTaskGenericCreate( ((x)->pvTaskCode), ((x)->pcName), ((x)->usStackDepth), ((x)->pvParameters), ((x)->uxPriority), (pxCreatedTask), ((x)->puxStackBuffer), ( NULL ), ((x)->xRegions) )
|
||||
|
||||
/**
|
||||
* task. h
|
||||
|
@ -1983,7 +2153,7 @@ BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGE
|
|||
* Generic version of the task creation function which is in turn called by the
|
||||
* xTaskCreate() and xTaskCreateRestricted() macros.
|
||||
*/
|
||||
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 ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
||||
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, DummyTCB_t * const pxTCBBuffer, const MemoryRegion_t * const xRegions ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
||||
|
||||
/*
|
||||
* Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
|
||||
|
|
|
@ -1935,8 +1935,8 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
|
|||
{
|
||||
if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
|
||||
{
|
||||
/* The task waiting has a higher priority so record that a
|
||||
context switch is required. */
|
||||
/* The task waiting has a higher priority so record that
|
||||
a context switch is required. */
|
||||
vTaskMissedYield();
|
||||
}
|
||||
else
|
||||
|
|
|
@ -105,6 +105,10 @@ functions but without including stdio.h here. */
|
|||
#endif /* INCLUDE_vTaskSuspend */
|
||||
#endif /* configUSE_TICKLESS_IDLE */
|
||||
|
||||
#if( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION != 1 ) )
|
||||
#error configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h when the MPU is used.
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Defines the size, in words, of the stack allocated to the idle task.
|
||||
*/
|
||||
|
@ -118,13 +122,12 @@ functions but without including stdio.h here. */
|
|||
#define taskYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API()
|
||||
#endif
|
||||
|
||||
/* Value that can be assigned to the eNotifyState member of the TCB. */
|
||||
typedef enum
|
||||
{
|
||||
eNotWaitingNotification = 0,
|
||||
eWaitingNotification,
|
||||
eNotified
|
||||
} eNotifyValue;
|
||||
/* Bits that can be set in tskTCB->uxStaticAllocationFlags to indicate that the
|
||||
stack and TCB were statically allocated respectively. When these are statically
|
||||
allocated they won't be freed if the task using the stack and TCB gets
|
||||
deleted. */
|
||||
#define taskSTATICALLY_ALLOCATED_STACK ( ( UBaseType_t ) 0x01 )
|
||||
#define taskSTATICALLY_ALLOCATED_TCB ( ( UBaseType_t ) 0x02 )
|
||||
|
||||
/*
|
||||
* Task control block. A task control block (TCB) is allocated for each task,
|
||||
|
@ -137,7 +140,6 @@ typedef struct tskTaskControlBlock
|
|||
|
||||
#if ( portUSING_MPU_WRAPPERS == 1 )
|
||||
xMPU_SETTINGS xMPUSettings; /*< The MPU settings are defined as part of the port layer. THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT. */
|
||||
BaseType_t xUsingStaticallyAllocatedStack; /* Set to pdTRUE if the stack is a statically allocated array, and pdFALSE if the stack is dynamically allocated. */
|
||||
#endif
|
||||
|
||||
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 ). */
|
||||
|
@ -151,17 +153,17 @@ typedef struct tskTaskControlBlock
|
|||
#endif
|
||||
|
||||
#if ( portCRITICAL_NESTING_IN_TCB == 1 )
|
||||
UBaseType_t uxCriticalNesting; /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */
|
||||
UBaseType_t uxCriticalNesting; /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */
|
||||
#endif
|
||||
|
||||
#if ( configUSE_TRACE_FACILITY == 1 )
|
||||
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. */
|
||||
UBaseType_t uxTaskNumber; /*< Stores a number specifically for use by third party trace code. */
|
||||
UBaseType_t uxTaskNumber; /*< Stores a number specifically for use by third party trace code. */
|
||||
#endif
|
||||
|
||||
#if ( configUSE_MUTEXES == 1 )
|
||||
UBaseType_t uxBasePriority; /*< The priority last assigned to the task - used by the priority inheritance mechanism. */
|
||||
UBaseType_t uxMutexesHeld;
|
||||
UBaseType_t uxBasePriority; /*< The priority last assigned to the task - used by the priority inheritance mechanism. */
|
||||
UBaseType_t uxMutexesHeld;
|
||||
#endif
|
||||
|
||||
#if ( configUSE_APPLICATION_TASK_TAG == 1 )
|
||||
|
@ -184,7 +186,7 @@ typedef struct tskTaskControlBlock
|
|||
newlib and must provide system-wide implementations of the necessary
|
||||
stubs. Be warned that (at the time of writing) the current newlib design
|
||||
implements a system-wide malloc() that must be provided with locks. */
|
||||
struct _reent xNewLib_reent;
|
||||
struct _reent xNewLib_reent;
|
||||
#endif
|
||||
|
||||
#if ( configUSE_TASK_NOTIFICATIONS == 1 )
|
||||
|
@ -192,7 +194,11 @@ typedef struct tskTaskControlBlock
|
|||
volatile eNotifyValue eNotifyState;
|
||||
#endif
|
||||
|
||||
} tskTCB;
|
||||
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
UBaseType_t uxStaticAllocationFlags; /* Set to pdTRUE if the stack is a statically allocated array, and pdFALSE if the stack is dynamically allocated. */
|
||||
#endif
|
||||
|
||||
} tskTCB;
|
||||
|
||||
/* The old tskTCB name is maintained above then typedefed to the new TCB_t name
|
||||
below to enable the use of older kernel aware debuggers. */
|
||||
|
@ -232,12 +238,6 @@ PRIVILEGED_DATA static List_t xPendingReadyList; /*< Tasks that have been r
|
|||
|
||||
#endif
|
||||
|
||||
#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )
|
||||
|
||||
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. */
|
||||
|
||||
#endif
|
||||
|
||||
/* Other file private variables. --------------------------------*/
|
||||
PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;
|
||||
PRIVILEGED_DATA static volatile TickType_t xTickCount = ( TickType_t ) 0U;
|
||||
|
@ -248,6 +248,7 @@ PRIVILEGED_DATA static volatile BaseType_t xYieldPending = pdFALSE;
|
|||
PRIVILEGED_DATA static volatile BaseType_t xNumOfOverflows = ( BaseType_t ) 0;
|
||||
PRIVILEGED_DATA static UBaseType_t uxTaskNumber = ( UBaseType_t ) 0U;
|
||||
PRIVILEGED_DATA static volatile TickType_t xNextTaskUnblockTime = ( TickType_t ) 0U; /* Initialised to portMAX_DELAY before the scheduler starts. */
|
||||
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. */
|
||||
|
||||
/* Context switches are held pending while the scheduler is suspended. Also,
|
||||
interrupts must not manipulate the xGenericListItem of a TCB, or any of the
|
||||
|
@ -409,21 +410,25 @@ being used for another purpose. The following bit definition is used to inform
|
|||
the scheduler that the value should not be changed - in which case it is the
|
||||
responsibility of whichever module is using the value to ensure it gets set back
|
||||
to its original value when it is released. */
|
||||
#if configUSE_16_BIT_TICKS == 1
|
||||
#if( configUSE_16_BIT_TICKS == 1 )
|
||||
#define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x8000U
|
||||
#else
|
||||
#define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x80000000UL
|
||||
#endif
|
||||
|
||||
/* Callback function prototypes. --------------------------*/
|
||||
#if configCHECK_FOR_STACK_OVERFLOW > 0
|
||||
#if( configCHECK_FOR_STACK_OVERFLOW > 0 )
|
||||
extern void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName );
|
||||
#endif
|
||||
|
||||
#if configUSE_TICK_HOOK > 0
|
||||
#if( configUSE_TICK_HOOK > 0 )
|
||||
extern void vApplicationTickHook( void );
|
||||
#endif
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
extern void vApplicationGetIdleTaskMemory( DummyTCB_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint16_t *pusIdleTaskStackSize );
|
||||
#endif
|
||||
|
||||
/* File private functions. --------------------------------*/
|
||||
|
||||
/*
|
||||
|
@ -490,7 +495,7 @@ static void prvAddCurrentTaskToDelayedList( const TickType_t xTimeToWake ) PRIVI
|
|||
* Allocates memory from the heap for a TCB and associated stack. Checks the
|
||||
* allocation was successful.
|
||||
*/
|
||||
static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t * const puxStackBuffer ) PRIVILEGED_FUNCTION;
|
||||
static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t * const puxStackBuffer, TCB_t * const pucTCBBuffer ) PRIVILEGED_FUNCTION;
|
||||
|
||||
/*
|
||||
* Fills an TaskStatus_t structure with information on each task that is
|
||||
|
@ -549,7 +554,7 @@ static void prvResetNextTaskUnblockTime( void );
|
|||
#endif
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
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. */
|
||||
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, DummyTCB_t * const pxTCBBuffer, const MemoryRegion_t * const xRegions ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
||||
{
|
||||
BaseType_t xReturn;
|
||||
TCB_t * pxNewTCB;
|
||||
|
@ -560,7 +565,7 @@ StackType_t *pxTopOfStack;
|
|||
|
||||
/* Allocate the memory required by the TCB and stack for the new task,
|
||||
checking that the allocation was successful. */
|
||||
pxNewTCB = prvAllocateTCBAndStack( usStackDepth, puxStackBuffer );
|
||||
pxNewTCB = prvAllocateTCBAndStack( usStackDepth, puxStackBuffer, ( TCB_t* ) pxTCBBuffer ); /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */
|
||||
|
||||
if( pxNewTCB != NULL )
|
||||
{
|
||||
|
@ -576,20 +581,6 @@ StackType_t *pxTopOfStack;
|
|||
xRunPrivileged = pdFALSE;
|
||||
}
|
||||
uxPriority &= ~portPRIVILEGE_BIT;
|
||||
|
||||
if( puxStackBuffer != NULL )
|
||||
{
|
||||
/* The application provided its own stack. Note this so no
|
||||
attempt is made to delete the stack should that task be
|
||||
deleted. */
|
||||
pxNewTCB->xUsingStaticallyAllocatedStack = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The stack was allocated dynamically. Note this so it can be
|
||||
deleted again if the task is deleted. */
|
||||
pxNewTCB->xUsingStaticallyAllocatedStack = pdFALSE;
|
||||
}
|
||||
#endif /* portUSING_MPU_WRAPPERS == 1 */
|
||||
|
||||
/* Calculate the top of stack address. This depends on whether the
|
||||
|
@ -1045,7 +1036,7 @@ StackType_t *pxTopOfStack;
|
|||
else if( ( pxStateList == &xTasksWaitingTermination ) || ( pxStateList == NULL ) )
|
||||
{
|
||||
/* The task being queried is referenced from the deleted
|
||||
tasks list, or it is not referenced from any lists at
|
||||
tasks list, or it is not referenced from any lists at
|
||||
all. */
|
||||
eReturn = eDeleted;
|
||||
}
|
||||
|
@ -1555,20 +1546,18 @@ StackType_t *pxTopOfStack;
|
|||
void vTaskStartScheduler( void )
|
||||
{
|
||||
BaseType_t xReturn;
|
||||
DummyTCB_t *pxIdleTaskTCBBuffer = NULL;
|
||||
StackType_t *pxIdleTaskStackBuffer = NULL;
|
||||
uint16_t usIdleTaskStackSize = tskIDLE_STACK_SIZE;
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
{
|
||||
vApplicationGetIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &usIdleTaskStackSize );
|
||||
}
|
||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
|
||||
/* Add the idle task at the lowest priority. */
|
||||
#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )
|
||||
{
|
||||
/* Create the idle task, storing its handle in xIdleTaskHandle so it can
|
||||
be returned by the xTaskGetIdleTaskHandle() function. */
|
||||
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. */
|
||||
}
|
||||
#else
|
||||
{
|
||||
/* Create the idle task without storing its handle. */
|
||||
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. */
|
||||
}
|
||||
#endif /* INCLUDE_xTaskGetIdleTaskHandle */
|
||||
xReturn = xTaskGenericCreate( prvIdleTask, "IDLE", usIdleTaskStackSize, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), &xIdleTaskHandle, pxIdleTaskStackBuffer, pxIdleTaskTCBBuffer, NULL ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */
|
||||
|
||||
#if ( configUSE_TIMERS == 1 )
|
||||
{
|
||||
|
@ -1628,6 +1617,10 @@ BaseType_t xReturn;
|
|||
or the timer task. */
|
||||
configASSERT( xReturn );
|
||||
}
|
||||
|
||||
/* Prevent compiler warnings if INCLUDE_xTaskGetIdleTaskHandle is set to 0,
|
||||
meaning xIdleTaskHandle is not used anywhere else. */
|
||||
( void ) xIdleTaskHandle;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
@ -3145,10 +3138,17 @@ static void prvAddCurrentTaskToDelayedList( const TickType_t xTimeToWake )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t * const puxStackBuffer )
|
||||
static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t * const puxStackBuffer, TCB_t * const pxTCBBuffer )
|
||||
{
|
||||
TCB_t *pxNewTCB;
|
||||
|
||||
#if( configASSERT_DEFINED == 1 )
|
||||
{
|
||||
volatile size_t xSize = sizeof( DummyTCB_t );
|
||||
configASSERT( xSize == sizeof( TCB_t ) );
|
||||
}
|
||||
#endif /* configASSERT_DEFINED */
|
||||
|
||||
/* If the stack grows down then allocate the stack then the TCB so the stack
|
||||
does not grow into the TCB. Likewise if the stack grows up then allocate
|
||||
the TCB then the stack. */
|
||||
|
@ -3156,7 +3156,7 @@ TCB_t *pxNewTCB;
|
|||
{
|
||||
/* Allocate space for the TCB. Where the memory comes from depends on
|
||||
the implementation of the port malloc function. */
|
||||
pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );
|
||||
pxNewTCB = ( TCB_t * ) pvPortMallocAligned( sizeof( TCB_t ), pxTCBBuffer );
|
||||
|
||||
if( pxNewTCB != NULL )
|
||||
{
|
||||
|
@ -3167,8 +3167,12 @@ TCB_t *pxNewTCB;
|
|||
|
||||
if( pxNewTCB->pxStack == NULL )
|
||||
{
|
||||
/* Could not allocate the stack. Delete the allocated TCB. */
|
||||
vPortFree( pxNewTCB );
|
||||
/* Could not allocate the stack. Delete the allocated TCB - if
|
||||
it was allocated dynamically. */
|
||||
if( pxTCBBuffer == NULL )
|
||||
{
|
||||
vPortFree( pxNewTCB );
|
||||
}
|
||||
pxNewTCB = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -3182,9 +3186,8 @@ TCB_t *pxNewTCB;
|
|||
|
||||
if( pxStack != NULL )
|
||||
{
|
||||
/* Allocate space for the TCB. Where the memory comes from depends
|
||||
on the implementation of the port malloc function. */
|
||||
pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );
|
||||
/* Allocate space for the TCB. */
|
||||
pxNewTCB = ( TCB_t * ) pvPortMallocAligned( sizeof( TCB_t ), pxTCBBuffer ); /*lint !e961 MISRA exception as the casts are only redundant for some paths. */
|
||||
|
||||
if( pxNewTCB != NULL )
|
||||
{
|
||||
|
@ -3199,6 +3202,10 @@ TCB_t *pxNewTCB;
|
|||
{
|
||||
vPortFree( pxStack );
|
||||
}
|
||||
else
|
||||
{
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -3217,6 +3224,34 @@ TCB_t *pxNewTCB;
|
|||
( void ) memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) usStackDepth * sizeof( StackType_t ) );
|
||||
}
|
||||
#endif /* ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) ) */
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
{
|
||||
pxNewTCB->uxStaticAllocationFlags = 0;
|
||||
|
||||
if( puxStackBuffer != NULL )
|
||||
{
|
||||
/* The application provided its own stack - note the fact so no
|
||||
attempt is made to delete the stack if the task is deleted. */
|
||||
pxNewTCB->uxStaticAllocationFlags |= taskSTATICALLY_ALLOCATED_STACK;
|
||||
}
|
||||
else
|
||||
{
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
if( pxTCBBuffer != NULL )
|
||||
{
|
||||
/* The application provided its own TCB. Note the fact so no
|
||||
attempt is made to delete the TCB if the task is deleted. */
|
||||
pxNewTCB->uxStaticAllocationFlags |= taskSTATICALLY_ALLOCATED_TCB;
|
||||
}
|
||||
else
|
||||
{
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
}
|
||||
|
||||
return pxNewTCB;
|
||||
|
@ -3373,22 +3408,34 @@ TCB_t *pxNewTCB;
|
|||
}
|
||||
#endif /* configUSE_NEWLIB_REENTRANT */
|
||||
|
||||
#if( portUSING_MPU_WRAPPERS == 1 )
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
{
|
||||
/* Only free the stack if it was allocated dynamically in the first
|
||||
place. */
|
||||
if( pxTCB->xUsingStaticallyAllocatedStack == pdFALSE )
|
||||
/* Only free the stack and TCB if they were allocated dynamically in
|
||||
the first place. */
|
||||
if( ( pxTCB->uxStaticAllocationFlags & taskSTATICALLY_ALLOCATED_STACK ) == ( UBaseType_t ) 0 )
|
||||
{
|
||||
vPortFreeAligned( pxTCB->pxStack );
|
||||
}
|
||||
else
|
||||
{
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
if( ( pxTCB->uxStaticAllocationFlags & taskSTATICALLY_ALLOCATED_TCB ) == ( UBaseType_t ) 0 )
|
||||
{
|
||||
vPortFreeAligned( pxTCB );
|
||||
}
|
||||
else
|
||||
{
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
vPortFreeAligned( pxTCB->pxStack );
|
||||
vPortFree( pxTCB );
|
||||
}
|
||||
#endif
|
||||
|
||||
vPortFree( pxTCB );
|
||||
}
|
||||
|
||||
#endif /* INCLUDE_vTaskDelete */
|
||||
|
@ -4392,6 +4439,13 @@ TickType_t uxReturn;
|
|||
{
|
||||
*pxHigherPriorityTaskWoken = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Mark that a yield is pending in case the user is not
|
||||
using the "xHigherPriorityTaskWoken" parameter to an ISR
|
||||
safe FreeRTOS function. */
|
||||
xYieldPending = pdTRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -4475,6 +4529,13 @@ TickType_t uxReturn;
|
|||
{
|
||||
*pxHigherPriorityTaskWoken = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Mark that a yield is pending in case the user is not
|
||||
using the "xHigherPriorityTaskWoken" parameter in an ISR
|
||||
safe FreeRTOS function. */
|
||||
xYieldPending = pdTRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -4496,11 +4557,9 @@ TickType_t uxReturn;
|
|||
TCB_t *pxTCB;
|
||||
BaseType_t xReturn;
|
||||
|
||||
pxTCB = ( TCB_t * ) xTask;
|
||||
|
||||
/* If null is passed in here then it is the calling task that is having
|
||||
its notification state cleared. */
|
||||
pxTCB = prvGetTCBFromHandle( pxTCB );
|
||||
pxTCB = prvGetTCBFromHandle( xTask );
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
|
@ -4520,6 +4579,8 @@ TickType_t uxReturn;
|
|||
}
|
||||
|
||||
#endif /* configUSE_TASK_NOTIFICATIONS */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifdef FREERTOS_MODULE_TEST
|
||||
#include "tasks_test_access_functions.h"
|
||||
|
|
|
@ -178,6 +178,16 @@ PRIVILEGED_DATA static QueueHandle_t xTimerQueue = NULL;
|
|||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
|
||||
/* If static allocation is supported then the application must provide the
|
||||
following callback function - which enables the application to optionally
|
||||
provide the memory that will be used by the timer task as the task's stack
|
||||
and TCB. */
|
||||
extern void vApplicationGetTimerTaskMemory( DummyTCB_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint16_t *pusTimerTaskStackSize );
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Initialise the infrastructure used by the timer service task if it has not
|
||||
* been initialised already.
|
||||
|
@ -240,6 +250,10 @@ static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, BaseTy
|
|||
BaseType_t xTimerCreateTimerTask( void )
|
||||
{
|
||||
BaseType_t xReturn = pdFAIL;
|
||||
DummyTCB_t *pxTimerTaskTCBBuffer = NULL;
|
||||
StackType_t *pxTimerTaskStackBuffer = NULL;
|
||||
uint16_t usTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
|
||||
|
||||
|
||||
/* This function is called when the scheduler is started if
|
||||
configUSE_TIMERS is set to 1. Check that the infrastructure used by the
|
||||
|
@ -249,16 +263,24 @@ BaseType_t xReturn = pdFAIL;
|
|||
|
||||
if( xTimerQueue != NULL )
|
||||
{
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
{
|
||||
vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &usTimerTaskStackSize );
|
||||
}
|
||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
|
||||
|
||||
#if ( INCLUDE_xTimerGetTimerDaemonTaskHandle == 1 )
|
||||
{
|
||||
/* Create the timer task, storing its handle in xTimerTaskHandle so
|
||||
it can be returned by the xTimerGetTimerDaemonTaskHandle() function. */
|
||||
xReturn = xTaskCreate( prvTimerTask, "Tmr Svc", ( uint16_t ) configTIMER_TASK_STACK_DEPTH, NULL, ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, &xTimerTaskHandle );
|
||||
xReturn = xTaskGenericCreate( prvTimerTask, "Tmr Svc", usTimerTaskStackSize, NULL, ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, &xTimerTaskHandle, pxTimerTaskStackBuffer, pxTimerTaskTCBBuffer, NULL );
|
||||
}
|
||||
#else
|
||||
{
|
||||
/* Create the timer task without storing its handle. */
|
||||
xReturn = xTaskCreate( prvTimerTask, "Tmr Svc", ( uint16_t ) configTIMER_TASK_STACK_DEPTH, NULL, ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, NULL);
|
||||
xReturn = xTaskGenericCreate( prvTimerTask, "Tmr Svc", usTimerTaskStackSize, NULL, ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, NULL, pxTimerTaskStackBuffer, pxTimerTaskTCBBuffer, NULL );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue