2021-03-03 13:22:26 +00:00
|
|
|
#![cfg_attr(target_os = "none", no_std)]
|
|
|
|
|
#![cfg_attr(target_os = "none", no_main)]
|
|
|
|
|
|
2021-03-25 03:03:42 +00:00
|
|
|
const EXTRA_KEY: usize = 42;
|
|
|
|
|
|
|
|
|
|
fn sleep_loop_4(sleep_ms: usize, conn: usize, pid: usize, extra: usize) {
|
2021-03-18 12:10:58 +00:00
|
|
|
let tid = xous::current_tid().unwrap();
|
2021-03-25 03:03:42 +00:00
|
|
|
let conn = conn as _;
|
|
|
|
|
// let pid = xous::current_pid().unwrap().get();
|
|
|
|
|
log::info!("My thread number is {}, sleeping 0x{:08x} ({}) ms and EXTRA: {}", tid, sleep_ms, sleep_ms, extra);
|
|
|
|
|
assert_eq!(extra, EXTRA_KEY, "extra key in arg 4 didn't match -- was {}, not {}", extra, EXTRA_KEY);
|
2021-03-18 12:10:58 +00:00
|
|
|
|
2021-03-23 11:53:54 +00:00
|
|
|
let mut loop_count = 0;
|
2021-03-18 12:10:58 +00:00
|
|
|
loop {
|
2021-03-23 11:53:54 +00:00
|
|
|
// log::info!(
|
|
|
|
|
// "TEST THREAD {}: {}ms Number of times slept: {}",
|
|
|
|
|
// tid,
|
|
|
|
|
// sleep_ms,
|
|
|
|
|
// loop_count
|
|
|
|
|
// );
|
2021-03-25 03:03:42 +00:00
|
|
|
let start_time = ticktimer_server::elapsed_ms(conn).unwrap();
|
|
|
|
|
ticktimer_server::sleep_ms(conn, sleep_ms).unwrap();
|
|
|
|
|
let end_time = ticktimer_server::elapsed_ms(conn).unwrap();
|
2021-03-23 11:53:54 +00:00
|
|
|
log::info!(
|
2021-03-24 04:51:06 +00:00
|
|
|
"TEST THREAD {}:{}: target {}ms, {} loops: Sleep finished (uptime: {}, took {} ms)",
|
|
|
|
|
pid,
|
2021-03-23 11:53:54 +00:00
|
|
|
tid,
|
|
|
|
|
sleep_ms,
|
|
|
|
|
loop_count,
|
|
|
|
|
end_time,
|
|
|
|
|
end_time - start_time,
|
|
|
|
|
);
|
|
|
|
|
loop_count += 1;
|
2021-03-03 13:22:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 03:03:42 +00:00
|
|
|
fn sleep_loop_3(sleep_ms: usize, conn: usize, pid: usize) {
|
|
|
|
|
sleep_loop_4(sleep_ms, conn, pid, EXTRA_KEY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn sleep_loop_2(sleep_ms: usize, conn: usize) {
|
|
|
|
|
sleep_loop_3(sleep_ms, conn, xous::current_pid().unwrap().get() as _);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn sleep_loop_1(sleep_ms: usize) {
|
|
|
|
|
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
|
|
|
|
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
|
|
|
sleep_loop_2(sleep_ms, ticktimer_conn as _);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn sleep_loop_0() {
|
|
|
|
|
let sleep_ms = (xous::current_pid().unwrap().get() as usize) * (xous::current_tid().unwrap() as usize);
|
|
|
|
|
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
|
|
|
|
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
|
|
|
sleep_loop_2(sleep_ms, ticktimer_conn as _);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 12:10:58 +00:00
|
|
|
#[xous::xous_main]
|
|
|
|
|
fn test_main() -> ! {
|
2021-03-25 03:03:42 +00:00
|
|
|
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
|
|
|
|
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
|
|
|
|
2021-03-18 12:10:58 +00:00
|
|
|
log_server::init_wait().unwrap();
|
2021-03-25 03:03:42 +00:00
|
|
|
let pid = xous::current_pid().unwrap().get() as usize;
|
|
|
|
|
|
|
|
|
|
xous::create_thread_0(sleep_loop_0).unwrap();
|
|
|
|
|
xous::create_thread_1(sleep_loop_1, 4 * pid).unwrap();
|
|
|
|
|
xous::create_thread_2(sleep_loop_2, 10 * pid, ticktimer_conn as _).unwrap();
|
2021-03-25 03:31:40 +00:00
|
|
|
xous::create_thread_3(sleep_loop_3, 42 * pid, ticktimer_conn as _, pid).unwrap();
|
2021-03-25 03:03:42 +00:00
|
|
|
xous::create_thread_4(sleep_loop_4, 180 * pid, ticktimer_conn as _, pid, EXTRA_KEY).unwrap();
|
2021-03-03 13:22:26 +00:00
|
|
|
|
|
|
|
|
loop {
|
2021-03-18 12:10:58 +00:00
|
|
|
xous::wait_event();
|
2021-03-03 13:22:26 +00:00
|
|
|
}
|
|
|
|
|
}
|