Tasks
4-44
4.4.4 Task Hooks
An application may specify functions to be called for various task-related
events. Such functions are called hook functions. Hook functions can be
called for program initialization, task creation (TSK_create), task deletion
(TSK_delete), task exits (TSK_exit), task readying, and task context switches
(TSK_sleep, SEM_pend, etc.). Such functions can be used to extend a task’s
context beyond the basic processor register set.
A single set of hook functions can be specified for the TSK module manager.
To create additional sets of hook functions, use the HOOK module. For
example, an application that integrates third-party software may need to
perform both its own hook functions and the hook functions required by the
third-party software. In addition, each HOOK object can maintain a private
data environment for each task.
When you configure the initial HOOK object, any TSK module hook functions
you have specified are automatically placed in a HOOK object called
HOOK_KNL. To set any properties of this object other than the Initialization
function, use the TSK module properties. To set the Initialization function
property of the HOOK_KNL object, use the HOOK object properties. If you
configure only a single set of hook functions using the TSK module, the
HOOK module is not used.
For details about hook functions, see the TSK Module and HOOK Module
topics in the TMS320 DSP/BIOS API Reference Guide for your platform.
4.4.5 Task Hooks for Extra Context
Consider, for example, a system that has special hardware registers (say, for
extended addressing) that need to be preserved on a per task basis. In
Example 4-6 the function doCreate is used to allocate a buffer to maintain
these registers on a per task basis, doDelete is used to free this buffer, and
doSwitch is used to save and restore these registers.
If task objects are created statically, the Switch function should not assume
(as Example 4-6 does) that a task’s environment is always set by the Create
function.