1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #11559 from PeterKietzmann/pr_nrf5x_hwrng_softdev

cpu/nrf5x_common: map hwrng to SoC library if SoftDevice is present
This commit is contained in:
Hauke Petersen 2019-07-04 14:23:55 +02:00 committed by GitHub
commit 1744b6bd92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,12 +24,20 @@
#include "cpu.h"
#include "periph/hwrng.h"
#ifndef MODULE_NORDIC_SOFTDEVICE_BLE
#include "assert.h"
#endif
void hwrng_init(void)
{
/* nothing to do here */
}
/*
* The hardware peripheral is used by the SoftDevice. When the SoftDevice is
* enabled, it shall only be accessed through the SoftDevice API
*/
#ifndef MODULE_NORDIC_SOFTDEVICE_BLE
void hwrng_read(void *buf, unsigned int num)
{
unsigned int count = 0;
@ -62,3 +70,24 @@ void hwrng_read(void *buf, unsigned int num)
NRF_RNG->POWER = 0;
#endif
}
#else
void hwrng_read(void *buf, unsigned int num)
{
uint32_t ret;
uint8_t avail;
assert(num <= 0xff);
/* this is not the most efficient, but this way we can assure that there are
* enough bytes of random data available */
do {
sd_rand_application_bytes_available_get(&avail);
} while (avail < (uint8_t)num);
ret = sd_rand_application_vector_get((uint8_t *)buf, (uint8_t)num);
assert(ret == NRF_SUCCESS);
(void)ret;
}
#endif /* MODULE_NORDIC_SOFTDEVICE_BLE */