Merge pull request #967 from arturo182/nrf_os
nrf: Rewrite the os common-hal using nrfx
This commit is contained in:
commit
ae82a93b56
|
@ -28,13 +28,12 @@
|
|||
#include "py/mpconfig.h"
|
||||
#include "py/objstr.h"
|
||||
#include "py/objtuple.h"
|
||||
#include "py/qstr.h"
|
||||
|
||||
#ifdef BLUETOOTH_SD
|
||||
#include "nrf_sdm.h"
|
||||
#endif
|
||||
|
||||
#include "nrf.h"
|
||||
#include "nrf_rng.h"
|
||||
|
||||
STATIC const qstr os_uname_info_fields[] = {
|
||||
MP_QSTR_sysname, MP_QSTR_nodename,
|
||||
|
@ -47,7 +46,6 @@ STATIC const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING
|
|||
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE);
|
||||
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME);
|
||||
|
||||
|
||||
STATIC MP_DEFINE_ATTRTUPLE(
|
||||
os_uname_info_obj,
|
||||
os_uname_info_fields,
|
||||
|
@ -68,23 +66,21 @@ bool common_hal_os_urandom(uint8_t* buffer, uint32_t length) {
|
|||
uint8_t sd_en = 0;
|
||||
(void) sd_softdevice_is_enabled(&sd_en);
|
||||
|
||||
if (sd_en) {
|
||||
if (sd_en)
|
||||
return NRF_SUCCESS == sd_rand_application_vector_get(buffer, length);
|
||||
}
|
||||
#endif
|
||||
|
||||
NRF_RNG->EVENTS_VALRDY = 0;
|
||||
NRF_RNG->TASKS_START = 1;
|
||||
nrf_rng_event_clear(NRF_RNG_EVENT_VALRDY);
|
||||
nrf_rng_task_trigger(NRF_RNG_TASK_START);
|
||||
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
while (NRF_RNG->EVENTS_VALRDY == 0) {
|
||||
;
|
||||
}
|
||||
NRF_RNG->EVENTS_VALRDY = 0;
|
||||
buffer[i] = (uint8_t) NRF_RNG->VALUE;
|
||||
while (nrf_rng_event_get(NRF_RNG_EVENT_VALRDY) == 0);
|
||||
nrf_rng_event_clear(NRF_RNG_EVENT_VALRDY);
|
||||
|
||||
buffer[i] = nrf_rng_random_value_get();
|
||||
}
|
||||
|
||||
NRF_RNG->TASKS_STOP = 1;
|
||||
nrf_rng_task_trigger(NRF_RNG_TASK_STOP);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue