diff --git a/services/cram-console/Cargo.toml b/services/cram-console/Cargo.toml index a8a348435..7ece8d48c 100644 --- a/services/cram-console/Cargo.toml +++ b/services/cram-console/Cargo.toml @@ -29,5 +29,5 @@ locales = { path = "../../locales" } "hwsim" = [] "pio-test" = ["xous-pio"] "pl230-test" = ["xous-pl230"] -"message-passing-test" = [] +"hwtest" = [] default = [] diff --git a/services/cram-console/src/hwtest.rs b/services/cram-console/src/hwtest.rs new file mode 100644 index 000000000..b53499125 --- /dev/null +++ b/services/cram-console/src/hwtest.rs @@ -0,0 +1,125 @@ +use utralib::generated::*; + +pub fn hwtest() { + #[cfg(feature = "hwsim")] + let csr = xous::syscall::map_memory( + xous::MemoryAddress::new(utra::main::HW_MAIN_BASE), + None, + 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) + .expect("couldn't map Core Control CSR range"); + #[cfg(feature = "hwsim")] + let mut core_csr = Some(CSR::new(csr.as_mut_ptr() as *mut u32)); + + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x600d_0000); + + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0xa51d_0000); + let coreuser_csr = xous::syscall::map_memory( + xous::MemoryAddress::new(utra::coreuser::HW_COREUSER_BASE), + None, + 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) + .expect("couldn't map Core User CSR range"); + let mut coreuser = CSR::new(coreuser_csr.as_mut_ptr() as *mut u32); + // first, clear the ASID table to 0 + for asid in 0..512 { + coreuser.wo( + utra::coreuser::SET_ASID, + coreuser.ms(utra::coreuser::SET_ASID_ASID, asid) + | coreuser.ms(utra::coreuser::SET_ASID_TRUSTED, 0), + ); + } + // set my PID to trusted + coreuser.wo( + utra::coreuser::SET_ASID, + coreuser.ms(utra::coreuser::SET_ASID_ASID, xous::process::id() as u32) + | coreuser.ms(utra::coreuser::SET_ASID_TRUSTED, 1), + ); + // set the required `mpp` state to user code (mpp == 0) + coreuser.wfo(utra::coreuser::SET_PRIVILEGE_MPP, 0); + // turn on the coreuser computation + coreuser.wo( + utra::coreuser::CONTROL, + coreuser.ms(utra::coreuser::CONTROL_ASID, 1) + | coreuser.ms(utra::coreuser::CONTROL_ENABLE, 1) + | coreuser.ms(utra::coreuser::CONTROL_PRIVILEGE, 1), + ); + // turn off coreuser control updates + coreuser.wo(utra::coreuser::PROTECT, 1); + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0xa51d_600d); + + log::info!("my PID is {}", xous::process::id()); + + #[cfg(feature = "pio-test")] + { + log::info!("running PIO tests"); + xous_pio::pio_tests::pio_tests(); + log::info!("resuming console tests"); + } + + #[cfg(feature = "pl230-test")] + { + log::info!("running PL230 tests"); + xous_pl230::pl230_tests::pl230_tests(); + log::info!("resuming console tests"); + } + + let tt = xous_api_ticktimer::Ticktimer::new().unwrap(); + let mut total = 0; + let mut iter = 0; + log::info!("running message passing test"); + loop { + // this conjures a scalar message + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x1111_0000 + iter); + let now = tt.elapsed_ms(); + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x2222_0000 + iter); + total += now; + + if iter >= 8 && iter < 12 { + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D001); + tt.sleep_ms(1).ok(); + } else if iter >= 12 && iter < 13 { + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D002); + tt.sleep_ms(2).ok(); + } else if iter >= 13 && iter < 14 { + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D002); + tt.sleep_ms(3).ok(); + } else if iter >= 14 { + break; + } + + // something lame to just conjure a memory message + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x3333_0000 + iter); + let version = tt.get_version(); + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x4444_0000 + iter); + total += version.len() as u64; + iter += 1; + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, now as u32); + log::info!("message passing test progress: {}ms", tt.elapsed_ms()); + } + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x6969_6969); + println!("Elapsed: {}", total); + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x600d_c0de); + + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::SUCCESS_SUCCESS, 1); + tt.sleep_ms(4).ok(); + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::DONE_DONE, 1); // this should stop the simulation + log::info!("message passing test done at {}ms!", tt.elapsed_ms()); +} diff --git a/services/cram-console/src/main.rs b/services/cram-console/src/main.rs index 5d2c2975e..ebc5ba5cf 100644 --- a/services/cram-console/src/main.rs +++ b/services/cram-console/src/main.rs @@ -1,3 +1,6 @@ +#[cfg(feature = "hwtest")] +mod hwtest; + use std::fmt::Write; use std::thread; @@ -6,7 +9,6 @@ use graphics_server::Gid; use graphics_server::*; use locales::t; use num_traits::*; -use utralib::generated::*; const SERVER_NAME_STATUS_GID: &str = "_Status bar GID receiver_"; const SERVER_NAME_STATUS: &str = "_Status_"; @@ -17,137 +19,14 @@ pub(crate) enum StatusOpcode { } // TODO: -// - create_server_with_address can OOM without recovery -- figure out how to fix this. // - clean up the mess here fn main() { log_server::init_wait().unwrap(); log::set_max_level(log::LevelFilter::Info); - #[cfg(feature = "hwsim")] - let csr = xous::syscall::map_memory( - xous::MemoryAddress::new(utra::main::HW_MAIN_BASE), - None, - 4096, - xous::MemoryFlags::R | xous::MemoryFlags::W, - ) - .expect("couldn't map Core Control CSR range"); - #[cfg(feature = "hwsim")] - let mut core_csr = Some(CSR::new(csr.as_mut_ptr() as *mut u32)); - - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::REPORT_REPORT, 0x600d_0000); - - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::REPORT_REPORT, 0xa51d_0000); - let coreuser_csr = xous::syscall::map_memory( - xous::MemoryAddress::new(utra::coreuser::HW_COREUSER_BASE), - None, - 4096, - xous::MemoryFlags::R | xous::MemoryFlags::W, - ) - .expect("couldn't map Core User CSR range"); - let mut coreuser = CSR::new(coreuser_csr.as_mut_ptr() as *mut u32); - // first, clear the ASID table to 0 - for asid in 0..512 { - coreuser.wo( - utra::coreuser::SET_ASID, - coreuser.ms(utra::coreuser::SET_ASID_ASID, asid) - | coreuser.ms(utra::coreuser::SET_ASID_TRUSTED, 0), - ); - } - // set my PID to trusted - coreuser.wo( - utra::coreuser::SET_ASID, - coreuser.ms(utra::coreuser::SET_ASID_ASID, xous::process::id() as u32) - | coreuser.ms(utra::coreuser::SET_ASID_TRUSTED, 1), - ); - // set the required `mpp` state to user code (mpp == 0) - coreuser.wfo(utra::coreuser::SET_PRIVILEGE_MPP, 0); - // turn on the coreuser computation - coreuser.wo( - utra::coreuser::CONTROL, - coreuser.ms(utra::coreuser::CONTROL_ASID, 1) - | coreuser.ms(utra::coreuser::CONTROL_ENABLE, 1) - | coreuser.ms(utra::coreuser::CONTROL_PRIVILEGE, 1), - ); - // turn off coreuser control updates - coreuser.wo(utra::coreuser::PROTECT, 1); - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::REPORT_REPORT, 0xa51d_600d); - - log::info!("my PID is {}", xous::process::id()); - - #[cfg(feature = "pio-test")] - { - log::info!("running PIO tests"); - xous_pio::pio_tests::pio_tests(); - log::info!("resuming console tests"); - } - - #[cfg(feature = "pl230-test")] - { - log::info!("running PL230 tests"); - xous_pl230::pl230_tests::pl230_tests(); - log::info!("resuming console tests"); - } - - #[cfg(feature = "message-passing-test")] - { - let tt = xous_api_ticktimer::Ticktimer::new().unwrap(); - let mut total = 0; - let mut iter = 0; - log::info!("running message passing test"); - loop { - // this conjures a scalar message - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::REPORT_REPORT, 0x1111_0000 + iter); - let now = tt.elapsed_ms(); - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::REPORT_REPORT, 0x2222_0000 + iter); - total += now; - - if iter >= 8 && iter < 12 { - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D001); - tt.sleep_ms(1).ok(); - } else if iter >= 12 && iter < 13 { - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D002); - tt.sleep_ms(2).ok(); - } else if iter >= 13 && iter < 14 { - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D002); - tt.sleep_ms(3).ok(); - } else if iter >= 14 { - break; - } - - // something lame to just conjure a memory message - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::REPORT_REPORT, 0x3333_0000 + iter); - let version = tt.get_version(); - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::REPORT_REPORT, 0x4444_0000 + iter); - total += version.len() as u64; - iter += 1; - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::REPORT_REPORT, now as u32); - log::info!("message passing test progress: {}ms", tt.elapsed_ms()); - } - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::REPORT_REPORT, 0x6969_6969); - println!("Elapsed: {}", total); - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::REPORT_REPORT, 0x600d_c0de); - - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::SUCCESS_SUCCESS, 1); - tt.sleep_ms(4).ok(); - #[cfg(feature = "hwsim")] - core_csr.wfo(utra::main::DONE_DONE, 1); // this should stop the simulation - log::info!("message passing test done at {}ms!", tt.elapsed_ms()); - } + #[cfg(feature = "hwtest")] + hwtest::hwtest(); thread::spawn(move || { let mut count = 0; @@ -158,6 +37,15 @@ fn main() { } }); + thread::spawn(move || { + let xns = xous_api_names::XousNames::new().unwrap(); + let mut ball = Ball::new(&xns); + log::info!("starting ball"); + loop { + ball.update(); + } + }); + let xns = xous_api_names::XousNames::new().unwrap(); let status_gam_getter = @@ -246,6 +134,13 @@ fn main() { modals.show_notification("This is a test", Some("This is a test")).ok(); log::info!("exiting modal"); + xous::send_message( + cb_cid, + xous::Message::new_blocking_scalar(StatusOpcode::Quit.to_usize().unwrap(), 0, 0, 0, 0), + ) + .expect("couldn't exit the gutter server"); + gutter.join().expect("status boot gutter server did not exit gracefully"); + let mut ball = Ball::new(&xns); log::info!("starting ball"); loop {