From da255cc1ab82b49165fc8a632e0380a408ff789f Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 2 Apr 2021 15:38:38 +0800 Subject: [PATCH] use macro expansion for argument extraction of scalars --- services/com/src/main.rs | 9 +++------ services/ticktimer-server/src/main.rs | 9 +++------ services/trng/src/main.rs | 14 +++++--------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/services/com/src/main.rs b/services/com/src/main.rs index a633a94de..5b5c0f40e 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -12,7 +12,7 @@ use log::{error, info, trace}; use com_rs_ref as com_rs; use com_rs::*; -use xous::CID; +use xous::{CID, msg_scalar_unpack, msg_blocking_scalar_unpack}; use xous_ipc::{Buffer, String}; const STD_TIMEOUT: u32 = 100; @@ -255,10 +255,7 @@ fn xmain() -> ! { let msg = xous::receive_message(com_sid).unwrap(); trace!("Message: {:?}", msg); match FromPrimitive::from_usize(msg.body.id()) { - Some(Opcode::RegisterBattStatsListener) => { - if let xous::Message::Scalar(xous::ScalarMessage { - id: _id, arg1: sid0, arg2: sid1, arg3: sid2, arg4: sid3 - }) = msg.body { + Some(Opcode::RegisterBattStatsListener) => msg_scalar_unpack!(msg, sid0, sid1, sid2, sid3, { let sid = xous::SID::from_u32(sid0 as _, sid1 as _, sid2 as _, sid3 as _); let cid = Some(xous::connect(sid).unwrap()); let mut found = false; @@ -273,7 +270,7 @@ fn xmain() -> ! { error!("RegisterBattStatsListener ran out of space registering callback"); } } - } + ), Some(Opcode::Wf200PdsLine) => { let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let l = buffer.to_original::, _>().unwrap(); diff --git a/services/ticktimer-server/src/main.rs b/services/ticktimer-server/src/main.rs index f618dfd55..5e6e16c7c 100644 --- a/services/ticktimer-server/src/main.rs +++ b/services/ticktimer-server/src/main.rs @@ -458,9 +458,7 @@ fn xmain() -> ! { ) .expect("couldn't return time request"); } - Some(api::Opcode::SleepMs) => { - if let xous::Message::BlockingScalar(xous::ScalarMessage { - id: _, arg1: ms, arg2: _, arg3: _, arg4: _}) = msg.body { + Some(api::Opcode::SleepMs) => xous::msg_blocking_scalar_unpack!(msg, ms, _, _, _, { recalculate_sleep( &mut ticktimer, &mut sleep_heap, @@ -468,9 +466,8 @@ fn xmain() -> ! { msec: ms as i64, sender: msg.sender, }), - ); - } - } + ) + }), Some(api::Opcode::RecalculateSleep) => { recalculate_sleep(&mut ticktimer, &mut sleep_heap, None); } diff --git a/services/trng/src/main.rs b/services/trng/src/main.rs index be92ceac7..20e02a17c 100644 --- a/services/trng/src/main.rs +++ b/services/trng/src/main.rs @@ -167,15 +167,11 @@ fn xmain() -> ! { loop { let msg = xous::receive_message(trng_sid).unwrap(); match FromPrimitive::from_usize(msg.body.id()) { - Some(api::Opcode::GetTrng) => { - if let xous::Message::BlockingScalar(xous::ScalarMessage { - id: _, arg1: count, arg2: _, arg3: _, arg4: _ - }) = msg.body { - let val: [u32; 2] = trng.get_trng(count); - xous::return_scalar2(msg.sender, val[0] as _, val[1] as _) - .expect("couldn't return GetTrng request"); - } else { log::error!("GetTrng malformed message"); } - } + Some(api::Opcode::GetTrng) => xous::msg_scalar_unpack!(msg, count, _, _, _, { + let val: [u32; 2] = trng.get_trng(count); + xous::return_scalar2(msg.sender, val[0] as _, val[1] as _) + .expect("couldn't return GetTrng request"); + }), None => { log::error!("couldn't convert opcode") }