mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add local panic handler for the USB stack
also clean up some debug statements and add a TODO list
This commit is contained in:
parent
e0b6d96fbd
commit
d9f8b5bcfc
2 changed files with 30 additions and 60 deletions
|
|
@ -64,16 +64,6 @@ pub enum UsbIrqReq {
|
|||
pub const CORIGINE_IRQ_MASK: u32 = 0x1;
|
||||
pub const SW_IRQ_MASK: u32 = 0x2;
|
||||
|
||||
/*
|
||||
pub(crate) fn irq19_handler(_irq_no: usize, arg: *mut usize) {
|
||||
crate::println!("irq19");
|
||||
let irqarray19 = AtomicCsr::new(arg as *mut u32);
|
||||
let pending = irqarray19.r(utra::irqarray19::EV_PENDING);
|
||||
crate::println!("pending {:x}", pending);
|
||||
irqarray19.wo(utra::irqarray19::EV_PENDING, pending);
|
||||
}
|
||||
*/
|
||||
|
||||
pub(crate) fn composite_handler(_irq_no: usize, arg: *mut usize) {
|
||||
let usb = unsafe { &mut *(arg as *mut CramiumUsb) };
|
||||
|
||||
|
|
@ -301,7 +291,6 @@ impl<'a> CramiumUsb<'a> {
|
|||
}
|
||||
|
||||
pub fn init(&mut self) {
|
||||
log::info!("claiming interrupt");
|
||||
// this has to be done in `main` because we're passing a pointer to the Box'd structure, which
|
||||
// the IRQ handler can freely and safely manipulate
|
||||
xous::claim_interrupt(
|
||||
|
|
@ -310,9 +299,7 @@ impl<'a> CramiumUsb<'a> {
|
|||
self as *mut CramiumUsb as *mut usize,
|
||||
)
|
||||
.expect("couldn't claim irq");
|
||||
log::info!("claimed IRQ with state at {:x}", self as *mut CramiumUsb as usize);
|
||||
|
||||
log::info!("Enabling IRQ");
|
||||
log::debug!("claimed IRQ with state at {:x}", self as *mut CramiumUsb as usize);
|
||||
|
||||
// enable both the corigine core IRQ and the software IRQ bit
|
||||
// software IRQ is used to initiate send/receive from software to the interrupt context
|
||||
|
|
@ -320,26 +307,13 @@ impl<'a> CramiumUsb<'a> {
|
|||
self.irq_csr.wo(utra::irqarray1::EV_EDGE_TRIGGERED, 0);
|
||||
self.irq_csr.wo(utra::irqarray1::EV_POLARITY, 0);
|
||||
|
||||
log::info!("init..");
|
||||
self.wrapper.hw.lock().unwrap().init();
|
||||
log::info!("start2..");
|
||||
self.wrapper.hw.lock().unwrap().start();
|
||||
log::info!("speed..");
|
||||
self.wrapper.hw.lock().unwrap().update_current_speed();
|
||||
|
||||
// irq must me enabled without dependency on the hw lock
|
||||
self.irq_csr.wo(utra::irqarray1::EV_PENDING, 0xFFFF_FFFF);
|
||||
self.irq_csr.wo(utra::irqarray1::EV_ENABLE, CORIGINE_IRQ_MASK | SW_IRQ_MASK);
|
||||
|
||||
/*
|
||||
let mut last_usb_state = self.wrapper.hw.lock().unwrap().get_device_state();
|
||||
let mut portsc = self.wrapper.hw.lock().unwrap().portsc_val();
|
||||
crate::println!("USB state: {:?}, {:x}", last_usb_state, portsc);
|
||||
|
||||
last_usb_state = self.wrapper.hw.lock().unwrap().get_device_state();
|
||||
portsc = self.wrapper.hw.lock().unwrap().portsc_val();
|
||||
crate::println!("USB state: {:?}, {:x}", last_usb_state, portsc);
|
||||
*/
|
||||
}
|
||||
|
||||
pub fn sw_irq(&mut self, request_type: UsbIrqReq) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@ use core::convert::TryFrom;
|
|||
use core::num::NonZeroU8;
|
||||
use core::sync::atomic::{AtomicBool, AtomicU32, Ordering};
|
||||
use std::collections::VecDeque;
|
||||
// Install a local panic handler
|
||||
#[cfg(feature = "debug-print-usb")]
|
||||
use std::panic;
|
||||
use std::sync::Arc;
|
||||
|
||||
use api::{HIDReport, LogLevel, Opcode, U2fCode, U2fMsgIpc, UsbListenerRegistration};
|
||||
|
|
@ -31,6 +34,16 @@ enum TimeoutOp {
|
|||
Quit,
|
||||
}
|
||||
|
||||
/*
|
||||
TODO:
|
||||
- [ ] USB stack doesn't know when the cable is unplugged. This is a hardware issue right now
|
||||
with MPW hardware. Wait until NTO chips come back to try and solve this? and if the bug isn't fixed
|
||||
there we can either work around this by adding a sense I/O for this purpose or we can use a timer
|
||||
to poll USB connection status.
|
||||
- [ ] Reduce debug spew. This is left in place for now because we will definitely need it in the
|
||||
future and it hasn't seemed to affect the stack operation like it did in the user-space implementation.
|
||||
*/
|
||||
|
||||
fn main() -> ! {
|
||||
#[cfg(target_os = "xous")]
|
||||
main_hw();
|
||||
|
|
@ -39,6 +52,15 @@ fn main() -> ! {
|
|||
}
|
||||
|
||||
pub(crate) fn main_hw() -> ! {
|
||||
// confirm that the app UART is initialized in our PID - this needs to happen in a userspace call
|
||||
// before any IRQ calls try to use it.
|
||||
crate::println!("APP UART in PID {}", xous::process::id());
|
||||
|
||||
#[cfg(feature = "debug-print-usb")]
|
||||
panic::set_hook(Box::new(|info| {
|
||||
crate::println!("{}", info);
|
||||
}));
|
||||
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
log::info!("my PID is {}", xous::process::id());
|
||||
|
|
@ -49,35 +71,6 @@ pub(crate) fn main_hw() -> ! {
|
|||
log::trace!("registered with NS -- {:?}", usbdev_sid);
|
||||
let tt = ticktimer::Ticktimer::new().unwrap();
|
||||
|
||||
// confirm that the app UART is initialized in our PID - this needs to happen in a userspace call
|
||||
// before any IRQ calls try to use it.
|
||||
crate::println!("APP UART in PID {}", xous::process::id());
|
||||
|
||||
/*
|
||||
log::info!("alloc 19");
|
||||
let irq19_range = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utralib::utra::irqarray19::HW_IRQARRAY19_BASE),
|
||||
None,
|
||||
0x1000,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't allocate IRQ19 pages");
|
||||
let irq19_csr = AtomicCsr::new(irq19_range.as_ptr() as *mut u32);
|
||||
log::info!("irq19 addr: {:x}", unsafe { irq19_csr.base() } as usize);
|
||||
xous::claim_interrupt(utralib::utra::irqarray19::IRQARRAY19_IRQ, hw::irq19_handler, unsafe {
|
||||
irq19_csr.base()
|
||||
} as *mut usize)
|
||||
.expect("couldn't claim irq");
|
||||
log::info!("enable IRQ19");
|
||||
irq19_csr.wo(utralib::utra::irqarray19::EV_ENABLE, 0x80);
|
||||
for i in 0..10 {
|
||||
log::info!("wait");
|
||||
tt.sleep_ms(1000).ok();
|
||||
log::info!("{}", i);
|
||||
irq19_csr.wfo(utralib::utra::irqarray19::EV_SOFT_TRIGGER, 0x80);
|
||||
}
|
||||
*/
|
||||
|
||||
let serial_number = format!("TODO!!"); // implement in cramium-hal once we have a serial number API
|
||||
|
||||
let native_kbd =
|
||||
|
|
@ -177,7 +170,10 @@ pub(crate) fn main_hw() -> ! {
|
|||
// loop only consumes CPU time when a timeout is active. Once it has timed out,
|
||||
// it will wait for a new pump call.
|
||||
let now = tt.elapsed_ms();
|
||||
match num_traits::FromPrimitive::from_usize(msg.body.id()).unwrap_or(TimeoutOp::InvalidCall) {
|
||||
let opcode =
|
||||
num_traits::FromPrimitive::from_usize(msg.body.id()).unwrap_or(TimeoutOp::InvalidCall);
|
||||
log::info!("Timeout thread: {:?}", opcode);
|
||||
match opcode {
|
||||
TimeoutOp::Pump => {
|
||||
if to_run.load(Ordering::SeqCst) {
|
||||
let tt_lsb = target_time_lsb.load(Ordering::SeqCst);
|
||||
|
|
@ -241,7 +237,7 @@ pub(crate) fn main_hw() -> ! {
|
|||
|
||||
let mut msg_opt = None;
|
||||
loop {
|
||||
xous::reply_and_receive_next(usbdev_sid, &mut msg_opt).unwrap();
|
||||
xous::reply_and_receive_next(usbdev_sid, &mut msg_opt).expect("Error fetching next message");
|
||||
let msg = msg_opt.as_mut().unwrap();
|
||||
let opcode = num_traits::FromPrimitive::from_usize(msg.body.id()).unwrap_or(Opcode::InvalidCall);
|
||||
log::info!("{:?}", opcode);
|
||||
|
|
@ -501,9 +497,9 @@ pub(crate) fn main_hw() -> ! {
|
|||
}
|
||||
}
|
||||
// clean up our program
|
||||
log::trace!("main loop exit, destroying servers");
|
||||
log::warn!("main loop exit, destroying servers");
|
||||
xns.unregister_server(usbdev_sid).unwrap();
|
||||
xous::destroy_server(usbdev_sid).unwrap();
|
||||
log::trace!("quitting");
|
||||
log::info!("quitting");
|
||||
xous::terminate_process(0)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue