add hooks for pre-clock transition on bio

this hook allows the application logic to warn the BIO
app that a clock transition is coming so that glitches can be
suppressed.
This commit is contained in:
bunnie 2026-04-21 16:27:10 +08:00
parent 2ec739e54e
commit 8521d698d7
5 changed files with 30 additions and 0 deletions

View file

@ -51,6 +51,10 @@ pub trait BioApi<'a> {
/// that the clocks may have changed.
fn update_bio_freq(&mut self, freq: u32) -> u32;
/// Called before frequency changes to activate any application-specific callbacks
/// to avoid glitches.
fn prep_freq_change(&mut self);
/// Returns the frequency, in Hz, of the incoming clock to the BIO cores.
fn get_bio_freq(&self) -> u32;
@ -192,6 +196,7 @@ pub enum BioOp {
InitCore,
DeInitCore,
UpdateBioFreq,
PrepFreqChange,
GetCoreFreq,
GetBioFreq,
CoreState,

View file

@ -134,6 +134,14 @@ impl<'a> BioApi<'a> for Bio {
}
}
fn prep_freq_change(&mut self) {
send_message(
self.conn,
Message::new_blocking_scalar(BioOp::PrepFreqChange.to_usize().unwrap(), 0, 0, 0, 0),
)
.ok();
}
fn get_bio_freq(&self) -> u32 {
match send_message(
self.conn,

View file

@ -502,6 +502,10 @@ impl<'a> BioApi<'a> for BioSharedState {
prev_freq
}
fn prep_freq_change(&mut self) {
// at the hw level, there's nothing to do; a handler at the `std` level is invoked instead
}
unsafe fn get_core_handle(&self, _fifo: Fifo) -> Result<Option<CoreHandle>, BioError> {
unimplemented!("This is managed by the main loop server, not the hardware interface");
}

View file

@ -15,6 +15,9 @@ fn bio_service(clk_freq: u32) {
let mut resource_tracker = ResourceTracker::new();
#[cfg(feature = "oem-baosec-lite")]
let led_conn = xns.request_connection_blocking("_oem_led_").unwrap();
let mut bio_ss = bio_hw::BioSharedState::new(clk_freq);
let mut msg_opt = None;
loop {
@ -125,6 +128,14 @@ fn bio_service(clk_freq: u32) {
}
}
BioOp::PrepFreqChange => {
if let Some(_scalar) = msg_opt.as_mut().unwrap().body.scalar_message_mut() {
// pause rendering while the clock transitions, avoiding 'bright glitches'
#[cfg(feature = "oem-baosec-lite")]
xous::send_message(led_conn, xous::Message::new_blocking_scalar(128, 0, 0, 0, 0)).ok();
}
}
BioOp::GetBioFreq => {
if let Some(scalar) = msg_opt.as_mut().unwrap().body.scalar_message_mut() {
scalar.arg1 = bio_ss.get_bio_freq() as usize;

View file

@ -210,6 +210,7 @@ fn susres_service() {
// - The update_bio_freq routine is being "too clever" and compensating for the fd
// setting. But it seems like the routine just takes the putative fclk setting as
// the argument to update_bio_freq(), I don't see any compensation happening...
bio.prep_freq_change();
if fclk_fd_backup == 0xff {
bio.update_bio_freq(48_000_000);
} else {
@ -222,6 +223,7 @@ fn susres_service() {
// clk_mgr.set_fclk_fd(fclk_fd_backup); // restore the FD before restoring potentially
// fast PLL setting
bio.prep_freq_change();
clk_mgr.restore_wfi();
bio.update_bio_freq(clk_mgr.fclk);