mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
this code works in hosted mode but fails on hardware
This commit is contained in:
parent
ec675eefb4
commit
0d869870ae
5 changed files with 88 additions and 17 deletions
|
|
@ -198,6 +198,10 @@ mod implementation {
|
||||||
0xDEAD as u16
|
0xDEAD as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn wait_txrx(&mut self, tx: u16, timeout: Option<u32>) -> u16 {
|
||||||
|
0xDEAD as u16
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_battstats(&mut self) -> BattStats {
|
pub fn get_battstats(&mut self) -> BattStats {
|
||||||
BattStats {
|
BattStats {
|
||||||
voltage: 3700,
|
voltage: 3700,
|
||||||
|
|
|
||||||
|
|
@ -356,8 +356,7 @@ fn shell_main() -> ! {
|
||||||
let registration = Registration::new();
|
let registration = Registration::new();
|
||||||
let mut sendable_registration = Sendable::new(registration)
|
let mut sendable_registration = Sendable::new(registration)
|
||||||
.expect("can't create sendable registration structure");
|
.expect("can't create sendable registration structure");
|
||||||
let test_name = b"A test Name!";
|
write!(sendable_registration.name, "A test Name!");
|
||||||
sendable_registration.name.name[..test_name.len()].clone_from_slice(test_name);
|
|
||||||
info!("namserver registration input: {:?}", sendable_registration.success);
|
info!("namserver registration input: {:?}", sendable_registration.success);
|
||||||
sendable_registration.lend_mut(ns_conn, sendable_registration.mid()).expect("nameserver registration failure!");
|
sendable_registration.lend_mut(ns_conn, sendable_registration.mid()).expect("nameserver registration failure!");
|
||||||
info!("nameserver registration result: {:?}, {:?}", sendable_registration.success, sendable_registration.sid);
|
info!("nameserver registration result: {:?}, {:?}", sendable_registration.success, sendable_registration.sid);
|
||||||
|
|
@ -368,9 +367,7 @@ fn shell_main() -> ! {
|
||||||
let mut sendable_lookup = Sendable::new(lookup)
|
let mut sendable_lookup = Sendable::new(lookup)
|
||||||
.expect("can't create sendable lookup structure");
|
.expect("can't create sendable lookup structure");
|
||||||
info!("making a test name");
|
info!("making a test name");
|
||||||
let another_name = b"A test Name!";
|
write!(sendable_lookup.name, "A test Name!");
|
||||||
info!("cloning into slice");
|
|
||||||
sendable_lookup.name.name[..another_name.len()].clone_from_slice(another_name);
|
|
||||||
info!("nameserver lookup input: {:?}", sendable_lookup.success);
|
info!("nameserver lookup input: {:?}", sendable_lookup.success);
|
||||||
sendable_lookup.lend_mut(ns_conn, sendable_lookup.mid()).expect("nameserver lookup failure!");
|
sendable_lookup.lend_mut(ns_conn, sendable_lookup.mid()).expect("nameserver lookup failure!");
|
||||||
info!("nameserver lookup result: {:?}, {:?}", sendable_lookup.success, sendable_lookup.cid);
|
info!("nameserver lookup result: {:?}, {:?}", sendable_lookup.success, sendable_lookup.cid);
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,90 @@ pub const ID_AUTHENTICATE: usize = 2;
|
||||||
|
|
||||||
pub const AUTHENTICATE_TIMEOUT: usize = 10_000; // time in ms that a process has to respond to an authentication request
|
pub const AUTHENTICATE_TIMEOUT: usize = 10_000; // time in ms that a process has to respond to an authentication request
|
||||||
|
|
||||||
|
//////////////////////// handle throwing strings across IPC boundary with hash comparison
|
||||||
|
|
||||||
#[derive(Hash32, Debug, Copy, Clone)]
|
#[derive(Hash32, Debug, Copy, Clone)]
|
||||||
pub struct XousServerName{pub name: [u8; 32]}
|
#[repr(C)]
|
||||||
|
pub struct XousServerName {
|
||||||
|
pub name: [u8; 32],
|
||||||
|
pub length: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl XousServerName {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_str(&self) -> &str {
|
||||||
|
core::str::from_utf8(unsafe {
|
||||||
|
core::slice::from_raw_parts(self.name.as_ptr(), self.length)
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for XousServerName {
|
impl Default for XousServerName {
|
||||||
fn default() -> Self { XousServerName{name: [0; 32]} }
|
fn default() -> Self {
|
||||||
|
XousServerName {
|
||||||
|
name: [0; 32],
|
||||||
|
length: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl PartialEq for XousServerName {
|
impl PartialEq for XousServerName {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.name == other.name
|
self.name[..self.length] == other.name[..other.length] && self.length == other.length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for XousServerName {}
|
impl Eq for XousServerName {}
|
||||||
|
|
||||||
|
// Allow using the `write!()` macro to write into a `&XousServerName`
|
||||||
|
impl core::fmt::Write for XousServerName {
|
||||||
|
fn write_str(&mut self, s: &str) -> core::result::Result<(), core::fmt::Error> {
|
||||||
|
self.length = 0;
|
||||||
|
let b = s.bytes();
|
||||||
|
|
||||||
|
// Ensure the length is acceptable
|
||||||
|
if b.len() > self.name.len() {
|
||||||
|
Err(core::fmt::Error)?;
|
||||||
|
}
|
||||||
|
self.length = b.len();
|
||||||
|
|
||||||
|
// Copy the string into this variable
|
||||||
|
for (dest, src) in self.name.iter_mut().zip(s.bytes()) {
|
||||||
|
*dest = src;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to convert the string to UTF-8 to validate it's correct UTF-8
|
||||||
|
core::str::from_utf8(unsafe {
|
||||||
|
core::slice::from_raw_parts(self.name.as_ptr(), self.length)
|
||||||
|
})
|
||||||
|
.map_err(|_| core::fmt::Error)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow a `&XousServerName` to be printed out
|
||||||
|
impl core::fmt::Display for XousServerName {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
write!(f, "{}", self.to_str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow a `&XousServerName` to be used anywhere that expects a `&str`
|
||||||
|
impl AsRef<str> for XousServerName {
|
||||||
|
fn as_ref(&self) -> &str {
|
||||||
|
self.to_str()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////// end server name string implementation functions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[repr(C)]
|
||||||
pub struct Registration {
|
pub struct Registration {
|
||||||
mid: usize,
|
mid: usize,
|
||||||
pub sid: SID, // query: do we even want to return this to the registering process??
|
pub sid: SID, // query: do we even want to return this to the registering process??
|
||||||
|
|
@ -43,7 +114,7 @@ impl Registration {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Registration {
|
Registration {
|
||||||
mid: ID_REGISTER_NAME,
|
mid: ID_REGISTER_NAME,
|
||||||
sid: xous::SID::from_u32(0,0,0,0),
|
sid: SID::from_u32(0,0,0,0),
|
||||||
name: XousServerName::default(),
|
name: XousServerName::default(),
|
||||||
success: false,
|
success: false,
|
||||||
}
|
}
|
||||||
|
|
@ -51,6 +122,7 @@ impl Registration {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[repr(C)]
|
||||||
pub struct Lookup {
|
pub struct Lookup {
|
||||||
mid: usize,
|
mid: usize,
|
||||||
pub cid: CID,
|
pub cid: CID,
|
||||||
|
|
@ -78,6 +150,7 @@ impl Lookup {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[repr(C)]
|
||||||
pub struct Authenticate {
|
pub struct Authenticate {
|
||||||
mid: usize,
|
mid: usize,
|
||||||
pub cid: CID,
|
pub cid: CID,
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,7 @@ fn xmain() -> ! {
|
||||||
let registration: &mut Registration = unsafe {
|
let registration: &mut Registration = unsafe {
|
||||||
&mut *(m.buf.as_mut_ptr() as *mut Registration)
|
&mut *(m.buf.as_mut_ptr() as *mut Registration)
|
||||||
};
|
};
|
||||||
let namevec: Vec<u8, U32> = Vec::from_slice(®istration.name.name).unwrap();
|
info!("NS: registration request for {}", registration.name);
|
||||||
let name: String<U32> = String::from_utf8(namevec).unwrap();
|
|
||||||
info!("NS: registration request for {}", name);
|
|
||||||
if !name_table.contains_key(®istration.name) {
|
if !name_table.contains_key(®istration.name) {
|
||||||
let new_sid = xous::create_server().expect("NS: create server failed, maybe OOM?");
|
let new_sid = xous::create_server().expect("NS: create server failed, maybe OOM?");
|
||||||
name_table.insert(registration.name, new_sid).expect("NS: register name failure, maybe out of HashMap capacity?");
|
name_table.insert(registration.name, new_sid).expect("NS: register name failure, maybe out of HashMap capacity?");
|
||||||
|
|
@ -59,10 +57,8 @@ fn xmain() -> ! {
|
||||||
let lookup: &mut Lookup = unsafe {
|
let lookup: &mut Lookup = unsafe {
|
||||||
&mut *(m.buf.as_mut_ptr() as *mut Lookup)
|
&mut *(m.buf.as_mut_ptr() as *mut Lookup)
|
||||||
};
|
};
|
||||||
let namevec: Vec<u8, U32> = Vec::from_slice(&lookup.name.name).unwrap();
|
info!("NS: Lookup request for {}", lookup.name);
|
||||||
let name: String<U32> = String::from_utf8(namevec).unwrap();
|
// lookup.cid = 1337;
|
||||||
info!("NS: Lookup request for {}", name);
|
|
||||||
lookup.cid = 1337;
|
|
||||||
lookup.success = true;
|
lookup.success = true;
|
||||||
} else {
|
} else {
|
||||||
error!("NS: unknown message ID received");
|
error!("NS: unknown message ID received");
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,8 @@ fn run(debug: bool) -> Result<(), DynError> {
|
||||||
"graphics-server",
|
"graphics-server",
|
||||||
"ticktimer-server",
|
"ticktimer-server",
|
||||||
"com",
|
"com",
|
||||||
]; // , "xous-names"
|
"xous-names",
|
||||||
|
];
|
||||||
|
|
||||||
// let mut init_paths = vec![];
|
// let mut init_paths = vec![];
|
||||||
for pkg in &init {
|
for pkg in &init {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue