diff --git a/Cargo.lock b/Cargo.lock index e5eee37ef..62c695186 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -176,39 +176,6 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" -[[package]] -name = "benchmark" -version = "0.1.0" -dependencies = [ - "benchmark-target", - "graphics-server", - "log", - "log-server", - "num-derive", - "num-traits", - "rkyv", - "ticktimer-server", - "utralib", - "xous", - "xous-ipc 0.9.7", - "xous-names", -] - -[[package]] -name = "benchmark-target" -version = "0.1.0" -dependencies = [ - "log", - "log-server", - "num-derive", - "num-traits", - "rkyv", - "utralib", - "xous", - "xous-ipc 0.9.7", - "xous-names", -] - [[package]] name = "bincode" version = "1.3.3" @@ -340,57 +307,6 @@ dependencies = [ "rustc_version 0.4.0", ] -[[package]] -name = "cb-test-c1" -version = "0.1.0" -dependencies = [ - "cb-test-srv", - "log", - "log-server", - "num-derive", - "num-traits", - "rkyv", - "ticktimer-server", - "utralib", - "xous", - "xous-ipc 0.9.7", - "xous-names", -] - -[[package]] -name = "cb-test-c2" -version = "0.1.0" -dependencies = [ - "cb-test-srv", - "log", - "log-server", - "num-derive", - "num-traits", - "rkyv", - "ticktimer-server", - "utralib", - "xous", - "xous-ipc 0.9.7", - "xous-names", -] - -[[package]] -name = "cb-test-srv" -version = "0.1.0" -dependencies = [ - "benchmark-target", - "log", - "log-server", - "num-derive", - "num-traits", - "rkyv", - "ticktimer-server", - "utralib", - "xous", - "xous-ipc 0.9.7", - "xous-names", -] - [[package]] name = "cc" version = "1.0.73" @@ -2683,36 +2599,6 @@ dependencies = [ "rkyv_derive", ] -[[package]] -name = "rkyv-test-client" -version = "0.1.0" -dependencies = [ - "com", - "keyboard", - "log", - "log-server", - "rkyv-test-server", - "susres", - "ticktimer-server", - "xous", - "xous-names", -] - -[[package]] -name = "rkyv-test-server" -version = "0.1.0" -dependencies = [ - "log", - "log-server", - "num-derive", - "num-traits", - "rkyv", - "ticktimer-server", - "xous", - "xous-ipc 0.9.7", - "xous-names", -] - [[package]] name = "rkyv_derive" version = "0.4.0" @@ -3300,36 +3186,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "test-stub" -version = "0.1.0" -dependencies = [ - "log", - "log-server", - "num-derive", - "num-traits", - "susres", - "ticktimer-server", - "utralib", - "xous", - "xous-names", -] - -[[package]] -name = "test-stub2" -version = "0.1.0" -dependencies = [ - "log", - "log-server", - "num-derive", - "num-traits", - "rkyv", - "ticktimer-server", - "utralib", - "xous", - "xous-ipc 0.9.7", -] - [[package]] name = "textwrap" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index 940e74a49..03e0ab3bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,26 +11,19 @@ default-members = [ "services/status", "imports/com_rs-ref", "services/ime-plugin-api", - "services/benchmark", - "services/benchmark-target", "services/ime-frontend", "services/ime-plugin-shell", "services/content-plugin-api", "services/shellchat", "services/llio", - "services/cb-test-srv", - "services/cb-test-c1", - "services/cb-test-c2", "services/susres", "services/codec", "services/engine-sha512", "services/engine-25519", "services/aes", - "services/test-stub", "services/spinor", "services/root-keys", "services/jtag", - "services/test-stub2", "services/pddb", "services/net", "services/dns", @@ -57,13 +50,9 @@ members = [ "services/trng", "services/gam", "services/status", - "services/benchmark", - "services/benchmark-target", "services/ime-frontend", "services/ime-plugin-shell", "services/ime-plugin-tts", - "services/rkyv-test-server", - "services/rkyv-test-client", "services/shellchat", "svd2repl", "svd2utra", @@ -73,20 +62,14 @@ members = [ "services/ime-plugin-api", "services/content-plugin-api", "services/llio", - "services/cb-test-srv", - "services/cb-test-c1", - "services/cb-test-c2", - "services/susres", "services/codec", "services/engine-sha512", "services/engine-25519", "services/aes", - "services/test-stub", "services/spinor", "services/root-keys", "services/jtag", "tools/wycheproof-import", - "services/test-stub2", "services/pddb", "services/net", "services/dns", diff --git a/services/cb-test-c1/Cargo.toml b/services/cb-test-c1/Cargo.toml deleted file mode 100644 index 41f8808d7..000000000 --- a/services/cb-test-c1/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "cb-test-c1" -version = "0.1.0" -authors = ["bunnie "] -edition = "2018" -description = "Callback Test Client 1" - -# Dependency policy: fully specify dependencies to the minor version number -[dependencies] -xous = { path = "../../xous-rs" } -log-server = { path = "../log-server" } -ticktimer-server = { path = "../ticktimer-server" } -xous-names = { path = "../xous-names" } -log = "0.4.14" -xous-ipc = {path = "../../xous-ipc"} -cb-test-srv = {path = "../cb-test-srv"} - -rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} -num-derive = {version = "0.3.3", default-features = false} -num-traits = {version = "0.2.14", default-features = false} - - -[target.'cfg(not(any(windows,unix)))'.dependencies] -utralib = { path = "../../utralib"} - -[features] -default = [] diff --git a/services/cb-test-c1/src/main.rs b/services/cb-test-c1/src/main.rs deleted file mode 100644 index 4c408edba..000000000 --- a/services/cb-test-c1/src/main.rs +++ /dev/null @@ -1,86 +0,0 @@ -#![cfg_attr(target_os = "none", no_std)] -#![cfg_attr(target_os = "none", no_main)] - -use cb_test_srv::*; -use num_traits::{FromPrimitive, ToPrimitive}; - -const SERVER_NAME: &str = "_CB test client 1_"; - -#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] -enum Opcode { - Tick, - Result, -} - -use core::sync::atomic::{AtomicU32, Ordering}; -static CB_TO_MAIN_CONN: AtomicU32 = AtomicU32::new(0); -fn do_result(result: u32) { - let cb_to_main_conn = CB_TO_MAIN_CONN.load(Ordering::Relaxed); - if cb_to_main_conn != 0 { - xous::send_message( - cb_to_main_conn, - xous::Message::new_scalar(Opcode::Result.to_usize().unwrap(), result as usize, 0, 0, 0), - ) - .unwrap(); - } -} - -#[xous::xous_main] -fn xmain() -> ! { - log_server::init_wait().unwrap(); - log::set_max_level(log::LevelFilter::Info); - log::info!("my PID is {}", xous::process::id()); - - let xns = xous_names::XousNames::new().unwrap(); - let sid = xns - .register_name(SERVER_NAME, None) - .expect("can't register server"); - log::trace!("registered with NS -- {:?}", sid); - - CB_TO_MAIN_CONN.store(xous::connect(sid).unwrap(), Ordering::Relaxed); - - let mut cb_serv = CbTestServer::new(&xns).unwrap(); - let tick_cid = xous::connect(sid).unwrap(); - cb_serv - .hook_tick_callback(Opcode::Tick.to_u32().unwrap(), tick_cid) - .unwrap(); - - log::trace!("ready to accept requests"); - let mut state = 0; - let mut hooked = false; - loop { - let msg = xous::receive_message(sid).unwrap(); - match FromPrimitive::from_usize(msg.body.id()) { - Some(Opcode::Tick) => xous::msg_scalar_unpack!(msg, _, _, _, _, { - if (state % 2) == 0 { - log::trace!("hook1"); - cb_serv.hook_req_callback(do_result).unwrap(); - hooked = true; - cb_serv.req().unwrap(); - } else { - log::trace!("idle1"); - } - state += 1; - }), - Some(Opcode::Result) => xous::msg_scalar_unpack!(msg, result, _, _, _, { - log::info!("C1 result: {}", result); - if hooked == false { - log::info!("**C1 without hook"); - } - cb_serv.unhook_req_callback().unwrap(); - hooked = false; - log::trace!("unhook1"); - }), - None => { - log::error!("couldn't convert opcode"); - break; - } - } - } - // clean up our program - log::trace!("main loop exit, destroying servers"); - xns.unregister_server(sid).unwrap(); - xous::destroy_server(sid).unwrap(); - log::trace!("quitting"); - xous::terminate_process(0) -} diff --git a/services/cb-test-c2/Cargo.toml b/services/cb-test-c2/Cargo.toml deleted file mode 100644 index dd07a204e..000000000 --- a/services/cb-test-c2/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "cb-test-c2" -version = "0.1.0" -authors = ["bunnie "] -edition = "2018" -description = "Callback Test Client 2" - -# Dependency policy: fully specify dependencies to the minor version number -[dependencies] -xous = { path = "../../xous-rs" } -log-server = { path = "../log-server" } -ticktimer-server = { path = "../ticktimer-server" } -xous-names = { path = "../xous-names" } -log = "0.4.14" -xous-ipc = {path = "../../xous-ipc"} -cb-test-srv = {path = "../cb-test-srv"} - -rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} -num-derive = {version = "0.3.3", default-features = false} -num-traits = {version = "0.2.14", default-features = false} - - -[target.'cfg(not(any(windows,unix)))'.dependencies] -utralib = { path = "../../utralib"} - -[features] -default = [] diff --git a/services/cb-test-c2/src/main.rs b/services/cb-test-c2/src/main.rs deleted file mode 100644 index 5ba7b93d0..000000000 --- a/services/cb-test-c2/src/main.rs +++ /dev/null @@ -1,86 +0,0 @@ -#![cfg_attr(target_os = "none", no_std)] -#![cfg_attr(target_os = "none", no_main)] - -use cb_test_srv::*; -use num_traits::{FromPrimitive, ToPrimitive}; - -const SERVER_NAME: &str = "_CB test client 2_"; - -#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] -enum Opcode { - Tick, - Result, -} - -use core::sync::atomic::{AtomicU32, Ordering}; -static CB_TO_MAIN_CONN: AtomicU32 = AtomicU32::new(0); -fn do_result(result: u32) { - let cb_to_main_conn = CB_TO_MAIN_CONN.load(Ordering::Relaxed); - if cb_to_main_conn != 0 { - xous::send_message( - cb_to_main_conn, - xous::Message::new_scalar(Opcode::Result.to_usize().unwrap(), result as usize, 0, 0, 0), - ) - .unwrap(); - } -} - -#[xous::xous_main] -fn xmain() -> ! { - log_server::init_wait().unwrap(); - log::set_max_level(log::LevelFilter::Info); - log::info!("my PID is {}", xous::process::id()); - - let xns = xous_names::XousNames::new().unwrap(); - let sid = xns - .register_name(SERVER_NAME, None) - .expect("can't register server"); - log::trace!("registered with NS -- {:?}", sid); - - CB_TO_MAIN_CONN.store(xous::connect(sid).unwrap(), Ordering::Relaxed); - - let mut cb_serv = CbTestServer::new(&xns).unwrap(); - let tick_cid = xous::connect(sid).unwrap(); - cb_serv - .hook_tick_callback(Opcode::Tick.to_u32().unwrap(), tick_cid) - .unwrap(); - - log::trace!("ready to accept requests"); - let mut state = 0; - let mut hooked = false; - loop { - let msg = xous::receive_message(sid).unwrap(); - match FromPrimitive::from_usize(msg.body.id()) { - Some(Opcode::Tick) => xous::msg_scalar_unpack!(msg, _, _, _, _, { - if (state % 4) == 0 { - log::trace!("hook2"); - cb_serv.hook_req_callback(do_result).unwrap(); - hooked = true; - cb_serv.req().unwrap(); - } else { - log::trace!("idle2"); - } - state += 1; - }), - Some(Opcode::Result) => xous::msg_scalar_unpack!(msg, result, _, _, _, { - log::info!("C2 result: {}", result); - if hooked == false { - log::info!("**C2 without hook"); - } - cb_serv.unhook_req_callback().unwrap(); - hooked = false; - log::trace!("unhook1"); - }), - None => { - log::error!("couldn't convert opcode"); - break; - } - } - } - // clean up our program - log::trace!("main loop exit, destroying servers"); - xns.unregister_server(sid).unwrap(); - xous::destroy_server(sid).unwrap(); - log::trace!("quitting"); - xous::terminate_process(0) -} diff --git a/services/cb-test-srv/Cargo.toml b/services/cb-test-srv/Cargo.toml deleted file mode 100644 index 33990a6c0..000000000 --- a/services/cb-test-srv/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "cb-test-srv" -version = "0.1.0" -authors = ["bunnie "] -edition = "2018" -description = "Callback test server" - -# Dependency policy: fully specify dependencies to the minor version number -[dependencies] -xous = { path = "../../xous-rs" } -ticktimer-server = { path = "../ticktimer-server" } -xous-names = { path = "../xous-names" } -log-server = { path = "../log-server" } -log = "0.4.14" -benchmark-target = { path = "../benchmark-target" } - -xous-ipc = {path = "../../xous-ipc"} -num-derive = {version = "0.3.3", default-features = false} -num-traits = {version = "0.2.14", default-features = false} -rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} - -[target.'cfg(not(any(windows,unix)))'.dependencies] -utralib = {path = "../../utralib"} - -[target.'cfg(any(windows,unix))'.dependencies] - -[features] -default = [] diff --git a/services/cb-test-srv/src/api.rs b/services/cb-test-srv/src/api.rs deleted file mode 100644 index 49e1e41df..000000000 --- a/services/cb-test-srv/src/api.rs +++ /dev/null @@ -1,29 +0,0 @@ -pub(crate) const SERVER_NAME: &str = "_Callback test server_"; - -#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] -pub(crate) enum Opcode { - RegisterTickListener, - RegisterReqListener, - UnregisterReqListener, - Tick, - Req, -} - -#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] -pub enum TickCallback { - Tick, - Drop, -} - -#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] -pub enum ResultCallback { - Result, - Drop, -} - -#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] -pub(crate) struct ScalarHook { - pub sid: (u32, u32, u32, u32), - pub id: u32, // ID of the scalar message to send through (e.g. the discriminant of the Enum on the caller's side API) - pub cid: xous::CID, // caller-side connection ID for the scalar message to route to. Created by the caller before hooking. -} diff --git a/services/cb-test-srv/src/lib.rs b/services/cb-test-srv/src/lib.rs deleted file mode 100644 index e9c005aa8..000000000 --- a/services/cb-test-srv/src/lib.rs +++ /dev/null @@ -1,200 +0,0 @@ -#![cfg_attr(target_os = "none", no_std)] -pub mod api; -use api::*; -use num_traits::{FromPrimitive, ToPrimitive}; -use xous::{msg_scalar_unpack, send_message, Message, CID}; -use xous_ipc::Buffer; - -pub struct CbTestServer { - conn: CID, - tick_cb_sid: Option, - req_cb_sid: Option, -} -static mut REQ_CB: Option = None; -impl CbTestServer { - pub fn new(xns: &xous_names::XousNames) -> Result { - let conn = xns - .request_connection_blocking(api::SERVER_NAME) - .expect("Can't connect to callback test server"); - Ok(CbTestServer { - conn, - tick_cb_sid: None, - req_cb_sid: None, - }) - } - pub fn req(&mut self) -> Result<(), xous::Error> { - send_message( - self.conn, - Message::new_scalar(Opcode::Req.to_usize().unwrap(), 0, 0, 0, 0), - ) - .map(|_| ()) - } - pub fn hook_tick_callback(&mut self, id: u32, cid: CID) -> Result<(), xous::Error> { - if self.tick_cb_sid.is_none() { - let sid = xous::create_server().unwrap(); - self.tick_cb_sid = Some(sid); - let sid_tuple = sid.to_u32(); - xous::create_thread_4( - tick_cb_server, - sid_tuple.0 as usize, - sid_tuple.1 as usize, - sid_tuple.2 as usize, - sid_tuple.3 as usize, - ) - .unwrap(); - let hookdata = ScalarHook { - sid: sid_tuple, - id, - cid, - }; - let buf = Buffer::into_buf(hookdata).or(Err(xous::Error::InternalError))?; - buf.lend(self.conn, Opcode::RegisterTickListener.to_u32().unwrap()) - .map(|_| ()) - } else { - Err(xous::Error::MemoryInUse) // can't hook it twice - } - } - pub fn hook_req_callback(&mut self, cb: fn(u32)) -> Result<(), xous::Error> { - log::info!("hooking req callback"); - if unsafe { REQ_CB }.is_some() { - return Err(xous::Error::MemoryInUse); - } - unsafe { REQ_CB = Some(cb) }; - let sid_tuple: (u32, u32, u32, u32); - if let Some(sid) = self.req_cb_sid { - sid_tuple = sid.to_u32(); - } else { - let sid = xous::create_server().unwrap(); - self.req_cb_sid = Some(sid); - sid_tuple = sid.to_u32(); - xous::create_thread_4( - req_cb_server, - sid_tuple.0 as usize, - sid_tuple.1 as usize, - sid_tuple.2 as usize, - sid_tuple.3 as usize, - ) - .unwrap(); - } - xous::send_message( - self.conn, - Message::new_scalar( - Opcode::RegisterReqListener.to_usize().unwrap(), - sid_tuple.0 as usize, - sid_tuple.1 as usize, - sid_tuple.2 as usize, - sid_tuple.3 as usize, - ), - ) - .unwrap(); - Ok(()) - } - pub fn unhook_req_callback(&mut self) -> Result<(), xous::Error> { - log::info!("UNhooking req callback"); - unsafe { REQ_CB = None }; - - /* - if let Some(sid) = self.req_cb_sid.take() { - // tell my handler thread to quit - log::trace!("connect for unhook"); - let cid = xous::connect(sid).expect("can't connect to CB server for disconnect message"); - log::trace!("sending drop to conn {}", cid); - send_message(cid, - Message::new_scalar(ResultCallback::Drop.to_usize().unwrap(), 0, 0, 0, 0) - ).unwrap(); - log::trace!("disconnecting unhook connection"); - unsafe{ - match xous::disconnect(cid) { - Ok(_) => log::trace!("disconnected unhook connection"), - Err(e) => log::error!("unhook req got error: {:?}", e), - }; - } - } - log::trace!("nullifying local state"); - self.req_cb_sid = None; */ - if let Some(sid) = self.req_cb_sid { - let sid_tuple = sid.to_u32(); - xous::send_message( - self.conn, - Message::new_scalar( - Opcode::UnregisterReqListener.to_usize().unwrap(), - sid_tuple.0 as usize, - sid_tuple.1 as usize, - sid_tuple.2 as usize, - sid_tuple.3 as usize, - ), - ) - .unwrap(); - } - Ok(()) - } -} -fn drop_conn(sid: xous::SID, id: usize) { - let cid = xous::connect(sid).unwrap(); - xous::send_message(cid, Message::new_scalar(id, 0, 0, 0, 0)).unwrap(); - unsafe { - xous::disconnect(cid).unwrap(); - } -} -impl Drop for CbTestServer { - fn drop(&mut self) { - if let Some(sid) = self.req_cb_sid.take() { - drop_conn(sid, ResultCallback::Drop.to_usize().unwrap()); - } - if let Some(sid) = self.tick_cb_sid.take() { - drop_conn(sid, TickCallback::Drop.to_usize().unwrap()); - } - unsafe { - xous::disconnect(self.conn).unwrap(); - } - } -} - -fn tick_cb_server(sid0: usize, sid1: usize, sid2: usize, sid3: usize) { - let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32); - loop { - let msg = xous::receive_message(sid).unwrap(); - match FromPrimitive::from_usize(msg.body.id()) { - Some(TickCallback::Tick) => msg_scalar_unpack!(msg, cid, id, _, _, { - // directly pass the scalar message onto the CID with the ID memorized in the original hook - send_message(cid as u32, Message::new_scalar(id, 0, 0, 0, 0)).unwrap(); - }), - Some(TickCallback::Drop) => { - break; // this exits the loop and kills the thread - } - None => (), - } - } - xous::destroy_server(sid).unwrap(); -} - -fn req_cb_server(sid0: usize, sid1: usize, sid2: usize, sid3: usize) { - let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32); - log::info!("req callback server started with SID {:x?}", sid); - loop { - let msg = xous::receive_message(sid).unwrap(); - log::trace!("req callback got msg: {:?}", msg); - match FromPrimitive::from_usize(msg.body.id()) { - Some(ResultCallback::Result) => msg_scalar_unpack!(msg, result, _, _, _, { - unsafe { - if let Some(cb) = REQ_CB { - cb(result as u32) - } else { - // we got a callback message after we unregistered - // not fatal, it just means the server may not have received - // our unregistration message in time - continue; - } - } - }), - Some(ResultCallback::Drop) => { - break; - } - None => { - log::error!("got unrecognized message in req CB server, ignoring"); - } - } - } - log::info!("req callback server exiting"); - xous::destroy_server(sid).expect("can't destroy my server on exit!"); -} diff --git a/services/cb-test-srv/src/main.rs b/services/cb-test-srv/src/main.rs deleted file mode 100644 index 808fb196b..000000000 --- a/services/cb-test-srv/src/main.rs +++ /dev/null @@ -1,182 +0,0 @@ -#![cfg_attr(target_os = "none", no_std)] -#![cfg_attr(target_os = "none", no_main)] - -mod api; -use api::*; - -use api::Opcode; -use num_traits::{FromPrimitive, ToPrimitive}; -use xous::{msg_scalar_unpack, CID}; -use xous_ipc::*; - -#[derive(Copy, Clone, Debug)] -struct ScalarCallback { - server_to_cb_cid: CID, - cb_to_client_cid: CID, - cb_to_client_id: u32, -} - -fn pump_thread() { - log::info!("starting pump thread"); - - let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer"); - - let xns = xous_names::XousNames::new().unwrap(); - let server_conn = xns - .request_connection_blocking(api::SERVER_NAME) - .expect("can't connect to main program"); - loop { - xous::send_message( - server_conn, - xous::Message::new_scalar(Opcode::Tick.to_usize().unwrap(), 0, 0, 0, 0), - ) - .expect("couldn't send Tick message"); - ticktimer.sleep_ms(100).expect("couldn't sleep"); - } -} - -#[xous::xous_main] -fn shell_main() -> ! { - log_server::init_wait().unwrap(); - log::set_max_level(log::LevelFilter::Info); - log::info!("my PID is {}", xous::process::id()); - - let xns = xous_names::XousNames::new().unwrap(); - let server = xns - .register_name(api::SERVER_NAME, None) - .expect("can't register server"); - - xous::create_thread_0(pump_thread).unwrap(); - log::info!("pump thread started"); - - let mut tick_cb: [Option; 32] = [None; 32]; - let mut req_cb: [bool; xous::MAX_CID] = [false; xous::MAX_CID]; - - let mut ticks = 0; - let mut state = 0; - loop { - let msg = xous::receive_message(server).unwrap(); - log::trace!("Message: {:?}", msg); - match FromPrimitive::from_usize(msg.body.id()) { - Some(Opcode::Tick) => { - // pump the tick callbacks - for maybe_conn in tick_cb.iter_mut() { - if let Some(scb) = maybe_conn { - match xous::send_message( - scb.server_to_cb_cid, - xous::Message::new_scalar( - api::TickCallback::Tick.to_usize().unwrap(), - scb.cb_to_client_cid as usize, - scb.cb_to_client_id as usize, - 0, - 0, - ), - ) { - Err(xous::Error::ServerNotFound) => { - *maybe_conn = None // automatically de-allocate callbacks for clients that have dropped - } - Ok(xous::Result::Ok) => {} - _ => panic!("unhandled error or result in callback processing"), - } - } - } - log::trace!("ticks: {}", ticks); - ticks += 1; - state += 1; - } - Some(Opcode::RegisterTickListener) => { - let buffer = - unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; - let hookdata = buffer.to_original::().unwrap(); - do_hook(hookdata, &mut tick_cb); - } - Some(Opcode::RegisterReqListener) => msg_scalar_unpack!(msg, sid0, sid1, sid2, sid3, { - let sid = xous::SID::from_u32(sid0 as _, sid1 as _, sid2 as _, sid3 as _); - let cid = xous::connect(sid).unwrap(); - if (cid as usize) < req_cb.len() { - req_cb[cid as usize] = true; - } else { - log::error!("cid out of allowable range"); - } - }), - Some(Opcode::UnregisterReqListener) => { - msg_scalar_unpack!(msg, sid0, sid1, sid2, sid3, { - let sid = xous::SID::from_u32(sid0 as _, sid1 as _, sid2 as _, sid3 as _); - let cid = xous::connect(sid).unwrap(); // if the connection already exists, this just looks it up in the table - log::info!("UnregisterReqListener cid {}", cid); - if (cid as usize) < req_cb.len() { - req_cb[cid as usize] = false; - } else { - log::error!("cid out of allowable range"); - } - unsafe { xous::disconnect(cid).unwrap() }; - }) - } - Some(Opcode::Req) => msg_scalar_unpack!(msg, _, _, _, _, { - log::debug!("req_cb: {:?}", req_cb); - // send results to request listeners - for cid in 1..req_cb.len() { - // 0 is not a valid connection - if req_cb[cid as usize] { - match xous::send_message( - cid as u32, - xous::Message::new_scalar( - api::ResultCallback::Result.to_usize().unwrap(), - state as _, - 0, - 0, - 0, - ), - ) { - Err(xous::Error::ServerNotFound) => { - log::info!("de-allocate ReqCallback"); - req_cb[cid] = false; - } - Ok(xous::Result::Ok) => {} - _ => panic!("unhandled error or result in callback processing"), - } - } - } - /* - for maybe_conn in req_cb.iter_mut() { - if let Some(conn) = maybe_conn { - match xous::send_message(*conn, - xous::Message::new_scalar(api::ResultCallback::Result.to_usize().unwrap(), state as _, 0, 0, 0)) { - Err(xous::Error::ServerNotFound) => { - log::info!("de-allocate ReqCallback"); - *maybe_conn = None // automatically de-allocate callbacks for clients that have dropped - }, - Ok(xous::Result::Ok) => {} - _ => panic!("unhandled error or result in callback processing") - } - } - }*/ - }), - None => { - log::error!("couldn't convert opcode"); - } - } - } -} - -fn do_hook(hookdata: ScalarHook, cb_conns: &mut [Option; 32]) { - let (s0, s1, s2, s3) = hookdata.sid; - let sid = xous::SID::from_u32(s0, s1, s2, s3); - let server_to_cb_cid = xous::connect(sid).unwrap(); - let cb_dat = Some(ScalarCallback { - server_to_cb_cid, - cb_to_client_cid: hookdata.cid, - cb_to_client_id: hookdata.id, - }); - let mut found = false; - for entry in cb_conns.iter_mut() { - if entry.is_none() { - *entry = cb_dat; - found = true; - break; - } - } - if !found { - log::error!("ran out of space registering callback"); - } -} diff --git a/services/test-stub/Cargo.toml b/services/test-stub/Cargo.toml deleted file mode 100644 index 8ed917646..000000000 --- a/services/test-stub/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "test-stub" -version = "0.1.0" -authors = ["bunnie "] -edition = "2018" -description = "Test Stub Program" - -# Dependency policy: fully specify dependencies to the minor version number -[dependencies] -xous = { path = "../../xous-rs" } -log-server = { path = "../log-server" } -ticktimer-server = { path = "../ticktimer-server" } -xous-names = { path = "../xous-names" } -log = "0.4.14" -num-derive = {version = "0.3.3", default-features = false} -num-traits = {version = "0.2.14", default-features = false} -susres = {path = "../susres"} - -[target.'cfg(not(any(windows,unix)))'.dependencies] -utralib = { path = "../../utralib"} - -[features] -default = [] diff --git a/services/test-stub/README.md b/services/test-stub/README.md deleted file mode 100644 index cb839c6db..000000000 --- a/services/test-stub/README.md +++ /dev/null @@ -1,2 +0,0 @@ -A test stub. Various small routines and tests get thrown here over time -for isolating parts of hairy bugs. diff --git a/services/test-stub/src/main.rs b/services/test-stub/src/main.rs deleted file mode 100644 index 7799bbee1..000000000 --- a/services/test-stub/src/main.rs +++ /dev/null @@ -1,204 +0,0 @@ -#![cfg_attr(target_os = "none", no_std)] -#![cfg_attr(target_os = "none", no_main)] - -use core::{fmt::Debug, hash::Hash, ptr::copy_nonoverlapping}; - -macro_rules! unsafe_read_slice { - ($src:expr, $dst:expr, $size:expr, $which:ident) => {{ - assert_eq!($src.len(), $size * $dst.len()); - - unsafe { - copy_nonoverlapping($src.as_ptr(), $dst.as_mut_ptr() as *mut u8, $src.len()); - } - for v in $dst.iter_mut() { - *v = v.$which(); - } - }}; -} -pub trait ByteOrder { - fn read_u64_into(src: &[u8], dst: &mut [u64]); -} -#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub enum LittleEndian {} - -impl Default for LittleEndian { - fn default() -> LittleEndian { - panic!("LittleEndian default") - } -} -impl ByteOrder for LittleEndian { - #[inline] - fn read_u64_into(src: &[u8], dst: &mut [u64]) { - unsafe_read_slice!(src, dst, 8, to_le); - } -} -#[derive(Copy, Clone, Hash)] -pub struct Scalar { - pub bytes: [u8; 32], -} -impl Scalar { - pub fn non_adjacent_form(&self, w: usize) -> [i8; 256] { - let mut naf = [0i8; 256]; - - #[repr(align(32))] - struct AlignedU64Slice([u64; N]); - - let mut x_u64 = AlignedU64Slice([0u64; 5]); - LittleEndian::read_u64_into(&self.bytes, &mut x_u64.0[0..4]); - - log::info!("x_u64: {:x?}", x_u64.0); - - let width = 1 << w; - let window_mask = width - 1; - - let mut pos = 0; - let mut carry = 0; - - while pos < 256 { - //log::info!("naf[{}]: {:?}", pos, naf); - - // Construct a buffer of bits of the scalar, starting at bit `pos` - let u64_idx = pos / 64; - let bit_idx = pos % 64; - - let mut x_u64_idx: u64 = x_u64.0[u64_idx]; - let mut x_u64_idx_plus_1: u64 = x_u64.0[u64_idx + 1]; - - let bit_buf: u64; - if bit_idx < 64 - w { - // This window's bits are contained in a single u64 - /* - let mut bits: [bool; 64] = [false; 64]; - for i in 0..64 { - if (x_u64[u64_idx] >> i) & 1 != 0 { - bits[i] = true; - } - } - log::info!("bits: {:?}", bits); - let mut buf: u64 = 0; - for i in u64_idx..64 { - if bits[i] { - buf |= 1 << i; - } - } - bit_buf = buf; - */ - /* - let mut modulus = 1; - for _ in 0..bit_idx { - modulus *= 2; - } - bit_buf = x_u64[u64_idx] / modulus;*/ - bit_buf = x_u64_idx >> bit_idx; /////////////////////////////// <----------- culprit - x_u64_idx += 1; - log::info!("bit_buf1: {:x}/{:x}/{}", x_u64_idx, bit_buf, u64_idx); - } else { - // Combine the current u64's bits with the bits from the next u64 - bit_buf = (x_u64_idx >> bit_idx) | (x_u64_idx_plus_1 << (64 - bit_idx)); - x_u64_idx_plus_1 += 1; - log::info!("bit_buf2: {:x}", bit_buf); - } - log::info!("dummy: {:x}", x_u64_idx + x_u64_idx_plus_1); - - // Add the carry into the current window - let window = carry + (bit_buf & window_mask); - - if window & 1 == 0 { - // If the window value is even, preserve the carry and continue. - // Why is the carry preserved? - // If carry == 0 and window & 1 == 0, then the next carry should be 0 - // If carry == 1 and window & 1 == 0, then bit_buf & 1 == 1 so the next carry should be 1 - pos += 1; - continue; - } - - if window < width / 2 { - log::info!("carry 0 width {} naf[{}] = {}; c.{} bb.{:x} wm.{} idx64.{} idxbit.{} xu64[0].{:x}", width, pos, window, - carry, bit_buf, window_mask, u64_idx, bit_idx, x_u64.0[0], - ); - carry = 0; - naf[pos] = window as i8; - } else { - log::info!("carry 1 width {} naf[{}] = {}/{}; c.{} bb.{:x} wm.{} idx64.{} idxbit.{} xu64[0].{:x}", width, pos, window, (window as i8).wrapping_sub(width as i8), - carry, bit_buf, window_mask, u64_idx, bit_idx, x_u64.0[0] - ); - carry = 1; - naf[pos] = (window as i8).wrapping_sub(width as i8); - } - - pos += w; - } - - naf - } -} - -// see https://godbolt.org/z/K8MK1v6f9 for the compiler explorer version of this -#[xous::xous_main] -fn xmain() -> ! { - log_server::init_wait().unwrap(); - log::set_max_level(log::LevelFilter::Info); - log::info!("my PID is {}", xous::process::id()); - - // let test_x: [u64; 5] = [3670528585167682493, 5751548057121892975, 14440402437776689254, 997049197504491580, 0]; - let mut test_x: [u64; 5] = [0u64; 5]; - LittleEndian::read_u64_into( - &[ - 189, 59, 214, 8, 77, 86, 240, 50, 111, 170, 86, 37, 124, 154, 209, 79, 102, 72, 93, 53, - 130, 157, 102, 200, 60, 240, 215, 104, 246, 58, 214, 13, - ], - &mut test_x[0..4], - ); - - let mut dummy: u64 = 0; - let mut bit_idx = 0; - for i in 0..4 { - let bit_buf: u64; - if i < 2 { - bit_buf = test_x[i] >> bit_idx; - } else { - bit_buf = (test_x[i] >> bit_idx) | (test_x[i + 1] << (64 - bit_idx)); - } - dummy += bit_buf; - bit_idx += 8; - log::info!("bit_buf: {:x}", bit_buf); - } - log::info!("dummy: {:x}", dummy); - - let scalar = Scalar { - bytes: [ - 189, 59, 214, 8, 77, 86, 240, 50, 111, 170, 86, 37, 124, 154, 209, 79, 102, 72, 93, 53, - 130, 157, 102, 200, 60, 240, 215, 104, 246, 58, 214, 13, - ], - }; - let mut padding: [u8; 33] = [0; 33]; - for (&src, dst) in scalar.bytes.iter().zip(padding.iter_mut()) { - *dst = src; - } - let a_naf = scalar.non_adjacent_form(5); - - let expected_result = [ - -3, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 13, 0, 0, 0, 0, 0, -7, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, -7, - 0, 0, 0, 0, -3, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, -11, 0, 0, 0, 0, -5, 0, 0, 0, 0, 11, 0, 0, 0, - 0, 5, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, - -3, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, -13, 0, 0, 0, 0, 0, -15, 0, 0, 0, 0, -11, 0, 0, 0, - 0, 15, 0, 0, 0, 0, -11, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, - -11, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, -7, 0, 0, 0, 0, -3, 0, 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, -1, 0, 0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 9, 0, 0, 0, 0, -13, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -5, 0, 0, 0, 0, 0, -7, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, - ]; - - log::info!("a_naf: {:?}", a_naf); - log::info!("expected_result: {:?}", expected_result); - assert!(a_naf == expected_result, "mismatch!"); - - log::info!("padding: {:?}", padding); - loop { - xous::yield_slice(); - } - /* - log::trace!("quitting"); - xous::terminate_process(0) - */ -} diff --git a/services/test-stub2/Cargo.toml b/services/test-stub2/Cargo.toml deleted file mode 100644 index dbd3f3c5e..000000000 --- a/services/test-stub2/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "test-stub2" -version = "0.1.0" -authors = ["bunnie "] -edition = "2018" -description = "Test stub 2" - -# Dependency policy: fully specify dependencies to the minor version number -[dependencies] -xous = { path = "../../xous-rs" } -ticktimer-server = { path = "../ticktimer-server" } -log-server = { path = "../log-server" } -log = "0.4.14" - -xous-ipc = {path = "../../xous-ipc"} -num-derive = {version = "0.3.3", default-features = false} -num-traits = {version = "0.2.14", default-features = false} -rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} - -[target.'cfg(not(any(windows,unix)))'.dependencies] -utralib = {path = "../../utralib"} - -[target.'cfg(any(windows,unix))'.dependencies] - -[features] -default = [] diff --git a/services/test-stub2/src/main.rs b/services/test-stub2/src/main.rs deleted file mode 100644 index a15c3f450..000000000 --- a/services/test-stub2/src/main.rs +++ /dev/null @@ -1,182 +0,0 @@ -#![cfg_attr(target_os = "none", no_std)] -#![cfg_attr(target_os = "none", no_main)] - -use num_traits::*; -use std::collections::HashMap; -use xous_ipc::{Buffer, String}; -use std::sync::{Arc, Mutex}; -use std::thread; -use utralib::generated::*; - -#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive)] -pub(crate) enum Op1 { - Test1, - Test2, - Test3, - Quit, -} -pub enum UartType { - Kernel = 0, - Log = 1, - Application = 2, - Invalid = 3, -} -// from/to for Xous messages -impl From for UartType { - fn from(code: usize) -> Self { - match code { - 0 => UartType::Kernel, - 1 => UartType::Log, - 2 => UartType::Application, - _ => UartType::Invalid, - } - } -} -impl Into for UartType { - fn into(self) -> usize { - match self { - UartType::Kernel => 0, - UartType::Log => 1, - UartType::Application => 2, - UartType::Invalid => 3, - } - } -} -// for the actual bitmask going to hardware -impl Into for UartType { - fn into(self) -> u32 { - match self { - UartType::Kernel => 0, - UartType::Log => 1, - UartType::Application => 2, - UartType::Invalid => 3, - } - } -} - -#[xous::xous_main] -fn shell_main() -> ! { - log_server::init_wait().unwrap(); - log::set_max_level(log::LevelFilter::Info); - log::info!("my PID is {}", xous::process::id()); - - let gpio_base = xous::syscall::map_memory( - xous::MemoryAddress::new(utra::gpio::HW_GPIO_BASE), - None, - 4096, - xous::MemoryFlags::R | xous::MemoryFlags::W, - ) - .expect("couldn't map GPIO CSR range"); - let mut gpio_csr = CSR::new(gpio_base.as_mut_ptr() as *mut u32); - // setup the initial logging output - gpio_csr.wfo(utra::gpio::UARTSEL_UARTSEL, UartType::Log as u32); - - let server1 = Arc::new(Mutex::new(xous::create_server_with_address(b"test-fooo-server") - .expect("Couldn't create xousnames-server"))); - - let _handle = thread::spawn({ - let sid = Arc::clone(&server1); - move || { - let ticktimer = ticktimer_server::Ticktimer::new().unwrap(); - let mut map = HashMap::::new(); - let mut value = 0; - log::info!("test target started"); - loop { - let msg = xous::receive_message(*sid.lock().unwrap()).unwrap(); - log::info!("received {:?}", msg); - match FromPrimitive::from_usize(msg.body.id()) { - Some(Op1::Test1) => xous::msg_blocking_scalar_unpack!(msg, token, _, _, _, { - log::info!("target test1"); - //icktimer.sleep_ms(1000).unwrap(); - value = token + 1; - xous::return_scalar(msg.sender, value).unwrap(); - }), - Some(Op1::Test2) => { - log::info!("target test2"); - let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; - let name = buffer.to_original::, _>().unwrap(); - map.insert(name.len(), value as i32); - }, - Some(Op1::Test3) => { - log::info!("target test3"); - let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; - let name = buffer.to_original::, _>().unwrap(); - log::info!("retrieved {:?}", map.get(&name.len())); - } - Some(Op1::Quit) => break, - None => { - log::info!("couldn't handle message"); - } - } - } - } - - }); - - let test_conn = xous::connect(*server1.lock().unwrap()).unwrap(); - let _handle2 = thread::spawn({ - move || { - let server2 = xous::create_server_with_address(b"test-food-server") - .expect("Couldn't create xousnames-server"); - let ticktimer = ticktimer_server::Ticktimer::new().unwrap(); - let identifier = String::<128>::from_str("test string"); - let mut local_id = 0; - let mut map = HashMap::::new(); - let mut value = 0; - loop { - let maybe_msg = xous::try_receive_message(server2).unwrap(); - match maybe_msg { - Some(msg) => { - log::info!("received {:?}", msg); - match FromPrimitive::from_usize(msg.body.id()) { - Some(Op1::Test1) => xous::msg_blocking_scalar_unpack!(msg, token, _, _, _, { - ticktimer.sleep_ms(1000).unwrap(); - value = token + 1; - xous::return_scalar(msg.sender, value).unwrap(); - }), - Some(Op1::Test2) => { - let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; - let name = buffer.to_original::, _>().unwrap(); - map.insert(name.len(), value as i32); - }, - Some(Op1::Test3) => { - let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; - let name = buffer.to_original::, _>().unwrap(); - log::info!("retrieved {:?}", map.get(&name.len())); - } - Some(Op1::Quit) => break, - None => { - log::info!("couldn't handle message"); - } - } - } - None => { - log::info!("test pump"); - ticktimer.sleep_ms(1000).unwrap(); - log::info!("sending msg {}", local_id); - - /* - let response = xous::send_message(test_conn, - xous::Message::new_blocking_scalar(Op1::Test1.to_usize().unwrap(), local_id, 0, 0, 0) - ).unwrap(); - if let xous::Result::Scalar1(result) = response { - local_id = result; - }*/ - log::info!("updated {}", local_id); - let buf = Buffer::into_buf(identifier).unwrap(); - log::info!("test2"); - buf.lend(test_conn, Op1::Test2.to_u32().unwrap()).unwrap(); - let buf2 = Buffer::into_buf(identifier).unwrap(); - log::info!("test3"); - buf2.lend(test_conn, Op1::Test3.to_u32().unwrap()).unwrap(); - } - } - } - } - }); - loop { - xous::yield_slice(); - } - - xous::terminate_process(0) -} \ No newline at end of file