From 1f55dd8ab194526a94e9282a3b54661839895df6 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 23 Jul 2025 01:23:45 +0800 Subject: [PATCH] add the messaging test into the mbox environment --- services/cram-mbox1/Cargo.toml | 1 + services/cram-mbox1/src/main.rs | 55 +++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/services/cram-mbox1/Cargo.toml b/services/cram-mbox1/Cargo.toml index 2e5b8506a..49fcb595e 100644 --- a/services/cram-mbox1/Cargo.toml +++ b/services/cram-mbox1/Cargo.toml @@ -18,6 +18,7 @@ num-traits = { version = "0.2.14", default-features = false } [features] "cramium" = ["utralib/cramium-fpga"] "hwsim" = [] +"message-test" = [] # ext specifies to use the APB client, instead of the loopback local "ext" = [] # must match setting in cram-mbox2 default = ["cramium"] diff --git a/services/cram-mbox1/src/main.rs b/services/cram-mbox1/src/main.rs index da9d4f748..2447c5745 100644 --- a/services/cram-mbox1/src/main.rs +++ b/services/cram-mbox1/src/main.rs @@ -168,6 +168,61 @@ fn main() { // enable the interrupt mailbox.csr.wo(utra::mailbox::EV_ENABLE, !0); // enable everything + #[cfg(feature = "message-test")] + { + #[cfg(feature = "hwsim")] + let c_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 = CSR::new(c_csr.as_mut_ptr() as *mut u32); + + 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()); + } + } // tests to run: // all tests take the form of loopback, data transmit -> data receive ^ 0xaaaa_0000 //