summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2018-06-28 13:55:34 -0700
committerGitHub <noreply@github.com>2018-06-28 13:55:34 -0700
commitae82a93b56b93fbf52899a69636ea558e332774e (patch)
tree8f4ea4cf3b334fe867ca15ae3a211d71fb22ece8
parenta0425d91349e538af937f7e8414e059e688829ab (diff)
parent6e6a500801aa3743d476c092dcc8385fd15fc1c1 (diff)
Merge pull request #967 from arturo182/nrf_os
nrf: Rewrite the os common-hal using nrfx
-rw-r--r--ports/nrf/common-hal/os/__init__.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/ports/nrf/common-hal/os/__init__.c b/ports/nrf/common-hal/os/__init__.c
index 402b32bc5..7671cc2a5 100644
--- a/ports/nrf/common-hal/os/__init__.c
+++ b/ports/nrf/common-hal/os/__init__.c
@@ -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,
@@ -63,28 +61,26 @@ mp_obj_t common_hal_os_uname(void) {
return (mp_obj_t)&os_uname_info_obj;
}
-bool common_hal_os_urandom(uint8_t* buffer, uint32_t length) {
+bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) {
#ifdef BLUETOOTH_SD
uint8_t sd_en = 0;
(void) sd_softdevice_is_enabled(&sd_en);
- if (sd_en) {
- return NRF_SUCCESS == sd_rand_application_vector_get(buffer,length);
- }
+ 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;
}