Texas Instruments TMS320 User Manual page 147

Dsp/bios v5.40
Hide thumbs Also See for TMS320:
Table of Contents

Advertisement

4.4.3
Testing for Stack Overflow
❏ The running task becomes TSK_TERMINATED by calling TSK_exit,
which is automatically called if and when a task returns from its top-level
function. After all tasks have returned, the TSK Manager terminates
program execution by calling SYS_exit with a status code of 0.
❏ The running task becomes TSK_BLOCKED when it calls a function (for
example, SEM_pend or TSK_sleep) that causes the current task to
suspend its execution; tasks can move into this state when they are
performing certain I/O operations, awaiting availability of some shared
resource, or idling.
❏ The running task becomes TSK_READY and is preempted whenever
some other, higher-priority task becomes ready to run. TSK_setpri can
cause this type of transition if the priority of the current task is no longer
the highest in the system. A task can also use TSK_yield to yield to other
tasks with the same priority. A task that yields becomes ready to run.
A task that is currently TSK_BLOCKED transitions to the ready state in
response to a particular event: completion of an I/O operation, availability of
a shared resource, the elapse of a specified period of time, and so forth. By
virtue of becoming TSK_READY, this task is scheduled for execution
according to its priority level; and, of course, this task immediately transitions
to the running state if its priority is higher than the currently executing task.
TSK schedules tasks of equal priority on a first-come, first-served basis.
When a task uses more memory than its stack has been allocated, it can write
into an area of memory used by another task or data. This results in
unpredictable and potentially fatal consequences. Therefore, a means of
checking for stack overflow is useful.
Two functions, TSK_checkstacks, and TSK_stat, can be used to watch stack
size. The structure returned by TSK_stat contains both the size of its stack
and the maximum number of MADUs ever used on its stack, so this code
segment could be used to warn of a nearly full stack:
TSK_Stat statbuf;
TSK_stat(TSK_self(), &statbuf); /* call func to get status */
if (statbuf.used > (statbuf.attrs.stacksize * 9 / 10)) {
LOG_printf(&trace, "Over 90% of task's stack is in use.\n")
}
See the TSK_stat and TSK_checkstacks sections in the TMS320 DSP/BIOS
API Reference Guide for your platform, for a description and examples of
their use.
/* declare buffer */
Thread Scheduling
Tasks
4-43

Advertisement

Table of Contents
loading

Table of Contents