mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
use a common device core for all views, with a lock on it for sharing
threading the needle between the USB device API requirments, and our system's unique requirements.
This commit is contained in:
parent
971bfea83d
commit
26d15084a3
1 changed files with 84 additions and 30 deletions
|
|
@ -214,8 +214,18 @@ pub(crate) fn main_hw() -> ! {
|
||||||
)
|
)
|
||||||
.expect("couldn't allocate IFRAM pages");
|
.expect("couldn't allocate IFRAM pages");
|
||||||
#[cfg(feature = "cramium-soc")]
|
#[cfg(feature = "cramium-soc")]
|
||||||
|
let irq_range = xous::syscall::map_memory(
|
||||||
|
xous::MemoryAddress::new(utralib::utra::irqarray1::HW_IRQARRAY1_BASE),
|
||||||
|
None,
|
||||||
|
0x1000,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
)
|
||||||
|
.expect("couldn't allocate IFRAM pages");
|
||||||
|
#[cfg(feature = "cramium-soc")]
|
||||||
let usb = AtomicCsr::new(usb_mapping.as_ptr() as *mut u32);
|
let usb = AtomicCsr::new(usb_mapping.as_ptr() as *mut u32);
|
||||||
#[cfg(feature = "cramium-soc")]
|
#[cfg(feature = "cramium-soc")]
|
||||||
|
let irq_csr = AtomicCsr::new(irq_range.as_ptr() as *mut u32);
|
||||||
|
#[cfg(feature = "cramium-soc")]
|
||||||
let h_op: usize = Opcode::UsbIrqHandler.to_usize().unwrap();
|
let h_op: usize = Opcode::UsbIrqHandler.to_usize().unwrap();
|
||||||
|
|
||||||
// Notes:
|
// Notes:
|
||||||
|
|
@ -224,38 +234,33 @@ pub(crate) fn main_hw() -> ! {
|
||||||
// another crate that implements the USB stack which can't handle Box'd structures.
|
// another crate that implements the USB stack which can't handle Box'd structures.
|
||||||
// - It is safe to call `.init()` repeatedly because within `init()` we have an atomic bool that tracks
|
// - It is safe to call `.init()` repeatedly because within `init()` we have an atomic bool that tracks
|
||||||
// if the interrupt handler has been hooked, and ignores further requests to hook it.
|
// if the interrupt handler has been hooked, and ignores further requests to hook it.
|
||||||
|
#[cfg(feature = "cramium-soc")]
|
||||||
|
// safety: this is safe because we allocated ifram_range to have the same physical and virtual addresses
|
||||||
|
#[cfg(feature = "cramium-soc")]
|
||||||
|
let usbwrapper = CorigineWrapper::new(unsafe {
|
||||||
|
CorigineUsb::new(cid, h_op, ifram_range.as_ptr() as usize, usb.clone(), irq_csr.clone())
|
||||||
|
});
|
||||||
|
|
||||||
#[cfg(any(feature = "renode", feature = "precursor"))]
|
#[cfg(any(feature = "renode", feature = "precursor"))]
|
||||||
let usb_fidokbd_dev = SpinalUsbDevice::new(usbdev_sid, usb.clone(), csr.clone());
|
let usb_fidokbd_dev = SpinalUsbDevice::new(usbdev_sid, usb.clone(), csr.clone());
|
||||||
#[cfg(feature = "cramium-soc")]
|
#[cfg(feature = "cramium-soc")]
|
||||||
// safety: this is safe because we allocated ifram_range to have the same physical and virtual addresses
|
// safety: this is safe because we allocated ifram_range to have the same physical and virtual addresses
|
||||||
let usb_fidokbd_dev = CorigineWrapper::new(unsafe {
|
let usb_fidokbd_dev = usbwrapper.clone();
|
||||||
CorigineUsb::new(cid, h_op, ifram_range.as_ptr() as usize, usb.clone())
|
|
||||||
});
|
|
||||||
#[cfg(any(feature = "renode", feature = "precursor"))]
|
#[cfg(any(feature = "renode", feature = "precursor"))]
|
||||||
usb_fidokbd_dev.init();
|
usb_fidokbd_dev.init();
|
||||||
#[cfg(any(feature = "renode", feature = "precursor"))]
|
#[cfg(any(feature = "renode", feature = "precursor"))]
|
||||||
let mut usbmgmt = usb_fidokbd_dev.get_iface();
|
let mut usbmgmt = usb_fidokbd_dev.get_iface();
|
||||||
#[cfg(feature = "cramium-soc")]
|
#[cfg(feature = "cramium-soc")]
|
||||||
// safety: this is safe because we allocated ifram_range to have the same physical and virtual addresses
|
{
|
||||||
let mut usbmgmt = unsafe {
|
usbwrapper.core().reset();
|
||||||
CorigineUsb::new(
|
}
|
||||||
cid,
|
|
||||||
Opcode::UsbIrqHandler.to_usize().unwrap(),
|
|
||||||
ifram_range.as_ptr() as usize,
|
|
||||||
usb.clone(),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
#[cfg(feature = "cramium-soc")]
|
|
||||||
usbmgmt.reset();
|
|
||||||
// before doing any allocs, clone a copy of the hardware access structure so we can build a second
|
// before doing any allocs, clone a copy of the hardware access structure so we can build a second
|
||||||
// view into the hardware with only FIDO descriptors
|
// view into the hardware with only FIDO descriptors
|
||||||
#[cfg(any(feature = "renode", feature = "precursor"))]
|
#[cfg(any(feature = "renode", feature = "precursor"))]
|
||||||
let usb_fido_dev: SpinalUsbDevice = SpinalUsbDevice::new(usbdev_sid, usb.clone(), csr.clone());
|
let usb_fido_dev: SpinalUsbDevice = SpinalUsbDevice::new(usbdev_sid, usb.clone(), csr.clone());
|
||||||
#[cfg(feature = "cramium-soc")]
|
#[cfg(feature = "cramium-soc")]
|
||||||
// safety: this is safe because we allocated ifram_range to have the same physical and virtual addresses
|
// safety: this is safe because we allocated ifram_range to have the same physical and virtual addresses
|
||||||
let usb_fido_dev = CorigineWrapper::new(unsafe {
|
let usb_fido_dev = usbwrapper.clone();
|
||||||
CorigineUsb::new(cid, h_op, ifram_range.as_ptr() as usize, usb.clone())
|
|
||||||
});
|
|
||||||
#[cfg(any(feature = "renode", feature = "precursor"))]
|
#[cfg(any(feature = "renode", feature = "precursor"))]
|
||||||
usb_fido_dev.init();
|
usb_fido_dev.init();
|
||||||
// do the same thing for mass storage
|
// do the same thing for mass storage
|
||||||
|
|
@ -263,9 +268,7 @@ pub(crate) fn main_hw() -> ! {
|
||||||
let ums_dev = SpinalUsbDevice::new(usbdev_sid, usb.clone(), csr.clone());
|
let ums_dev = SpinalUsbDevice::new(usbdev_sid, usb.clone(), csr.clone());
|
||||||
#[cfg(all(feature = "mass-storage", any(feature = "cramium-soc")))]
|
#[cfg(all(feature = "mass-storage", any(feature = "cramium-soc")))]
|
||||||
// safety: this is safe because we allocated ifram_range to have the same physical and virtual addresses
|
// safety: this is safe because we allocated ifram_range to have the same physical and virtual addresses
|
||||||
let ums_dev = CorigineWrapper::new(unsafe {
|
let ums_dev = usbwrapper.clone();
|
||||||
CorigineUsb::new(cid, h_op, ifram_range.as_ptr() as usize, usb.clone())
|
|
||||||
});
|
|
||||||
#[cfg(feature = "mass-storage")]
|
#[cfg(feature = "mass-storage")]
|
||||||
#[cfg(any(feature = "renode", feature = "precursor"))]
|
#[cfg(any(feature = "renode", feature = "precursor"))]
|
||||||
ums_dev.init();
|
ums_dev.init();
|
||||||
|
|
@ -273,9 +276,7 @@ pub(crate) fn main_hw() -> ! {
|
||||||
let serial_dev = SpinalUsbDevice::new(usbdev_sid, usb.clone(), csr.clone());
|
let serial_dev = SpinalUsbDevice::new(usbdev_sid, usb.clone(), csr.clone());
|
||||||
#[cfg(feature = "cramium-soc")]
|
#[cfg(feature = "cramium-soc")]
|
||||||
// safety: this is safe because we allocated ifram_range to have the same physical and virtual addresses
|
// safety: this is safe because we allocated ifram_range to have the same physical and virtual addresses
|
||||||
let serial_dev = CorigineWrapper::new(unsafe {
|
let serial_dev = usbwrapper.clone();
|
||||||
CorigineUsb::new(cid, h_op, ifram_range.as_ptr() as usize, usb.clone())
|
|
||||||
});
|
|
||||||
#[cfg(any(feature = "renode", feature = "precursor"))]
|
#[cfg(any(feature = "renode", feature = "precursor"))]
|
||||||
serial_dev.init();
|
serial_dev.init();
|
||||||
|
|
||||||
|
|
@ -368,9 +369,7 @@ pub(crate) fn main_hw() -> ! {
|
||||||
let usb_hidv2_dev = SpinalUsbDevice::new(usbdev_sid, usb.clone(), csr.clone());
|
let usb_hidv2_dev = SpinalUsbDevice::new(usbdev_sid, usb.clone(), csr.clone());
|
||||||
#[cfg(feature = "cramium-soc")]
|
#[cfg(feature = "cramium-soc")]
|
||||||
// safety: this is safe because we allocated ifram_range to have the same physical and virtual addresses
|
// safety: this is safe because we allocated ifram_range to have the same physical and virtual addresses
|
||||||
let usb_hidv2_dev = CorigineWrapper::new(unsafe {
|
let usb_hidv2_dev = usbwrapper.clone();
|
||||||
CorigineUsb::new(cid, h_op, ifram_range.as_ptr() as usize, usb.clone())
|
|
||||||
});
|
|
||||||
|
|
||||||
let hidv2_alloc = UsbBusAllocator::new(usb_hidv2_dev);
|
let hidv2_alloc = UsbBusAllocator::new(usb_hidv2_dev);
|
||||||
|
|
||||||
|
|
@ -384,13 +383,51 @@ pub(crate) fn main_hw() -> ! {
|
||||||
|
|
||||||
#[cfg(feature = "cramium-soc")]
|
#[cfg(feature = "cramium-soc")]
|
||||||
{
|
{
|
||||||
log::info!("Starting USB hardware in 5 seconds...");
|
log::info!("Starting USB hardware in 2 seconds...");
|
||||||
tt.sleep_ms(5000).ok();
|
tt.sleep_ms(2000).ok();
|
||||||
log::info!("NOW!");
|
log::info!("NOW!");
|
||||||
// for the cramium target, call init only once via management structure
|
// for the cramium target, call init only once via management structure
|
||||||
usbmgmt.init();
|
usbwrapper.reset();
|
||||||
usbmgmt.start();
|
let mut poweron = 0;
|
||||||
|
loop {
|
||||||
|
usbwrapper.core().udc_handle_interrupt();
|
||||||
|
if usbwrapper.core().pp() {
|
||||||
|
poweron += 1;
|
||||||
|
}
|
||||||
|
tt.sleep_ms(100).ok();
|
||||||
|
if poweron >= 4 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
usbwrapper.core().print_status(usb.r(cramium_hal::usb::utra::PORTSC));
|
||||||
|
usbwrapper.core().reset();
|
||||||
|
usbwrapper.core().print_status(usb.r(cramium_hal::usb::utra::PORTSC));
|
||||||
|
usbwrapper.core().init();
|
||||||
|
usbwrapper.core().print_status(usb.r(cramium_hal::usb::utra::PORTSC));
|
||||||
|
usbwrapper.core().start();
|
||||||
|
usbwrapper.core().print_status(usb.r(cramium_hal::usb::utra::PORTSC));
|
||||||
log::info!("HW started...");
|
log::info!("HW started...");
|
||||||
|
#[cfg(feature = "pinger")]
|
||||||
|
std::thread::spawn({
|
||||||
|
let irq_csr = irq_csr.clone();
|
||||||
|
let usb = usb.clone();
|
||||||
|
move || {
|
||||||
|
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
||||||
|
loop {
|
||||||
|
log::info!(
|
||||||
|
" pd: {:x}/{:x} st: {:x}/{:x} cf: {:x}/{:x} cmd: {:x}",
|
||||||
|
irq_csr.r(utralib::utra::irqarray1::EV_PENDING),
|
||||||
|
irq_csr.r(utralib::utra::irqarray1::EV_STATUS),
|
||||||
|
usb.r(cramium_hal::usb::utra::USBSTS),
|
||||||
|
usb.r(cramium_hal::usb::utra::PORTSC),
|
||||||
|
usb.r(cramium_hal::usb::utra::DEVCONFIG),
|
||||||
|
usb.r(cramium_hal::usb::utra::EVENTCONFIG),
|
||||||
|
usb.r(cramium_hal::usb::utra::USBCMD),
|
||||||
|
);
|
||||||
|
tt.sleep_ms(5000).ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut led_state: KeyboardLedsReport = KeyboardLedsReport::default();
|
let mut led_state: KeyboardLedsReport = KeyboardLedsReport::default();
|
||||||
|
|
@ -733,9 +770,14 @@ pub(crate) fn main_hw() -> ! {
|
||||||
}
|
}
|
||||||
buffer.replace(u2f_ipc).unwrap();
|
buffer.replace(u2f_ipc).unwrap();
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "cramium-soc"))]
|
||||||
|
Some(Opcode::UsbIrqHandler) => {
|
||||||
|
usbwrapper.core().udc_handle_interrupt();
|
||||||
|
}
|
||||||
Some(Opcode::UsbIrqHandler) => {
|
Some(Opcode::UsbIrqHandler) => {
|
||||||
let maybe_u2f = match view {
|
let maybe_u2f = match view {
|
||||||
Views::FidoWithKbd => {
|
Views::FidoWithKbd => {
|
||||||
|
log::info!("FidoWithKbd poll");
|
||||||
if usb_dev.poll(&mut [&mut composite]) {
|
if usb_dev.poll(&mut [&mut composite]) {
|
||||||
match composite.device::<NKROBootKeyboard<_>, _>().read_report() {
|
match composite.device::<NKROBootKeyboard<_>, _>().read_report() {
|
||||||
Ok(l) => {
|
Ok(l) => {
|
||||||
|
|
@ -971,6 +1013,8 @@ pub(crate) fn main_hw() -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
let devtype: UsbDeviceType = core.try_into().unwrap();
|
let devtype: UsbDeviceType = core.try_into().unwrap();
|
||||||
|
#[cfg(feature = "cramium-soc")]
|
||||||
|
let mut usbmgmt = usbwrapper.core();
|
||||||
match devtype {
|
match devtype {
|
||||||
UsbDeviceType::Debug => {
|
UsbDeviceType::Debug => {
|
||||||
log::info!("Connecting debug core; disconnecting USB device core");
|
log::info!("Connecting debug core; disconnecting USB device core");
|
||||||
|
|
@ -1087,6 +1131,8 @@ pub(crate) fn main_hw() -> ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "cramium-soc")]
|
||||||
|
let mut usbmgmt = usbwrapper.core();
|
||||||
match devtype {
|
match devtype {
|
||||||
UsbDeviceType::Debug => {
|
UsbDeviceType::Debug => {
|
||||||
if usbmgmt.is_device_connected() {
|
if usbmgmt.is_device_connected() {
|
||||||
|
|
@ -1188,6 +1234,8 @@ pub(crate) fn main_hw() -> ! {
|
||||||
xous::return_scalar(msg.sender, 0).unwrap();
|
xous::return_scalar(msg.sender, 0).unwrap();
|
||||||
}),
|
}),
|
||||||
Some(Opcode::WhichCore) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
Some(Opcode::WhichCore) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||||
|
#[cfg(feature = "cramium-soc")]
|
||||||
|
let mut usbmgmt = usbwrapper.core();
|
||||||
if usbmgmt.is_device_connected() {
|
if usbmgmt.is_device_connected() {
|
||||||
match view {
|
match view {
|
||||||
Views::FidoWithKbd => {
|
Views::FidoWithKbd => {
|
||||||
|
|
@ -1212,6 +1260,8 @@ pub(crate) fn main_hw() -> ! {
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Some(Opcode::RestrictDebugAccess) => msg_scalar_unpack!(msg, restrict, _, _, _, {
|
Some(Opcode::RestrictDebugAccess) => msg_scalar_unpack!(msg, restrict, _, _, _, {
|
||||||
|
#[cfg(feature = "cramium-soc")]
|
||||||
|
let mut usbmgmt = usbwrapper.core();
|
||||||
if restrict == 0 {
|
if restrict == 0 {
|
||||||
usbmgmt.disable_debug(false);
|
usbmgmt.disable_debug(false);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1219,6 +1269,8 @@ pub(crate) fn main_hw() -> ! {
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Some(Opcode::IsRestricted) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
Some(Opcode::IsRestricted) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||||
|
#[cfg(feature = "cramium-soc")]
|
||||||
|
let mut usbmgmt = usbwrapper.core();
|
||||||
if usbmgmt.get_disable_debug() {
|
if usbmgmt.get_disable_debug() {
|
||||||
xous::return_scalar(msg.sender, 1).unwrap();
|
xous::return_scalar(msg.sender, 1).unwrap();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1226,6 +1278,8 @@ pub(crate) fn main_hw() -> ! {
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Some(Opcode::DebugUsbOp) => msg_blocking_scalar_unpack!(msg, update_req, new_state, _, _, {
|
Some(Opcode::DebugUsbOp) => msg_blocking_scalar_unpack!(msg, update_req, new_state, _, _, {
|
||||||
|
#[cfg(feature = "cramium-soc")]
|
||||||
|
let mut usbmgmt = usbwrapper.core();
|
||||||
if update_req != 0 {
|
if update_req != 0 {
|
||||||
// if new_state is true (not 0), then try to lock the USB port
|
// if new_state is true (not 0), then try to lock the USB port
|
||||||
// if false, try to unlock the USB port
|
// if false, try to unlock the USB port
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue