rng: handle noise source / seed error.

If noise source error occurs, flag must be cleared and data register
must be discarded (at least 12 reads to flush pipeline on G0). Other
device mention start/restart of chip, so, do both (better safe than
sorry).

Reviewed-on: https://github.com/libopencm3/libopencm3/pull/1062
This commit is contained in:
Guillaume Revaillot 2019-02-05 17:17:34 +01:00 committed by Karl Palsson
parent 5a53f18a78
commit 5866852a90

View File

@ -94,10 +94,16 @@ uint32_t rng_get_random_blocking(void)
uint32_t rv;
bool done;
do {
if (RNG_SR & RNG_SR_SECS) {
rng_disable();
rng_enable();
if (RNG_SR & RNG_SR_SEIS) {
RNG_SR = RNG_SR & ~RNG_SR_SEIS;
for (int i = 12; i != 0; i--) {
rv = RNG_DR;
}
RNG_CR &= ~RNG_CR_RNGEN;
RNG_CR |= RNG_CR_RNGEN;
}
done = rng_get_random(&rv);
} while (!done);