cleanup apis after std implementation

This commit is contained in:
bunnie 2025-12-26 21:03:19 +08:00
parent 1c0d8eea17
commit 5be682b37f
3 changed files with 30 additions and 12 deletions

View file

@ -75,6 +75,7 @@ pub enum BioOp {
IoConfig, IoConfig,
FifoEventTriggers, FifoEventTriggers,
GetVersion, GetVersion,
InvalidCall,
} }
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
@ -100,6 +101,18 @@ pub enum BioCore {
Core3 = 3, Core3 = 3,
} }
impl From<usize> 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)] #[repr(usize)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] #[cfg_attr(feature = "std", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
@ -109,14 +122,13 @@ pub enum CoreRunSetting {
Stop = 2, Stop = 2,
} }
impl From<usize> for BioCore { impl From<usize> for CoreRunSetting {
fn from(value: usize) -> Self { fn from(value: usize) -> Self {
match value { match value {
0 => BioCore::Core0, 0 => CoreRunSetting::Unchanged,
1 => BioCore::Core1, 1 => CoreRunSetting::Start,
2 => BioCore::Core2, 2 => CoreRunSetting::Start,
3 => BioCore::Core3, _ => panic!("Invalid CoreRunSetting: {}", value),
_ => panic!("Invalid BioCore value: {}", 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 /// 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. /// the lifetime of this object, to prevent `Drop` from being called at the wrong time.
unsafe fn get_core_handle(&'a mut self) -> Result<CoreHandle<'a>, BioError>; ///
/// Returns `None` if no more handles are available
unsafe fn get_core_handle(&'a mut self) -> Result<Option<CoreHandle<'a>>, BioError>;
/// This call sets up the BIO's IRQ routing. It doesn't actually claim the IRQ /// 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. /// or install the handler - that's up to the caller to do with Xous API calls.

View file

@ -81,14 +81,18 @@ impl<'a> BioApi<'a> for Bio {
Ok(()) Ok(())
} }
unsafe fn get_core_handle(&'a mut self) -> Result<CoreHandle<'a>, BioError> { unsafe fn get_core_handle(&'a mut self) -> Result<Option<CoreHandle<'a>>, BioError> {
match send_message( match send_message(
self.conn, self.conn,
Message::new_blocking_scalar(BioOp::GetCoreHandle.to_usize().unwrap(), 0, 0, 0, 0), Message::new_blocking_scalar(BioOp::GetCoreHandle.to_usize().unwrap(), 0, 0, 0, 0),
) )
.map_err(|e| <xous::Error as Into<BioError>>::into(e))? .map_err(|e| <xous::Error as Into<BioError>>::into(e))?
{ {
xous::Result::Scalar5(_, bank, _, _, _) => { xous::Result::Scalar5(_, bank, valid, _, _) => {
if valid == 0 {
// no handles available
return Ok(None);
}
let base = match bank { let base = match bank {
0 => utralib::HW_BIO_FIFO0_BASE, 0 => utralib::HW_BIO_FIFO0_BASE,
1 => utralib::HW_BIO_FIFO1_BASE, 1 => utralib::HW_BIO_FIFO1_BASE,
@ -105,11 +109,11 @@ impl<'a> BioApi<'a> for Bio {
xous::MemoryFlags::R | xous::MemoryFlags::W, xous::MemoryFlags::R | xous::MemoryFlags::W,
) )
.expect("couldn't map BIO memory handle"); .expect("couldn't map BIO memory handle");
Ok(CoreHandle::new( Ok(Some(CoreHandle::new(
self.conn, self.conn,
virtual_page.as_ptr() as usize, virtual_page.as_ptr() as usize,
arbitrary_int::u2::from_u32(bank as u32), arbitrary_int::u2::from_u32(bank as u32),
)) )))
} }
_ => unimplemented!("Unhandled return type on get_core_handle()"), _ => unimplemented!("Unhandled return type on get_core_handle()"),
} }

View file

@ -453,7 +453,7 @@ impl<'a> BioApi<'a> for BioSharedState {
prev_freq prev_freq
} }
unsafe fn get_core_handle(&'a mut self) -> Result<CoreHandle<'a>, BioError> { unsafe fn get_core_handle(&'a mut self) -> Result<Option<CoreHandle<'a>>, BioError> {
unimplemented!("This is managed by the main loop server, not the hardware interface"); unimplemented!("This is managed by the main loop server, not the hardware interface");
} }