aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal
diff options
context:
space:
mode:
authorStephane D'Alu <sdalu@sdalu.com>2016-02-09 18:54:05 +0100
committerStephane D'Alu <sdalu@sdalu.com>2016-02-09 18:54:05 +0100
commit9a6ca01c850785363ea5051ffc18697c406109f8 (patch)
tree67f8d9028a4e18ab7c394f5af69ff8f315e92366 /os/hal
parentd27b4471063fa4ad1e4d1717ff0c88346b43ec21 (diff)
downloadChibiOS-Contrib-9a6ca01c850785363ea5051ffc18697c406109f8.tar.gz
ChibiOS-Contrib-9a6ca01c850785363ea5051ffc18697c406109f8.tar.bz2
ChibiOS-Contrib-9a6ca01c850785363ea5051ffc18697c406109f8.zip
cleanup, added comments
Diffstat (limited to 'os/hal')
-rw-r--r--os/hal/ports/NRF51/NRF51822/rng_lld.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/os/hal/ports/NRF51/NRF51822/rng_lld.c b/os/hal/ports/NRF51/NRF51822/rng_lld.c
index 12a75e7..74bba64 100644
--- a/os/hal/ports/NRF51/NRF51822/rng_lld.c
+++ b/os/hal/ports/NRF51/NRF51822/rng_lld.c
@@ -35,7 +35,6 @@
*/
static const RNGConfig default_config = {
.digital_error_correction = 1,
- .power_on_write = 1,
};
/*===========================================================================*/
@@ -84,15 +83,16 @@ void rng_lld_start(RNGDriver *rngp) {
if (rngp->config == NULL)
rngp->config = &default_config;
- rngp->rng->POWER = 1;
+ rngp->rng->POWER = 1;
if (rngp->config->digital_error_correction)
rngp->rng->CONFIG |= RNG_CONFIG_DERCEN_Msk;
else
rngp->rng->CONFIG &= ~RNG_CONFIG_DERCEN_Msk;
- rngp->rng->INTENSET = RNG_INTENSET_VALRDY_Msk;
- rngp->rng->TASKS_START = 1;
+ rngp->rng->EVENTS_VALRDY = 0;
+ rngp->rng->INTENSET = RNG_INTENSET_VALRDY_Msk;
+ rngp->rng->TASKS_START = 1;
}
@@ -105,7 +105,7 @@ void rng_lld_start(RNGDriver *rngp) {
*/
void rng_lld_stop(RNGDriver *rngp) {
rngp->rng->TASKS_STOP = 1;
- rngp->rng->POWER = 0;
+ rngp->rng->POWER = 0;
}
@@ -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;