trying out new API names

This commit is contained in:
bunnie 2021-04-01 03:47:10 +08:00
parent 470b5c6440
commit dc2519c5ef
8 changed files with 33 additions and 46 deletions

View file

@ -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 {

View file

@ -31,7 +31,7 @@ pub fn add(arg1: i32, arg2: i32) -> Result<i32, api::Error> {
// 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<i32, api::Error> {
// 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<i32, api::Error> {
// 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<i32, api::Error> {
.or(Err(api::Error::InternalError))?;
// Don't deserialize it -- use the archived version
match *buf.try_into::<api::MathResult, _>().unwrap() {
match *buf.as_zerocopy_obj::<api::MathResult, _>().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<S: AsRef<str>, T: AsRef<str>>(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<S: AsRef<str>, T: AsRef<str>>(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::<api::LogString, _>().unwrap();
let log_string = buffer.as_zerocopy_obj::<api::LogString, _>().unwrap();
unsafe {
for entry in CALLBACK_ARRAY.iter() {
if let Some(cb) = entry {
@ -197,7 +197,7 @@ pub fn double_string<T>(value: &T) -> String<512> where T: AsRef<str> {
// 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<T>(value: &T) -> String<512> where T: AsRef<str> {
)
.unwrap();
String::from_str(buf.try_into::<api::StringDoubler, _>().unwrap().value.as_str())
String::from_str(buf.as_zerocopy_obj::<api::StringDoubler, _>().unwrap().value.as_str())
}

View file

@ -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::<api::MathOperation, _>().unwrap() {
match *buffer.as_zerocopy_obj::<api::MathOperation, _>().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::<api::LogString, _>().unwrap();
let log_string = buffer.as_zerocopy_obj::<api::LogString, _>().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::<api::StringDoubler, _>()
.as_zerocopy_obj::<api::StringDoubler, _>()
.unwrap()
.value
.as_str()

View file

@ -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;

View file

@ -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),

View file

@ -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::<String::<64>, _>().unwrap();
let xous_string = buffer.as_zerocopy_obj::<String::<64>, _>().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::<String::<64>, _>().unwrap();
let name_string = buffer.as_zerocopy_obj::<String::<64>, _>().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");

View file

@ -129,7 +129,7 @@ impl<'a> Buffer<'a> {
}
#[allow(dead_code)]
pub fn try_from<S>(src: S) -> core::result::Result<Self, ()>
pub fn as_buf<S>(src: S) -> core::result::Result<Self, ()>
where
S: rkyv::Serialize<rkyv::ser::serializers::BufferSerializer<Buffer<'a>>>,
{
@ -170,7 +170,7 @@ impl<'a> Buffer<'a> {
}
#[allow(dead_code)]
pub fn try_into<T, U>(&self) -> core::result::Result<&U, ()>
pub fn as_zerocopy_obj<T, U>(&self) -> core::result::Result<&U, ()>
where
T: rkyv::Archive<Archived = U>,
{
@ -180,7 +180,7 @@ impl<'a> Buffer<'a> {
}
#[allow(dead_code)]
pub fn deserialize<T, U>(&self) -> core::result::Result<T, ()>
pub fn as_copy_obj<T, U>(&self) -> core::result::Result<T, ()>
where
T: rkyv::Archive<Archived = U>,
U: rkyv::Deserialize<T, dyn Fallible<Error = XousUnreachable>>,

View file

@ -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