diff --git a/libs/bao1x-api/src/bio.rs b/libs/bao1x-api/src/bio.rs index d2cbc4e7e..b635c9459 100644 --- a/libs/bao1x-api/src/bio.rs +++ b/libs/bao1x-api/src/bio.rs @@ -75,6 +75,7 @@ pub enum BioOp { IoConfig, FifoEventTriggers, GetVersion, + InvalidCall, } #[derive(Debug, Copy, Clone)] @@ -100,6 +101,18 @@ pub enum BioCore { Core3 = 3, } +impl From for BioCore { + fn from(value: usize) -> Self { + match value { + 0 => BioCore::Core0, + 1 => BioCore::Core1, + 2 => BioCore::Core2, + 3 => BioCore::Core3, + _ => panic!("Invalid BioCore value: {}", value), + } + } +} + #[repr(usize)] #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "std", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] @@ -109,14 +122,13 @@ pub enum CoreRunSetting { Stop = 2, } -impl From for BioCore { +impl From for CoreRunSetting { fn from(value: usize) -> Self { match value { - 0 => BioCore::Core0, - 1 => BioCore::Core1, - 2 => BioCore::Core2, - 3 => BioCore::Core3, - _ => panic!("Invalid BioCore value: {}", value), + 0 => CoreRunSetting::Unchanged, + 1 => CoreRunSetting::Start, + 2 => CoreRunSetting::Start, + _ => panic!("Invalid CoreRunSetting: {}", value), } } } @@ -478,7 +490,9 @@ pub trait BioApi<'a> { /// /// Safety: this has to be wrapped in an object that derives a CSR that also tracks /// the lifetime of this object, to prevent `Drop` from being called at the wrong time. - unsafe fn get_core_handle(&'a mut self) -> Result, BioError>; + /// + /// Returns `None` if no more handles are available + unsafe fn get_core_handle(&'a mut self) -> Result>, BioError>; /// This call sets up the BIO's IRQ routing. It doesn't actually claim the IRQ /// or install the handler - that's up to the caller to do with Xous API calls. diff --git a/libs/bao1x-hal/src/bio.rs b/libs/bao1x-hal/src/bio.rs index 665d99c5f..246efe1c1 100644 --- a/libs/bao1x-hal/src/bio.rs +++ b/libs/bao1x-hal/src/bio.rs @@ -81,14 +81,18 @@ impl<'a> BioApi<'a> for Bio { Ok(()) } - unsafe fn get_core_handle(&'a mut self) -> Result, BioError> { + unsafe fn get_core_handle(&'a mut self) -> Result>, BioError> { match send_message( self.conn, Message::new_blocking_scalar(BioOp::GetCoreHandle.to_usize().unwrap(), 0, 0, 0, 0), ) .map_err(|e| >::into(e))? { - xous::Result::Scalar5(_, bank, _, _, _) => { + xous::Result::Scalar5(_, bank, valid, _, _) => { + if valid == 0 { + // no handles available + return Ok(None); + } let base = match bank { 0 => utralib::HW_BIO_FIFO0_BASE, 1 => utralib::HW_BIO_FIFO1_BASE, @@ -105,11 +109,11 @@ impl<'a> BioApi<'a> for Bio { xous::MemoryFlags::R | xous::MemoryFlags::W, ) .expect("couldn't map BIO memory handle"); - Ok(CoreHandle::new( + Ok(Some(CoreHandle::new( self.conn, virtual_page.as_ptr() as usize, arbitrary_int::u2::from_u32(bank as u32), - )) + ))) } _ => unimplemented!("Unhandled return type on get_core_handle()"), } diff --git a/libs/bao1x-hal/src/bio_hw.rs b/libs/bao1x-hal/src/bio_hw.rs index fcb078e3d..475343490 100644 --- a/libs/bao1x-hal/src/bio_hw.rs +++ b/libs/bao1x-hal/src/bio_hw.rs @@ -453,7 +453,7 @@ impl<'a> BioApi<'a> for BioSharedState { prev_freq } - unsafe fn get_core_handle(&'a mut self) -> Result, BioError> { + unsafe fn get_core_handle(&'a mut self) -> Result>, BioError> { unimplemented!("This is managed by the main loop server, not the hardware interface"); }