mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
ticktimer: add opcodes for msleep
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
b8f69b4a7f
commit
5a66f72938
2 changed files with 34 additions and 14 deletions
|
|
@ -4,8 +4,15 @@ use xous::{Message, ScalarMessage};
|
||||||
pub enum Opcode {
|
pub enum Opcode {
|
||||||
/// Reset the timer
|
/// Reset the timer
|
||||||
Reset,
|
Reset,
|
||||||
|
|
||||||
/// Get the elapsed time in milliseconds
|
/// Get the elapsed time in milliseconds
|
||||||
ElapsedMs,
|
ElapsedMs,
|
||||||
|
|
||||||
|
/// Sleep for the specified numer of milliseconds
|
||||||
|
SleepMs(usize),
|
||||||
|
|
||||||
|
/// Recalculate the sleep time
|
||||||
|
RecalculateSleep,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> core::convert::TryFrom<&'a Message> for Opcode {
|
impl<'a> core::convert::TryFrom<&'a Message> for Opcode {
|
||||||
|
|
@ -14,12 +21,14 @@ impl<'a> core::convert::TryFrom<&'a Message> for Opcode {
|
||||||
match message {
|
match message {
|
||||||
Message::Scalar(m) => match m.id {
|
Message::Scalar(m) => match m.id {
|
||||||
1 => Ok(Opcode::Reset),
|
1 => Ok(Opcode::Reset),
|
||||||
|
131072 => Ok(Opcode::RecalculateSleep),
|
||||||
_ => Err("unrecognized opcode"),
|
_ => Err("unrecognized opcode"),
|
||||||
},
|
},
|
||||||
Message::BlockingScalar(m) => match m.id {
|
Message::BlockingScalar(m) => match m.id {
|
||||||
4919 => Ok(Opcode::ElapsedMs),
|
4919 => Ok(Opcode::ElapsedMs),
|
||||||
|
3 => Ok(Opcode::SleepMs(m.arg1)),
|
||||||
_ => Err("unrecognized opcode"),
|
_ => Err("unrecognized opcode"),
|
||||||
}
|
},
|
||||||
_ => Err("unhandled message type"),
|
_ => Err("unhandled message type"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -35,6 +44,13 @@ impl Into<Message> for Opcode {
|
||||||
arg3: 0,
|
arg3: 0,
|
||||||
arg4: 0,
|
arg4: 0,
|
||||||
}),
|
}),
|
||||||
|
Opcode::RecalculateSleep => Message::Scalar(ScalarMessage {
|
||||||
|
id: 131072,
|
||||||
|
arg1: 0,
|
||||||
|
arg2: 0,
|
||||||
|
arg3: 0,
|
||||||
|
arg4: 0,
|
||||||
|
}),
|
||||||
Opcode::ElapsedMs => Message::BlockingScalar(ScalarMessage {
|
Opcode::ElapsedMs => Message::BlockingScalar(ScalarMessage {
|
||||||
id: 4919,
|
id: 4919,
|
||||||
arg1: 0,
|
arg1: 0,
|
||||||
|
|
@ -42,6 +58,13 @@ impl Into<Message> for Opcode {
|
||||||
arg3: 0,
|
arg3: 0,
|
||||||
arg4: 0,
|
arg4: 0,
|
||||||
}),
|
}),
|
||||||
|
Opcode::SleepMs(ms) => Message::BlockingScalar(ScalarMessage {
|
||||||
|
id: 3,
|
||||||
|
arg1: ms,
|
||||||
|
arg2: 0,
|
||||||
|
arg3: 0,
|
||||||
|
arg4: 0,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,21 @@
|
||||||
|
|
||||||
pub mod api;
|
pub mod api;
|
||||||
|
|
||||||
use xous::{try_send_message, CID, Error};
|
use xous::{send_message, Error, CID};
|
||||||
|
|
||||||
pub fn elapsed_ms(cid: CID) -> Result<u64, Error> {
|
pub fn elapsed_ms(cid: CID) -> Result<u64, Error> {
|
||||||
let response = try_send_message(cid, api::Opcode::ElapsedMs.into())?;
|
let response = send_message(cid, api::Opcode::ElapsedMs.into())?;
|
||||||
if let xous::Result::Scalar2(upper, lower) = response {
|
if let xous::Result::Scalar2(upper, lower) = response {
|
||||||
Ok(upper as u64 | ((lower as u64) << 32))
|
Ok(upper as u64 | ((lower as u64) << 32))
|
||||||
} else {
|
} else {
|
||||||
panic!("unexpected return value: {:#?}", response);
|
panic!("unexpected return value: {:#?}", response);
|
||||||
}
|
}
|
||||||
/* // scalar1 experimental reply to see if this makes it any better. It doesn't.
|
|
||||||
if let xous::Result::Scalar1(lower) = response {
|
|
||||||
Ok(lower as u64)
|
|
||||||
} else {
|
|
||||||
panic!("unexpected return value: {:#?}", response);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(cid: CID) -> Result<(), xous::Error> {
|
pub fn reset(cid: CID) -> Result<(), xous::Error> {
|
||||||
try_send_message(cid, api::Opcode::Reset.into()).map(|_| ())
|
send_message(cid, api::Opcode::Reset.into()).map(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sleep_ms(cid: CID, ms: usize) -> Result<(), xous::Error> {
|
||||||
|
send_message(cid, api::Opcode::SleepMs(ms).into()).map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue