From d88254b1b1cefe21e15e2d897795ed24bf07554e Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 29 Dec 2022 21:00:35 +0800 Subject: [PATCH] xous: add reply_and_receive_next_legacy call This call is used to return values while simultaneously listening for new messages. The -legacy suffix is used to disambiguate scalar values, so we know whether to send Scalar1, Scalar2, or Scalar5 messages. Signed-off-by: Sean Cross --- xous-rs/src/definitions/messages/mod.rs | 11 +++++++- xous-rs/src/syscall.rs | 34 +++++++++++++++++++++---- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/xous-rs/src/definitions/messages/mod.rs b/xous-rs/src/definitions/messages/mod.rs index a3d5fa7fc..714b7549c 100644 --- a/xous-rs/src/definitions/messages/mod.rs +++ b/xous-rs/src/definitions/messages/mod.rs @@ -92,7 +92,7 @@ impl MemoryMessage { } #[repr(C)] -#[derive(Debug, PartialEq, Clone, Copy)] +#[derive(Debug, PartialEq, Clone, Copy, Default)] /// A simple scalar message. This is similar to a `move` message. pub struct ScalarMessage { pub id: MessageId, @@ -239,6 +239,15 @@ impl Message { } } + pub fn scalar_message_mut(&mut self) -> Option<&mut ScalarMessage> { + match self { + Message::MutableBorrow(_) + | Message::Borrow(_) + | Message::Move(_) + | Message::Scalar(_) => None, + Message::BlockingScalar(scalar) => Some(scalar), + } + } pub(crate) fn message_type(&self) -> usize { match *self { Message::MutableBorrow(_) => 1, diff --git a/xous-rs/src/syscall.rs b/xous-rs/src/syscall.rs index 6082f8343..01e0f9ec9 100644 --- a/xous-rs/src/syscall.rs +++ b/xous-rs/src/syscall.rs @@ -850,15 +850,15 @@ impl SysCall { 0, 0, ], - SysCall::ReplyAndReceiveNext(sender, result, arg1, arg2, arg3, arg4) => [ - SysCallNumber::ReturnMemory as usize, + SysCall::ReplyAndReceiveNext(sender, arg0, arg1, arg2, arg3, arg4, return_type) => [ + SysCallNumber::ReplyAndReceiveNext as usize, sender.to_usize(), - *result, + *arg0, *arg1, *arg2, *arg3, *arg4, - 0, + *return_type, ], SysCall::CreateThread(init) => { @@ -1086,7 +1086,7 @@ impl SysCall { MemorySize::new(a5), ), SysCallNumber::ReplyAndReceiveNext => { - SysCall::ReplyAndReceiveNext(MessageSender::from_usize(a1), a2, a3, a4, a5, a6) + SysCall::ReplyAndReceiveNext(MessageSender::from_usize(a1), a2, a3, a4, a5, a6, a7) } SysCallNumber::CreateThread => { SysCall::CreateThread(crate::arch::args_to_thread(a1, a2, a3, a4, a5, a6, a7)?) @@ -1936,6 +1936,30 @@ pub fn reply_and_receive_next( server: SID, msg: &mut Option, ) -> core::result::Result<(), crate::Error> { + reply_and_receive_next_legacy(server, msg, &mut 0) +} + +/// Reply to the message, if one exists, and receive the next one. +/// If no message exists, delegate the call to `receive_syscall()`. +/// Allow specifying the scalar return type. +/// +/// This is named `_legacy` because it is meant to work with calls that +/// expect both `Scalar1` and `Scalar2` values, in addition to `Scalar5`. +/// +/// ## Arguments +/// +/// * **server**: The SID of the server to receive messages from +/// * **msg**: An Option specifying the message to return. +/// * **return_type**: If 1 or 2, responds to a BlockingScalarMessage +/// with a Scalar1 or a Scalar2. Otherwise, will respond +/// as normal. +pub fn reply_and_receive_next_legacy( + server: SID, + msg: &mut Option, + return_type: &mut usize, +) -> core::result::Result<(), crate::Error> { + let rt = *return_type; + *return_type = 0; if let Some(envelope) = msg.take() { // If the message inside is nonblocking, then there's nothing to return. // Delegate reception to the `receive_message()` call