mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
make i2c/peri conns lazy
this prevents race conditions on boot between the various hardware manager dependencies.
This commit is contained in:
parent
2f7196679f
commit
0f1cae49f0
1 changed files with 18 additions and 7 deletions
|
|
@ -255,11 +255,11 @@ fn main() {
|
||||||
// we want a static array defined like this.
|
// we want a static array defined like this.
|
||||||
let mut irq_table: [Option<IrqLocalRegistration>; 8] = [const { None }; 8];
|
let mut irq_table: [Option<IrqLocalRegistration>; 8] = [const { None }; 8];
|
||||||
|
|
||||||
let i2c_conn =
|
// defer these connections until required by the UpdatePerClk call. This prevents
|
||||||
xns.request_connection(SERVER_NAME_BAO1X_I2C).expect("Couldn't connect to bao1x I2C server");
|
// race conditions on startup, as both i2c and peri rely on the loop below running
|
||||||
let peri_conn = xns
|
// to complete their initializations.
|
||||||
.request_connection(SERVER_NAME_BAO1X_OTHERS)
|
let mut i2c_conn: Option<xous::CID> = None;
|
||||||
.expect("Couldn't connect to bao1x misc peri server");
|
let mut peri_conn: Option<xous::CID> = None;
|
||||||
|
|
||||||
let mut msg_opt = None;
|
let mut msg_opt = None;
|
||||||
log::debug!("Starting main loop");
|
log::debug!("Starting main loop");
|
||||||
|
|
@ -611,9 +611,20 @@ fn main() {
|
||||||
}
|
}
|
||||||
HalOpcode::UpdatePerclk => {
|
HalOpcode::UpdatePerclk => {
|
||||||
if let Some(scalar) = msg_opt.as_mut().unwrap().body.scalar_message_mut() {
|
if let Some(scalar) = msg_opt.as_mut().unwrap().body.scalar_message_mut() {
|
||||||
|
// lazily fill in these connections on demand. This prevents race conditions on
|
||||||
|
// process startup.
|
||||||
|
let i2c_cid = i2c_conn.get_or_insert_with(|| {
|
||||||
|
xns.request_connection_blocking(SERVER_NAME_BAO1X_I2C)
|
||||||
|
.expect("Couldn't connect to bao1x I2C server")
|
||||||
|
});
|
||||||
|
let peri_cid = peri_conn.get_or_insert_with(|| {
|
||||||
|
xns.request_connection_blocking(SERVER_NAME_BAO1X_OTHERS)
|
||||||
|
.expect("Couldn't connect to bao1x misc peri server")
|
||||||
|
});
|
||||||
|
|
||||||
// forward to peri block
|
// forward to peri block
|
||||||
xous::send_message(
|
xous::send_message(
|
||||||
peri_conn,
|
*peri_cid,
|
||||||
xous::Message::new_blocking_scalar(
|
xous::Message::new_blocking_scalar(
|
||||||
PeripheralOpcode::UpdatePerclk.to_usize().unwrap(),
|
PeripheralOpcode::UpdatePerclk.to_usize().unwrap(),
|
||||||
scalar.arg1,
|
scalar.arg1,
|
||||||
|
|
@ -624,7 +635,7 @@ fn main() {
|
||||||
)
|
)
|
||||||
.ok();
|
.ok();
|
||||||
xous::send_message(
|
xous::send_message(
|
||||||
i2c_conn,
|
*i2c_cid,
|
||||||
xous::Message::new_blocking_scalar(
|
xous::Message::new_blocking_scalar(
|
||||||
I2cOpcode::UpdatePerclk.to_usize().unwrap(),
|
I2cOpcode::UpdatePerclk.to_usize().unwrap(),
|
||||||
scalar.arg1,
|
scalar.arg1,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue