cleanup, added comments
This commit is contained in:
parent
d27b447106
commit
9a6ca01c85
|
@ -35,7 +35,6 @@
|
|||
*/
|
||||
static const RNGConfig default_config = {
|
||||
.digital_error_correction = 1,
|
||||
.power_on_write = 1,
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
|
@ -91,6 +90,7 @@ void rng_lld_start(RNGDriver *rngp) {
|
|||
else
|
||||
rngp->rng->CONFIG &= ~RNG_CONFIG_DERCEN_Msk;
|
||||
|
||||
rngp->rng->EVENTS_VALRDY = 0;
|
||||
rngp->rng->INTENSET = RNG_INTENSET_VALRDY_Msk;
|
||||
rngp->rng->TASKS_START = 1;
|
||||
}
|
||||
|
@ -121,23 +121,27 @@ void rng_lld_stop(RNGDriver *rngp) {
|
|||
msg_t rng_lld_write(RNGDriver *rngp, uint8_t *buf, size_t n,
|
||||
systime_t timeout) {
|
||||
size_t i;
|
||||
if (n == 0)
|
||||
return MSG_OK;
|
||||
|
||||
NRF_RNG->EVENTS_VALRDY = 0;
|
||||
|
||||
for (i = 0 ; i < n ; i++) {
|
||||
/* wait for next byte */
|
||||
/* Wait for byte ready
|
||||
* It take about 677µs to generate a new byte, not sure if
|
||||
* forcing a context switch will be a benefit
|
||||
*/
|
||||
while (NRF_RNG->EVENTS_VALRDY == 0) {
|
||||
/* Sleep and wakeup on ARM event (interrupt) */
|
||||
SCB->SCR |= SCB_SCR_SEVONPEND_Msk;
|
||||
__SEV();
|
||||
__WFE();
|
||||
__WFE();
|
||||
}
|
||||
|
||||
/* Read byte */
|
||||
buf[i] = (char)NRF_RNG->VALUE;
|
||||
|
||||
/* Mark as read */
|
||||
NRF_RNG->EVENTS_VALRDY = 0;
|
||||
|
||||
/* Clear interrupt so we can wake up again */
|
||||
nvicClearPending(RNG_IRQn);
|
||||
}
|
||||
return MSG_OK;
|
||||
|
|
Loading…
Reference in New Issue