From dc2519c5ef919b0540b105cc4c08ca9827f42e85 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 1 Apr 2021 03:47:10 +0800 Subject: [PATCH] trying out new API names --- services/llio/src/i2c.rs | 2 +- services/rkyv-test-server/src/lib.rs | 18 +++++++++--------- services/rkyv-test-server/src/main.rs | 8 ++++---- services/ticktimer-server/src/main.rs | 6 +++++- services/xous-names/src/lib.rs | 8 ++++---- services/xous-names/src/main.rs | 6 +++--- xous-ipc/src/buffer.rs | 6 +++--- xtask/src/main.rs | 25 ++++--------------------- 8 files changed, 33 insertions(+), 46 deletions(-) diff --git a/services/llio/src/i2c.rs b/services/llio/src/i2c.rs index aef765349..574176ee6 100644 --- a/services/llio/src/i2c.rs +++ b/services/llio/src/i2c.rs @@ -19,7 +19,7 @@ pub struct I2cStateMachine { } #[cfg(not(target_os = "none"))] 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 {} } pub fn initiate(&mut self, _transaction: I2cTransaction ) -> I2cStatus { diff --git a/services/rkyv-test-server/src/lib.rs b/services/rkyv-test-server/src/lib.rs index 9d49be2cb..4442ca59f 100644 --- a/services/rkyv-test-server/src/lib.rs +++ b/services/rkyv-test-server/src/lib.rs @@ -31,7 +31,7 @@ pub fn add(arg1: i32, arg2: i32) -> Result { // Convert the opcode into a serialized buffer. This consumes the opcode, which will // exist on the heap in its own page. Furthermore, this will be in a flattened format // suitable for passing around as a message. - let mut buf = Buffer::try_from(op).or(Err(api::Error::InternalError))?; + let mut buf = Buffer::as_buf(op).or(Err(api::Error::InternalError))?; // Mutably lend our op to the server, specifying the `api::Opcode::Mathematics` opcode. // This will return a structure that we can deserialize back into something we @@ -44,7 +44,7 @@ pub fn add(arg1: i32, arg2: i32) -> Result { // Turn the result of the response into a friendly value that can be understood // by the caller. - match buf.deserialize().unwrap() { + match buf.as_copy_obj().unwrap() { api::MathResult::Value(v) => Ok(v), api::MathResult::Error(val) => Err(val), } @@ -55,7 +55,7 @@ fn do_op(op: api::MathOperation) -> Result { // Convert the opcode into a serialized buffer. This consumes the opcode, which will // exist on the heap in its own page. Furthermore, this will be in a flattened format // suitable for passing around as a message. - let mut buf = Buffer::try_from(op).or(Err(api::Error::InternalError))?; + let mut buf = Buffer::as_buf(op).or(Err(api::Error::InternalError))?; // Lend our op to the server, specifying the `api::Opcode::Mathematics` opcode. // This will return a structure that we can deserialize back into something we @@ -67,7 +67,7 @@ fn do_op(op: api::MathOperation) -> Result { .or(Err(api::Error::InternalError))?; // Don't deserialize it -- use the archived version - match *buf.try_into::().unwrap() { + match *buf.as_zerocopy_obj::().unwrap() { api::ArchivedMathResult::Value(v) => Ok(v), api::ArchivedMathResult::Error(api::ArchivedError::InternalError) => Err(api::Error::InternalError), api::ArchivedMathResult::Error(api::ArchivedError::Overflow) => Err(api::Error::Overflow), @@ -98,7 +98,7 @@ pub fn log_message, T: AsRef>(prefix: S, message: T) { // Convert the opcode into a serialized buffer. This consumes the opcode, which will // exist on the heap in its own page. Furthermore, this will be in a flattened format // suitable for passing around as a message. - let buf = Buffer::try_from(op).unwrap(); + let buf = Buffer::as_buf(op).unwrap(); // Send the message to the server. buf.lend( @@ -119,7 +119,7 @@ pub fn log_message_send, T: AsRef>(prefix: S, message: T) { // Convert the opcode into a serialized buffer. This consumes the opcode, which will // exist on the heap in its own page. Furthermore, this will be in a flattened format // suitable for passing around as a message. - let buf = Buffer::try_from(op).unwrap(); + let buf = Buffer::as_buf(op).unwrap(); // Send the message to the server. buf.send( @@ -143,7 +143,7 @@ fn callback_server() { Some(api::CallbackType::LogString) => { let mem = msg.body.memory_message().unwrap(); let buffer = unsafe { Buffer::from_memory_message(mem) }; - let log_string = buffer.try_into::().unwrap(); + let log_string = buffer.as_zerocopy_obj::().unwrap(); unsafe { for entry in CALLBACK_ARRAY.iter() { if let Some(cb) = entry { @@ -197,7 +197,7 @@ pub fn double_string(value: &T) -> String<512> where T: AsRef { // Convert the opcode into a serialized buffer. This consumes the opcode, which will // exist on the heap in its own page. Furthermore, this will be in a flattened format // suitable for passing around as a message. - let mut buf = Buffer::try_from(op).unwrap(); + let mut buf = Buffer::as_buf(op).unwrap(); // Send the message to the server. buf.lend_mut( @@ -206,5 +206,5 @@ pub fn double_string(value: &T) -> String<512> where T: AsRef { ) .unwrap(); - String::from_str(buf.try_into::().unwrap().value.as_str()) + String::from_str(buf.as_zerocopy_obj::().unwrap().value.as_str()) } diff --git a/services/rkyv-test-server/src/main.rs b/services/rkyv-test-server/src/main.rs index 8b800593f..5812d7074 100644 --- a/services/rkyv-test-server/src/main.rs +++ b/services/rkyv-test-server/src/main.rs @@ -13,7 +13,7 @@ fn handle_math_withcopy(mem: &mut xous::MemoryMessage) { let mut buffer = unsafe { Buffer::from_memory_message_mut(mem) }; let response = { use api::MathOperation::*; - match buffer.deserialize().unwrap() { + match buffer.as_copy_obj().unwrap() { Add(a, b) => value_or( a.checked_add(b), api::MathResult::Error(api::Error::Overflow), @@ -41,7 +41,7 @@ fn handle_math_zerocopy(mem: &mut xous::MemoryMessage) { let mut buffer = unsafe { Buffer::from_memory_message_mut(mem) }; let response = { use api::ArchivedMathOperation::*; - match *buffer.try_into::().unwrap() { + match *buffer.as_zerocopy_obj::().unwrap() { Add(a, b) => value_or( a.checked_add(b), api::MathResult::Error(api::Error::Overflow), @@ -65,7 +65,7 @@ fn handle_math_zerocopy(mem: &mut xous::MemoryMessage) { fn handle_log_string(mem: &xous::MemoryMessage) { let buffer = unsafe { Buffer::from_memory_message(mem) }; - let log_string = buffer.try_into::().unwrap(); + let log_string = buffer.as_zerocopy_obj::().unwrap(); log::info!( "Prefix: {} Message: {}", log_string.prefix.as_str(), @@ -81,7 +81,7 @@ fn double_string(mem: &mut xous::MemoryMessage) { value: String::new(), }; for ch in buffer - .try_into::() + .as_zerocopy_obj::() .unwrap() .value .as_str() diff --git a/services/ticktimer-server/src/main.rs b/services/ticktimer-server/src/main.rs index f3f08c70a..e2cb7d739 100644 --- a/services/ticktimer-server/src/main.rs +++ b/services/ticktimer-server/src/main.rs @@ -245,6 +245,7 @@ mod implementation { mod implementation { use super::SleepRequest; use std::convert::TryInto; + use num_traits::ToPrimitive; #[derive(Debug)] enum SleepComms { @@ -285,7 +286,10 @@ mod implementation { // This is dangerous and may panic if the queue is full. xous::try_send_message( cid, - crate::api::Opcode::RecalculateSleep.into(), + xous::Message::Scalar(xous::ScalarMessage { + id: crate::api::Opcode::RecalculateSleep.to_usize().unwrap(), + arg1: 0, arg2: 0, arg3: 0, arg4: 0 + }) ) .unwrap(); timeout = None; diff --git a/services/xous-names/src/lib.rs b/services/xous-names/src/lib.rs index e4126d9dc..a266e6896 100644 --- a/services/xous-names/src/lib.rs +++ b/services/xous-names/src/lib.rs @@ -22,7 +22,7 @@ impl XousNames { // could also do String::from_str() but in this case we want things to fail if the string is too long. write!(registration_name, "{}", name).expect("NS: name probably too long"); - let mut buf = Buffer::try_from(registration_name).or(Err(xous::Error::InternalError))?; + let mut buf = Buffer::as_buf(registration_name).or(Err(xous::Error::InternalError))?; buf.lend_mut( self.conn, @@ -30,7 +30,7 @@ impl XousNames { ) .or(Err(xous::Error::InternalError))?; - match buf.deserialize().unwrap() { + match buf.as_copy_obj().unwrap() { api::Return::SID(sid_raw) => { let sid = sid_raw.into(); xous::create_server_with_sid(sid).expect("NS: can't auto-register server"); @@ -48,7 +48,7 @@ impl XousNames { let mut lookup_name = xous_ipc::String::<64>::new(); write!(lookup_name, "{}", name).expect("NS: name problably too long"); - let mut buf = Buffer::try_from(lookup_name).or(Err(xous::Error::InternalError))?; + let mut buf = Buffer::as_buf(lookup_name).or(Err(xous::Error::InternalError))?; buf.lend_mut( self.conn, @@ -56,7 +56,7 @@ impl XousNames { ) .or(Err(xous::Error::InternalError))?; - match buf.deserialize().unwrap() { + match buf.as_copy_obj().unwrap() { api::Return::CID(cid) => Ok(cid), api::Return::AuthenticateRequest(_) => Err(xous::Error::AccessDenied), _ => Err(xous::Error::ServerNotFound), diff --git a/services/xous-names/src/main.rs b/services/xous-names/src/main.rs index 5887e5a3d..c279bd2aa 100644 --- a/services/xous-names/src/main.rs +++ b/services/xous-names/src/main.rs @@ -40,7 +40,7 @@ fn xmain() -> ! { Some(api::Opcode::Register) => { let mem = msg.body.memory_message_mut().unwrap(); let mut buffer = unsafe { Buffer::from_memory_message_mut(mem) }; - let xous_string = buffer.try_into::, _>().unwrap(); + let xous_string = buffer.as_zerocopy_obj::, _>().unwrap(); let name = XousServerName::from_str(xous_string.as_str()); let response: api::Return; @@ -73,7 +73,7 @@ fn xmain() -> ! { Some(api::Opcode::Lookup) => { let mem = msg.body.memory_message_mut().unwrap(); let mut buffer = unsafe { Buffer::from_memory_message_mut(mem) }; - let name_string = buffer.try_into::, _>().unwrap(); + let name_string = buffer.as_zerocopy_obj::, _>().unwrap(); let name = XousServerName::from_str(name_string.as_str()); if debug1{info!("NS: Lookup request for '{}'", name);} let response: api::Return; @@ -122,7 +122,7 @@ fn xmain() -> ! { Some(api::Opcode::AuthenticatedLookup) => { let mem = msg.body.memory_message_mut().unwrap(); let buffer = unsafe { Buffer::from_memory_message_mut(mem) }; - let auth_lookup: AuthenticatedLookup = buffer.deserialize().unwrap(); + let auth_lookup: AuthenticatedLookup = buffer.as_copy_obj().unwrap(); info!("NS: AuthenticatedLookup request {:?}", auth_lookup); error!("NS: AuthenticatedLookup not yet implemented"); unimplemented!("NS: AuthenticatedLookup not yet implemented"); diff --git a/xous-ipc/src/buffer.rs b/xous-ipc/src/buffer.rs index 8b5af32ee..7c44d049c 100644 --- a/xous-ipc/src/buffer.rs +++ b/xous-ipc/src/buffer.rs @@ -129,7 +129,7 @@ impl<'a> Buffer<'a> { } #[allow(dead_code)] - pub fn try_from(src: S) -> core::result::Result + pub fn as_buf(src: S) -> core::result::Result where S: rkyv::Serialize>>, { @@ -170,7 +170,7 @@ impl<'a> Buffer<'a> { } #[allow(dead_code)] - pub fn try_into(&self) -> core::result::Result<&U, ()> + pub fn as_zerocopy_obj(&self) -> core::result::Result<&U, ()> where T: rkyv::Archive, { @@ -180,7 +180,7 @@ impl<'a> Buffer<'a> { } #[allow(dead_code)] - pub fn deserialize(&self) -> core::result::Result + pub fn as_copy_obj(&self) -> core::result::Result where T: rkyv::Archive, U: rkyv::Deserialize>, diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 4df89da8b..b9bff2ea9 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -95,12 +95,12 @@ fn try_main() -> Result<(), DynError> { ], )?, Some("renode-image-debug") => renode_image(true, &hw_pkgs)?, - Some("run") => run(false)?, + Some("run") => run(false, &minimal_pkgs)?, Some("hw-image") => build_hw_image(false, env::args().nth(2), &hw_pkgs)?, Some("benchmark") => build_hw_image(false, env::args().nth(2), &benchmark_pkgs)?, Some("fcc-agent") => build_hw_image(false, env::args().nth(2), &fcc_pkgs)?, Some("minimal") => build_hw_image(false, env::args().nth(2), &minimal_pkgs)?, - Some("debug") => run(true)?, + Some("debug") => run(true, &hw_pkgs)?, _ => print_help(), } Ok(()) @@ -215,25 +215,8 @@ fn renode_image(debug: bool, packages: &[&str]) -> Result<(), DynError> { Ok(()) } -fn run(debug: bool) -> Result<(), DynError> { +fn run(debug: bool, init: &[&str]) -> Result<(), DynError> { let stream = if debug { "debug" } else { "release" }; - let init = [ - //"shell", - "gam", - "ime-frontend", - "ime-plugin-shell", - "shellchat", - //"benchmark", - //"benchmark-target", - "log-server", - "graphics-server", - "ticktimer-server", - "com", - "xous-names", - "keyboard", - "trng", - "llio", - ]; build(&init, debug, None, None)?; @@ -246,7 +229,7 @@ fn run(debug: bool) -> Result<(), DynError> { args.push("--"); let mut paths = vec![]; - for i in &init { + for i in init { let tmp: PathBuf = Path::new(&format!( "..{}target{}{}{}{}", MAIN_SEPARATOR, MAIN_SEPARATOR, stream, MAIN_SEPARATOR, i