add some debugging, convenience routines to trng driver

This commit is contained in:
bunnie 2024-04-28 02:44:10 +08:00
parent fcf3dfb4cd
commit 588e1cf9f1

View file

@ -68,6 +68,7 @@ bitflags! {
}
}
#[derive(PartialEq, Eq)]
enum Mode {
Uninit,
Raw,
@ -76,7 +77,7 @@ enum Mode {
}
pub struct Trng {
csr: CSR<u32>,
pub csr: CSR<u32>,
count: u16,
mode: Mode,
}
@ -132,7 +133,7 @@ impl Trng {
Some(self.csr.r(utra::trng::SFR_BUF))
} else {
// re-init generation automatically
self.setup_raw_generation(256);
self.setup_raw_generation(32);
self.count -= 1;
while self.csr.r(utra::trng::SFR_SR) & Status::BUFREADY.bits() == 0 {}
Some(self.csr.r(utra::trng::SFR_BUF))
@ -152,6 +153,10 @@ impl Trng {
}
pub fn get_count_remaining(&self) -> u16 { self.count }
pub fn start(&mut self) { self.csr.wo(utra::trng::SFR_AR_GEN, 0x5A); }
pub fn stop(&mut self) { self.csr.wo(utra::trng::SFR_AR_GEN, 0xA5); }
}
// some old test code