mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
fix deadlock on boot issue
io need to be active early on to get clocks to function on baosec putting that in its own thread fixes the issue.
This commit is contained in:
parent
1d3f264be4
commit
2805f7a14a
1 changed files with 484 additions and 468 deletions
|
|
@ -137,6 +137,7 @@ fn main() {
|
||||||
let sid = xns.register_name(bao1x_api::SERVER_NAME_BAO1X_HAL, None).expect("can't register server");
|
let sid = xns.register_name(bao1x_api::SERVER_NAME_BAO1X_HAL, None).expect("can't register server");
|
||||||
let self_cid = xous::connect(sid).expect("couldn't create self-connection");
|
let self_cid = xous::connect(sid).expect("couldn't create self-connection");
|
||||||
|
|
||||||
|
std::thread::spawn(move || {
|
||||||
let mut ifram_allocs = [Vec::new(), Vec::new()];
|
let mut ifram_allocs = [Vec::new(), Vec::new()];
|
||||||
// code is written assuming the IFRAM blocks have the same size. Since this is fixed in
|
// code is written assuming the IFRAM blocks have the same size. Since this is fixed in
|
||||||
// hardware, it's a good assumption; but the assert is put here in case we port this to
|
// hardware, it's a good assumption; but the assert is put here in case we port this to
|
||||||
|
|
@ -148,12 +149,14 @@ fn main() {
|
||||||
ifram_allocs[1].push(None);
|
ifram_allocs[1].push(None);
|
||||||
}
|
}
|
||||||
// mark loader-hardwired pages for IFRAM0
|
// mark loader-hardwired pages for IFRAM0
|
||||||
for i in bao1x_hal::board::IFRAM0_RESERVED_PAGE_RANGE[0]..=bao1x_hal::board::IFRAM0_RESERVED_PAGE_RANGE[1]
|
for i in
|
||||||
|
bao1x_hal::board::IFRAM0_RESERVED_PAGE_RANGE[0]..=bao1x_hal::board::IFRAM0_RESERVED_PAGE_RANGE[1]
|
||||||
{
|
{
|
||||||
ifram_allocs[0][i] = Some(Sender::from_usize(usize::MAX));
|
ifram_allocs[0][i] = Some(Sender::from_usize(usize::MAX));
|
||||||
}
|
}
|
||||||
// mark loader-hardwired pages for IFRAM1
|
// mark loader-hardwired pages for IFRAM1
|
||||||
for i in bao1x_hal::board::IFRAM1_RESERVED_PAGE_RANGE[0]..=bao1x_hal::board::IFRAM1_RESERVED_PAGE_RANGE[1]
|
for i in
|
||||||
|
bao1x_hal::board::IFRAM1_RESERVED_PAGE_RANGE[0]..=bao1x_hal::board::IFRAM1_RESERVED_PAGE_RANGE[1]
|
||||||
{
|
{
|
||||||
ifram_allocs[1][i] = Some(Sender::from_usize(usize::MAX));
|
ifram_allocs[1][i] = Some(Sender::from_usize(usize::MAX));
|
||||||
}
|
}
|
||||||
|
|
@ -253,7 +256,11 @@ fn main() {
|
||||||
// ensure that iox interrupts are gated off by default
|
// ensure that iox interrupts are gated off by default
|
||||||
for index in 0..8 {
|
for index in 0..8 {
|
||||||
unsafe {
|
unsafe {
|
||||||
iox.csr.base().add(utralib::utra::iox::SFR_INTCR_CRINT0.offset()).add(index).write_volatile(0);
|
iox.csr
|
||||||
|
.base()
|
||||||
|
.add(utralib::utra::iox::SFR_INTCR_CRINT0.offset())
|
||||||
|
.add(index)
|
||||||
|
.write_volatile(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
iox.csr.wo(utra::iox::SFR_INTFR, 0);
|
iox.csr.wo(utra::iox::SFR_INTFR, 0);
|
||||||
|
|
@ -269,27 +276,17 @@ fn main() {
|
||||||
// The index of the array corresponds to the slot.
|
// The index of the array corresponds to the slot.
|
||||||
let mut irq_table: [Option<IrqLocalRegistration>; 8] = [None; 8];
|
let mut irq_table: [Option<IrqLocalRegistration>; 8] = [None; 8];
|
||||||
|
|
||||||
servers::keyboard::start_keyboard_service();
|
|
||||||
|
|
||||||
servers::susres::start_susres_service();
|
|
||||||
|
|
||||||
let clk_mgr = bao1x_hal_service::ClockManager::new();
|
|
||||||
servers::bio::start_bio_service(clk_mgr.get_fclk());
|
|
||||||
|
|
||||||
// claim BIO, based on the platform
|
|
||||||
servers::trng::start_trng_service();
|
|
||||||
servers::rtc::start_rtc_service();
|
|
||||||
|
|
||||||
let mut msg_opt = None;
|
let mut msg_opt = None;
|
||||||
log::debug!("Starting main loop");
|
log::debug!("Starting main loop");
|
||||||
loop {
|
loop {
|
||||||
xous::reply_and_receive_next(sid, &mut msg_opt).unwrap();
|
xous::reply_and_receive_next(sid, &mut msg_opt).unwrap();
|
||||||
// this loop uses a unique form of reply_and_receive next that allows us to store and delegate
|
// this loop uses a unique form of reply_and_receive next that allows us to store and delegate
|
||||||
// scalar messages if necessary (that feature is currently unused). To do this, .take() the msg_opt
|
// scalar messages if necessary (that feature is currently unused). To do this, .take() the
|
||||||
// and store it in a Vec; then use an explicit rsyscall to do a return_scalar1[2,5] to unblock all
|
// msg_opt and store it in a Vec; then use an explicit rsyscall to do a
|
||||||
// the blocking threads. The current loop doesn't actually do this - the feature was deemed unneeded
|
// return_scalar1[2,5] to unblock all the blocking threads. The current loop doesn't
|
||||||
// in the end - but the structural refactor is left here because I can see it being useful in the
|
// actually do this - the feature was deemed unneeded in the end - but the structural
|
||||||
// future as this server does more and more hardware air traffic control.
|
// refactor is left here because I can see it being useful in the future as this
|
||||||
|
// server does more and more hardware air traffic control.
|
||||||
let opcode = {
|
let opcode = {
|
||||||
let msg = msg_opt.as_mut().unwrap();
|
let msg = msg_opt.as_mut().unwrap();
|
||||||
num_traits::FromPrimitive::from_usize(msg.body.id()).unwrap_or(HalOpcode::InvalidCall)
|
num_traits::FromPrimitive::from_usize(msg.body.id()).unwrap_or(HalOpcode::InvalidCall)
|
||||||
|
|
@ -431,7 +428,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
int_cr.set_enable(true);
|
int_cr.set_enable(true);
|
||||||
// safety: the index and offset are mapped to the intended range because the index is
|
// safety: the index and offset are mapped to the intended range because the index is
|
||||||
// bounded by the size of irq_table, and the offset comes from the generated header file.
|
// bounded by the size of irq_table, and the offset comes from the generated header
|
||||||
|
// file.
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"writing {:x} to {:x} at index {}",
|
"writing {:x} to {:x} at index {}",
|
||||||
int_cr.0,
|
int_cr.0,
|
||||||
|
|
@ -464,8 +462,9 @@ fn main() {
|
||||||
if ((irq_flag << (bitpos as u32)) & 0x80) != 0 {
|
if ((irq_flag << (bitpos as u32)) & 0x80) != 0 {
|
||||||
if let Some(local_reg) = irq_table[bitpos] {
|
if let Some(local_reg) = irq_table[bitpos] {
|
||||||
found = true;
|
found = true;
|
||||||
// interrupts are "Best effort" and can gracefully fail if the receiver has
|
// interrupts are "Best effort" and can gracefully fail if the receiver
|
||||||
// been overwhelmed by too many interrupts
|
// has been overwhelmed by too many
|
||||||
|
// interrupts
|
||||||
xous::try_send_message(
|
xous::try_send_message(
|
||||||
local_reg.cid,
|
local_reg.cid,
|
||||||
xous::Message::new_scalar(local_reg.opcode, 0, 0, 0, 0),
|
xous::Message::new_scalar(local_reg.opcode, 0, 0, 0, 0),
|
||||||
|
|
@ -486,7 +485,10 @@ fn main() {
|
||||||
irq_flag
|
irq_flag
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
log::info!("Interrupt received but maybe not for us? pending {:x}", scalar.arg1);
|
log::info!(
|
||||||
|
"Interrupt received but maybe not for us? pending {:x}",
|
||||||
|
scalar.arg1
|
||||||
|
);
|
||||||
log::info!("CR0 {:x}", iox.csr.r(utralib::utra::iox::SFR_INTCR_CRINT0));
|
log::info!("CR0 {:x}", iox.csr.r(utralib::utra::iox::SFR_INTCR_CRINT0));
|
||||||
log::info!("CR1 {:x}", iox.csr.r(utralib::utra::iox::SFR_INTCR_CRINT1));
|
log::info!("CR1 {:x}", iox.csr.r(utralib::utra::iox::SFR_INTCR_CRINT1));
|
||||||
log::info!("CR2 {:x}", iox.csr.r(utralib::utra::iox::SFR_INTCR_CRINT2));
|
log::info!("CR2 {:x}", iox.csr.r(utralib::utra::iox::SFR_INTCR_CRINT2));
|
||||||
|
|
@ -579,7 +581,11 @@ fn main() {
|
||||||
for transaction in list.transactions.iter_mut() {
|
for transaction in list.transactions.iter_mut() {
|
||||||
match transaction.i2c_type {
|
match transaction.i2c_type {
|
||||||
I2cTransactionType::Write => {
|
I2cTransactionType::Write => {
|
||||||
match i2c.i2c_write(transaction.device, transaction.address, &transaction.data) {
|
match i2c.i2c_write(
|
||||||
|
transaction.device,
|
||||||
|
transaction.address,
|
||||||
|
&transaction.data,
|
||||||
|
) {
|
||||||
Ok(result) => transaction.result = result,
|
Ok(result) => transaction.result = result,
|
||||||
_ => transaction.result = I2cResult::Nack,
|
_ => transaction.result = I2cResult::Nack,
|
||||||
}
|
}
|
||||||
|
|
@ -610,14 +616,24 @@ fn main() {
|
||||||
HalOpcode::InvalidCall => {
|
HalOpcode::InvalidCall => {
|
||||||
log::error!("Invalid opcode received: {:?}", msg_opt);
|
log::error!("Invalid opcode received: {:?}", msg_opt);
|
||||||
}
|
}
|
||||||
HalOpcode::Quit => {
|
|
||||||
log::info!("Received quit opcode, exiting.");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
servers::keyboard::start_keyboard_service();
|
||||||
|
|
||||||
|
servers::susres::start_susres_service();
|
||||||
|
|
||||||
|
let clk_mgr = bao1x_hal_service::ClockManager::new();
|
||||||
|
servers::bio::start_bio_service(clk_mgr.get_fclk());
|
||||||
|
|
||||||
|
// claim BIO, based on the platform
|
||||||
|
servers::trng::start_trng_service();
|
||||||
|
servers::rtc::start_rtc_service();
|
||||||
|
|
||||||
|
let tt = ticktimer::Ticktimer::new().unwrap();
|
||||||
|
// placeholder - we can put an actual service here but for now just sleep the main thread.
|
||||||
|
loop {
|
||||||
|
tt.sleep_ms(10_000).ok();
|
||||||
}
|
}
|
||||||
xns.unregister_server(sid).unwrap();
|
|
||||||
xous::destroy_server(sid).unwrap();
|
|
||||||
log::trace!("quitting");
|
|
||||||
xous::terminate_process(0)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue