Texas Instruments TMS320 User Manual page 179

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

Advertisement

4.9.3
Example—System Clock
Example 4-16. Using the System Clock to Drive a Task
Example 4-16, clktest.c, shows a simple use of the DSP/BIOS functions that
use the system clock, TSK_time and TSK_sleep. The task, labeled task, in
clktest.c sleeps for 1000 ticks before it is awakened by the task scheduler.
Since no other tasks have been created, the program runs the idle functions
while task is blocked. The program assumes that the system clock is
configured and driven by PRD_clock. The trace log output for the code in
Example 4-16 would be similar to that shown in Example 4-17.
/*
======== clktest.c =======
*
In this example, a task goes to sleep for 1 sec and
*
prints the time after it wakes up. */
#include <std.h>
#include <log.h>
#include <clk.h>
#include <tsk.h>
extern LOG_Obj trace;
/*
======== main ======== */
Void main()
{
LOG_printf(&trace, "clktest example started.\n");
}
Void taskFxn()
{
Uns ticks;
LOG_printf(&trace, "The time in task is: %d ticks",
(Int)TSK_time());
ticks = (1000 * CLK_countspms()) / CLK_getprd();
LOG_printf(&trace, "task going to sleep for 1 second... ");
TSK_sleep(ticks);
LOG_printf(&trace, "...awake! Time is: %d ticks",
(Int)TSK_time());
}
Note:
Non-pointer type function arguments to LOG_printf need explicit type
casting to (Arg) as shown in the following code example:
LOG_printf(&trace, "Task %d Done", (Arg)id);
Timers, Interrupts, and the System Clock
Thread Scheduling
4-75

Advertisement

Table of Contents
loading

Table of Contents