diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 073035f80..e63e3f7d0 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -21,8 +21,8 @@ riscv = "0.5.6" debug-print = [] print-panics = [] report-memory = ["stats_alloc"] -# default = ["print-panics", "debug-print"] -default = ["print-panics"] +default = ["print-panics", "debug-print"] +# default = ["print-panics"] [target.'cfg(any(windows, unix))'.dependencies] lazy_static = "1.4" diff --git a/services/graphics-server/src/lib.rs b/services/graphics-server/src/lib.rs index ff644a9ab..8a0ac00dd 100644 --- a/services/graphics-server/src/lib.rs +++ b/services/graphics-server/src/lib.rs @@ -67,9 +67,9 @@ pub fn draw_string(cid: CID, s: &String<4096>) -> Result<(), xous::Error> { let pos = writer.archive(&request).expect("GFX: couldn't archive String request"); let xous_buffer = writer.into_inner(); - log::info!("GFX: draw_string message being sent"); + //log::info!("GFX: draw_string message being sent"); xous_buffer.lend(cid, pos as u32).expect("GFX: String request failure"); - log::info!("GFX: draw_string completed"); + //log::info!("GFX: draw_string completed"); Ok(()) } @@ -111,7 +111,9 @@ pub fn glyph_height_hint(cid: CID, glyph: GlyphStyle) -> Result Result<(), xous::Error> { + /*/ let mut sendable_tv = Sendable::new(tv) .expect("can't create sendable TextView structure"); - sendable_tv.lend_mut(cid, 0x100).map(|_| ()) + sendable_tv.lend_mut(cid, 0x100).map(|_| ()) */ + Ok(()) } \ No newline at end of file diff --git a/services/graphics-server/src/main.rs b/services/graphics-server/src/main.rs index c63013df3..32da0ff5a 100644 --- a/services/graphics-server/src/main.rs +++ b/services/graphics-server/src/main.rs @@ -47,7 +47,7 @@ fn xmain() -> ! { display.redraw(); loop { let msg = xous::receive_message(sid).unwrap(); - info!("GFX: Message: {:?}", msg); + //info!("GFX: Message: {:?}", msg); if let xous::Message::Borrow(m) = &msg.body { let mut buf = unsafe { buffer::XousBuffer::from_memory_message(m) }; let bytes = Pin::new(buf.as_ref()); @@ -57,7 +57,7 @@ fn xmain() -> ! { let new_value = match &*value { rkyv::Archived::::String(rkyv_s) => { let s: xous::String<4096> = rkyv_s.unarchive(); - info!("GFX: unarchived string: {:?}", s); + //info!("GFX: unarchived string: {:?}", s); blitstr::paint_str( display.native_buffer(), current_string_clip.into(), @@ -67,7 +67,7 @@ fn xmain() -> ! { false, blitstr::xor_char ); - info!("GFX: string painted"); + //info!("GFX: string painted"); }, rkyv::Archived::::StringXor(rkyv_s) => { let s: xous::String<4096> = rkyv_s.unarchive(); diff --git a/services/keyboard/src/api.rs b/services/keyboard/src/api.rs index 2a5491048..a29bc34cf 100644 --- a/services/keyboard/src/api.rs +++ b/services/keyboard/src/api.rs @@ -1,6 +1,10 @@ +use core::ops::Deref; + use heapless::consts::*; use heapless::Vec; use xous::{Message, ScalarMessage}; +use rkyv::{RelPtr, Archive, Archived, Resolve, Resolver, Write}; +use core::slice; pub const REGISTER_BASIC_LISTENER: u32 = 0x1000_0000; pub const REGISTER_RAW_LISTENER: u32 = 0x1000_0001; @@ -22,9 +26,7 @@ pub struct RowCol { pub r: u8, pub c: u8, } - -#[derive(Debug)] -#[repr(C)] +#[repr(packed)] pub struct KeyRawStates { mid: u32, pub keydowns: Vec, @@ -46,15 +48,61 @@ impl KeyRawStates { #[allow(dead_code)] pub fn copy(&self) -> KeyRawStates { let mut krs = KeyRawStates::new(); - for kd in self.keydowns.iter() { - krs.keydowns.push(*kd).unwrap(); - } - for ku in self.keyups.iter() { - krs.keyups.push(*ku).unwrap(); + unsafe { // because KeyRawStates is *packed* + for kd in self.keydowns.iter() { + krs.keydowns.push(*kd).unwrap(); + } + for ku in self.keyups.iter() { + krs.keyups.push(*ku).unwrap(); + } } krs } } +impl Clone for KeyRawStates { + fn clone(&self) -> KeyRawStates { + self.copy() + } +} +impl Deref for KeyRawStates { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts(self as *const KeyRawStates as *const u8, core::mem::size_of::()) + as &[u8] + } + } +} + +// warning: this rkyv code is totally untested +pub struct ArchivedKeyRawStates { + ptr: RelPtr, + len: u32, +} +pub struct KeyRawStatesResolver { + bytes_pos: usize, +} +impl Resolve for KeyRawStatesResolver { + type Archived = ArchivedKeyRawStates; + fn resolve(self, pos: usize, value: &KeyRawStates) -> Self::Archived { + Self::Archived { + ptr: unsafe { + rkyv::RelPtr::new(pos + rkyv::offset_of!(ArchivedKeyRawStates, ptr), self.bytes_pos) + }, + len: value.deref().len() as u32, + } + } +} +impl Archive for KeyRawStates { + type Archived = ArchivedKeyRawStates; + type Resolver = KeyRawStatesResolver; + + fn archive(&self, writer: &mut W) -> Result { + let bytes_pos = writer.pos(); + writer.write( self.deref())?; + Ok(Self::Resolver { bytes_pos }) + } +} #[derive(Debug, Copy, Clone, rkyv::Archive)] pub enum KeyMap { diff --git a/services/keyboard/src/main.rs b/services/keyboard/src/main.rs index c1c16260d..a15adfbc8 100644 --- a/services/keyboard/src/main.rs +++ b/services/keyboard/src/main.rs @@ -3,7 +3,6 @@ mod api; use api::*; -use xous::ipc::Sendable; use heapless::Vec; use heapless::consts::*; @@ -18,6 +17,7 @@ use log::{error, info}; use core::pin::Pin; use xous::buffer; use rkyv::{archived_value_mut, Unarchive}; +use rkyv::Write; /// Compute the dvorak key mapping of row/col to key tuples fn map_dvorak(code: RowCol) -> ScanCode { @@ -875,6 +875,8 @@ fn xmain() -> ! { } } */ + + // this code is totally untested if keyups.is_some() || keydowns.is_some() { // send the raw codes for conn in raw_conns.iter() { @@ -889,9 +891,10 @@ fn xmain() -> ! { rs.keydowns.push(k).unwrap(); } } - let sendable_rs = Sendable::new(rs).expect("KBD: can't create sendable raw codes structure"); - sendable_rs.send(*conn, KeyRawStates::new().mid() as u32) // tortured syntax to stick with the abstraction that message ID comes from the struct - .expect("KBD: can't send raw code"); + let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096)); + let pos = writer.archive(&rs).expect("couldn't archive request"); + let mut xous_buffer = writer.into_inner(); + xous_buffer.send(*conn, pos as u32).expect("KBD: can't send raw code"); } } diff --git a/services/log-server/src/main.rs b/services/log-server/src/main.rs index abdc1df51..8fd871bdd 100644 --- a/services/log-server/src/main.rs +++ b/services/log-server/src/main.rs @@ -258,7 +258,7 @@ fn reader_thread(mut output: implementation::OutputWriter) { .unwrap(); } xous::Message::Move(msg) => { - String::from_message(msg) + String<4000>::from_message(msg) .map(|log_entry: String<4000>| { writeln!( output, @@ -285,7 +285,7 @@ fn reader_thread(mut output: implementation::OutputWriter) { .ok(); } xous::Message::MutableBorrow(msg) => { - String::from_message(msg) + String<4000>::from_message(msg) .map(|mut log_entry: String<4000>| { writeln!( output, @@ -324,7 +324,7 @@ fn some_main() -> ! { ) .expect("couldn't map GPIO CSR range"); let mut gpio = CSR::new(gpio_base.as_mut_ptr() as *mut u32); - gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 1); // 0 = kernel, 1 = log, 2 = app_uart + gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 0); // 0 = kernel, 1 = log, 2 = app_uart } let mut output = implementation::init(); diff --git a/services/shell/src/main.rs b/services/shell/src/main.rs index d4dd166e9..1dc2875ac 100644 --- a/services/shell/src/main.rs +++ b/services/shell/src/main.rs @@ -175,6 +175,10 @@ fn shell_main() -> ! { // make a thread to catch responses from the COM xous::create_thread_simple(event_thread, 0).unwrap(); info!("SHELL: COM responder thread started"); + let start_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap(); + while ticktimer_server::elapsed_ms(ticktimer_conn).unwrap() - start_time < 1000 { + xous::yield_slice(); + } let screensize = graphics_server::screen_size(graphics_conn).expect("Couldn't get screen size"); @@ -236,7 +240,7 @@ fn shell_main() -> ! { graphics_server::set_cursor(graphics_conn, status_cursor).expect("can't set cursor"); //info!("SHELL: debug0"); graphics_server::draw_string(graphics_conn, &string_buffer).expect("unable to draw string"); - info!("SHELL: debug1"); + //info!("SHELL: debug1"); status_cursor.pt.x = 95; string_buffer.clear(); write!( @@ -246,8 +250,9 @@ fn shell_main() -> ! { ) .expect("Can't write"); graphics_server::set_cursor(graphics_conn, status_cursor).expect("can't set cursor"); - info!("SHELL: debug2"); + //info!("SHELL: debug2"); graphics_server::draw_string(graphics_conn, &string_buffer).expect("unable to draw string"); + //info!("SHELL: debug3"); status_cursor.pt.x = 190; string_buffer.clear(); write!( @@ -373,19 +378,6 @@ fn shell_main() -> ! { ) .expect("unable to draw to screen"); - /* test code to exhaust memory allocation - let mut iter = 0; - info!("Test memory allocation"); - loop { - let lookup = Lookup::new(); - let mut sendable_lookup = Sendable::new(lookup) - .expect("can't create sendable lookup structure"); - write!(sendable_lookup.name, "A test Name!").unwrap(); - sendable_lookup.lend_mut(ns_conn, sendable_lookup.mid()).expect("nameserver lookup failure!"); - 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/lib.rs b/services/xous-names/src/lib.rs index 877d5847e..625b713c1 100644 --- a/services/xous-names/src/lib.rs +++ b/services/xous-names/src/lib.rs @@ -78,21 +78,3 @@ pub fn request_connection_blocking(name: &str) -> Result xous::yield_slice(); } } - -// /// API for other processes to re-use the Registration record for brokering requests -// pub fn request_core( -// name: &str, -// conn: xous::CID, -// subtype: u16, -// ) -> Result { -// let registration = api::default(); -// let mut sendable_registration = -// Sendable::new(registration).expect("can't create sendable registration structure"); -// // sendable_registration.set_subtype(subtype); -// write!(sendable_registration.name, "{}", name).unwrap(); -// sendable_registration -// .lend(conn, api::ID_REGISTER_NAME | (subtype as u32)) -// .expect("event request registration failure!"); - -// Ok(xous::Result::Ok) -// } diff --git a/xous-rs/src/buffer.rs b/xous-rs/src/buffer.rs index e2f19902e..c0e7c311f 100644 --- a/xous-rs/src/buffer.rs +++ b/xous-rs/src/buffer.rs @@ -55,7 +55,7 @@ impl<'a> XousBuffer<'a> { id: id as usize, buf: self.valid, offset: None, - valid: None, + valid: crate::MemorySize::new(self.slice.len()), }; send_message(connection, Message::MutableBorrow(msg)) } @@ -70,7 +70,7 @@ impl<'a> XousBuffer<'a> { id: id as usize, buf: self.valid, offset: None, - valid: None, + valid: crate::MemorySize::new(self.slice.len()), }; send_message(connection, Message::Borrow(msg)) } @@ -94,7 +94,6 @@ impl<'a> XousBuffer<'a> { Ok(result) } } - impl<'a> core::convert::AsRef<[u8]> for XousBuffer<'a> { fn as_ref(&self) -> &[u8] { self.slice diff --git a/xous-rs/src/string.rs b/xous-rs/src/string.rs index 7d8e6323b..5eb35726b 100644 --- a/xous-rs/src/string.rs +++ b/xous-rs/src/string.rs @@ -60,6 +60,7 @@ impl String { xous_buffer.lend(connection, pos as u32) } +/* /// Move this string from the client into the server. pub fn send( self, @@ -72,7 +73,7 @@ impl String { xous_buffer.send(connection, pos as u32) } - +*/ /// Clear the contents of this String and set the length to 0 pub fn clear(&mut self) { self.len = 0;