35 lines
884 B
Rust
35 lines
884 B
Rust
use core::sync::atomic::{AtomicBool, Ordering};
|
|
|
|
const NLOOPS: i32 = 5;
|
|
|
|
static WRONG_TICK: AtomicBool = AtomicBool::new(false);
|
|
|
|
fn sleep_periodic(period: rt::tick::Utick) {
|
|
rt::task::drop_privilege();
|
|
let mut last_wake_tick = 0;
|
|
|
|
for _ in 0..NLOOPS {
|
|
rt::task::sleep_periodic(&mut last_wake_tick, period);
|
|
let wake_tick = rt::tick::count();
|
|
if wake_tick != last_wake_tick {
|
|
WRONG_TICK.store(true, Ordering::Release);
|
|
}
|
|
}
|
|
|
|
// Only the second task to finish will call rt_stop.
|
|
rt::semaphore!(STOP_SEM, 1);
|
|
if !STOP_SEM.try_wait() {
|
|
rt::stop();
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
rt::task!(sleep_periodic(5), rt::task::STACK_MIN, 2);
|
|
rt::task!(sleep_periodic(10), rt::task::STACK_MIN, 1);
|
|
rt::start();
|
|
|
|
if WRONG_TICK.load(Ordering::Acquire) {
|
|
panic!("a task woke up at the wrong tick");
|
|
}
|
|
}
|