refine trng-tester configuration

This commit is contained in:
bunnie 2021-04-19 04:54:32 +08:00
parent 995ebdccc5
commit 9f9575fdd8
4 changed files with 23 additions and 50 deletions

View file

@ -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 <hostname> copies the files to a remote host and skips provisioning."

View file

@ -3,7 +3,7 @@ name = "trng-tester"
version = "0.1.0"
authors = ["bunnie <bunnie@kosagi.com>"]
edition = "2018"
description = "COM interface to the EC"
description = "TRNG tester"
[dependencies]
xous = { path = "../../xous-rs" }

View file

@ -18,7 +18,6 @@ mod implementation {
pub struct Trng {
server_csr: utralib::CSR<u32>,
xadc_csr: utralib::CSR<u32>,
messible_csr: utralib::CSR<u32>,
messible2_csr: utralib::CSR<u32>,
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;

View file

@ -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() {