mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
refactor the Ticktimer API.
This commit is contained in:
parent
45239c61ef
commit
e889765caf
22 changed files with 144 additions and 219 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -1341,6 +1341,8 @@ dependencies = [
|
||||||
"heapless",
|
"heapless",
|
||||||
"log",
|
"log",
|
||||||
"log-server",
|
"log-server",
|
||||||
|
"num-derive",
|
||||||
|
"num-traits",
|
||||||
"utralib",
|
"utralib",
|
||||||
"xous",
|
"xous",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -54,14 +54,13 @@ impl Into<Message> for Opcode {
|
||||||
fn stopwatch_thread(_arg: xous::SID) {
|
fn stopwatch_thread(_arg: xous::SID) {
|
||||||
info!("BENCHMARK|stopwatch: starting");
|
info!("BENCHMARK|stopwatch: starting");
|
||||||
|
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
|
|
||||||
let shell_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_SHELL).expect("BENCHMARK|stopwatch: can't connect to main program");
|
let shell_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_SHELL).expect("BENCHMARK|stopwatch: can't connect to main program");
|
||||||
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
let mut last_time: u64 = ticktimer.elapsed_ms().unwrap();
|
||||||
let mut start_sent = false;
|
let mut start_sent = false;
|
||||||
loop {
|
loop {
|
||||||
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
|
if let Ok(elapsed_time) = ticktimer.elapsed_ms() {
|
||||||
if elapsed_time - last_time > 500 && !start_sent {
|
if elapsed_time - last_time > 500 && !start_sent {
|
||||||
last_time = elapsed_time;
|
last_time = elapsed_time;
|
||||||
xous::send_message(shell_conn, Opcode::Start.into()).expect("BENCHMARK|stopwatch: couldn't send Start message");
|
xous::send_message(shell_conn, Opcode::Start.into()).expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||||
|
|
@ -77,11 +76,11 @@ fn stopwatch_thread(_arg: xous::SID) {
|
||||||
if false {
|
if false {
|
||||||
// send a start loop message
|
// send a start loop message
|
||||||
xous::send_message(shell_conn, Opcode::Start.into()).expect("BENCHMARK|stopwatch: couldn't send Start message");
|
xous::send_message(shell_conn, Opcode::Start.into()).expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||||
ticktimer_server::sleep_ms(ticktimer_conn, 10_000).expect("couldn't sleep");
|
ticktimer.sleep_ms(ticktimer_conn, 10_000).expect("couldn't sleep");
|
||||||
// send a stop loop message
|
// send a stop loop message
|
||||||
xous::send_message(shell_conn, Opcode::Stop.into()).expect("BENCHMARK|stopwatch: couldn't send Stop message");
|
xous::send_message(shell_conn, Opcode::Stop.into()).expect("BENCHMARK|stopwatch: couldn't send Stop message");
|
||||||
// give a moment for the result to update
|
// give a moment for the result to update
|
||||||
ticktimer_server::sleep_ms(ticktimer_conn, 500).expect("couldn't sleep");
|
ticktimer.sleep_ms(ticktimer_conn, 500).expect("couldn't sleep");
|
||||||
}
|
}
|
||||||
xous::yield_slice();
|
xous::yield_slice();
|
||||||
}
|
}
|
||||||
|
|
@ -93,8 +92,7 @@ fn shell_main() -> ! {
|
||||||
info!("BENCHMARK: my PID is {}", xous::process::id());
|
info!("BENCHMARK: my PID is {}", xous::process::id());
|
||||||
|
|
||||||
info!("BENCHMARK: ticktimer");
|
info!("BENCHMARK: ticktimer");
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
|
|
||||||
let shell_server = xous_names::register_name(xous::names::SERVER_NAME_SHELL).expect("BENCHMARK: can't register server");
|
let shell_server = xous_names::register_name(xous::names::SERVER_NAME_SHELL).expect("BENCHMARK: can't register server");
|
||||||
|
|
||||||
|
|
@ -137,10 +135,10 @@ fn shell_main() -> ! {
|
||||||
if let Ok(opcode) = Opcode::try_from(&envelope.body) {
|
if let Ok(opcode) = Opcode::try_from(&envelope.body) {
|
||||||
match opcode {
|
match opcode {
|
||||||
Opcode::Start => {
|
Opcode::Start => {
|
||||||
start_time = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
start_time = ticktimer.elapsed_ms().unwrap();
|
||||||
},
|
},
|
||||||
Opcode::Stop => {
|
Opcode::Stop => {
|
||||||
stop_time = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
stop_time = ticktimer.elapsed_ms().unwrap();
|
||||||
update_result = true;
|
update_result = true;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,7 @@ mod implementation {
|
||||||
)
|
)
|
||||||
.expect("couldn't map COM CSR range");
|
.expect("couldn't map COM CSR range");
|
||||||
|
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
|
|
||||||
let mut xc = XousCom {
|
let mut xc = XousCom {
|
||||||
csr: CSR::new(csr.as_mut_ptr() as *mut u32),
|
csr: CSR::new(csr.as_mut_ptr() as *mut u32),
|
||||||
|
|
@ -108,12 +107,12 @@ mod implementation {
|
||||||
|
|
||||||
pub fn wait_txrx(&mut self, tx: u16, timeout: Option<u32>) -> u16 {
|
pub fn wait_txrx(&mut self, tx: u16, timeout: Option<u32>) -> u16 {
|
||||||
if timeout.is_some() {
|
if timeout.is_some() {
|
||||||
let curtime = ticktimer_server::elapsed_ms(self.ticktimer)
|
let curtime = self.ticktimer.elapsed_ms()
|
||||||
.expect("couldn't connect to ticktimer");
|
.expect("couldn't connect to ticktimer");
|
||||||
let mut timed_out = false;
|
let mut timed_out = false;
|
||||||
let to = timeout.unwrap() as u64;
|
let to = timeout.unwrap() as u64;
|
||||||
while self.csr.rf(utra::com::STATUS_HOLD) == 1 && !timed_out {
|
while self.csr.rf(utra::com::STATUS_HOLD) == 1 && !timed_out {
|
||||||
if (ticktimer_server::elapsed_ms(self.ticktimer)
|
if (self.ticktimer.elapsed_ms()
|
||||||
.expect("couldn't connect to ticktimer")
|
.expect("couldn't connect to ticktimer")
|
||||||
- curtime)
|
- curtime)
|
||||||
> to
|
> to
|
||||||
|
|
|
||||||
|
|
@ -376,17 +376,16 @@ fn do_agent(cmd: &mut String<U2048>, com_cid: xous::CID, pds_list: &mut Vec<Stri
|
||||||
println!("rx stats request disabled!!");
|
println!("rx stats request disabled!!");
|
||||||
//get_rx_stats_agent(com_cid).unwrap();
|
//get_rx_stats_agent(com_cid).unwrap();
|
||||||
} else if tokens[1].trim() == "commit_pds" {
|
} else if tokens[1].trim() == "commit_pds" {
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
|
|
||||||
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
let mut last_time: u64 = ticktimer.elapsed_ms().unwrap();
|
||||||
for pds in pds_list.iter() {
|
for pds in pds_list.iter() {
|
||||||
let mut sendable_string = xous::String::<512>::new();
|
let mut sendable_string = xous::String::<512>::new();
|
||||||
write!(&mut sendable_string, "{}", pds);
|
write!(&mut sendable_string, "{}", pds);
|
||||||
println!("{}", sendable_string);
|
println!("{}", sendable_string);
|
||||||
send_pds_line(com_cid, &sendable_string);
|
send_pds_line(com_cid, &sendable_string);
|
||||||
loop {
|
loop {
|
||||||
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
|
if let Ok(elapsed_time) = ticktimer.elapsed_ms() {
|
||||||
if elapsed_time - last_time > 250 {
|
if elapsed_time - last_time > 250 {
|
||||||
last_time = elapsed_time;
|
last_time = elapsed_time;
|
||||||
break;
|
break;
|
||||||
|
|
@ -480,8 +479,7 @@ fn xmain() -> ! {
|
||||||
let agent_server_sid = xous_names::register_name(xous::names::SERVER_NAME_FCCAGENT).expect("FCCAGENT: can't register server");
|
let agent_server_sid = xous_names::register_name(xous::names::SERVER_NAME_FCCAGENT).expect("FCCAGENT: can't register server");
|
||||||
let agent_server_client = xous_names::request_connection_blocking(xous::names::SERVER_NAME_FCCAGENT).expect("FCCAGENT: can't connect to COM");
|
let agent_server_client = xous_names::request_connection_blocking(xous::names::SERVER_NAME_FCCAGENT).expect("FCCAGENT: can't connect to COM");
|
||||||
|
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
|
|
||||||
let mut uart = Uart::new(agent_server_client);
|
let mut uart = Uart::new(agent_server_client);
|
||||||
|
|
||||||
|
|
@ -501,7 +499,7 @@ fn xmain() -> ! {
|
||||||
uart.enable_rx();
|
uart.enable_rx();
|
||||||
|
|
||||||
print!("\n\r\n\r*** FCC agent ***\n\r\n\r");
|
print!("\n\r\n\r*** FCC agent ***\n\r\n\r");
|
||||||
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
let mut last_time: u64 = ticktimer.elapsed_ms().unwrap();
|
||||||
let mut pds_list: Vec<String<U512>, U16> = Vec::new();
|
let mut pds_list: Vec<String<U512>, U16> = Vec::new();
|
||||||
let mut repeat = false;
|
let mut repeat = false;
|
||||||
let mut phase = 0;
|
let mut phase = 0;
|
||||||
|
|
@ -543,7 +541,7 @@ fn xmain() -> ! {
|
||||||
_ => () //xous::yield_slice(), // no message received, idle
|
_ => () //xous::yield_slice(), // no message received, idle
|
||||||
}
|
}
|
||||||
// Periodic tasks
|
// Periodic tasks
|
||||||
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
|
if let Ok(elapsed_time) = ticktimer.elapsed_ms() {
|
||||||
if elapsed_time - last_time > 20_000 {
|
if elapsed_time - last_time > 20_000 {
|
||||||
last_time = elapsed_time;
|
last_time = elapsed_time;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -188,8 +188,7 @@ fn xmain() -> ! {
|
||||||
let gam_sid = xous_names::register_name(xous::names::SERVER_NAME_GAM).expect("GAM: can't register server");
|
let gam_sid = xous_names::register_name(xous::names::SERVER_NAME_GAM).expect("GAM: can't register server");
|
||||||
info!("GAM: starting up...");
|
info!("GAM: starting up...");
|
||||||
|
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
|
|
||||||
let gfx_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_GFX).expect("GAM: can't connect to COM");
|
let gfx_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_GFX).expect("GAM: can't connect to COM");
|
||||||
let trng_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_TRNG).expect("GAM: can't connect to TRNG");
|
let trng_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_TRNG).expect("GAM: can't connect to TRNG");
|
||||||
|
|
@ -228,7 +227,7 @@ fn xmain() -> ! {
|
||||||
xous::create_thread_4(status_thread, gid[0] as _, gid[1] as _, gid[2] as _, gid[3] as _).expect("GAM: couldn't create status thread");
|
xous::create_thread_4(status_thread, gid[0] as _, gid[1] as _, gid[2] as _, gid[3] as _).expect("GAM: couldn't create status thread");
|
||||||
|
|
||||||
let mut powerdown_requested = false;
|
let mut powerdown_requested = false;
|
||||||
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
let mut last_time: u64 = ticktimer.elapsed_ms().unwrap();
|
||||||
info!("GAM: entering main loop");
|
info!("GAM: entering main loop");
|
||||||
loop {
|
loop {
|
||||||
let envelope = xous::receive_message(gam_sid).unwrap();
|
let envelope = xous::receive_message(gam_sid).unwrap();
|
||||||
|
|
@ -269,7 +268,7 @@ fn xmain() -> ! {
|
||||||
if powerdown_requested {
|
if powerdown_requested {
|
||||||
continue; // don't allow any redraws if a powerdown is requested
|
continue; // don't allow any redraws if a powerdown is requested
|
||||||
}
|
}
|
||||||
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
|
if let Ok(elapsed_time) = ticktimer.elapsed_ms() {
|
||||||
if elapsed_time - last_time > 33 { // rate limit updates, no point in going faster than the eye can see
|
if elapsed_time - last_time > 33 { // rate limit updates, no point in going faster than the eye can see
|
||||||
last_time = elapsed_time;
|
last_time = elapsed_time;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ pub fn status_thread(canvas_gid_0: usize, canvas_gid_1: usize, canvas_gid_2: usi
|
||||||
let status_sid = xous_names::register_name(xous::names::SERVER_NAME_STATUS).expect("GAM|status: can't register server");
|
let status_sid = xous_names::register_name(xous::names::SERVER_NAME_STATUS).expect("GAM|status: can't register server");
|
||||||
|
|
||||||
let gam_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_GAM).expect("GAM|status: can't connect to GAM");
|
let gam_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_GAM).expect("GAM|status: can't connect to GAM");
|
||||||
let ticktimer_conn = xous::connect(xous::SID::from_bytes(b"ticktimer-server").unwrap()).unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let com_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_COM).expect("GAM|status: can't connect to COM");
|
let com_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_COM).expect("GAM|status: can't connect to COM");
|
||||||
|
|
||||||
if debug1{info!("GAM|status: getting screen size");}
|
if debug1{info!("GAM|status: getting screen size");}
|
||||||
|
|
@ -46,7 +46,7 @@ pub fn status_thread(canvas_gid_0: usize, canvas_gid_1: usize, canvas_gid_2: usi
|
||||||
battstats_tv.margin = Point::new(0, 0);
|
battstats_tv.margin = Point::new(0, 0);
|
||||||
|
|
||||||
let mut stats: BattStats;
|
let mut stats: BattStats;
|
||||||
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
let mut last_time: u64 = ticktimer.elapsed_ms().unwrap();
|
||||||
let mut stats_phase: usize = 0;
|
let mut stats_phase: usize = 0;
|
||||||
let mut last_seconds: usize = ((last_time / 1000) % 60) as usize;
|
let mut last_seconds: usize = ((last_time / 1000) % 60) as usize;
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ pub fn status_thread(canvas_gid_0: usize, canvas_gid_1: usize, canvas_gid_2: usi
|
||||||
_ => xous::yield_slice(),
|
_ => xous::yield_slice(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
|
if let Ok(elapsed_time) = ticktimer.elapsed_ms() {
|
||||||
let now_seconds: usize = ((elapsed_time / 1000) % 60) as usize;
|
let now_seconds: usize = ((elapsed_time / 1000) % 60) as usize;
|
||||||
if now_seconds != last_seconds {
|
if now_seconds != last_seconds {
|
||||||
last_seconds = now_seconds;
|
last_seconds = now_seconds;
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ fn sleep_loop_4(main_conn: usize, sleep_ms: usize, ticktimer_conn: usize, pid: u
|
||||||
// sleep_ms,
|
// sleep_ms,
|
||||||
// loop_count
|
// loop_count
|
||||||
// );
|
// );
|
||||||
let start_time = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
let start_time = ticktimer.elapsed_ms().unwrap();
|
||||||
ticktimer_server::sleep_ms(ticktimer_conn, sleep_ms).unwrap();
|
ticktimer.sleep_ms(ticktimer_conn, sleep_ms).unwrap();
|
||||||
let end_time = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
let end_time = ticktimer.elapsed_ms().unwrap();
|
||||||
log::info!(
|
log::info!(
|
||||||
"TEST THREAD {}:{}: target {}ms, {} loops: Sleep finished (uptime: {}, took {} ms)",
|
"TEST THREAD {}:{}: target {}ms, {} loops: Sleep finished (uptime: {}, took {} ms)",
|
||||||
pid,
|
pid,
|
||||||
|
|
@ -60,8 +60,7 @@ fn sleep_loop_3(main_conn: usize, sleep_ms: usize, ticktimer_conn: usize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sleep_loop_2(main_conn: usize, sleep_ms: usize) {
|
fn sleep_loop_2(main_conn: usize, sleep_ms: usize) {
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap() as usize;
|
|
||||||
sleep_loop_3(main_conn, sleep_ms, ticktimer_conn);
|
sleep_loop_3(main_conn, sleep_ms, ticktimer_conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,8 +79,7 @@ fn sleep_loop_0() {
|
||||||
fn test_main() -> ! {
|
fn test_main() -> ! {
|
||||||
log_server::init_wait().unwrap();
|
log_server::init_wait().unwrap();
|
||||||
|
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
|
|
||||||
let main_server = xous::create_server().unwrap();
|
let main_server = xous::create_server().unwrap();
|
||||||
let server_conn = xous::connect(main_server).unwrap();
|
let server_conn = xous::connect(main_server).unwrap();
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ mod implementation {
|
||||||
/// remember the last keycode since a change event
|
/// remember the last keycode since a change event
|
||||||
lastcode: Option<Vec<RowCol, U16>>,
|
lastcode: Option<Vec<RowCol, U16>>,
|
||||||
/// connection to the timer for real-time events
|
/// connection to the timer for real-time events
|
||||||
ticktimer: xous::CID,
|
ticktimer: Ticktimer,
|
||||||
/// mapping for ScanCode translation
|
/// mapping for ScanCode translation
|
||||||
map: KeyMap,
|
map: KeyMap,
|
||||||
/// delay in ms before a key is considered to be repeating
|
/// delay in ms before a key is considered to be repeating
|
||||||
|
|
@ -227,10 +227,9 @@ mod implementation {
|
||||||
)
|
)
|
||||||
.expect("couldn't map Keyboard CSR range");
|
.expect("couldn't map Keyboard CSR range");
|
||||||
|
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let mut ticktimer = XousTickTimer::new(ticktimer_client).expect("KBD: couldn't connect to ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
|
|
||||||
let timestamp = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
let timestamp = ticktimer.elapsed_ms().unwrap();
|
||||||
let kbd = Keyboard {
|
let kbd = Keyboard {
|
||||||
csr: CSR::new(csr.as_mut_ptr() as *mut u32),
|
csr: CSR::new(csr.as_mut_ptr() as *mut u32),
|
||||||
debounce: [[0; KBD_COLS]; KBD_ROWS],
|
debounce: [[0; KBD_COLS]; KBD_ROWS],
|
||||||
|
|
@ -342,7 +341,7 @@ mod implementation {
|
||||||
// clear the pending bit
|
// clear the pending bit
|
||||||
self.csr.wfo(utra::keyboard::EV_PENDING_KEYPRESSED, 1);
|
self.csr.wfo(utra::keyboard::EV_PENDING_KEYPRESSED, 1);
|
||||||
|
|
||||||
let elapsed = ticktimer_server::elapsed_ms(self.ticktimer).unwrap() - self.timestamp;
|
let elapsed = self.ticktimer.elapsed_ms().unwrap() - self.timestamp;
|
||||||
if elapsed <= 1 {
|
if elapsed <= 1 {
|
||||||
// skip debounce processing if time elapsed is too short
|
// skip debounce processing if time elapsed is too short
|
||||||
(None, None)
|
(None, None)
|
||||||
|
|
@ -436,7 +435,7 @@ mod implementation {
|
||||||
let mut keystates: Vec<char, U4> = Vec::new();
|
let mut keystates: Vec<char, U4> = Vec::new();
|
||||||
|
|
||||||
if self.chord_active || keydowns.is_some() {
|
if self.chord_active || keydowns.is_some() {
|
||||||
let now = ticktimer_server::elapsed_ms(self.ticktimer).unwrap();
|
let now = self.ticktimer.elapsed_ms().unwrap();
|
||||||
|
|
||||||
if !self.chord_active && keydowns.is_some() {
|
if !self.chord_active && keydowns.is_some() {
|
||||||
self.chord_active = true;
|
self.chord_active = true;
|
||||||
|
|
@ -623,7 +622,7 @@ mod implementation {
|
||||||
|
|
||||||
// interpret keys in the context of the shift/alt modifiers
|
// interpret keys in the context of the shift/alt modifiers
|
||||||
if let Some(kds) = &keydowns {
|
if let Some(kds) = &keydowns {
|
||||||
self.chord_timestamp = ticktimer_server::elapsed_ms(self.ticktimer).unwrap();
|
self.chord_timestamp = self.ticktimer.elapsed_ms().unwrap();
|
||||||
// if more than one is held, the key that gets picked for the repeat function is arbitrary!
|
// if more than one is held, the key that gets picked for the repeat function is arbitrary!
|
||||||
for &rc in kds.iter() {
|
for &rc in kds.iter() {
|
||||||
let code = match self.map {
|
let code = match self.map {
|
||||||
|
|
@ -638,7 +637,7 @@ mod implementation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let now = ticktimer_server::elapsed_ms(self.ticktimer).unwrap();
|
let now = self.ticktimer.elapsed_ms().unwrap();
|
||||||
let hold: bool;
|
let hold: bool;
|
||||||
if (now - self.chord_timestamp) >= self.delay as u64 {
|
if (now - self.chord_timestamp) >= self.delay as u64 {
|
||||||
if self.rate_timestamp <= self.chord_timestamp {
|
if self.rate_timestamp <= self.chord_timestamp {
|
||||||
|
|
|
||||||
|
|
@ -37,17 +37,17 @@ pub struct I2cStateMachine {
|
||||||
state: I2cState,
|
state: I2cState,
|
||||||
index: u32, // index of the current buffer in the state machine
|
index: u32, // index of the current buffer in the state machine
|
||||||
timestamp: u64, // timestamp of the last transaction
|
timestamp: u64, // timestamp of the last transaction
|
||||||
ticktimer: xous::CID, // a connection to the ticktimer so we can measure timeouts
|
ticktimer: ticktimer_server::Ticktimer, // a connection to the ticktimer so we can measure timeouts
|
||||||
i2c_csr: utralib::CSR<u32>,
|
i2c_csr: utralib::CSR<u32>,
|
||||||
listeners: Vec<xous::CID, U32>,
|
listeners: Vec<xous::CID, U32>,
|
||||||
}
|
}
|
||||||
#[cfg(target_os = "none")]
|
#[cfg(target_os = "none")]
|
||||||
impl I2cStateMachine {
|
impl I2cStateMachine {
|
||||||
pub fn new(ticktimer: xous::CID, i2c_base: *mut u32) -> Self {
|
pub fn new(ticktimer: ticktimer_server::Ticktimer, i2c_base: *mut u32) -> Self {
|
||||||
I2cStateMachine {
|
I2cStateMachine {
|
||||||
transaction: I2cTransaction::new(),
|
transaction: I2cTransaction::new(),
|
||||||
state: I2cState::Idle,
|
state: I2cState::Idle,
|
||||||
timestamp: ticktimer_server::elapsed_ms(ticktimer).unwrap(),
|
timestamp: ticktimer.elapsed_ms().unwrap(),
|
||||||
ticktimer,
|
ticktimer,
|
||||||
i2c_csr: CSR::new(i2c_base),
|
i2c_csr: CSR::new(i2c_base),
|
||||||
index: 0,
|
index: 0,
|
||||||
|
|
@ -60,7 +60,7 @@ impl I2cStateMachine {
|
||||||
return I2cStatus::ResponseFormatError
|
return I2cStatus::ResponseFormatError
|
||||||
}
|
}
|
||||||
|
|
||||||
let now = ticktimer_server::elapsed_ms(self.ticktimer).unwrap();
|
let now = self.ticktimer.elapsed_ms().unwrap();
|
||||||
if self.state != I2cState::Idle && ((now - self.timestamp) < self.transaction.timeout_ms as u64) {
|
if self.state != I2cState::Idle && ((now - self.timestamp) < self.transaction.timeout_ms as u64) {
|
||||||
// we're in a transaction that hadn't timed out, can't accept a new one
|
// we're in a transaction that hadn't timed out, can't accept a new one
|
||||||
I2cStatus::ResponseBusy
|
I2cStatus::ResponseBusy
|
||||||
|
|
@ -145,7 +145,7 @@ impl I2cStateMachine {
|
||||||
}
|
}
|
||||||
pub fn handler(&mut self) {
|
pub fn handler(&mut self) {
|
||||||
// check if the transaction had actually timed out
|
// check if the transaction had actually timed out
|
||||||
let now = ticktimer_server::elapsed_ms(self.ticktimer).unwrap();
|
let now = self.ticktimer.elapsed_ms().unwrap();
|
||||||
if now - self.timestamp > self.transaction.timeout_ms as u64 {
|
if now - self.timestamp > self.transaction.timeout_ms as u64 {
|
||||||
// previous transaction had timed out...
|
// previous transaction had timed out...
|
||||||
self.report_timeout();
|
self.report_timeout();
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ mod implementation {
|
||||||
power_csr: utralib::CSR<u32>,
|
power_csr: utralib::CSR<u32>,
|
||||||
seed_csr: utralib::CSR<u32>,
|
seed_csr: utralib::CSR<u32>,
|
||||||
xadc_csr: utralib::CSR<u32>, // be careful with this as XADC is shared with TRNG
|
xadc_csr: utralib::CSR<u32>, // be careful with this as XADC is shared with TRNG
|
||||||
ticktimer_conn: xous::CID,
|
ticktimer: ticktimer_server::Ticktimer,
|
||||||
destruct_armed: bool,
|
destruct_armed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,7 +71,7 @@ mod implementation {
|
||||||
.expect("couldn't map GPIO CSR range");
|
.expect("couldn't map GPIO CSR range");
|
||||||
let mut gpio_csr = CSR::new(gpio_base.as_mut_ptr() as *mut u32);
|
let mut gpio_csr = CSR::new(gpio_base.as_mut_ptr() as *mut u32);
|
||||||
// setup the initial logging output
|
// setup the initial logging output
|
||||||
gpio_csr.wfo(utra::gpio::UARTSEL_UARTSEL, 0); // 0 = kernel, 1 = log, 2 = app_uart
|
gpio_csr.wfo(utra::gpio::UARTSEL_UARTSEL, 1); // 0 = kernel, 1 = log, 2 = app_uart
|
||||||
|
|
||||||
gpio_base.as_mut_ptr() as *mut u32
|
gpio_base.as_mut_ptr() as *mut u32
|
||||||
}
|
}
|
||||||
|
|
@ -144,8 +144,7 @@ mod implementation {
|
||||||
)
|
)
|
||||||
.expect("couldn't map Xadc CSR range"); // note that Xadc is "in" the TRNG because TRNG can override Xadc in hardware
|
.expect("couldn't map Xadc CSR range"); // note that Xadc is "in" the TRNG because TRNG can override Xadc in hardware
|
||||||
|
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
|
|
||||||
let mut xl = Llio {
|
let mut xl = Llio {
|
||||||
reboot_csr: CSR::new(reboot_csr.as_mut_ptr() as *mut u32),
|
reboot_csr: CSR::new(reboot_csr.as_mut_ptr() as *mut u32),
|
||||||
|
|
@ -159,7 +158,7 @@ mod implementation {
|
||||||
power_csr: CSR::new(power_csr.as_mut_ptr() as *mut u32),
|
power_csr: CSR::new(power_csr.as_mut_ptr() as *mut u32),
|
||||||
seed_csr: CSR::new(seed_csr.as_mut_ptr() as *mut u32),
|
seed_csr: CSR::new(seed_csr.as_mut_ptr() as *mut u32),
|
||||||
xadc_csr: CSR::new(xadc_csr.as_mut_ptr() as *mut u32),
|
xadc_csr: CSR::new(xadc_csr.as_mut_ptr() as *mut u32),
|
||||||
ticktimer_conn,
|
ticktimer,
|
||||||
destruct_armed: false,
|
destruct_armed: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -296,7 +295,7 @@ mod implementation {
|
||||||
}
|
}
|
||||||
pub fn ec_reset(&mut self) {
|
pub fn ec_reset(&mut self) {
|
||||||
self.power_csr.rmwf(utra::power::POWER_RESET_EC, 1);
|
self.power_csr.rmwf(utra::power::POWER_RESET_EC, 1);
|
||||||
ticktimer_server::sleep_ms(self.ticktimer_conn, 100).unwrap();
|
self.ticktimer.sleep_ms(100).unwrap();
|
||||||
self.power_csr.rmwf(utra::power::POWER_RESET_EC, 0);
|
self.power_csr.rmwf(utra::power::POWER_RESET_EC, 0);
|
||||||
}
|
}
|
||||||
pub fn ec_power_on(&mut self) {
|
pub fn ec_power_on(&mut self) {
|
||||||
|
|
@ -316,21 +315,21 @@ mod implementation {
|
||||||
match pattern {
|
match pattern {
|
||||||
VibePattern::Short => {
|
VibePattern::Short => {
|
||||||
self.power_csr.wfo(utra::power::VIBE_VIBE, 1);
|
self.power_csr.wfo(utra::power::VIBE_VIBE, 1);
|
||||||
ticktimer_server::sleep_ms(self.ticktimer_conn, 250).unwrap();
|
self.ticktimer.sleep_ms(250).unwrap();
|
||||||
self.power_csr.wfo(utra::power::VIBE_VIBE, 0);
|
self.power_csr.wfo(utra::power::VIBE_VIBE, 0);
|
||||||
},
|
},
|
||||||
VibePattern::Long => {
|
VibePattern::Long => {
|
||||||
self.power_csr.wfo(utra::power::VIBE_VIBE, 1);
|
self.power_csr.wfo(utra::power::VIBE_VIBE, 1);
|
||||||
ticktimer_server::sleep_ms(self.ticktimer_conn, 1000).unwrap();
|
self.ticktimer.sleep_ms(1000).unwrap();
|
||||||
self.power_csr.wfo(utra::power::VIBE_VIBE, 0);
|
self.power_csr.wfo(utra::power::VIBE_VIBE, 0);
|
||||||
},
|
},
|
||||||
VibePattern::Double => {
|
VibePattern::Double => {
|
||||||
self.power_csr.wfo(utra::power::VIBE_VIBE, 1);
|
self.power_csr.wfo(utra::power::VIBE_VIBE, 1);
|
||||||
ticktimer_server::sleep_ms(self.ticktimer_conn, 250).unwrap();
|
self.ticktimer.sleep_ms(250).unwrap();
|
||||||
self.power_csr.wfo(utra::power::VIBE_VIBE, 0);
|
self.power_csr.wfo(utra::power::VIBE_VIBE, 0);
|
||||||
ticktimer_server::sleep_ms(self.ticktimer_conn, 250).unwrap();
|
self.ticktimer.sleep_ms(250).unwrap();
|
||||||
self.power_csr.wfo(utra::power::VIBE_VIBE, 1);
|
self.power_csr.wfo(utra::power::VIBE_VIBE, 1);
|
||||||
ticktimer_server::sleep_ms(self.ticktimer_conn, 250).unwrap();
|
self.ticktimer.sleep_ms(250).unwrap();
|
||||||
self.power_csr.wfo(utra::power::VIBE_VIBE, 0);
|
self.power_csr.wfo(utra::power::VIBE_VIBE, 0);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -456,10 +455,9 @@ fn xmain() -> ! {
|
||||||
let mut llio = Llio::new(handler_conn, gpio_base);
|
let mut llio = Llio::new(handler_conn, gpio_base);
|
||||||
|
|
||||||
// ticktimer is a well-known server
|
// ticktimer is a well-known server
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
// create an i2c state machine handler
|
// create an i2c state machine handler
|
||||||
let mut i2c_machine = I2cStateMachine::new(ticktimer_conn, llio.get_i2c_base());
|
let mut i2c_machine = I2cStateMachine::new(ticktimer, llio.get_i2c_base());
|
||||||
|
|
||||||
if debug1{info!("LLIO: starting main loop");}
|
if debug1{info!("LLIO: starting main loop");}
|
||||||
let mut reboot_requested: bool = false;
|
let mut reboot_requested: bool = false;
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,7 @@ fn rkyv_test_client() -> ! {
|
||||||
"Hello, world! This is the client, PID {}",
|
"Hello, world! This is the client, PID {}",
|
||||||
xous::current_pid().unwrap().get()
|
xous::current_pid().unwrap().get()
|
||||||
);
|
);
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("couldn't create ticktimer object");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
|
|
||||||
rkyv_test_server::hook_log_messages(print_log_messages);
|
rkyv_test_server::hook_log_messages(print_log_messages);
|
||||||
|
|
||||||
|
|
@ -33,7 +32,7 @@ fn rkyv_test_client() -> ! {
|
||||||
let mut message_string = xous::String::<64>::new();
|
let mut message_string = xous::String::<64>::new();
|
||||||
loop {
|
loop {
|
||||||
log::info!("2 + {} = {}", idx, rkyv_test_server::add(2, idx).unwrap());
|
log::info!("2 + {} = {}", idx, rkyv_test_server::add(2, idx).unwrap());
|
||||||
ticktimer_server::sleep_ms(ticktimer_conn, 500).ok();
|
ticktimer.sleep_ms(500).ok();
|
||||||
|
|
||||||
message_string.clear();
|
message_string.clear();
|
||||||
write!(message_string, "I'm at loop # {:^4} (some numer: {})", idx, some_number).unwrap();
|
write!(message_string, "I'm at loop # {:^4} (some numer: {})", idx, some_number).unwrap();
|
||||||
|
|
|
||||||
|
|
@ -157,8 +157,7 @@ fn shell_main() -> ! {
|
||||||
log_server::init_wait().unwrap();
|
log_server::init_wait().unwrap();
|
||||||
info!("SHELL: my PID is {}", xous::process::id());
|
info!("SHELL: my PID is {}", xous::process::id());
|
||||||
|
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
|
|
||||||
let graphics_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_GFX).expect("SHELL: can't connect to COM");
|
let graphics_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_GFX).expect("SHELL: can't connect to COM");
|
||||||
|
|
||||||
|
|
@ -175,8 +174,8 @@ fn shell_main() -> ! {
|
||||||
// make a thread to catch responses from the COM
|
// make a thread to catch responses from the COM
|
||||||
xous::create_thread_simple(event_thread, 0).unwrap();
|
xous::create_thread_simple(event_thread, 0).unwrap();
|
||||||
info!("SHELL: COM responder thread started");
|
info!("SHELL: COM responder thread started");
|
||||||
let start_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
let start_time: u64 = ticktimer.elapsed_ms().unwrap();
|
||||||
while ticktimer_server::elapsed_ms(ticktimer_conn).unwrap() - start_time < 1000 {
|
while ticktimer.elapsed_ms().unwrap() - start_time < 1000 {
|
||||||
xous::yield_slice();
|
xous::yield_slice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -218,7 +217,7 @@ fn shell_main() -> ! {
|
||||||
graphics_server::draw_rectangle(graphics_conn, work_clipregion)
|
graphics_server::draw_rectangle(graphics_conn, work_clipregion)
|
||||||
.expect("unable to clear region");
|
.expect("unable to clear region");
|
||||||
|
|
||||||
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
let mut last_time: u64 = ticktimer.elapsed_ms().unwrap();
|
||||||
let mut first_time = true;
|
let mut first_time = true;
|
||||||
loop {
|
loop {
|
||||||
//////////////// status bar
|
//////////////// status bar
|
||||||
|
|
@ -379,7 +378,7 @@ fn shell_main() -> ! {
|
||||||
.expect("unable to draw to screen");
|
.expect("unable to draw to screen");
|
||||||
|
|
||||||
// Periodic tasks
|
// Periodic tasks
|
||||||
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
|
if let Ok(elapsed_time) = ticktimer.elapsed_ms() {
|
||||||
if elapsed_time - last_time > 500 {
|
if elapsed_time - last_time > 500 {
|
||||||
last_time = elapsed_time;
|
last_time = elapsed_time;
|
||||||
get_batt_stats_nb(com_conn).expect("Can't get battery stats from COM");
|
get_batt_stats_nb(com_conn).expect("Can't get battery stats from COM");
|
||||||
|
|
@ -391,6 +390,6 @@ fn shell_main() -> ! {
|
||||||
graphics_server::flush(graphics_conn).expect("unable to draw to screen");
|
graphics_server::flush(graphics_conn).expect("unable to draw to screen");
|
||||||
|
|
||||||
// rate limit graphics
|
// rate limit graphics
|
||||||
//ticktimer_server::sleep_ms(ticktimer_conn, 500).expect("couldn't sleep");
|
//ticktimer.sleep_ms(ticktimer_conn, 500).expect("couldn't sleep");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ macro_rules! cmd_api {
|
||||||
pub struct CommonEnv {
|
pub struct CommonEnv {
|
||||||
llio: xous::CID,
|
llio: xous::CID,
|
||||||
com: xous::CID,
|
com: xous::CID,
|
||||||
ticktimer: xous::CID,
|
ticktimer: Ticktimer,
|
||||||
gam: xous::CID,
|
gam: xous::CID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,12 +76,12 @@ pub struct CmdEnv {
|
||||||
}
|
}
|
||||||
impl CmdEnv {
|
impl CmdEnv {
|
||||||
pub fn new(gam: xous::CID) -> CmdEnv {
|
pub fn new(gam: xous::CID) -> CmdEnv {
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
CmdEnv {
|
CmdEnv {
|
||||||
common_env: CommonEnv {
|
common_env: CommonEnv {
|
||||||
llio: xous_names::request_connection_blocking(xous::names::SERVER_NAME_LLIO).expect("CMD: can't connect to LLIO"),
|
llio: xous_names::request_connection_blocking(xous::names::SERVER_NAME_LLIO).expect("CMD: can't connect to LLIO"),
|
||||||
com: xous_names::request_connection_blocking(xous::names::SERVER_NAME_COM).expect("CMD: can't connect to COM"),
|
com: xous_names::request_connection_blocking(xous::names::SERVER_NAME_COM).expect("CMD: can't connect to COM"),
|
||||||
ticktimer: xous::connect(ticktimer_server_id).unwrap(),
|
ticktimer: ticktimer,
|
||||||
gam,
|
gam,
|
||||||
},
|
},
|
||||||
lastverb: String::<256>::new(),
|
lastverb: String::<256>::new(),
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,14 @@ use xous_ipc::String;
|
||||||
use core::sync::atomic::{AtomicBool, Ordering};
|
use core::sync::atomic::{AtomicBool, Ordering};
|
||||||
static CB_RUN: AtomicBool = AtomicBool::new(false);
|
static CB_RUN: AtomicBool = AtomicBool::new(false);
|
||||||
pub fn callback_thread() {
|
pub fn callback_thread() {
|
||||||
let ticktimer_conn = xous::connect(xous::SID::from_bytes(b"ticktimer-server").unwrap()).unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let callback_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_SHELLCHAT).unwrap();
|
|
||||||
|
|
||||||
log::info!("callback initiator test thread started");
|
log::info!("callback initiator test thread started");
|
||||||
loop {
|
loop {
|
||||||
if CB_RUN.load(Ordering::Relaxed) {
|
if CB_RUN.load(Ordering::Relaxed) {
|
||||||
|
|
||||||
CB_RUN.store(false, Ordering::Relaxed);
|
CB_RUN.store(false, Ordering::Relaxed);
|
||||||
ticktimer_server::sleep_ms(ticktimer_conn, 10000).unwrap();
|
ticktimer.sleep_ms(10000).unwrap();
|
||||||
// just send a bogus message
|
// just send a bogus message
|
||||||
xous::send_message(callback_conn, Message::Scalar(ScalarMessage{
|
xous::send_message(callback_conn, Message::Scalar(ScalarMessage{
|
||||||
id: 0xdeadbeef, arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
id: 0xdeadbeef, arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ impl<'a> ShellCmdApi<'a> for Sleep {
|
||||||
Ok(Some(ret))
|
Ok(Some(ret))
|
||||||
} else {
|
} else {
|
||||||
if Ok(true) == gam::powerdown_request(env.gam) {
|
if Ok(true) == gam::powerdown_request(env.gam) {
|
||||||
ticktimer_server::sleep_ms(env.ticktimer, 500).unwrap(); // let the screen redraw
|
ticktimer.sleep_ms(env.ticktimer, 500).unwrap(); // let the screen redraw
|
||||||
|
|
||||||
// allow EC to snoop, so that it can wake up the system
|
// allow EC to snoop, so that it can wake up the system
|
||||||
llio::allow_ec_snoop(env.llio, true).unwrap();
|
llio::allow_ec_snoop(env.llio, true).unwrap();
|
||||||
|
|
@ -34,7 +34,7 @@ impl<'a> ShellCmdApi<'a> for Sleep {
|
||||||
|
|
||||||
log::info!("CMD: powering down now!");
|
log::info!("CMD: powering down now!");
|
||||||
// pause execution, nothing after this should be reachable
|
// pause execution, nothing after this should be reachable
|
||||||
ticktimer_server::sleep_ms(env.ticktimer, 2000).unwrap(); // should power off within 2 seconds
|
ticktimer.sleep_ms(env.ticktimer, 2000).unwrap(); // should power off within 2 seconds
|
||||||
log::info!("CMD: if you can read this, power down failed!");
|
log::info!("CMD: if you can read this, power down failed!");
|
||||||
}
|
}
|
||||||
write!(ret, "Powerdown request denied").unwrap();
|
write!(ret, "Powerdown request denied").unwrap();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ heapless = "0.5"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
log-server = {path = "../log-server"}
|
log-server = {path = "../log-server"}
|
||||||
xous = {path = "../../xous-rs"}
|
xous = {path = "../../xous-rs"}
|
||||||
|
num-derive = {version = "0.3", default-features = false}
|
||||||
|
num-traits = {version = "0.2", default-features = false}
|
||||||
|
|
||||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||||
utralib = {path = "../../utralib"}
|
utralib = {path = "../../utralib"}
|
||||||
|
|
|
||||||
|
|
@ -1,93 +1,11 @@
|
||||||
use xous::{Message, ScalarMessage};
|
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||||
|
pub(crate) enum Opcode {
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct TimerToken {
|
|
||||||
token: u64, // this field is 48 bits wide, random number
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Opcode {
|
|
||||||
/// Reset the timer
|
|
||||||
// Reset, // This is a bad idea, in retrospect.
|
|
||||||
|
|
||||||
/// Get the elapsed time in milliseconds
|
/// Get the elapsed time in milliseconds
|
||||||
ElapsedMs,
|
ElapsedMs,
|
||||||
|
|
||||||
/// Sleep for the specified numer of milliseconds
|
/// Sleep for the specified numer of milliseconds
|
||||||
SleepMs(usize),
|
SleepMs,
|
||||||
|
|
||||||
/// Recalculate the sleep time
|
/// Recalculate the sleep time
|
||||||
RecalculateSleep,
|
RecalculateSleep,
|
||||||
/*
|
|
||||||
////////// new APIs
|
|
||||||
/// Subscribe to wakeup alarms. Takes in the server name that's subcribed, returns a Token to refer to the subscription.
|
|
||||||
SubscribeWakeup(xous::String::<64>),
|
|
||||||
|
|
||||||
/// set an alarm in milliseconds, which is returned via the SubscribeWakeup registration token
|
|
||||||
WakeupAlarm(u16, TimerToken),
|
|
||||||
|
|
||||||
/// The generic message that gets sent to other servers, at the alarm time
|
|
||||||
WakeupMessage,
|
|
||||||
|
|
||||||
/// Request a blocking, in-line delay server -- returns a CID that can be used to send the BlockingDelayMs message
|
|
||||||
/// each request consumes a thread in the ticktimer that tracks & responds to a blockingdelay
|
|
||||||
RequestBlockingDelay,
|
|
||||||
|
|
||||||
/// Do a blocking delay. Responds with the current ElapsedMs by default.
|
|
||||||
BlockingDelayMs(u32),
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> core::convert::TryFrom<&'a Message> for Opcode {
|
|
||||||
type Error = &'static str;
|
|
||||||
fn try_from(message: &'a Message) -> Result<Self, Self::Error> {
|
|
||||||
match message {
|
|
||||||
Message::Scalar(m) => match m.id {
|
|
||||||
// 1 => Ok(Opcode::Reset),
|
|
||||||
131072 => Ok(Opcode::RecalculateSleep),
|
|
||||||
_ => Err("unrecognized opcode"),
|
|
||||||
},
|
|
||||||
Message::BlockingScalar(m) => match m.id {
|
|
||||||
4919 => Ok(Opcode::ElapsedMs),
|
|
||||||
3 => Ok(Opcode::SleepMs(m.arg1)),
|
|
||||||
_ => Err("unrecognized opcode"),
|
|
||||||
},
|
|
||||||
_ => Err("unhandled message type"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Message> for Opcode {
|
|
||||||
fn into(self) -> Message {
|
|
||||||
match self {
|
|
||||||
/* Opcode::Reset => Message::Scalar(ScalarMessage {
|
|
||||||
id: 1,
|
|
||||||
arg1: 0,
|
|
||||||
arg2: 0,
|
|
||||||
arg3: 0,
|
|
||||||
arg4: 0,
|
|
||||||
}),*/
|
|
||||||
Opcode::RecalculateSleep => Message::Scalar(ScalarMessage {
|
|
||||||
id: 131072,
|
|
||||||
arg1: 0,
|
|
||||||
arg2: 0,
|
|
||||||
arg3: 0,
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
Opcode::ElapsedMs => Message::BlockingScalar(ScalarMessage {
|
|
||||||
id: 4919,
|
|
||||||
arg1: 0,
|
|
||||||
arg2: 0,
|
|
||||||
arg3: 0,
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
Opcode::SleepMs(ms) => Message::BlockingScalar(ScalarMessage {
|
|
||||||
id: 3,
|
|
||||||
arg1: ms,
|
|
||||||
arg2: 0,
|
|
||||||
arg3: 0,
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,22 +3,40 @@
|
||||||
pub mod api;
|
pub mod api;
|
||||||
|
|
||||||
use xous::{send_message, Error, CID};
|
use xous::{send_message, Error, CID};
|
||||||
|
use num_traits::ToPrimitive;
|
||||||
|
|
||||||
pub fn elapsed_ms(cid: CID) -> Result<u64, Error> {
|
pub struct Ticktimer {
|
||||||
let response = send_message(cid, api::Opcode::ElapsedMs.into())?;
|
conn: CID,
|
||||||
if let xous::Result::Scalar2(upper, lower) = response {
|
}
|
||||||
Ok(upper as u64 | ((lower as u64) << 32))
|
impl Ticktimer {
|
||||||
} else {
|
pub fn new() -> Result<Self, Error> {
|
||||||
panic!("unexpected return value: {:#?}", response);
|
let conn = xous::connect(xous::SID::from_bytes(b"ticktimer-server").unwrap())?;
|
||||||
|
Ok(Ticktimer {
|
||||||
|
conn,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn elapsed_ms(&self) -> Result<u64, Error> {
|
||||||
|
let response = send_message(self.conn,
|
||||||
|
xous::Message::BlockingScalar(xous::ScalarMessage {
|
||||||
|
id: api::Opcode::ElapsedMs.to_usize().unwrap(),
|
||||||
|
arg1: 0, arg2: 0, arg3: 0, arg4: 0
|
||||||
|
})
|
||||||
|
)?;
|
||||||
|
if let xous::Result::Scalar2(upper, lower) = response {
|
||||||
|
Ok(upper as u64 | ((lower as u64) << 32))
|
||||||
|
} else {
|
||||||
|
panic!("unexpected return value: {:#?}", response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sleep_ms(&self, ms: usize) -> Result<(), Error> {
|
||||||
|
send_message(self.conn,
|
||||||
|
xous::Message::BlockingScalar(xous::ScalarMessage {
|
||||||
|
id: api::Opcode::SleepMs.to_usize().unwrap(),
|
||||||
|
arg1: ms,
|
||||||
|
arg2: 0, arg3: 0, arg4: 0
|
||||||
|
})
|
||||||
|
).map(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
pub fn reset(cid: CID) -> Result<(), xous::Error> {
|
|
||||||
send_message(cid, api::Opcode::Reset.into()).map(|_| ())
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
pub fn sleep_ms(cid: CID, ms: usize) -> Result<(), xous::Error> {
|
|
||||||
send_message(cid, api::Opcode::SleepMs(ms).into()).map(|_| ())
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,12 @@
|
||||||
#![cfg_attr(target_os = "none", no_main)]
|
#![cfg_attr(target_os = "none", no_main)]
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
use api::Opcode;
|
|
||||||
|
|
||||||
mod os_timer;
|
mod os_timer;
|
||||||
|
|
||||||
use heapless::binary_heap::{BinaryHeap, Min};
|
use heapless::binary_heap::{BinaryHeap, Min};
|
||||||
use heapless::consts::*;
|
use heapless::consts::*;
|
||||||
|
|
||||||
use core::convert::TryFrom;
|
|
||||||
|
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
|
|
||||||
#[derive(Eq)]
|
#[derive(Eq)]
|
||||||
|
|
@ -110,7 +107,13 @@ mod implementation {
|
||||||
|
|
||||||
// This is dangerous and may return an error if the queue is full.
|
// This is dangerous and may return an error if the queue is full.
|
||||||
// Which is fine, because the queue is always recalculated any time a message arrives.
|
// Which is fine, because the queue is always recalculated any time a message arrives.
|
||||||
xous::try_send_message(xtt.connection, crate::api::Opcode::RecalculateSleep.into()).ok();
|
use num_traits::ToPrimitive;
|
||||||
|
xous::try_send_message(xtt.connection,
|
||||||
|
xous::Message::Scalar(xous::ScalarMessage {
|
||||||
|
id: crate::api::Opcode::RecalculateSleep.to_usize().unwrap(),
|
||||||
|
arg1: 0, arg2: 0, arg3: 0, arg4: 0
|
||||||
|
})
|
||||||
|
).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XousTickTimer {
|
impl XousTickTimer {
|
||||||
|
|
@ -440,39 +443,36 @@ fn xmain() -> ! {
|
||||||
#[cfg(feature = "watchdog")]
|
#[cfg(feature = "watchdog")]
|
||||||
ticktimer.reset_wdt();
|
ticktimer.reset_wdt();
|
||||||
|
|
||||||
let envelope = xous::receive_message(ticktimer_server).unwrap();
|
let msg = xous::receive_message(ticktimer_server).unwrap();
|
||||||
if let Ok(opcode) = Opcode::try_from(&envelope.body) {
|
match num_traits::FromPrimitive::from_usize(msg.body.id()) {
|
||||||
// info!("TickTimer: Opcode: {:?}", opcode);
|
Some(api::Opcode::ElapsedMs) => {
|
||||||
match opcode {
|
let time = ticktimer.elapsed_ms() as i64;
|
||||||
/*Opcode::Reset => {
|
xous::return_scalar2(
|
||||||
info!("TickTimer: reset called");
|
msg.sender,
|
||||||
ticktimer.reset();
|
(time & 0xFFFF_FFFFi64) as usize,
|
||||||
}*/
|
((time >> 32) & 0xFFF_FFFFi64) as usize,
|
||||||
Opcode::ElapsedMs => {
|
)
|
||||||
let time = ticktimer.elapsed_ms() as i64;
|
.expect("TickTimer: couldn't return time request");
|
||||||
xous::return_scalar2(
|
}
|
||||||
envelope.sender,
|
Some(api::Opcode::SleepMs) => {
|
||||||
(time & 0xFFFF_FFFFi64) as usize,
|
if let xous::Message::BlockingScalar(xous::ScalarMessage {
|
||||||
((time >> 32) & 0xFFF_FFFFi64) as usize,
|
id: _, arg1: ms, arg2: _, arg3: _, arg4: _}) = msg.body {
|
||||||
)
|
|
||||||
.expect("TickTimer: couldn't return time request");
|
|
||||||
}
|
|
||||||
Opcode::SleepMs(ms) => {
|
|
||||||
recalculate_sleep(
|
recalculate_sleep(
|
||||||
&mut ticktimer,
|
&mut ticktimer,
|
||||||
&mut sleep_heap,
|
&mut sleep_heap,
|
||||||
Some(SleepRequest {
|
Some(SleepRequest {
|
||||||
msec: ms as i64,
|
msec: ms as i64,
|
||||||
sender: envelope.sender,
|
sender: msg.sender,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Opcode::RecalculateSleep => {
|
|
||||||
recalculate_sleep(&mut ticktimer, &mut sleep_heap, None);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
Some(api::Opcode::RecalculateSleep) => {
|
||||||
error!("couldn't convert opcode");
|
recalculate_sleep(&mut ticktimer, &mut sleep_heap, None);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
error!("couldn't convert opcode");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -237,8 +237,7 @@ fn xmain() -> ! {
|
||||||
let log_server_id = xous::SID::from_bytes(b"xous-log-server ").unwrap();
|
let log_server_id = xous::SID::from_bytes(b"xous-log-server ").unwrap();
|
||||||
let log_conn = xous::connect(log_server_id).unwrap();
|
let log_conn = xous::connect(log_server_id).unwrap();
|
||||||
|
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
|
|
||||||
// Create a new com object
|
// Create a new com object
|
||||||
let mut trng = Trng::new();
|
let mut trng = Trng::new();
|
||||||
|
|
@ -263,12 +262,12 @@ fn xmain() -> ! {
|
||||||
if false {
|
if false {
|
||||||
// to test the powerdown feature
|
// to test the powerdown feature
|
||||||
trng.wait_full();
|
trng.wait_full();
|
||||||
ticktimer_server::sleep_ms(ticktimer_conn, 5000).expect("couldn't sleep");
|
ticktimer.sleep_ms(5000).expect("couldn't sleep");
|
||||||
}
|
}
|
||||||
|
|
||||||
if false {
|
if false {
|
||||||
// select this to print XADC data to info!()
|
// select this to print XADC data to info!()
|
||||||
ticktimer_server::sleep_ms(ticktimer_conn, 20).expect("couldn't sleep"); // sleep to allow xadc sampling in case we're in a very tight TRNG request loop
|
ticktimer.sleep_ms(20).expect("couldn't sleep"); // sleep to allow xadc sampling in case we're in a very tight TRNG request loop
|
||||||
info!("temperature: {}C", trng.read_temperature());
|
info!("temperature: {}C", trng.read_temperature());
|
||||||
info!("vccint: {}mV", trng.read_vccint());
|
info!("vccint: {}mV", trng.read_vccint());
|
||||||
info!("vccaux: {}mV", trng.read_vccaux());
|
info!("vccaux: {}mV", trng.read_vccaux());
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,7 @@ fn xmain() -> ! {
|
||||||
let name_server = xous::create_server_with_address(b"xous-name-server")
|
let name_server = xous::create_server_with_address(b"xous-name-server")
|
||||||
.expect("Couldn't create xousnames-server");
|
.expect("Couldn't create xousnames-server");
|
||||||
|
|
||||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
|
|
||||||
|
|
||||||
// this limits the number of available servers to be requested to 128...!
|
// this limits the number of available servers to be requested to 128...!
|
||||||
let mut name_table = FnvIndexMap::<_, _, U128>::new();
|
let mut name_table = FnvIndexMap::<_, _, U128>::new();
|
||||||
|
|
@ -57,13 +56,13 @@ fn xmain() -> ! {
|
||||||
rkyv::Archived::<api::Request>::SID(new_sid.into())
|
rkyv::Archived::<api::Request>::SID(new_sid.into())
|
||||||
} else {
|
} else {
|
||||||
// compute the next interval, rounded to a multiple of FAIL_TIMEOUT_MS to reduce timing side channels
|
// compute the next interval, rounded to a multiple of FAIL_TIMEOUT_MS to reduce timing side channels
|
||||||
let target_time: u64 = ((ticktimer_server::elapsed_ms(ticktimer_conn)
|
let target_time: u64 = ((ticktimer.elapsed_ms()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
/ FAIL_TIMEOUT_MS)
|
/ FAIL_TIMEOUT_MS)
|
||||||
+ 1)
|
+ 1)
|
||||||
* FAIL_TIMEOUT_MS;
|
* FAIL_TIMEOUT_MS;
|
||||||
info!("NS: request failed, waiting for deterministic timeout");
|
info!("NS: request failed, waiting for deterministic timeout");
|
||||||
while ticktimer_server::elapsed_ms(ticktimer_conn).unwrap() < target_time {
|
while ticktimer.elapsed_ms().unwrap() < target_time {
|
||||||
xous::yield_slice();
|
xous::yield_slice();
|
||||||
}
|
}
|
||||||
info!("NS: deterministic timeout done");
|
info!("NS: deterministic timeout done");
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,8 @@ fn try_main() -> Result<(), DynError> {
|
||||||
"xous-names",
|
"xous-names",
|
||||||
"trng",
|
"trng",
|
||||||
"llio",
|
"llio",
|
||||||
"kernel-test",
|
"rkyv-test-client",
|
||||||
|
"rkyv-test-server",
|
||||||
];
|
];
|
||||||
let task = env::args().nth(1);
|
let task = env::args().nth(1);
|
||||||
match task.as_deref() {
|
match task.as_deref() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue