AM261x MCU+ SDK: Task

| AM261x MCU+ SDK 26.00.00 |

Task

Attention
  This module is not applicable for NO RTOS environment

# Features Supported

- APIs to create and destroy tasks
- APIs to yeild a task
- Ability to specify task priority, task entry function, stack pointer, stack size
- Ability to get task and CPU load

# Features NOT Supported

NA

# Important Usage Guidelines

- On R5F, and M4F, make sure memory provided as stack is 32b aligned and size is also multiple of 32b
- Stack and stack size MUST be provided by application and is not allocated internally
- TaskP_loadResetAll() needs to be called in the application. If load counters are not reset, the accumulated load counters can lead to filtered and less steady CPU load values.

# Example Usage

Include the below file to access the APIs,

#include <kernel/dpl/TaskP.h>

Example usage to define task objects and parameters

/* Task priority, stack, stack size and task objects, these MUST be global's */
#define MY_TASK_PRI (8U)
#define MY_TASK_STACK_SIZE (4*1024U)
uint8_t gMyTaskStack[MY_TASK_STACK_SIZE] __attribute__((aligned(32)));
TaskP_Object gMyTask;
/* Application specific task arguments */
typedef struct {
uint32_t value;
} MyTask_Args;
MyTask_Args gMyTask_args;

Example task main function

/* Task entry point or main function for this task */
void myTaskMain(void *args)
{
MyTask_Args *myArgs = (MyTask_Args*)args;
DebugP_assert(myArgs != NULL);
/* myArgs points to structure pointer passed during TaskP_construct */
/* do something in the task */
/* when done call below function, DO NOT 'return` from this function */
TaskP_exit();
}

Example usage to create a task

int32_t status;
TaskP_Params myTaskParams; /* this need not be global variable */
TaskP_Params_init(&myTaskParams);
myTaskParams.name = "MY_TASK";
myTaskParams.stackSize = MY_TASK_STACK_SIZE;
myTaskParams.stack = gMyTaskStack;
myTaskParams.priority = MY_TASK_PRI;
myTaskParams.args = &gMyTask_args;
myTaskParams.taskMain = myTaskMain;
status = TaskP_construct(&gMyTask, &myTaskParams);
DebugP_assert(status == SystemP_SUCCESS);

Example usage to get task and CPU load

TaskP_Load taskLoad;
uint32_t cpuLoad;
cpuLoad = TaskP_loadGetTotalCpuLoad();
DebugP_log(" LOAD: CPU = %2d.%2d %%\r\n", cpuLoad/100, cpuLoad%100 );
TaskP_loadGet(&gMyTask, &taskLoad);
DebugP_log(" LOAD: %s = %2d.%2d %%\r\n", taskLoad.name, taskLoad.cpuLoad/100, taskLoad.cpuLoad%100 );

# API

APIs for Task

TaskP_Params
Opaque task object used with the task APIs.
Definition: TaskP.h:140
args
void * args
Definition: hsmclient_msg.h:4
TaskP_Load
Task load statistics.
Definition: TaskP.h:79
TaskP_Load::name
const char * name
Definition: TaskP.h:81
TaskP_Params::args
void * args
Definition: TaskP.h:146
DebugP_log
#define DebugP_log(format,...)
Function to log a string to the enabled console.
Definition: DebugP.h:235
TaskP_Params::name
const char * name
Definition: TaskP.h:142
__attribute__
struct lld_sockaddr __attribute__
This is the SecureBoot Stream type which holds the data for a specific bootloader to HSM call....
TaskP_Params::taskMain
TaskP_FxnMain taskMain
Definition: TaskP.h:147
TaskP_exit
void TaskP_exit(void)
Exit current task.
SystemP_SUCCESS
#define SystemP_SUCCESS
Return status when the API execution was successful.
Definition: SystemP.h:56
TaskP_Params::stackSize
uint32_t stackSize
Definition: TaskP.h:143
TaskP.h
TaskP_Load::cpuLoad
uint32_t cpuLoad
Definition: TaskP.h:84
TaskP_Params::priority
uint32_t priority
Definition: TaskP.h:145
TaskP_construct
int32_t TaskP_construct(TaskP_Object *obj, const TaskP_Params *params)
Create a task object.
TaskP_loadGetTotalCpuLoad
uint32_t TaskP_loadGetTotalCpuLoad(void)
Get total CPU load including all task and ISR execution time.
TaskP_loadGet
void TaskP_loadGet(TaskP_Object *obj, TaskP_Load *taskLoad)
Get task load.
DebugP_assert
#define DebugP_assert(expression)
Function to call for assert check.
Definition: DebugP.h:187
TaskP_Params::stack
uint8_t * stack
Definition: TaskP.h:144
TaskP_Params_init
void TaskP_Params_init(TaskP_Params *params)
Set default values to TaskP_Params.