Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
xTaskCreateRestrictedStatic

task.

h

 BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );

Only available when configSUPPORT_STATIC_ALLOCATION is set to 1.

xTaskCreateRestrictedStatic() should only be used in systems that include an MPU implementation.

Internally, within the FreeRTOS implementation, tasks use two blocks of memory. The first block is used to hold the task's data structures. The second block is used by the task as its stack. If a task is created using xTaskCreateRestricted() then the stack is provided by the application writer, and the memory used to hold the task's data structure is automatically dynamically allocated inside the xTaskCreateRestricted() function. If a task is created using xTaskCreateRestrictedStatic() then the application writer must provide the memory used to hold the task's data structures too. xTaskCreateRestrictedStatic() therefore allows a memory protected task to be created without using any dynamic memory allocation.

Parameters
pxTaskDefinitionPointer to a structure that contains a member for each of the normal xTaskCreate() parameters (see the xTaskCreate() API documentation) plus an optional stack buffer and the memory region definitions. If configSUPPORT_STATIC_ALLOCATION is set to 1 the structure contains an additional member, which is used to point to a variable of type StaticTask_t - which is then used to hold the task's data structure.
pxCreatedTaskUsed to pass back a handle by which the created task can be referenced.
Returns
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:

Create an TaskParameters_t structure that defines the task to be created.
The StaticTask_t variable is only included in the structure when
configSUPPORT_STATIC_ALLOCATION is set to 1.  The PRIVILEGED_DATA macro can
be used to force the variable into the RTOS kernel's privileged data area.
static PRIVILEGED_DATA StaticTask_t xTaskBuffer;
static const TaskParameters_t xCheckTaskParameters =
{
    vATask,     // pvTaskCode - the function that implements the task.
    "ATask",    // pcName - just a text name for the task to assist debugging.
    100,        // usStackDepth - the stack size DEFINED IN WORDS.
    NULL,       // pvParameters - passed into the task function as the function parameters.
    ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
    cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
xRegions - Allocate up to three separate memory regions for access by
the task, with appropriate access permissions.  Different processors have
different memory alignment requirements - refer to the FreeRTOS documentation
for full information.
    {
Base address                    Length  Parameters
        { cReadWriteArray,              32,     portMPU_REGION_READ_WRITE },
        { cReadOnlyArray,               32,     portMPU_REGION_READ_ONLY },
        { cPrivilegedOnlyAccessArray,   128,    portMPU_REGION_PRIVILEGED_READ_WRITE }
    }
     // Holds the task's data structure.
};
int main( void )
{
TaskHandle_t xHandle;
Create a task from the const structure defined above.  The task handle
is requested (the second parameter is not NULL) but in this case just for
demonstration purposes as its not actually used.
    xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
Start the scheduler.
    vTaskStartScheduler();
Will only get here if there was insufficient memory to create the idle
and/or timer task.
    for( ;; );
}