mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-24 09:40:52 +00:00
38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
|
|
use xous::{Message, ScalarMessage};
|
||
|
|
use xous_names::api::Lookup;
|
||
|
|
|
||
|
|
#[allow(dead_code)]
|
||
|
|
#[derive(Debug)]
|
||
|
|
pub enum Opcode {
|
||
|
|
TestScalar(u32),
|
||
|
|
TestMemory(Lookup),
|
||
|
|
}
|
||
|
|
|
||
|
|
impl core::convert::TryFrom<& Message> for Opcode {
|
||
|
|
type Error = &'static str;
|
||
|
|
fn try_from(message: & Message) -> Result<Self, Self::Error> {
|
||
|
|
match message {
|
||
|
|
Message::BlockingScalar(m) => match m.id {
|
||
|
|
0 => Ok(Opcode::TestScalar(m.arg1 as u32)),
|
||
|
|
_ => Err("BENCHMARK-TARGET api: unknown BlockingScalar ID"),
|
||
|
|
},
|
||
|
|
_ => Err("BENCHMARK-TARGET api: unhandled message type"),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Into<Message> for Opcode {
|
||
|
|
fn into(self) -> Message {
|
||
|
|
match self {
|
||
|
|
Opcode::TestScalar(count) => Message::BlockingScalar(ScalarMessage {
|
||
|
|
id: 0,
|
||
|
|
arg1: count as usize,
|
||
|
|
arg2: 0,
|
||
|
|
arg3: 0,
|
||
|
|
arg4: 0,
|
||
|
|
}),
|
||
|
|
_ => panic!("GFX api: Opcode type not handled by Into(), maybe you meant to use a helper method?"),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|