From 9f9575fdd88316b7f6a90bad7d56885b8e13ad1c Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 19 Apr 2021 04:54:32 +0800 Subject: [PATCH] refine trng-tester configuration --- buildpush.sh | 4 +++ services/trng-tester/Cargo.toml | 2 +- services/trng-tester/src/main.rs | 54 ++++++-------------------------- xtask/src/main.rs | 13 +++++--- 4 files changed, 23 insertions(+), 50 deletions(-) diff --git a/buildpush.sh b/buildpush.sh index 69590ceff..04b2ef468 100755 --- a/buildpush.sh +++ b/buildpush.sh @@ -55,6 +55,10 @@ do IMAGE=minimal shift ;; + -t|--trngtest) + IMAGE=trng-test + shift + ;; -h|--help) echo "$0 provisions betrusted. --kernel-skip skips the kernel, --fpga-skip skips the FPGA. --current-csr indicates to use the CSR for the new FPGA image to do the update (normally you want to use the one corresponding to the older, currently installed version)." echo "Alternatively, using --copy-to copies the files to a remote host and skips provisioning." diff --git a/services/trng-tester/Cargo.toml b/services/trng-tester/Cargo.toml index 9506fb50e..e01bff50b 100644 --- a/services/trng-tester/Cargo.toml +++ b/services/trng-tester/Cargo.toml @@ -3,7 +3,7 @@ name = "trng-tester" version = "0.1.0" authors = ["bunnie "] edition = "2018" -description = "COM interface to the EC" +description = "TRNG tester" [dependencies] xous = { path = "../../xous-rs" } diff --git a/services/trng-tester/src/main.rs b/services/trng-tester/src/main.rs index ece32db19..d06815dac 100644 --- a/services/trng-tester/src/main.rs +++ b/services/trng-tester/src/main.rs @@ -18,7 +18,6 @@ mod implementation { pub struct Trng { server_csr: utralib::CSR, - xadc_csr: utralib::CSR, messible_csr: utralib::CSR, messible2_csr: utralib::CSR, buffer_a: MemoryRange, @@ -41,14 +40,6 @@ mod implementation { ) .expect("couldn't map TRNG Server CSR range"); - let xadc_csr = xous::syscall::map_memory( - xous::MemoryAddress::new(utra::trng::HW_TRNG_BASE), - None, - 4096, - xous::MemoryFlags::R | xous::MemoryFlags::W, - ) - .expect("couldn't map TRNG xadc CSR range"); - let buff_a = xous::syscall::map_memory( xous::MemoryAddress::new(0x4020_0000), // fix this at a known physical address None, @@ -83,7 +74,6 @@ mod implementation { let mut trng = Trng { server_csr: CSR::new(server_csr.as_mut_ptr() as *mut u32), - xadc_csr: CSR::new(xadc_csr.as_mut_ptr() as *mut u32), buffer_a: buff_a, buffer_b: buff_b, messible_csr: CSR::new(messible.as_mut_ptr() as *mut u32), @@ -184,28 +174,6 @@ mod implementation { xous::yield_slice(); } } - pub fn read_temperature(&self) -> f32 { - (self.xadc_csr.rf(utra::trng::XADC_TEMPERATURE_XADC_TEMPERATURE) as f32 * 503.975) / 4096.0 - 273.15 - } - pub fn read_vccint(&self) -> u32 { - (self.xadc_csr.rf(utra::trng::XADC_VCCINT_XADC_VCCINT) * 3000) / 4096 - } - pub fn read_vccaux(&self) -> u32 { - (self.xadc_csr.rf(utra::trng::XADC_VCCAUX_XADC_VCCAUX) * 3000) / 4096 - } - pub fn read_vccbram(&self) -> u32 { - (self.xadc_csr.rf(utra::trng::XADC_VCCBRAM_XADC_VCCBRAM) * 3000) / 4096 - } - pub fn read_vbus(&self) -> u32 { - (self.xadc_csr.rf(utra::trng::XADC_VBUS_XADC_VBUS) * 5033) / 1000 - } - pub fn read_usb_p(&self) -> u32 { - (self.xadc_csr.rf(utra::trng::XADC_USB_P_XADC_USB_P) * 1000) / 4096 - } - pub fn read_usb_n(&self) -> u32 { - (self.xadc_csr.rf(utra::trng::XADC_USB_N_XADC_USB_N) * 1000) / 4096 - } - } } @@ -229,6 +197,14 @@ mod implementation { } } +fn wdt_thread() { + let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer"); + + loop { + ticktimer.sleep_ms(100).unwrap(); + } +} + #[xous::xous_main] fn xmain() -> ! { use crate::implementation::Trng; @@ -239,6 +215,8 @@ fn xmain() -> ! { let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer"); + xous::create_thread_0(wdt_thread).expect("couldn't create waking thread"); + // Create a new com object let mut trng = Trng::new(); trng.init(); @@ -265,18 +243,6 @@ fn xmain() -> ! { ticktimer.sleep_ms(5000).expect("couldn't sleep"); } - if false { - // select this to print XADC data to info!() - ticktimer.sleep_ms(20).expect("couldn't sleep"); // sleep to allow xadc sampling in case we're in a very tight TRNG request loop - info!("temperature: {}C", trng.read_temperature()); - info!("vccint: {}mV", trng.read_vccint()); - info!("vccaux: {}mV", trng.read_vccaux()); - info!("vccbram: {}mV", trng.read_vccbram()); - info!("vbus: {}mV", trng.read_vbus()); - info!("usb_p: {}mV", trng.read_usb_p()); - info!("usb_n: {}mV", trng.read_usb_n()); - } - // to test the full loop trng.messible_wait_get(WhichMessible::Two); phase += 1; diff --git a/xtask/src/main.rs b/xtask/src/main.rs index d4a6cf2a6..f134fce8a 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -91,17 +91,20 @@ fn try_main() -> Result<(), DynError> { "cb-test-c2", ]; let trng_pkgs = [ - "gam", - "ime-frontend", - "ime-plugin-shell", - "trng-tester", + //"gam", + //"shellchat", + //"ime-frontend", + //"ime-plugin-shell", "graphics-server", "ticktimer-server", "log-server", "com", "xous-names", "keyboard", - "trng", + "llio", + "rtc", + + "trng-tester", ]; let task = env::args().nth(1); match task.as_deref() {