update apis in hal-service

This commit is contained in:
bunnie 2025-12-11 02:18:44 +08:00
parent 577efdfdd2
commit 261ea7a880
5 changed files with 44 additions and 2 deletions

View file

@ -54,6 +54,9 @@ pub enum HalOpcode {
/// Manipulate the OS timer
SetPreemptionState = 64,
/// Trigger wfi
Wfi = 128,
/// Exit server
Quit = 255,

View file

@ -42,3 +42,9 @@ pub fn clk_to_per(top_in_mhz: u32, perclk_in_mhz: u32) -> Option<(u8, u8, u32)>
None
}
}
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
pub enum PowerOp {
Wfi,
Invalid,
}

View file

@ -31,7 +31,7 @@ rand = "0.8.5"
rand_core = "0.6.4"
rand_chacha = "0.3.1"
bitfield = "0.13.2"
# TOODO: migrate from bitfield to bitbybit
# TODO: migrate from bitfield to bitbybit
bitbybit = "1.4.0"
arbitrary-int = "1.2"
bytemuck = "1.24.0"
@ -54,4 +54,6 @@ bmp180 = ["bao1x-hal/bmp180"]
board-baosec = ["bao1x-hal/board-baosec"]
board-baosor = ["bao1x-hal/board-baosor"]
board-dabao = ["bao1x-hal/board-dabao"]
with-duart = ["bao1x-hal/debug-print-duart"]
default = ["app-uart", "utralib"]

View file

@ -129,6 +129,8 @@ fn try_alloc(ifram_allocs: &mut Vec<Option<Sender>>, size: usize, sender: Sender
}
}
fn main() {
#[cfg(feature = "with-duart")]
bao1x_hal::claim_duart();
log_server::init_wait().unwrap();
log::set_max_level(log::LevelFilter::Info);
log::info!("my PID is {}", xous::process::id());
@ -200,7 +202,13 @@ fn main() {
)
};
let mut i2c = unsafe {
bao1x_hal::udma::I2c::new_with_ifram(i2c_channel, 400_000, bao1x_api::PERCLK, i2c_ifram, &udma_global)
bao1x_hal::udma::I2cDriver::new_with_ifram(
i2c_channel,
400_000,
bao1x_api::PERCLK,
i2c_ifram,
&udma_global,
)
};
// os timer initializations
@ -265,6 +273,13 @@ fn main() {
servers::keyboard::start_keyboard_service();
#[cfg(feature = "board-baosec")]
let power_sid = xous::create_server().unwrap();
#[cfg(feature = "board-baosec")]
servers::power::start_power_service(power_sid);
#[cfg(feature = "board-baosec")]
let power_cid = xous::connect(power_sid).unwrap();
// claim BIO
#[cfg(feature = "board-baosec")]
let bio_ss = Arc::new(Mutex::new(xous_bio_bdma::BioSharedState::new()));
@ -285,6 +300,19 @@ fn main() {
let opcode = num_traits::FromPrimitive::from_usize(msg.body.id()).unwrap_or(HalOpcode::InvalidCall);
log::debug!("{:?}", opcode);
match opcode {
#[cfg(feature = "board-baosec")]
HalOpcode::Wfi => {
log::info!("turn off preemption");
os_timer.wfo(utra::timer0::EV_ENABLE_ZERO, 0);
// this call *can't* block because WFI relies on HAL services to operate!
xous::send_message(
power_cid,
xous::Message::new_scalar(PowerOp::Wfi.to_usize().unwrap(), 0, 0, 0, 0),
)
.unwrap();
}
#[cfg(not(feature = "board-baosec"))]
HalOpcode::Wfi => unimplemented!(),
HalOpcode::MapIfram => {
if let Some(scalar) = msg.body.scalar_message_mut() {
let requested_size = scalar.arg1; // requested size

View file

@ -3,5 +3,8 @@ pub mod keyboard;
// TRNG server is only needed for baosec; dabao can cheat and use the kernel TRNG port
#[cfg(feature = "board-baosec")]
mod baosec_hw;
// only baosec has power management facilities
#[cfg(feature = "board-baosec")]
pub mod power;
pub mod rtc;
pub mod trng; // not public - for internal use only