User`s guide

Timers, Interrupts, and the System Clock
4-72
4.8.3 Example—System Clock
Example 4-17, 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. This program is included in the
c:\ti\examples\target\bios\clktest folder where target represents your
platform. The trace log output for the code in Example 4-17 would be similar
to that shown in Example 4-20.
Example 4-17. Using the System Clock to Drive a Task
/* ======== 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());
}