31 lines
727 B
C++
31 lines
727 B
C++
#include <rt/sem.hpp>
|
|
#include <rt/task.hpp>
|
|
#include <rt/tick.hpp>
|
|
#include <rt/trap.hpp>
|
|
|
|
#include <rt/assert.h>
|
|
|
|
static const int nloops = 5;
|
|
|
|
static void sleep_periodic(uintptr_t period)
|
|
{
|
|
rt::task::drop_privilege();
|
|
unsigned long last_wake_tick = 0;
|
|
for (int i = 0; i < nloops; ++i)
|
|
{
|
|
rt::task::sleep_periodic(last_wake_tick, period);
|
|
rt_assert(rt::tick::count() == last_wake_tick,
|
|
"woke up at the wrong tick");
|
|
}
|
|
|
|
// Only the second task to finish will call rt::trap.
|
|
static rt::sem trap_sem(1);
|
|
if (!trap_sem.trywait())
|
|
{
|
|
rt::trap();
|
|
}
|
|
}
|
|
|
|
RT_TASK_ARG(sleep_periodic, 5, RT_STACK_MIN, 0);
|
|
RT_TASK_ARG(sleep_periodic, 10, RT_STACK_MIN, 1);
|