From 95d4f035910884ba62da284a3a21bbcbc7c8e933 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 7 Jan 2021 21:53:08 +0800 Subject: [PATCH] intermediate checkin --- services/com/src/main.rs | 15 +++++---------- services/shell/src/main.rs | 16 ++++++---------- services/xous-names/src/api.rs | 2 +- services/xous-names/src/lib.rs | 13 +++++++++++-- xous-rs/src/lib.rs | 2 ++ 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/services/com/src/main.rs b/services/com/src/main.rs index b5c414790..228006339 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -237,16 +237,11 @@ fn xmain() -> ! { log_server::init_wait().unwrap(); - xous_names::register_name("COM manager to EC"); + let com_sid = xous_names::register_name(xous::names::SERVER_NAME_COM).expect("COM: can't register server"); - let com_server = - xous::create_server_with_address(b"com ").expect("Couldn't create COM server"); - - let shell_id = xous::SID::from_bytes(b"shell ").unwrap(); - let shell_conn = xous::connect(shell_id).unwrap(); - - let testconn = xous_names::request_connection("COM manager to EC"); - info!("testconn result: {:?}", testconn); + // let shell_id = xous::SID::from_bytes(b"shell ").unwrap(); + // let shell_conn = xous::connect(shell_id).unwrap(); + let shell_conn = xous_names::request_connection(xous::names::SERVER_NAME_SHELL).expect("COM: couldn't establish shell connection"); let agent_conn: usize; if cfg!(feature = "fccagent") { @@ -261,7 +256,7 @@ fn xmain() -> ! { info!("COM: starting main loop"); loop { - let envelope = xous::receive_message(com_server).unwrap(); + let envelope = xous::receive_message(com_sid).unwrap(); // info!("COM: Message: {:?}", envelope); if let Ok(opcode) = Opcode::try_from(&envelope.body) { // info!("COM: Opcode: {:?}", opcode); diff --git a/services/shell/src/main.rs b/services/shell/src/main.rs index 0094a34a9..a1b8e1cc6 100644 --- a/services/shell/src/main.rs +++ b/services/shell/src/main.rs @@ -5,11 +5,9 @@ use blitstr::{Cursor, GlyphStyle}; use com::*; use core::fmt::Write; use graphics_server::{Circle, DrawStyle, Line, PixelColor, Point, Rectangle}; -use xous_names::api::{Registration, Lookup}; use log::{error, info}; use xous::String; -use xous::ipc::*; use core::convert::TryFrom; @@ -107,9 +105,7 @@ static BATT_STATS_CURRENT: AtomicI16 = AtomicI16::new(-150); static BATT_STATS_SOC: AtomicU8 = AtomicU8::new(50); static BATT_STATS_REMAINING: AtomicU16 = AtomicU16::new(750); -fn com_thread(_arg: Option) { - let shell_server = xous::create_server_with_address(b"shell ") - .expect("Couldn't create Shell server"); +fn com_thread(shell_server: xous::SID) { info!("SHELL|com_thread: starting COM response handler thread"); loop { let envelope = xous::syscall::receive_message(shell_server).expect("couldn't get address"); @@ -134,18 +130,18 @@ fn com_thread(_arg: Option) { fn shell_main() -> ! { log_server::init_wait().unwrap(); + let shell_sid = xous_names::register_name(xous::names::SERVER_NAME_SHELL).expect("SHELL: can't register server"); + // let log_server_id = xous::SID::from_bytes(b"xous-logs-output").unwrap(); let graphics_server_id = xous::SID::from_bytes(b"graphics-server ").unwrap(); let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap(); let log_server_id = xous::SID::from_bytes(b"xous-log-server ").unwrap(); let com_id = xous::SID::from_bytes(b"com ").unwrap(); - let ns_id = xous::SID::from_bytes(b"xous-name-server").unwrap(); let log_conn = xous::connect(log_server_id).unwrap(); let graphics_conn = xous::connect(graphics_server_id).unwrap(); let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap(); let com_conn = xous::connect(com_id).unwrap(); - let ns_conn = xous::connect(ns_id).unwrap(); info!( "SHELL: Connected to Log server: {} Graphics server: {} Ticktimer server: {} Com: {}", @@ -163,7 +159,7 @@ fn shell_main() -> ! { ); // make a thread to catch responses from the COM - xous::create_thread_simple(com_thread, None).unwrap(); + xous::create_thread_simple(com_thread, shell_sid).unwrap(); info!("SHELL: COM responder thread started"); let screensize = graphics_server::screen_size(graphics_conn).expect("Couldn't get screen size"); @@ -345,7 +341,7 @@ fn shell_main() -> ! { ) .expect("unable to draw to screen"); - /* test code to exhaust memory allocation */ + /* test code to exhaust memory allocation let mut iter = 0; info!("Test memory allocation"); loop { @@ -357,7 +353,7 @@ fn shell_main() -> ! { info!("memtest: iter {}", iter); iter += 1; } - + */ // Periodic tasks if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) { if elapsed_time - last_time > 500 { diff --git a/services/xous-names/src/api.rs b/services/xous-names/src/api.rs index 2377bfe37..cf8c3ca9a 100644 --- a/services/xous-names/src/api.rs +++ b/services/xous-names/src/api.rs @@ -107,7 +107,7 @@ impl AsRef for XousServerName { #[repr(C)] pub struct Registration { mid: usize, - pub sid: SID, // query: do we even want to return this to the registering process?? + pub sid: SID, // we use fixed-length, u8-only records to pass server names. This is different from // your typical Rust String object; but, a key restriction on IPC calls is that the size diff --git a/services/xous-names/src/lib.rs b/services/xous-names/src/lib.rs index 6134eec7b..49c317388 100644 --- a/services/xous-names/src/lib.rs +++ b/services/xous-names/src/lib.rs @@ -6,7 +6,10 @@ use xous::ipc::*; use api::{Registration, Lookup}; use core::fmt::Write; -pub fn register_name(name: &str) -> Result { +pub fn register_name(name: &str) -> Result { + let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap(); + let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap(); + let ns_id = xous::SID::from_bytes(b"xous-name-server").unwrap(); let ns_conn = xous::connect(ns_id).unwrap(); @@ -16,7 +19,13 @@ pub fn register_name(name: &str) -> Result { write!(sendable_registration.name, "{}", name).unwrap(); sendable_registration.lend_mut(ns_conn, sendable_registration.mid()).expect("nameserver registration failure!"); - Ok(sendable_registration.success) + ticktimer_server::sleep_ms(ticktimer_conn, 100).expect("Failed to wait for server boot"); + + if sendable_registration.success { + Ok(sendable_registration.sid) + } else { + Err(xous::Error::InternalError) + } } /// note: if this throws an AccessDenied error, you can retry with a request_authenticat_connection() call (to be written) diff --git a/xous-rs/src/lib.rs b/xous-rs/src/lib.rs index dc900a3d6..c833e0809 100644 --- a/xous-rs/src/lib.rs +++ b/xous-rs/src/lib.rs @@ -16,6 +16,8 @@ mod messages; pub mod string; pub mod syscall; +pub mod names; + pub use arch::{ProcessArgs, ProcessInit, ProcessKey, ThreadInit}; pub use definitions::*; pub use messages::*;