First version that includes the FreeRTOS-MPU implementation.

pull/1/head
Richard Barry 16 years ago
parent 6b7397ee92
commit 291ea26bfe

@ -24,10 +24,10 @@
*************************************************************************** ***************************************************************************
* * * *
* Looking for a quick start? Then check out the FreeRTOS eBook! * * Looking for a quick start? Then check out the FreeRTOS eBook! *
* See http://www.FreeRTOS.org/Documentation for details * * See http://www.FreeRTOS.org/Documentation for details *
* * * *
*************************************************************************** ***************************************************************************
1 tab == 4 spaces! 1 tab == 4 spaces!
@ -66,7 +66,7 @@ extern "C" {
* MACROS AND DEFINITIONS * MACROS AND DEFINITIONS
*----------------------------------------------------------*/ *----------------------------------------------------------*/
#define tskKERNEL_VERSION_NUMBER "V5.4.0" #define tskKERNEL_VERSION_NUMBER "V5.4.2"
/** /**
* task. h * task. h
@ -85,10 +85,34 @@ typedef void * xTaskHandle;
*/ */
typedef struct xTIME_OUT typedef struct xTIME_OUT
{ {
portBASE_TYPE xOverflowCount; portBASE_TYPE xOverflowCount;
portTickType xTimeOnEntering; portTickType xTimeOnEntering;
} xTimeOutType; } xTimeOutType;
/*
* Defines the memory ranges allocated to the task when an MPU is used.
*/
typedef struct xMEMORY_REGION
{
void *pvBaseAddress;
unsigned portLONG ulLengthInBytes;
unsigned portLONG ulParameters;
} xMemoryRegion;
/*
* Parameters required to create an MPU protected task.
*/
typedef struct xTASK_PARAMTERS
{
pdTASK_CODE pvTaskCode;
const signed portCHAR * const pcName;
unsigned portSHORT usStackDepth;
void *pvParameters;
unsigned portBASE_TYPE uxPriority;
portSTACK_TYPE *puxStackBuffer;
xMemoryRegion xRegions[ portNUM_CONFIGURABLE_REGIONS ];
} xTaskParameters;
/* /*
* Defines the priority used by the idle task. This must not be modified. * Defines the priority used by the idle task. This must not be modified.
* *
@ -167,16 +191,21 @@ typedef struct xTIME_OUT
* task. h * task. h
*<pre> *<pre>
portBASE_TYPE xTaskCreate( portBASE_TYPE xTaskCreate(
pdTASK_CODE pvTaskCode, pdTASK_CODE pvTaskCode,
const portCHAR * const pcName, const portCHAR * const pcName,
unsigned portSHORT usStackDepth, unsigned portSHORT usStackDepth,
void *pvParameters, void *pvParameters,
unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxPriority,
xTaskHandle *pvCreatedTask xTaskHandle *pvCreatedTask
);</pre> );</pre>
* *
* Create a new task and add it to the list of tasks that are ready to run. * Create a new task and add it to the list of tasks that are ready to run.
* *
* xTaskCreate() can only be used to create a task that has unrestricted
* access to the entire microcontroller memory map. Systems that include MPU
* support can alternatively create an MPU constrained task using
* xTaskCreateRestricted().
*
* @param pvTaskCode Pointer to the task entry function. Tasks * @param pvTaskCode Pointer to the task entry function. Tasks
* must be implemented to never return (i.e. continuous loop). * must be implemented to never return (i.e. continuous loop).
* *
@ -192,7 +221,11 @@ typedef struct xTIME_OUT
* @param pvParameters Pointer that will be used as the parameter for the task * @param pvParameters Pointer that will be used as the parameter for the task
* being created. * being created.
* *
* @param uxPriority The priority at which the task should run. * @param uxPriority The priority at which the task should run. Systems that
* include MPU support can optionally create tasks in a privileged (system)
* mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
* example, to create a privileged task at priority 2 the uxPriority parameter
* should be set to ( 2 | portPRIVILEGE_BIT ).
* *
* @param pvCreatedTask Used to pass back a handle by which the created task * @param pvCreatedTask Used to pass back a handle by which the created task
* can be referenced. * can be referenced.
@ -205,10 +238,10 @@ typedef struct xTIME_OUT
// Task to be created. // Task to be created.
void vTaskCode( void * pvParameters ) void vTaskCode( void * pvParameters )
{ {
for( ;; ) for( ;; )
{ {
// Task code goes here. // Task code goes here.
} }
} }
// Function that creates a task. // Function that creates a task.
@ -217,20 +250,141 @@ typedef struct xTIME_OUT
static unsigned char ucParameterToPass; static unsigned char ucParameterToPass;
xTaskHandle xHandle; xTaskHandle xHandle;
// Create the task, storing the handle. Note that the passed parameter ucParameterToPass // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
// must exist for the lifetime of the task, so in this case is declared static. If it was just an // must exist for the lifetime of the task, so in this case is declared static. If it was just an
// an automatic stack variable it might no longer exist, or at least have been corrupted, by the time // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
// the new time attempts to access it. // the new time attempts to access it.
xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle ); xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
// Use the handle to delete the task. // Use the handle to delete the task.
vTaskDelete( xHandle ); vTaskDelete( xHandle );
} }
</pre> </pre>
* \defgroup xTaskCreate xTaskCreate * \defgroup xTaskCreate xTaskCreate
* \ingroup Tasks * \ingroup Tasks
*/ */
signed portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, const signed portCHAR * const pcName, unsigned portSHORT usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pvCreatedTask ); #define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ) )
/**
* task. h
*<pre>
portBASE_TYPE xTaskCreateRestricted( xTaskParameters *pxTaskDefinition, xTaskHandle pxCreatedTask );</pre>
*
* xTaskCreateRestricted() should only be used in systems that include an MPU
* implementation.
*
* Create a new task and add it to the list of tasks that are ready to run.
* The function parameters define the memory regions and associated access
* permissions allocated to the task.
*
* @param pxTaskDefinition Pointer 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.
*
* @param pcName A descriptive name for the task. This is mainly used to
* facilitate debugging. Max length defined by tskMAX_TASK_NAME_LEN - default
* is 16.
*
* @param pxCreatedTask Used to pass back a handle by which the created task
* can be referenced.
*
* @return pdPASS if the task was successfully created and added to a ready
* list, otherwise an error code defined in the file errors. h
*
* Example usage:
<pre>
// Create an xTaskParameters structure that defines the task to be created.
static const xTaskParameters 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 }
}
};
int main( void )
{
xTaskHandle 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
// task.
for( ;; );
}
</pre>
* \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) )
/**
* task. h
*<pre>
void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxRegions );</pre>
*
* Memory regions are assigned to a restricted task when the task is created by
* a call to xTaskCreateRestricted(). These regions can be redefined using
* vTaskAllocateMPURegions().
*
* @param xTask The handle of the task being updated.
*
* @param xRegions A pointer to an xMemoryRegion structure that contains the
* new memory region definitions.
*
* Example usage:
<pre>
// Define an array of xMemoryRegion structures that configures an MPU region
// allowing read/write access for 1024 bytes starting at the beginning of the
// ucOneKByte array. The other two of the maximum 3 definable regions are
// unused so set to zero.
static const xMemoryRegion xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
{
// Base address Length Parameters
{ ucOneKByte, 1024, portMPU_REGION_READ_WRITE },
{ 0, 0, 0 },
{ 0, 0, 0 }
};
void vATask( void *pvParameters )
{
// This task was created such that it has access to certain regions of
// memory as defined by the MPU configuration. At some point it is
// desired that these MPU regions are replaced with that defined in the
// xAltRegions const struct above. Use a call to vTaskAllocateMPURegions()
// for this purpose. NULL is used as the task handle to indicate that this
// function should modify the MPU regions of the calling task.
vTaskAllocateMPURegions( NULL, xAltRegions );
// Now the task can continue its function, but from this point on can only
// access its stack and the ucOneKByte array (unless any other statically
// defined or shared regions have been declared elsewhere).
}
</pre>
* \defgroup xTaskCreateRestricted xTaskCreateRestricted
* \ingroup Tasks
*/
void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxRegions ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -261,17 +415,17 @@ signed portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, const signed portCHAR
{ {
xTaskHandle xHandle; xTaskHandle xHandle;
// Create the task, storing the handle. // Create the task, storing the handle.
xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
// Use the handle to delete the task. // Use the handle to delete the task.
vTaskDelete( xHandle ); vTaskDelete( xHandle );
} }
</pre> </pre>
* \defgroup vTaskDelete vTaskDelete * \defgroup vTaskDelete vTaskDelete
* \ingroup Tasks * \ingroup Tasks
*/ */
void vTaskDelete( xTaskHandle pxTask ); void vTaskDelete( xTaskHandle pxTask ) PRIVILEGED_FUNCTION;
/*----------------------------------------------------------- /*-----------------------------------------------------------
@ -315,18 +469,18 @@ void vTaskDelete( xTaskHandle pxTask );
// Block for 500ms. // Block for 500ms.
const portTickType xDelay = 500 / portTICK_RATE_MS; const portTickType xDelay = 500 / portTICK_RATE_MS;
for( ;; ) for( ;; )
{ {
// Simply toggle the LED every 500ms, blocking between each toggle. // Simply toggle the LED every 500ms, blocking between each toggle.
vToggleLED(); vToggleLED();
vTaskDelay( xDelay ); vTaskDelay( xDelay );
} }
} }
* \defgroup vTaskDelay vTaskDelay * \defgroup vTaskDelay vTaskDelay
* \ingroup TaskCtrl * \ingroup TaskCtrl
*/ */
void vTaskDelay( portTickType xTicksToDelay ); void vTaskDelay( portTickType xTicksToDelay ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -371,21 +525,21 @@ void vTaskDelay( portTickType xTicksToDelay );
portTickType xLastWakeTime; portTickType xLastWakeTime;
const portTickType xFrequency = 10; const portTickType xFrequency = 10;
// Initialise the xLastWakeTime variable with the current time. // Initialise the xLastWakeTime variable with the current time.
xLastWakeTime = xTaskGetTickCount (); xLastWakeTime = xTaskGetTickCount ();
for( ;; ) for( ;; )
{ {
// Wait for the next cycle. // Wait for the next cycle.
vTaskDelayUntil( &xLastWakeTime, xFrequency ); vTaskDelayUntil( &xLastWakeTime, xFrequency );
// Perform action here. // Perform action here.
} }
} }
</pre> </pre>
* \defgroup vTaskDelayUntil vTaskDelayUntil * \defgroup vTaskDelayUntil vTaskDelayUntil
* \ingroup TaskCtrl * \ingroup TaskCtrl
*/ */
void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement ); void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -407,32 +561,32 @@ void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTim
{ {
xTaskHandle xHandle; xTaskHandle xHandle;
// Create a task, storing the handle. // Create a task, storing the handle.
xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
// ... // ...
// Use the handle to obtain the priority of the created task. // Use the handle to obtain the priority of the created task.
// It was created with tskIDLE_PRIORITY, but may have changed // It was created with tskIDLE_PRIORITY, but may have changed
// it itself. // it itself.
if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY ) if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
{ {
// The task has changed it's priority. // The task has changed it's priority.
} }
// ... // ...
// Is our priority higher than the created task? // Is our priority higher than the created task?
if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) ) if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
{ {
// Our priority (obtained using NULL handle) is higher. // Our priority (obtained using NULL handle) is higher.
} }
} }
</pre> </pre>
* \defgroup uxTaskPriorityGet uxTaskPriorityGet * \defgroup uxTaskPriorityGet uxTaskPriorityGet
* \ingroup TaskCtrl * \ingroup TaskCtrl
*/ */
unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask ); unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -457,24 +611,24 @@ unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );
{ {
xTaskHandle xHandle; xTaskHandle xHandle;
// Create a task, storing the handle. // Create a task, storing the handle.
xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
// ... // ...
// Use the handle to raise the priority of the created task. // Use the handle to raise the priority of the created task.
vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 ); vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
// ... // ...
// Use a NULL handle to raise our priority to the same value. // Use a NULL handle to raise our priority to the same value.
vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 ); vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
} }
</pre> </pre>
* \defgroup vTaskPrioritySet vTaskPrioritySet * \defgroup vTaskPrioritySet vTaskPrioritySet
* \ingroup TaskCtrl * \ingroup TaskCtrl
*/ */
void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority ); void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -499,33 +653,33 @@ void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority
{ {
xTaskHandle xHandle; xTaskHandle xHandle;
// Create a task, storing the handle. // Create a task, storing the handle.
xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
// ... // ...
// Use the handle to suspend the created task. // Use the handle to suspend the created task.
vTaskSuspend( xHandle ); vTaskSuspend( xHandle );
// ... // ...
// The created task will not run during this period, unless // The created task will not run during this period, unless
// another task calls vTaskResume( xHandle ). // another task calls vTaskResume( xHandle ).
//... //...
// Suspend ourselves. // Suspend ourselves.
vTaskSuspend( NULL ); vTaskSuspend( NULL );
// We cannot get here unless another task calls vTaskResume // We cannot get here unless another task calls vTaskResume
// with our handle as the parameter. // with our handle as the parameter.
} }
</pre> </pre>
* \defgroup vTaskSuspend vTaskSuspend * \defgroup vTaskSuspend vTaskSuspend
* \ingroup TaskCtrl * \ingroup TaskCtrl
*/ */
void vTaskSuspend( xTaskHandle pxTaskToSuspend ); void vTaskSuspend( xTaskHandle pxTaskToSuspend ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -548,33 +702,33 @@ void vTaskSuspend( xTaskHandle pxTaskToSuspend );
{ {
xTaskHandle xHandle; xTaskHandle xHandle;
// Create a task, storing the handle. // Create a task, storing the handle.
xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
// ... // ...
// Use the handle to suspend the created task. // Use the handle to suspend the created task.
vTaskSuspend( xHandle ); vTaskSuspend( xHandle );
// ... // ...
// The created task will not run during this period, unless // The created task will not run during this period, unless
// another task calls vTaskResume( xHandle ). // another task calls vTaskResume( xHandle ).
//... //...
// Resume the suspended task ourselves. // Resume the suspended task ourselves.
vTaskResume( xHandle ); vTaskResume( xHandle );
// The created task will once again get microcontroller processing // The created task will once again get microcontroller processing
// time in accordance with it priority within the system. // time in accordance with it priority within the system.
} }
</pre> </pre>
* \defgroup vTaskResume vTaskResume * \defgroup vTaskResume vTaskResume
* \ingroup TaskCtrl * \ingroup TaskCtrl
*/ */
void vTaskResume( xTaskHandle pxTaskToResume ); void vTaskResume( xTaskHandle pxTaskToResume ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -594,7 +748,7 @@ void vTaskResume( xTaskHandle pxTaskToResume );
* \defgroup vTaskResumeFromISR vTaskResumeFromISR * \defgroup vTaskResumeFromISR vTaskResumeFromISR
* \ingroup TaskCtrl * \ingroup TaskCtrl
*/ */
portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume ); portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume ) PRIVILEGED_FUNCTION;
/*----------------------------------------------------------- /*-----------------------------------------------------------
* SCHEDULER CONTROL * SCHEDULER CONTROL
@ -619,20 +773,20 @@ portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume );
<pre> <pre>
void vAFunction( void ) void vAFunction( void )
{ {
// Create at least one task before starting the kernel. // Create at least one task before starting the kernel.
xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
// Start the real time kernel with preemption. // Start the real time kernel with preemption.
vTaskStartScheduler (); vTaskStartScheduler ();
// Will not get here unless a task calls vTaskEndScheduler () // Will not get here unless a task calls vTaskEndScheduler ()
} }
</pre> </pre>
* *
* \defgroup vTaskStartScheduler vTaskStartScheduler * \defgroup vTaskStartScheduler vTaskStartScheduler
* \ingroup SchedulerControl * \ingroup SchedulerControl
*/ */
void vTaskStartScheduler( void ); void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -658,34 +812,34 @@ void vTaskStartScheduler( void );
<pre> <pre>
void vTaskCode( void * pvParameters ) void vTaskCode( void * pvParameters )
{ {
for( ;; ) for( ;; )
{ {
// Task code goes here. // Task code goes here.
// At some point we want to end the real time kernel processing // At some point we want to end the real time kernel processing
// so call ... // so call ...
vTaskEndScheduler (); vTaskEndScheduler ();
} }
} }
void vAFunction( void ) void vAFunction( void )
{ {
// Create at least one task before starting the kernel. // Create at least one task before starting the kernel.
xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
// Start the real time kernel with preemption. // Start the real time kernel with preemption.
vTaskStartScheduler (); vTaskStartScheduler ();
// Will only get here when the vTaskCode () task has called // Will only get here when the vTaskCode () task has called
// vTaskEndScheduler (). When we get here we are back to single task // vTaskEndScheduler (). When we get here we are back to single task
// execution. // execution.
} }
</pre> </pre>
* *
* \defgroup vTaskEndScheduler vTaskEndScheduler * \defgroup vTaskEndScheduler vTaskEndScheduler
* \ingroup SchedulerControl * \ingroup SchedulerControl
*/ */
void vTaskEndScheduler( void ); void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -706,37 +860,37 @@ void vTaskEndScheduler( void );
<pre> <pre>
void vTask1( void * pvParameters ) void vTask1( void * pvParameters )
{ {
for( ;; ) for( ;; )
{ {
// Task code goes here. // Task code goes here.
// ... // ...
// At some point the task wants to perform a long operation during // At some point the task wants to perform a long operation during
// which it does not want to get swapped out. It cannot use // which it does not want to get swapped out. It cannot use
// taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
// operation may cause interrupts to be missed - including the // operation may cause interrupts to be missed - including the
// ticks. // ticks.
// Prevent the real time kernel swapping out the task. // Prevent the real time kernel swapping out the task.
vTaskSuspendAll (); vTaskSuspendAll ();
// Perform the operation here. There is no need to use critical // Perform the operation here. There is no need to use critical
// sections as we have all the microcontroller processing time. // sections as we have all the microcontroller processing time.
// During this time interrupts will still operate and the kernel // During this time interrupts will still operate and the kernel
// tick count will be maintained. // tick count will be maintained.
// ... // ...
// The operation is complete. Restart the kernel. // The operation is complete. Restart the kernel.
xTaskResumeAll (); xTaskResumeAll ();
} }
} }
</pre> </pre>
* \defgroup vTaskSuspendAll vTaskSuspendAll * \defgroup vTaskSuspendAll vTaskSuspendAll
* \ingroup SchedulerControl * \ingroup SchedulerControl
*/ */
void vTaskSuspendAll( void ); void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -747,48 +901,48 @@ void vTaskSuspendAll( void );
* task is executing at any time. * task is executing at any time.
* *
* @return If resuming the scheduler caused a context switch then pdTRUE is * @return If resuming the scheduler caused a context switch then pdTRUE is
* returned, otherwise pdFALSE is returned. * returned, otherwise pdFALSE is returned.
* *
* Example usage: * Example usage:
<pre> <pre>
void vTask1( void * pvParameters ) void vTask1( void * pvParameters )
{ {
for( ;; ) for( ;; )
{ {
// Task code goes here. // Task code goes here.
// ... // ...
// At some point the task wants to perform a long operation during // At some point the task wants to perform a long operation during
// which it does not want to get swapped out. It cannot use // which it does not want to get swapped out. It cannot use
// taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
// operation may cause interrupts to be missed - including the // operation may cause interrupts to be missed - including the
// ticks. // ticks.
// Prevent the real time kernel swapping out the task. // Prevent the real time kernel swapping out the task.
vTaskSuspendAll (); vTaskSuspendAll ();
// Perform the operation here. There is no need to use critical // Perform the operation here. There is no need to use critical
// sections as we have all the microcontroller processing time. // sections as we have all the microcontroller processing time.
// During this time interrupts will still operate and the real // During this time interrupts will still operate and the real
// time kernel tick count will be maintained. // time kernel tick count will be maintained.
// ... // ...
// The operation is complete. Restart the kernel. We want to force // The operation is complete. Restart the kernel. We want to force
// a context switch - but there is no point if resuming the scheduler // a context switch - but there is no point if resuming the scheduler
// caused a context switch already. // caused a context switch already.
if( !xTaskResumeAll () ) if( !xTaskResumeAll () )
{ {
taskYIELD (); taskYIELD ();
} }
} }
} }
</pre> </pre>
* \defgroup xTaskResumeAll xTaskResumeAll * \defgroup xTaskResumeAll xTaskResumeAll
* \ingroup SchedulerControl * \ingroup SchedulerControl
*/ */
signed portBASE_TYPE xTaskResumeAll( void ); signed portBASE_TYPE xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -799,7 +953,7 @@ signed portBASE_TYPE xTaskResumeAll( void );
* is in any other state. * is in any other state.
* *
*/ */
signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask ); signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
/*----------------------------------------------------------- /*-----------------------------------------------------------
* TASK UTILITIES * TASK UTILITIES
@ -814,7 +968,7 @@ signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );
* \page xTaskGetTickCount xTaskGetTickCount * \page xTaskGetTickCount xTaskGetTickCount
* \ingroup TaskUtils * \ingroup TaskUtils
*/ */
portTickType xTaskGetTickCount( void ); portTickType xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -828,7 +982,7 @@ portTickType xTaskGetTickCount( void );
* \page uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks * \page uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
* \ingroup TaskUtils * \ingroup TaskUtils
*/ */
unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ); unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -854,7 +1008,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void );
* \page vTaskList vTaskList * \page vTaskList vTaskList
* \ingroup TaskUtils * \ingroup TaskUtils
*/ */
void vTaskList( signed portCHAR *pcWriteBuffer ); void vTaskList( signed portCHAR *pcWriteBuffer ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -886,7 +1040,7 @@ void vTaskList( signed portCHAR *pcWriteBuffer );
* \page vTaskGetRunTimeStats vTaskGetRunTimeStats * \page vTaskGetRunTimeStats vTaskGetRunTimeStats
* \ingroup TaskUtils * \ingroup TaskUtils
*/ */
void vTaskGetRunTimeStats( signed portCHAR *pcWriteBuffer ); void vTaskGetRunTimeStats( signed portCHAR *pcWriteBuffer ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -907,7 +1061,7 @@ void vTaskGetRunTimeStats( signed portCHAR *pcWriteBuffer );
* \page vTaskStartTrace vTaskStartTrace * \page vTaskStartTrace vTaskStartTrace
* \ingroup TaskUtils * \ingroup TaskUtils
*/ */
void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize ); void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize ) PRIVILEGED_FUNCTION;
/** /**
* task. h * task. h
@ -920,7 +1074,7 @@ void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize
* \page usTaskEndTrace usTaskEndTrace * \page usTaskEndTrace usTaskEndTrace
* \ingroup TaskUtils * \ingroup TaskUtils
*/ */
unsigned portLONG ulTaskEndTrace( void ); unsigned portLONG ulTaskEndTrace( void ) PRIVILEGED_FUNCTION;
/** /**
* task.h * task.h
@ -940,7 +1094,7 @@ unsigned portLONG ulTaskEndTrace( void );
* @return The smallest amount of free stack space there has been (in bytes) * @return The smallest amount of free stack space there has been (in bytes)
* since the task referenced by xTask was created. * since the task referenced by xTask was created.
*/ */
unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask ); unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
/** /**
* task.h * task.h
@ -950,7 +1104,7 @@ unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );
* Passing xTask as NULL has the effect of setting the calling tasks hook * Passing xTask as NULL has the effect of setting the calling tasks hook
* function. * function.
*/ */
void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction ); void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction ) PRIVILEGED_FUNCTION;
/** /**
* task.h * task.h
@ -958,7 +1112,7 @@ void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunct
* *
* Returns the pxHookFunction value assigned to the task xTask. * Returns the pxHookFunction value assigned to the task xTask.
*/ */
pdTASK_HOOK_CODE xTaskGetApplicationTaskTag( xTaskHandle xTask ); pdTASK_HOOK_CODE xTaskGetApplicationTaskTag( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
/** /**
* task.h * task.h
@ -970,7 +1124,7 @@ pdTASK_HOOK_CODE xTaskGetApplicationTaskTag( xTaskHandle xTask );
* pvParameter is passed to the hook function for the task to interpret as it * pvParameter is passed to the hook function for the task to interpret as it
* wants. * wants.
*/ */
portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter ); portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter ) PRIVILEGED_FUNCTION;
/*----------------------------------------------------------- /*-----------------------------------------------------------
@ -987,7 +1141,7 @@ portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter
* for a finite period required removing from a blocked list and placing on * for a finite period required removing from a blocked list and placing on
* a ready list. * a ready list.
*/ */
void vTaskIncrementTick( void ); void vTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
/* /*
* THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
@ -1010,7 +1164,7 @@ void vTaskIncrementTick( void );
* portTICK_RATE_MS can be used to convert kernel ticks into a real time * portTICK_RATE_MS can be used to convert kernel ticks into a real time
* period. * period.
*/ */
void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait ); void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;
/* /*
* THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
@ -1027,7 +1181,7 @@ void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicks
* @return pdTRUE if the task being removed has a higher priority than the task * @return pdTRUE if the task being removed has a higher priority than the task
* making the call, otherwise pdFALSE. * making the call, otherwise pdFALSE.
*/ */
signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList ); signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList ) PRIVILEGED_FUNCTION;
/* /*
* THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
@ -1040,7 +1194,7 @@ signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList )
* Empties the ready and delayed queues of task control blocks, freeing the * Empties the ready and delayed queues of task control blocks, freeing the
* memory allocated for the task control block and task stacks as it goes. * memory allocated for the task control block and task stacks as it goes.
*/ */
void vTaskCleanUpResources( void ); void vTaskCleanUpResources( void ) PRIVILEGED_FUNCTION;
/* /*
* THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
@ -1050,47 +1204,53 @@ void vTaskCleanUpResources( void );
* Sets the pointer to the current TCB to the TCB of the highest priority task * Sets the pointer to the current TCB to the TCB of the highest priority task
* that is ready to run. * that is ready to run.
*/ */
void vTaskSwitchContext( void ); void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
/* /*
* Return the handle of the calling task. * Return the handle of the calling task.
*/ */
xTaskHandle xTaskGetCurrentTaskHandle( void ); xTaskHandle xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
/* /*
* Capture the current time status for future reference. * Capture the current time status for future reference.
*/ */
void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut ); void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut ) PRIVILEGED_FUNCTION;
/* /*
* Compare the time status now with that previously captured to see if the * Compare the time status now with that previously captured to see if the
* timeout has expired. * timeout has expired.
*/ */
portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait ); portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait ) PRIVILEGED_FUNCTION;
/* /*
* Shortcut used by the queue implementation to prevent unnecessary call to * Shortcut used by the queue implementation to prevent unnecessary call to
* taskYIELD(); * taskYIELD();
*/ */
void vTaskMissedYield( void ); void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
/* /*
* Returns the scheduler state as taskSCHEDULER_RUNNING, * Returns the scheduler state as taskSCHEDULER_RUNNING,
* taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED. * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
*/ */
portBASE_TYPE xTaskGetSchedulerState( void ); portBASE_TYPE xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
/* /*
* Raises the priority of the mutex holder to that of the calling task should * Raises the priority of the mutex holder to that of the calling task should
* the mutex holder have a priority less than the calling task. * the mutex holder have a priority less than the calling task.
*/ */
void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder ); void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder ) PRIVILEGED_FUNCTION;
/* /*
* Set the priority of a task back to its proper priority in the case that it * Set the priority of a task back to its proper priority in the case that it
* inherited a higher priority while it was holding a semaphore. * inherited a higher priority while it was holding a semaphore.
*/ */
void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder ); void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder ) PRIVILEGED_FUNCTION;
/*
* Generic version of the task creation function which is in turn called by the
* xTaskCreate() and xTaskCreateProtected() macros.
*/
signed portBASE_TYPE xTaskGenericCreate( pdTASK_CODE pvTaskCode, const signed portCHAR * const pcName, unsigned portSHORT usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pxCreatedTask, portSTACK_TYPE *puxStackBuffer, const xMemoryRegion * const xRegions ) PRIVILEGED_FUNCTION;
#ifdef __cplusplus #ifdef __cplusplus
} }

Loading…
Cancel
Save