apply deferred-init + Box idiom to engine-sha512

This commit is contained in:
bunnie 2023-07-16 17:34:19 +08:00
parent b275d8f53b
commit 04ca49b1cc

View file

@ -76,37 +76,39 @@ mod implementation {
.expect("couldn't map Engine512 CSR range"); .expect("couldn't map Engine512 CSR range");
#[cfg(not(feature = "event_wait"))] #[cfg(not(feature = "event_wait"))]
let mut engine512 = Engine512 { let engine512 = Engine512 {
csr: CSR::new(csr.as_mut_ptr() as *mut u32), csr: CSR::new(csr.as_mut_ptr() as *mut u32),
fifo, fifo,
}; };
#[cfg(feature = "event_wait")] #[cfg(feature = "event_wait")]
let mut engine512 = Engine512 { let engine512 = Engine512 {
csr: CSR::new(csr.as_mut_ptr() as *mut u32), csr: CSR::new(csr.as_mut_ptr() as *mut u32),
fifo, fifo,
handler_conn: _handler_conn, handler_conn: _handler_conn,
}; };
engine512
}
pub (crate) fn init(&mut self) {
#[cfg(feature = "event_wait")] #[cfg(feature = "event_wait")]
xous::claim_interrupt( xous::claim_interrupt(
utra::sha512::SHA512_IRQ, utra::sha512::SHA512_IRQ,
handle_irq, handle_irq,
(&mut engine512) as *mut Engine512 as *mut usize, self as *mut Engine512 as *mut usize,
) )
.expect("couldn't claim irq"); .expect("couldn't claim irq");
// note: we can't use a "susres" manager here because this block has un-suspendable state // note: we can't use a "susres" manager here because this block has un-suspendable state
// instead, we rely on every usage of this mechanism to explicitly set this enable bit before relying upon it // instead, we rely on every usage of this mechanism to explicitly set this enable bit before relying upon it
#[cfg(feature = "event_wait")] #[cfg(feature = "event_wait")]
engine512.csr.wfo(utra::sha512::EV_ENABLE_SHA512_DONE, 1); self.csr.wfo(utra::sha512::EV_ENABLE_SHA512_DONE, 1);
// reset the block on boot // reset the block on boot
// we don't save this as part of the susres set because // we don't save this as part of the susres set because
// on a "proper" resume, the block was already reset by the secure boot process // on a "proper" resume, the block was already reset by the secure boot process
// the code path where this really becomes necessary is if we have a WDT reset or // the code path where this really becomes necessary is if we have a WDT reset or
// some sort of server-restart. // some sort of server-restart.
engine512.csr.wfo(utra::sha512::CONFIG_RESET, 1); // takes ~32 cycles to complete self.csr.wfo(utra::sha512::CONFIG_RESET, 1); // takes ~32 cycles to complete
engine512
} }
pub(crate) fn setup(&mut self, config: Sha2Config) { pub(crate) fn setup(&mut self, config: Sha2Config) {
@ -348,9 +350,10 @@ fn main() -> ! {
log::trace!("registered with NS -- {:?}", engine512_sid); log::trace!("registered with NS -- {:?}", engine512_sid);
#[cfg(feature="event_wait")] #[cfg(feature="event_wait")]
let mut engine512 = Engine512::new(xous::connect(engine512_sid).ok()); let mut engine512 = Box::new(Engine512::new(xous::connect(engine512_sid).ok()));
#[cfg(not(feature="event_wait"))] #[cfg(not(feature="event_wait"))]
let mut engine512 = Engine512::new(None); let mut engine512 = Box::new(Engine512::new(None));
engine512.init();
log::trace!("ready to accept requests"); log::trace!("ready to accept requests");