summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarturo182 <arturo182@tlen.pl>2018-06-27 20:38:36 +0200
committerarturo182 <arturo182@tlen.pl>2018-06-27 21:01:07 +0200
commit6e6a500801aa3743d476c092dcc8385fd15fc1c1 (patch)
tree42d61df424ffd28f9dc39153e78752fc318bbd9e
parent91427b0b2366a792e165b48e81453d0cf98e1fb9 (diff)
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;
}