diff --git a/services/llio/src/api.rs b/services/llio/src/api.rs index 967176d91..e5a15a3ff 100644 --- a/services/llio/src/api.rs +++ b/services/llio/src/api.rs @@ -104,7 +104,7 @@ pub(crate) enum Opcode { AdcGpio5, AdcGpio2, - /// partially tested -- events + /// events EventComSubscribe, //(String<64>), //EventRtcSubscribe, //(String<64>), EventUsbAttachSubscribe, //(String<64>), @@ -113,6 +113,11 @@ pub(crate) enum Opcode { EventUsbAttachEnable, //(bool), EventActivityHappened, + /// Set EC status is ready + EventEcSetReady, + /// Query if EC status is ready + EventEcIsReady, + /// internal from handler to main loop EventComHappened, //EventRtcHappened, diff --git a/services/llio/src/llio_lib.rs b/services/llio/src/llio_lib.rs index 7e5324d06..617fe53d3 100644 --- a/services/llio/src/llio_lib.rs +++ b/services/llio/src/llio_lib.rs @@ -190,6 +190,26 @@ impl Llio { Message::new_scalar(Opcode::EventComEnable.to_usize().unwrap(), arg, 0, 0, 0) ).map(|_| ()) } + /// Called by the updater routine when EC is ready to run. Note: no authenticity check is done, anyone + /// could call this and troll the system. + pub fn set_ec_ready(&self, ready: bool) { + send_message(self.conn, + Message::new_scalar(Opcode::EventEcSetReady.to_usize().unwrap(), if ready {1} else {0}, 0, 0, 0) + ).unwrap(); + } + /// Used to poll if the EC has been set as ready by the updating routine. Domiciled in the LLIO because + /// this crate is already depended upon by most crates that need to poll this status, and we'd rather not + /// expose the COM directly to generic crates. + pub fn is_ec_ready(&self) -> bool { + let response = send_message(self.conn, + Message::new_blocking_scalar(Opcode::EventEcIsReady.to_usize().unwrap(), 0, 0, 0, 0)).unwrap(); + if let xous::Result::Scalar1(val) = response { + val != 0 + } else { + log::error!("LLIO: unexpected return value: {:#?}", response); + false + } + } /// GPIO IRQ hook. When using this, ensure that the WFI power saving mode is turned off. /// Otherwise interrupts that hit during power save mode can be missed. pub fn hook_gpio_event_callback(&mut self, id: u32, cid: CID) -> Result<(), xous::Error> { diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index 88ce65abf..e8e5e497c 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -285,6 +285,12 @@ fn main() -> ! { let mut i2c = llio::I2c::new(&xns); let tt = ticktimer_server::Ticktimer::new().unwrap(); + // a variable to track if the EC has been registered as ready. This should be set by a call from + // whatever handles the EC updating routine: it is responsible for checking if the EC is up to date, + // and once it is brought into an up to date state, it then sets this variable. That routine is + // nominally domiciled in the status server. + let mut ec_ready = false; + log::debug!("starting main loop"); loop { let msg = xous::receive_message(llio_sid).unwrap(); @@ -507,6 +513,12 @@ fn main() -> ! { latest_activity %= period; } }), + Some(Opcode::EventEcSetReady) => msg_scalar_unpack!(msg, ready, _, _, _, { + ec_ready = ready != 0; + }), + Some(Opcode::EventEcIsReady) => msg_blocking_scalar_unpack!(msg, _, _, _, _, { + xous::return_scalar(msg.sender, if ec_ready {1} else {0}).ok(); + }), Some(Opcode::SetWakeupAlarm) => msg_blocking_scalar_unpack!(msg, delay, _, _, _, { if delay > u8::MAX as usize { log::error!("Wakeup must be no longer than {} secs in the future", u8::MAX);