mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
re-add the usb test directory
This commit is contained in:
parent
ec34c4ba91
commit
a09d773269
3 changed files with 163 additions and 0 deletions
23
services/usb-test/Cargo.toml
Normal file
23
services/usb-test/Cargo.toml
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
[package]
|
||||
name = "usb-test"
|
||||
version = "0.1.0"
|
||||
authors = ["bunnie <bunnie@kosagi.com>"]
|
||||
edition = "2018"
|
||||
description = "USB test & development stub"
|
||||
|
||||
# Dependency policy: fully specify dependencies to the minor version number
|
||||
[dependencies]
|
||||
xous = { path = "../../xous-rs" }
|
||||
log-server = { path = "../log-server" }
|
||||
ticktimer-server = { path = "../ticktimer-server" }
|
||||
xous-names = { path = "../xous-names" }
|
||||
log = "0.4.14"
|
||||
num-derive = {version = "0.3.3", default-features = false}
|
||||
num-traits = {version = "0.2.14", default-features = false}
|
||||
susres = {path = "../susres"}
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
utralib = { path = "../../utralib"}
|
||||
|
||||
[features]
|
||||
default = []
|
||||
9
services/usb-test/src/api.rs
Normal file
9
services/usb-test/src/api.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
pub(crate) const SERVER_NAME_USBTEST: &'static str = "_USB test and development server_";
|
||||
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum Opcode {
|
||||
/// Suspend/resume callback
|
||||
SuspendResume,
|
||||
/// Exits the server
|
||||
Quit,
|
||||
}
|
||||
131
services/usb-test/src/main.rs
Normal file
131
services/usb-test/src/main.rs
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![cfg_attr(target_os = "none", no_main)]
|
||||
|
||||
mod api;
|
||||
use api::*;
|
||||
|
||||
use num_traits::FromPrimitive;
|
||||
|
||||
#[cfg(any(target_os = "none", target_os = "xous"))]
|
||||
mod implementation {
|
||||
use utralib::generated::*;
|
||||
// use crate::api::*;
|
||||
use susres::{RegManager, RegOrField, SuspendResume};
|
||||
|
||||
pub struct UsbTest {
|
||||
//csr: utralib::CSR<u32>,
|
||||
//fifo: xous::MemoryRange,
|
||||
// susres_manager: RegManager::<{utra::audio::AUDIO_NUMREGS}>,
|
||||
}
|
||||
|
||||
impl UsbTest {
|
||||
pub fn new() -> UsbTest {
|
||||
/*
|
||||
let csr = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utra::audio::HW_AUDIO_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map Audio CSR range");
|
||||
let fifo = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utralib::HW_AUDIO_MEM),
|
||||
None,
|
||||
utralib::HW_AUDIO_MEM_LEN,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map Audio CSR range");
|
||||
*/
|
||||
let mut usbtest = UsbTest {
|
||||
// csr: CSR::new(csr.as_mut_ptr() as *mut u32),
|
||||
// susres_manager: RegManager::new(csr.as_mut_ptr() as *mut u32),
|
||||
// fifo,
|
||||
};
|
||||
|
||||
usbtest
|
||||
}
|
||||
|
||||
pub fn suspend(&mut self) {
|
||||
// self.susres_manager.suspend();
|
||||
}
|
||||
pub fn resume(&mut self) {
|
||||
// self.susres_manager.resume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// a stub to try to avoid breaking hosted mode for as long as possible.
|
||||
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||
mod implementation {
|
||||
pub struct UsbTest {
|
||||
}
|
||||
|
||||
impl UsbTest {
|
||||
pub fn new() -> UsbTest {
|
||||
UsbTest {
|
||||
}
|
||||
}
|
||||
pub fn suspend(&self) {
|
||||
}
|
||||
pub fn resume(&self) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
use crate::implementation::UsbTest;
|
||||
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
log::info!("my PID is {}", xous::process::id());
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let usbtest_sid = xns.register_name(api::SERVER_NAME_USBTEST, None).expect("can't register server");
|
||||
log::trace!("registered with NS -- {:?}", usbtest_sid);
|
||||
|
||||
let mut usbtest = UsbTest::new();
|
||||
|
||||
log::trace!("ready to accept requests");
|
||||
|
||||
std::thread::spawn({
|
||||
move || {
|
||||
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
||||
let mut keepalive = 0;
|
||||
loop {
|
||||
tt.sleep_ms(2500).unwrap();
|
||||
log::info!("keepalive {}", keepalive);
|
||||
keepalive += 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// register a suspend/resume listener
|
||||
let sr_cid = xous::connect(usbtest_sid).expect("couldn't create suspend callback connection");
|
||||
let mut susres = susres::Susres::new(None, &xns, api::Opcode::SuspendResume as u32, sr_cid).expect("couldn't create suspend/resume object");
|
||||
|
||||
loop {
|
||||
let msg = xous::receive_message(usbtest_sid).unwrap();
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(Opcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, {
|
||||
usbtest.suspend();
|
||||
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
|
||||
usbtest.resume();
|
||||
}),
|
||||
Some(Opcode::Quit) => {
|
||||
log::warn!("Quit received, goodbye world!");
|
||||
break;
|
||||
},
|
||||
None => {
|
||||
log::error!("couldn't convert opcode: {:?}", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
// clean up our program
|
||||
log::trace!("main loop exit, destroying servers");
|
||||
xns.unregister_server(usbtest_sid).unwrap();
|
||||
xous::destroy_server(usbtest_sid).unwrap();
|
||||
log::trace!("quitting");
|
||||
xous::terminate_process(0)
|
||||
}
|
||||
Loading…
Reference in a new issue