When you create a task, it is provided with its own run-time stack,
used for storing local variables as well as for further nesting of
function calls. Each stack must be large enough to handle normal
subroutine calls and one task preemption context.
A task preemption context is the context that gets saved when one task
preempts another as a result of an interrupt thread readying
a higher-priority task.
All tasks executing within a single program share a common set of
global variables, accessed according to the standard rules of scope
defined for C functions.
Each task is in one of five modes of execution at any point in time:
running, ready, blocked, terminated, or inactive. By design, there is
always one
(and only one) task currently running, even if it is only the idle task
managed internally by Task. The current task can be suspended from
execution by calling certain Task functions, as well as functions
provided by other modules like the Semaphore or Event Modules.
The current task
can also terminate its own execution. In either case, the processor
is switched to the highest priority task that is ready to run.
You can assign numeric priorities to tasks. Tasks are
readied for execution in strict priority order; tasks of the same
priority are scheduled on a first-come, first-served basis.
The priority of the currently running task is never lower
than the priority of any ready task. Conversely, the running task
is preempted and re-scheduled for execution whenever there exists
some ready task of higher priority.
Task_delete() removes the task from all internal queues and calls
Memory_free() to free the task object and stack.
Memory_free() must acquire a lock to the memory before proceeding.
If another task already holds a lock to the memory, then there is
a context switch.
You can specify application-wide Delete hook functions that
run whenever a task is deleted. See the discussion of Hook Functions
below for details.
Note: Unless the mode of the deleted task is Task_Mode_TERMINATED,
Task_delete should be called with care. For example, if the task has
obtained exclusive access to a resource, deleting the task makes the
resource unavailable.
Stack size parameters for both static and dynamic tasks are rounded
up to the nearest integer multiple of a target-specific alignment
requirement.
In the case of Task's which are created with a user-provided stack,
both the base address and the stackSize are aligned. The base address
is increased to the nearest aligned address. The stack size is decreased
accordingly and then rounded down to the nearest integer multiple of the
target-specific required alignment.
Sets of hook functions can be specified for the Task module. Each
set can contains these hook functions:
Hook functions can only be configured statically.
If you define more than one set of hook functions, all the functions
of a particular type will be run when a Swi triggers that type of
hook.
The create and delete functions are called whenever a Task is created
or deleted. They are called with interrupts enabled (unless called
at boot time or from main()).
If a switch function is specified, it is invoked just before the new task
is switched to. The switch function is called with interrupts enabled.
This function can be used to save/restore additional task context (for
example, external hardware registers), to check for task stack overflow,
to monitor the time used by each task, etc.
To properly handle the switch to the first task your switchFxn should
check for "prev == NULL" before using prev:
If a ready function is specified, it is invoked whenever a task is made
ready to run. The ready function is called with interrupts enabled
(unless called at boot time or from main()).
If an exit function is specified, it is invoked when a task exits (via
call to Task_exit() or when a task returns from its' main function).
The Exit Function is called with interrupts enabled.
enum Task_Mode |
|
Task execution modes
typedef enum Task_Mode {
Task_Mode_RUNNING,
// Task is currently executing
Task_Mode_READY,
// Task is scheduled for execution
Task_Mode_BLOCKED,
// Task is suspended from execution
Task_Mode_TERMINATED,
// Task is terminated from execution
Task_Mode_INACTIVE
// Task is on inactive task list
} Task_Mode;
DETAILS
These enumerations are the range of modes or states that
a task can be in. A task's current mode can be gotten using
stat.
typedef Task_AllBlockedFuncPtr |
|
"All Task Blocked" function type definition
typedef Void (*Task_AllBlockedFuncPtr)(Void);
typedef Task_FuncPtr |
|
Task function type definition
typedef Void (*Task_FuncPtr)(UArg,UArg);
struct Task_HookSet |
|
Task hook set type definition
typedef struct Task_HookSet {
Void (*registerFxn)(Int);
} Task_HookSet;
DETAILS
Sets of hook functions can be specified for the Task module.
See
Hook Functions for details.
struct Task_Stat |
|
Task Status Buffer
typedef struct Task_Stat {
Int priority;
// Task priority
Ptr stack;
// Task stack
SizeT stackSize;
// Task stack size
// Heap used to alloc stack
Ptr env;
// Global environment struct
// Task's current mode
Ptr sp;
// Task's current stack pointer
SizeT used;
// max # of words used on stack
} Task_Stat;
DETAILS
Passed to and filled in by
stat;
config Task_A_badPriority // module-wide |
|
Asserted in Task_create
config Task_A_badTaskState // module-wide |
|
Asserted in Task_delete
config Task_A_badThreadType // module-wide |
|
Asserted in Task_create and Task_delete
config Task_A_badTimeout // module-wide |
|
Asserted in Task_sleep
config Task_A_noPendElem // module-wide |
|
Asserted in Task_delete
config Task_A_taskDisabled // module-wide |
|
Asserted in Task_create
config Task_E_spOutOfBounds // module-wide |
|
Error raised when a task's stack pointer (SP) does not point
somewhere within the task's stack
extern const Error_Id Task_E_spOutOfBounds;
DETAILS
This error is raised by kernel's stack checking function. This
function checks the SPs before every task switch to make sure
they point within the task's stack.
The stack checking logic is enabled by the
initStackFlag and
checkStackFlag configuration parameters. If both of these
flags are set to true, the kernel will validate the stack pointers.
config Task_E_stackOverflow // module-wide |
|
Error raised when a stack overflow (or corruption) is detected
extern const Error_Id Task_E_stackOverflow;
DETAILS
This error is raised by kernel's stack checking function. This
function checks the stacks before every task switch to make sure
that reserved word at top of stack has not been modified.
The stack checking logic is enabled by the
initStackFlag and
checkStackFlag configuration parameters. If both of these
flags are set to true, the kernel will validate the stacks.
config Task_LD_block // module-wide |
|
Logged when a task is blocked (ie Semaphore_pend())
config Task_LD_exit // module-wide |
|
Logged when Task functions fall thru the bottom
or when Task_exit() is explicitly called
config Task_LD_ready // module-wide |
|
Logged when a task is made ready to run (ie Semaphore_post())
config Task_LM_setPri // module-wide |
|
Logged on calls to Task_setPri
config Task_LM_sleep // module-wide |
|
Logged on calls to Task_sleep
config Task_LM_switch // module-wide |
|
Logged on every task switch
config Task_LM_yield // module-wide |
|
Logged on calls to Task_yield
config Task_allBlockedFunc // module-wide |
|
Function to call while all tasks are blocked
DETAILS
This function will be called repeatedly while no tasks are
ready to run.
Ordinarily (in applications that have tasks ready to run at startup),
the function will run in the context of the last task to block.
In an application where there are no tasks ready to run
when BIOS_start() is called, the allBlockedFunc function is
called within the BIOS_start() thread which runs on the system/ISR
stack.
By default, allBlockedFunc is initialized to point to an internal
function that simply returns.
By adding the following lines to the config script, the Idle
functions will run whenever all tasks are blocked:
Task.enableIdleTask = false;
Task.allBlockedFunc = Idle.run;
SEE
CONSTRAINTS
The configured allBlockedFunc is designed to be called repeatedly.
It must return in order for the task scheduler to check if all
tasks are STILL blocked and if not, run the highest priority task
currently ready to run.
The configured allBlockedFunc function is called with interrupts
disabled. If your function must run with interrupts enabled,
surround the body of your code with Hwi_enable()/Hwi_restore()
function calls per the following example:
Void yourFunc() {
UInt hwiKey;
hwiKey = Hwi_enable();
... // your code here
Hwi_restore(hwiKey);
}
config Task_defaultStackHeap // module-wide |
|
Default Mem heap used for all dynamically created task stacks
DETAILS
Default is null.
config Task_defaultStackSize // module-wide |
|
Default stack size (in MAUs) used for all tasks
extern const SizeT Task_defaultStackSize;
DETAILS
Default is obtained from the family-specific TaskSupport module
(e.g.
ti.sysbios.family.arm.m3.TaskSupport,
ti.sysbios.family.c62.TaskSupport).
config Task_deleteTerminatedTasks // module-wide |
|
Automatically delete terminated tasks
extern const Bool Task_deleteTerminatedTasks;
DETAILS
If this feature is enabled, an Idle function is installed that
deletes dynamically created Tasks that have terminated either
by falling through their task function or by explicitly calling
Task_exit().
A list of terminated Tasks that were created dynmically is
maintained internally. Each invocation of the installed Idle function
deletes the first Task on this list. This one-at-a-time process
continues until the list is empty.
NOTE
This feature is disabled by default.
If this feature is enable, the user's application must not
also delete terminated tasks or undefined and/or potentially
catastrophic behavior will result.
config Task_hooks // module-wide |
|
Const array that holds the HookSet objects
DETAILS
See
Hook Functions for details about HookSets.
config Task_initStackFlag // module-wide |
|
Initialize stack with known value for stack checking at runtime
(see checkStackFlag)
extern const Bool Task_initStackFlag;
DETAILS
This is also useful for inspection of stack in debugger or core
dump utilities.
Default is true.
config Task_numPriorities // module-wide |
|
Number of Task priorities supported. Default is 16
extern const UInt Task_numPriorities;
DETAILS
The maximum number of priorities supported is
target specific and depends on the number of
bits in a UInt data type. For 6x and ARM devices
the maximum number of priorities is therefore 32.
For 28x, 55x, and MSP430 devices, the maximum number of
priorities is 16.
Task_disable() // module-wide |
|
Disable the task scheduler
RETURNS
DETAILS
disable and
restore control Task scheduling.
disable disables all other Tasks from running until
restore is called. Hardware and Software interrupts
can still run.
disable and
restore allow you to ensure that
statements
that must be performed together during critical processing are not
preempted by other Tasks.
The value of the key returned is opaque to applications and is meant
to be passed to Task_restore().
In the following example, the critical section is
not preempted by any Tasks.
key = Task_disable();
`critical section`
Task_restore(key);
You can also use
disable and
restore to
create several Tasks and allow them to be invoked in
priority order.
disable calls can be nested.
CONSTRAINTS
Do not call any function that can cause the current task to block
within a
disable/
restore block. For example,
Semaphore_pend
(if timeout is non-zero),
sleep,
yield, and Memory_alloc can all
cause blocking.
Task_exit() // module-wide |
|
Terminate execution of the current task
DETAILS
Task_exit terminates execution of the current task, changing its mode
from
Mode_RUNNING to
Mode_TERMINATED. If all tasks
have been terminated, or if all remaining tasks have their
vitalTaskFlag attribute set to FALSE, then SYS/BIOS terminates the
program as a whole by calling the function System_exit with a status
code of 0.
Task_exit is automatically called whenever a task returns from its
top-level function.
Exit Hooks (see exitFxn in
HookSet) can be used to provide
functions that run whenever a task is terminated. The exitFxn Hooks
are called before the task has been blocked and marked
Mode_TERMINATED.
See
Hook Functions for more information.
Any SYS/BIOS function can be called from an Exit Hook function.
Calling
self within an Exit function returns the task
being exited. Your Exit function declaration should be similar to
the following:
A task switch occurs when calling Task_exit unless the program as a
whole is terminated
CONSTRAINTS
Task_exit cannot be called from a Swi or Hwi.
Task_exit cannot be called from the program's main() function.
Task_getIdleTask() // module-wide |
|
returns a handle to idle task object
Task_restore() // module-wide |
|
Restore Task scheduling state
Void Task_restore(UInt key);
ARGUMENTS
key
key to restore previous Task scheduler state
DETAILS
disable and
restore control Task scheduling
disable disables all other Tasks from running until
restore is called. Hardware and Software interrupts
can still run.
disable and
restore allow you to ensure that
statements
that must be performed together during critical processing are not
preempted.
In the following example, the critical section is not preempted
by any Tasks.
key = Task_disable();
`critical section`
Task_restore(key);
You can also use
disable and
restore to create
several Tasks and allow them to be performed in priority order.
disable calls can be nested.
restore returns with interrupts enabled if the key unlocks
the scheduler
CONSTRAINTS
Do not call any function that can cause the current task to block
within a
disable/
restore block. For example,
Semaphore_pend()
(if timeout is non-zero),
sleep,
yield, and Memory_alloc can all
cause blocking.
restore internally calls Hwi_enable() if the key passed
to it results in the unlocking of the Task scheduler (ie if this
is root Task_disable/Task_restore pair).
Task_self() // module-wide |
|
Returns a handle to the currently executing Task object
RETURNS
address of currently executing task object
DETAILS
Task_self returns the object handle for the currently executing task.
This function is useful when inspecting the object or when the current
task changes its own priority through
setPri.
No task switch occurs when calling Task_self.
Task_self will return NULL until Tasking is initiated at the end of
BIOS_start().
Task_selfMacro() // module-wide |
|
Returns a handle to the currently executing Task object
RETURNS
address of currently executing task object
DETAILS
Task_selfMacro is identical to
self but is implemented as
and inline macro.
Task_sleep() // module-wide |
|
Delay execution of the current task
Void Task_sleep(UInt nticks);
ARGUMENTS
nticks
number of system clock ticks to sleep
DETAILS
Task_sleep changes the current task's mode from
Mode_RUNNING
to
Mode_BLOCKED, and delays its execution for nticks
increments of the
system clock. The actual time
delayed can be up to 1 system clock tick less than nticks due to
granularity in system timekeeping and the time elapsed per
tick is determined by
Clock_tickPeriod.
After the specified period of time has elapsed, the task reverts to
the
Mode_READY mode and is scheduled for execution.
A task switch always occurs when calling Task_sleep if nticks > 0.
CONSTRAINTS
Task_sleep cannot be called from a Swi or Hwi, or within a
disable /
restore block.
Task_sleep cannot be called from the program's main() function.
Task_sleep should not be called from within an Idle function. Doing
so prevents analysis tools from gathering run-time information.
nticks cannot be
BIOS_WAIT_FOREVER.
Task_yield() // module-wide |
|
Yield processor to equal priority task
DETAILS
Task_yield yields the processor to another task of equal priority.
A task switch occurs when you call Task_yield if there is an equal
priority task ready to run.
Tasks of higher priority preempt the currently running task without
the need for a call to Task_yield. If only lower-priority tasks are
ready to run when you call Task_yield, the current task continues to
run. Control does not pass to a lower-priority task.
CONSTRAINTS
When called within an Hwi, the code sequence calling Task_yield
must be invoked by the Hwi dispatcher.
Task_yield cannot be called from the program's main() function.
Module-Wide Built-Ins |
|
// Get this module's unique id
Bool Task_Module_startupDone();
// Test if this module has completed startup
// The heap from which this module allocates memory
Bool Task_Module_hasMask();
// Test whether this module has a diagnostics mask
Bits16 Task_Module_getMask();
// Returns the diagnostics mask for this module
Void Task_Module_setMask(Bits16 mask);
// Set the diagnostics mask for this module
Instance Object Types |
|
typedef struct Task_Object Task_Object;
// Opaque internal representation of an instance object
// Client reference to an instance object
typedef struct Task_Struct Task_Struct;
// Opaque client structure large enough to hold an instance object
// Convert this instance structure pointer into an instance handle
// Convert this instance handle into an instance structure pointer
Instance Config Parameters |
|
typedef struct Task_Params {
// Instance config-params structure
// Common per-instance configs
UArg arg0;
// Task function argument. Default is 0
UArg arg1;
// Task function argument. Default is 0
Ptr env;
// Environment data struct
Int priority;
// Task priority (0 to numPriorities-1 or -1).
Default is 1
Ptr stack;
// Task stack pointer. Default = null
// Mem heap used for dynamically created task stack
SizeT stackSize;
// Task stack size in MAUs
Bool vitalTaskFlag;
// Exit system immediately when the last task with this
flag set to TRUE has terminated
} Task_Params;
// Initialize this config-params structure with supplier-specified defaults before instance creation
config Task_arg0 // instance |
|
Task function argument. Default is 0
config Task_arg1 // instance |
|
Task function argument. Default is 0
config Task_env // instance |
|
Environment data struct
config Task_priority // instance |
|
Task priority (0 to numPriorities-1 or -1).
Default is 1
config Task_stack // instance |
|
Task stack pointer. Default = null
DETAILS
Null indicates that the stack is to be allocated by create().
Example: To statically initialize "tsk0"'s stack to a literal
address, use the following syntax:
Program.global.tsk0.stack = $addr(literal);
config Task_stackHeap // instance |
|
Mem heap used for dynamically created task stack
DETAILS
The default value of NULL means that the module config
defaultStackHeap is used.
config Task_stackSize // instance |
|
Task stack size in MAUs
DETAILS
The default value of 0 means that the module config
defaultStackSize is used.
config Task_vitalTaskFlag // instance |
|
Exit system immediately when the last task with this
flag set to TRUE has terminated
DETAILS
Default is true.
Instance Creation |
|
// Allocate and initialize a new instance object and return its handle
// Initialize a new instance object inside the provided structure
ARGUMENTS
fxn
Task Function
params
per-instance config params, or NULL to select default values (target-domain only)
eb
active error-handling block, or NULL to select default policy (target-domain only)
DETAILS
Task_create creates a new task object. If successful, Task_create
returns the handle of the new task object. If unsuccessful,
Task_create returns NULL unless it aborts.
The fxn parameter uses the
FuncPtr type to pass a pointer to
the function the Task object should run. For example, if myFxn is a
function in your program, your C code can create a Task object
to call that
function as follows:
Task_Params taskParams;
// Create task with priority 15
Task_Params_init(&taskParams);
taskParams.stackSize = 512;
taskParams.priority = 15;
Task_create((Task_FuncPtr)myFxn, &taskParams, &eb);
The following statements statically create a task in the
configuration file:
var params = new Task.Params;
params.instance.name = "tsk0";
params.arg0 = 1;
params.arg1 = 2;
params.priority = 1;
Task.create('&tsk0_func', params);
If NULL is passed instead of a pointer to an actual Task_Params
struct, a
default set of parameters is used. The "eb" is an error block that
you can use
to handle errors that may occur during Task object creation.
The newly created task is placed in
Mode_READY mode, and is
scheduled to begin concurrent execution of the following function
call:
As a result of being made ready to run, the task runs any
application-wide Ready functions that have been specified.
Task_exit is automatically called if and when the task returns
from fxn.
Create Hook Functions
You can specify application-wide Create hook functions in your config
file that run whenever a task is created. This includes tasks that
are created statically and those created dynamically using
Task_create.
For Task objects created statically, Create functions are called
during the Task module initialization phase of the program startup
process prior to main().
For Task objects created dynamically, Create functions
are called after the task handle has been initialized but before the
task has been placed on its ready queue.
Any SYS/BIOS function can be called from Create functions.
SYS/BIOS passes the task handle of the task being created to each of
the Create functions.
All Create function declarations should be similar to this:
Void myCreateFxn(Task_Handle task);
CONSTRAINTS
- The fxn parameter and the name attribute cannot be NULL.
- The priority attribute must be less than or equal to
(numPriorities - 1) and greater than or equal to one (1)
(priority 0 is owned by the Idle task).
- The priority can be set to -1 for tasks that will not execute
until another task changes the priority to a positive value.
- The stackHeap attribute must identify a valid memory Heap.
Instance Deletion |
|
// Finalize and free this previously allocated instance object, setting the referenced handle to NULL
// Finalize the instance object inside the provided structure
Task_getEnv() // instance |
|
Get task environment pointer
ARGUMENTS
handle
handle of a previously-created Task instance object
RETURNS
task environment pointer
DETAILS
Task_getEnv returns the environment pointer of the specified task. The
environment pointer references an arbitrary application-defined data
structure.
If your program uses multiple hook sets,
getHookContext
allows you to get environment pointers you have set for a particular
hook set and Task object combination.
Task_getHookContext() // instance |
|
Get hook set's context for a task
ARGUMENTS
handle
handle of a previously-created Task instance object
id
hook set ID
RETURNS
hook set context for task
DETAILS
For example, this C code gets the HookContext, prints it,
and sets a new value for the HookContext.
Ptr pEnv;
Task_Handle myTask;
Int myHookSetId1;
pEnv = Task_getHookContext(task, myHookSetId1);
System_printf("myEnd1: pEnv = 0x%lx, time = %ld\n",
(ULong)pEnv, (ULong)Timestamp_get32());
Task_setHookContext(task, myHookSetId1, (Ptr)0xc0de1);
See
Hook Functions for more details.
Task_getMode() // instance |
|
Retrieve the Mode of a task
ARGUMENTS
handle
handle of a previously-created Task instance object
Task_getPri() // instance |
|
Get task priority
ARGUMENTS
handle
handle of a previously-created Task instance object
RETURNS
task priority
DETAILS
Task_getPri returns the priority of the referenced task.
Task_setEnv() // instance |
|
Set task environment
ARGUMENTS
handle
handle of a previously-created Task instance object
env
task environment pointer
DETAILS
Task_setEnv sets the task environment pointer to env. The
environment pointer references an arbitrary application-defined
data structure.
If your program uses multiple hook sets,
setHookContext
allows you to set environment pointers for any
hook set and Task object combination.
Task_setHookContext() // instance |
|
Set hook instance's context for a task
Void Task_setHookContext(
Task_Handle handle,
Int id,
Ptr hookContext);
ARGUMENTS
handle
handle of a previously-created Task instance object
id
hook set ID
hookContext
value to write to context
DETAILS
For example, this C code gets the HookContext, prints it,
and sets a new value for the HookContext.
Ptr pEnv;
Task_Handle myTask;
Int myHookSetId1;
pEnv = Task_getHookContext(task, myHookSetId1);
System_printf("myEnd1: pEnv = 0x%lx, time = %ld\n",
(ULong)pEnv, (ULong)Timestamp_get32());
Task_setHookContext(task, myHookSetId1, (Ptr)0xc0de1);
See
Hook Functions for more details.
Task_setPri() // instance |
|
Set a task's priority
ARGUMENTS
handle
handle of a previously-created Task instance object
newpri
task's new priority
RETURNS
task's old priority
DETAILS
Task_setpri sets the execution priority of task to newpri, and returns
that task's old priority value. Raising or lowering a task's priority
does not necessarily force preemption and re-scheduling of the caller:
tasks in the
Mode_BLOCKED mode remain suspended despite a
change in priority; and tasks in the
Mode_READY mode gain
control only if their new priority is greater than that of the
currently executing task.
newpri should be set to a value greater than or equal to 1 and
less than or equal to (
numPriorities - 1). newpri can also
be set to -1 which puts the the task into the INACTIVE state and the
task will not run until its priority is raised at a later time by
another task. Priority 0 is reserved for the idle task.
If newpri equals (
numPriorities - 1), execution of the task
effectively locks out all other program activity, except for the
handling of interrupts.
The current task can change its own priority (and possibly preempt its
execution) by passing the output of
self as the value of the
task parameter.
A context switch occurs when calling Task_setpri if a currently
running task priority is set lower than the priority of another
currently ready task, or if another ready task is made to have a
higher priority than the currently running task.
Task_setpri can be used for mutual exclusion.
If a task's new priority is different than its previous priority,
then its relative placement in its new ready task priority
queue can be different than the one it was removed from. This can
effect the relative order in which it becomes the running task.
The effected task is placed at the head of its new priority queue
if it is the currently running task. Otherwise it is placed at
at the end of its new task priority queue.
CONSTRAINTS
newpri must be a value between 1 and (
numPriorities - 1) or -1.
The task cannot be in the
Mode_TERMINATED mode.
The new priority should not be zero (0). This priority level is
reserved for the Idle task.
Task_stat() // instance |
|
Retrieve the status of a task
ARGUMENTS
handle
handle of a previously-created Task instance object
statbuf
pointer to task status structure
DETAILS
Task_stat retrieves attribute values and status information about a
task.
Status information is returned through statbuf, which references a
structure of type
Stat.
When a task is preempted by a software or hardware interrupt, the task
execution mode returned for that task by Task_stat is still
Mode_RUNNING because the task runs when the preemption ends.
The current task can inquire about itself by passing the output of
self as the first argument to Task_stat. However, the task
stack pointer (sp) in the
Stat structure is the value from
the previous context switch.
Task_stat has a non-deterministic execution time. As such, it is not
recommended to call this API from Swis or Hwis.
CONSTRAINTS
statbuf cannot be NULL;
Instance Built-Ins |
|
Int Task_Object_count();
// The number of statically-created instance objects
// The handle of the i-th statically-created instance object (array == NULL)
// The handle of the first dynamically-created instance object, or NULL
// The handle of the next dynamically-created instance object, or NULL
// The heap used to allocate dynamically-created instance objects
// The label associated with this instance object
// The name of this instance object
enum Task.Mode |
|
Task execution modes
XDCscript usage |
meta-domain |
values of type Task.Mode
const Task.Mode_RUNNING;
// Task is currently executing
const Task.Mode_READY;
// Task is scheduled for execution
const Task.Mode_BLOCKED;
// Task is suspended from execution
const Task.Mode_TERMINATED;
// Task is terminated from execution
const Task.Mode_INACTIVE;
// Task is on inactive task list
DETAILS
These enumerations are the range of modes or states that
a task can be in. A task's current mode can be gotten using
stat.
C SYNOPSIS
struct Task.HookSet |
|
Task hook set type definition
XDCscript usage |
meta-domain |
var obj = new Task.HookSet;
obj.registerFxn = Void(*)(Int) ...
DETAILS
Sets of hook functions can be specified for the Task module.
See
Hook Functions for details.
C SYNOPSIS
struct Task.Stat |
|
Task Status Buffer
XDCscript usage |
meta-domain |
var obj = new Task.Stat;
obj.priority = Int ...
// Task priority
obj.stack = Ptr ...
// Task stack
obj.stackSize = SizeT ...
// Task stack size
// Heap used to alloc stack
obj.env = Ptr ...
// Global environment struct
// Task's current mode
obj.sp = Ptr ...
// Task's current stack pointer
obj.used = SizeT ...
// max # of words used on stack
DETAILS
Passed to and filled in by
stat;
C SYNOPSIS
config Task.A_badPriority // module-wide |
|
Asserted in Task_create
XDCscript usage |
meta-domain |
msg: "A_badPriority: An invalid task priority was used."
};
C SYNOPSIS
config Task.A_badTaskState // module-wide |
|
Asserted in Task_delete
XDCscript usage |
meta-domain |
msg: "A_badTaskState: Can't delete a task in RUNNING state."
};
C SYNOPSIS
config Task.A_badThreadType // module-wide |
|
Asserted in Task_create and Task_delete
XDCscript usage |
meta-domain |
msg: "A_badThreadType: Cannot create/delete a task from Hwi or Swi thread."
};
C SYNOPSIS
config Task.A_badTimeout // module-wide |
|
Asserted in Task_sleep
XDCscript usage |
meta-domain |
msg: "A_badTimeout: Can't sleep FOREVER."
};
C SYNOPSIS
config Task.A_noPendElem // module-wide |
|
Asserted in Task_delete
XDCscript usage |
meta-domain |
msg: "A_noPendElem: Not enough info to delete BLOCKED task."
};
C SYNOPSIS
config Task.A_taskDisabled // module-wide |
|
Asserted in Task_create
XDCscript usage |
meta-domain |
msg: "A_taskDisabled: Cannot create a task when tasking is disabled."
};
C SYNOPSIS
config Task.E_spOutOfBounds // module-wide |
|
Error raised when a task's stack pointer (SP) does not point
somewhere within the task's stack
XDCscript usage |
meta-domain |
msg: "E_spOutOfBounds: Task 0x%x stack error, SP = 0x%x."
};
DETAILS
This error is raised by kernel's stack checking function. This
function checks the SPs before every task switch to make sure
they point within the task's stack.
The stack checking logic is enabled by the
initStackFlag and
checkStackFlag configuration parameters. If both of these
flags are set to true, the kernel will validate the stack pointers.
C SYNOPSIS
config Task.E_stackOverflow // module-wide |
|
Error raised when a stack overflow (or corruption) is detected
XDCscript usage |
meta-domain |
msg: "E_stackOverflow: Task 0x%x stack overflow."
};
DETAILS
This error is raised by kernel's stack checking function. This
function checks the stacks before every task switch to make sure
that reserved word at top of stack has not been modified.
The stack checking logic is enabled by the
initStackFlag and
checkStackFlag configuration parameters. If both of these
flags are set to true, the kernel will validate the stacks.
C SYNOPSIS
config Task.LD_block // module-wide |
|
Logged when a task is blocked (ie Semaphore_pend())
XDCscript usage |
meta-domain |
msg: "LD_block: tsk: 0x%x, func: 0x%x"
};
C SYNOPSIS
config Task.LD_exit // module-wide |
|
Logged when Task functions fall thru the bottom
or when Task_exit() is explicitly called
XDCscript usage |
meta-domain |
msg: "LD_exit: tsk: 0x%x, func: 0x%x"
};
C SYNOPSIS
config Task.LD_ready // module-wide |
|
Logged when a task is made ready to run (ie Semaphore_post())
XDCscript usage |
meta-domain |
msg: "LD_ready: tsk: 0x%x, func: 0x%x, pri: %d"
};
C SYNOPSIS
config Task.LM_setPri // module-wide |
|
Logged on calls to Task_setPri
XDCscript usage |
meta-domain |
msg: "LM_setPri: tsk: 0x%x, func: 0x%x, oldPri: %d, newPri %d"
};
C SYNOPSIS
config Task.LM_sleep // module-wide |
|
Logged on calls to Task_sleep
XDCscript usage |
meta-domain |
msg: "LM_sleep: tsk: 0x%x, func: 0x%x, timeout: %d"
};
C SYNOPSIS
config Task.LM_switch // module-wide |
|
Logged on every task switch
XDCscript usage |
meta-domain |
msg: "LM_switch: oldtsk: 0x%x, oldfunc: 0x%x, newtsk: 0x%x, newfunc: 0x%x"
};
C SYNOPSIS
config Task.LM_yield // module-wide |
|
Logged on calls to Task_yield
XDCscript usage |
meta-domain |
msg: "LM_yield: tsk: 0x%x, func: 0x%x, currThread: %d"
};
C SYNOPSIS
config Task.allBlockedFunc // module-wide |
|
Function to call while all tasks are blocked
XDCscript usage |
meta-domain |
Task.allBlockedFunc = Void(*)(Void) undefined;
DETAILS
This function will be called repeatedly while no tasks are
ready to run.
Ordinarily (in applications that have tasks ready to run at startup),
the function will run in the context of the last task to block.
In an application where there are no tasks ready to run
when BIOS_start() is called, the allBlockedFunc function is
called within the BIOS_start() thread which runs on the system/ISR
stack.
By default, allBlockedFunc is initialized to point to an internal
function that simply returns.
By adding the following lines to the config script, the Idle
functions will run whenever all tasks are blocked:
Task.enableIdleTask = false;
Task.allBlockedFunc = Idle.run;
SEE
CONSTRAINTS
The configured allBlockedFunc is designed to be called repeatedly.
It must return in order for the task scheduler to check if all
tasks are STILL blocked and if not, run the highest priority task
currently ready to run.
The configured allBlockedFunc function is called with interrupts
disabled. If your function must run with interrupts enabled,
surround the body of your code with Hwi_enable()/Hwi_restore()
function calls per the following example:
Void yourFunc() {
UInt hwiKey;
hwiKey = Hwi_enable();
... // your code here
Hwi_restore(hwiKey);
}
C SYNOPSIS
config Task.defaultStackHeap // module-wide |
|
Default Mem heap used for all dynamically created task stacks
XDCscript usage |
meta-domain |
DETAILS
Default is null.
C SYNOPSIS
config Task.defaultStackSize // module-wide |
|
Default stack size (in MAUs) used for all tasks
XDCscript usage |
meta-domain |
Task.defaultStackSize = SizeT undefined;
DETAILS
Default is obtained from the family-specific TaskSupport module
(e.g.
ti.sysbios.family.arm.m3.TaskSupport,
ti.sysbios.family.c62.TaskSupport).
C SYNOPSIS
config Task.deleteTerminatedTasks // module-wide |
|
Automatically delete terminated tasks
XDCscript usage |
meta-domain |
Task.deleteTerminatedTasks = Bool false;
DETAILS
If this feature is enabled, an Idle function is installed that
deletes dynamically created Tasks that have terminated either
by falling through their task function or by explicitly calling
Task_exit().
A list of terminated Tasks that were created dynmically is
maintained internally. Each invocation of the installed Idle function
deletes the first Task on this list. This one-at-a-time process
continues until the list is empty.
NOTE
This feature is disabled by default.
If this feature is enable, the user's application must not
also delete terminated tasks or undefined and/or potentially
catastrophic behavior will result.
C SYNOPSIS
config Task.hooks // module-wide |
|
Const array that holds the HookSet objects
XDCscript usage |
meta-domain |
DETAILS
See
Hook Functions for details about HookSets.
C SYNOPSIS
config Task.initStackFlag // module-wide |
|
Initialize stack with known value for stack checking at runtime
(see checkStackFlag)
XDCscript usage |
meta-domain |
Task.initStackFlag = Bool true;
DETAILS
This is also useful for inspection of stack in debugger or core
dump utilities.
Default is true.
C SYNOPSIS
config Task.numPriorities // module-wide |
|
Number of Task priorities supported. Default is 16
XDCscript usage |
meta-domain |
Task.numPriorities = UInt 16;
DETAILS
The maximum number of priorities supported is
target specific and depends on the number of
bits in a UInt data type. For 6x and ARM devices
the maximum number of priorities is therefore 32.
For 28x, 55x, and MSP430 devices, the maximum number of
priorities is 16.
C SYNOPSIS
metaonly config Task.checkStackFlag // module-wide |
|
Check 'from' and 'to' task stacks before task context switch
XDCscript usage |
meta-domain |
Task.checkStackFlag = Bool true;
DETAILS
The check consists of testing the top of stack value against
its initial value (see
initStackFlag). If it is no
longer at this value, the assumption is that the task has
overrun its stack. If the test fails, then the
E_stackOverflow error is raised.
Runtime stack checking is only performed if
initStackFlag is
also true.
Default is true.
To enable or disable full stack checking, you should set both this
flag and the
ti.sysbios.hal.Hwi.checkStackFlag.
metaonly config Task.common$ // module-wide |
|
Common module configuration parameters
XDCscript usage |
meta-domain |
DETAILS
All modules have this configuration parameter. Its name
contains the '$' character to ensure it does not conflict with
configuration parameters declared by the module. This allows
new configuration parameters to be added in the future without
any chance of breaking existing modules.
metaonly config Task.defaultStackSection // module-wide |
|
Default memory section used for all statically created task stacks
XDCscript usage |
meta-domain |
Task.defaultStackSection = String undefined;
DETAILS
The default stack section name is target/device specific.
For C6x targets it is ".far:taskStackSection".
For C28x targets it is ".taskStackSection".
For all other targets it is ".bss:taskStackSection".
By default, all statically created task stacks are grouped together
into the defaultStackSection and placed where ever
the target specific defaultStackSection base section name
(ie .bss, .far, .ebss) is placed.
To place all task stacks into a different memory segment,
add the following to your config script:
Program.sectMap[Task.defaultStackSection] = new Program.SectionSpec();
Program.sectMap[Task.defaultStackSection].loadSegment =
"yourMemorySegment";
To group all task stacks into a different section AND place that
section into a specific memory segment, add the following to your
config script:
Task.defaultStackSection = ".yourSectionName";
Program.sectMap[Task.defaultStackSection] = new Program.SectionSpec();
Program.sectMap[Task.defaultStackSection].loadSegment =
"yourMemorySegment";
Where "yourSectionName" can be just about anything, and
"yourMemorySegment"
must be a memory segment defined for your board.
metaonly config Task.enableIdleTask // module-wide |
|
Create a task (of priority 0) to run the Idle functions in
XDCscript usage |
meta-domain |
Task.enableIdleTask = Bool true;
DETAILS
When set to true, a task is created that continuously calls the
Idle_run() function, which, in turn calls each of
the configured Idle functions.
When set to false, no Idle Task is created and it is up to the
user to call the Idle_run() function if the configured Idle
functions need to be run. Or, by adding the following lines to
the config script, the Idle functions will run whenever all
tasks are blocked (
Task.allBlockedFunc):
Task.enableIdleTask = false;
Task.allBlockedFunc = Idle.run;
Default is true.
SEE
metaonly config Task.idleTaskStackSection // module-wide |
|
Idle task stack section
XDCscript usage |
meta-domain |
Task.idleTaskStackSection = String undefined;
DETAILS
Default is inherited from module config defaultStackSection;
metaonly config Task.idleTaskStackSize // module-wide |
|
Idle task stack size in MAUs
XDCscript usage |
meta-domain |
Task.idleTaskStackSize = SizeT undefined;
DETAILS
Default is inherited from module config defaultStackSize.
metaonly config Task.idleTaskVitalTaskFlag // module-wide |
|
Idle task's vitalTaskFlag.
(see vitalTaskFlag)
XDCscript usage |
meta-domain |
Task.idleTaskVitalTaskFlag = Bool true;
DETAILS
Default is true.
metaonly Task.addHookSet() // module-wide |
|
addHookSet is used in a config file to add a hook set
XDCscript usage |
meta-domain |
ARGUMENTS
hook
structure of type HookSet
DETAILS
Configures a set of hook functions for the
Task module. Each set contains these hook functions:
- Register: A function called before any statically created tasks
are initialized at runtime. The register hook is called at boot time
before main() and before interrupts are enabled.
- Create: A function that is called when a task is created.
This includes tasks that are created statically and those
created dynamically using create or construct.
The create hook is called outside of a Task_disable/enable block and
before the task has been added to the ready list.
- Ready: A function that is called when a task becomes ready to run.
The ready hook is called from within a Task_disable/enable block with
interrupts enabled.
- Switch: A function that is called just before a task switch
occurs. The 'prev' and 'next' task handles are passed to the Switch
hook. 'prev' is set to NULL for the initial task switch that occurs
during SYS/BIOS startup. The Switch hook is called from within a
Task_disable/enable block with interrupts enabled.
- Exit: A function that is called when a task exits using
exit. The exit hook is passed the handle of the exiting
task. The exit hook is called outside of a Task_disable/enable block
and before the task has been removed from the kernel lists.
- Delete: A function that is called when any task is deleted at
run-time with delete. The delete hook is called outside
of a Task_disable/enable block.
Hook functions can only be configured statically.
See
Hook Functions for more details.
HookSet structure elements may be omitted, in which case those
elements will not exist.
For example, the following configuration code defines a HookSet:
// Hook Set 1
Task.addHookSet({
registerFxn: '&myRegister1',
createFxn: '&myCreate1',
readyFxn: '&myReady1',
switchFxn: '&mySwitch1',
exitFxn: '&myExit1',
deleteFxn: '&myDelete1'
});
metaonly Task.getNickName() // module-wide |
|
XDCscript usage |
meta-domain |
Task.getNickName(Any tskView) returns String
Instance Config Parameters |
|
XDCscript usage |
meta-domain |
var params = new Task.Params;
// Instance config-params object
params.arg0 = UArg 0;
// Task function argument. Default is 0
params.arg1 = UArg 0;
// Task function argument. Default is 0
params.env = Ptr null;
// Environment data struct
params.priority = Int 1;
// Task priority (0 to numPriorities-1 or -1).
Default is 1
params.stack = Ptr null;
// Task stack pointer. Default = null
// Mem heap used for dynamically created task stack
params.stackSection = String undefined;
// Mem section used for statically created task stacks
params.stackSize = SizeT 0;
// Task stack size in MAUs
params.vitalTaskFlag = Bool true;
// Exit system immediately when the last task with this
flag set to TRUE has terminated
config Task.arg0 // instance |
|
Task function argument. Default is 0
XDCscript usage |
meta-domain |
var params = new Task.Params;
...
params.arg0 = UArg 0;
C SYNOPSIS
config Task.arg1 // instance |
|
Task function argument. Default is 0
XDCscript usage |
meta-domain |
var params = new Task.Params;
...
params.arg1 = UArg 0;
C SYNOPSIS
config Task.env // instance |
|
Environment data struct
XDCscript usage |
meta-domain |
var params = new Task.Params;
...
params.env = Ptr null;
C SYNOPSIS
config Task.priority // instance |
|
Task priority (0 to numPriorities-1 or -1).
Default is 1
XDCscript usage |
meta-domain |
var params = new Task.Params;
...
params.priority = Int 1;
C SYNOPSIS
config Task.stack // instance |
|
Task stack pointer. Default = null
XDCscript usage |
meta-domain |
var params = new Task.Params;
...
params.stack = Ptr null;
DETAILS
Null indicates that the stack is to be allocated by create().
Example: To statically initialize "tsk0"'s stack to a literal
address, use the following syntax:
Program.global.tsk0.stack = $addr(literal);
C SYNOPSIS
config Task.stackHeap // instance |
|
Mem heap used for dynamically created task stack
XDCscript usage |
meta-domain |
var params = new Task.Params;
...
DETAILS
The default value of NULL means that the module config
defaultStackHeap is used.
C SYNOPSIS
config Task.stackSize // instance |
|
Task stack size in MAUs
XDCscript usage |
meta-domain |
var params = new Task.Params;
...
params.stackSize = SizeT 0;
DETAILS
The default value of 0 means that the module config
defaultStackSize is used.
C SYNOPSIS
config Task.vitalTaskFlag // instance |
|
Exit system immediately when the last task with this
flag set to TRUE has terminated
XDCscript usage |
meta-domain |
var params = new Task.Params;
...
params.vitalTaskFlag = Bool true;
DETAILS
Default is true.
C SYNOPSIS
metaonly config Task.stackSection // instance |
|
Mem section used for statically created task stacks
XDCscript usage |
meta-domain |
var params = new Task.Params;
...
params.stackSection = String undefined;
DETAILS
Default is inherited from module config defaultStackSection.
Instance Creation |
|
XDCscript usage |
meta-domain |
// Allocate instance config-params
params.config = ...
// Assign individual configs
var inst = Task.create(Void(*)(UArg,UArg) fxn, params);
// Create an instance-object
ARGUMENTS
fxn
Task Function
params
per-instance config params, or NULL to select default values (target-domain only)
eb
active error-handling block, or NULL to select default policy (target-domain only)
DETAILS
Task_create creates a new task object. If successful, Task_create
returns the handle of the new task object. If unsuccessful,
Task_create returns NULL unless it aborts.
The fxn parameter uses the
FuncPtr type to pass a pointer to
the function the Task object should run. For example, if myFxn is a
function in your program, your C code can create a Task object
to call that
function as follows:
Task_Params taskParams;
// Create task with priority 15
Task_Params_init(&taskParams);
taskParams.stackSize = 512;
taskParams.priority = 15;
Task_create((Task_FuncPtr)myFxn, &taskParams, &eb);
The following statements statically create a task in the
configuration file:
var params = new Task.Params;
params.instance.name = "tsk0";
params.arg0 = 1;
params.arg1 = 2;
params.priority = 1;
Task.create('&tsk0_func', params);
If NULL is passed instead of a pointer to an actual Task_Params
struct, a
default set of parameters is used. The "eb" is an error block that
you can use
to handle errors that may occur during Task object creation.
The newly created task is placed in
Mode_READY mode, and is
scheduled to begin concurrent execution of the following function
call:
As a result of being made ready to run, the task runs any
application-wide Ready functions that have been specified.
Task_exit is automatically called if and when the task returns
from fxn.
Create Hook Functions
You can specify application-wide Create hook functions in your config
file that run whenever a task is created. This includes tasks that
are created statically and those created dynamically using
Task_create.
For Task objects created statically, Create functions are called
during the Task module initialization phase of the program startup
process prior to main().
For Task objects created dynamically, Create functions
are called after the task handle has been initialized but before the
task has been placed on its ready queue.
Any SYS/BIOS function can be called from Create functions.
SYS/BIOS passes the task handle of the task being created to each of
the Create functions.
All Create function declarations should be similar to this:
Void myCreateFxn(Task_Handle task);
CONSTRAINTS
- The fxn parameter and the name attribute cannot be NULL.
- The priority attribute must be less than or equal to
(numPriorities - 1) and greater than or equal to one (1)
(priority 0 is owned by the Idle task).
- The priority can be set to -1 for tasks that will not execute
until another task changes the priority to a positive value.
- The stackHeap attribute must identify a valid memory Heap.