Merge pull request #967 from arturo182/nrf_os

nrf: Rewrite the os common-hal using nrfx
This commit is contained in:
Scott Shawcroft 2018-06-28 13:55:34 -07:00 committed by GitHub
commit ae82a93b56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 15 deletions

View File

@ -28,13 +28,12 @@
#include "py/mpconfig.h" #include "py/mpconfig.h"
#include "py/objstr.h" #include "py/objstr.h"
#include "py/objtuple.h" #include "py/objtuple.h"
#include "py/qstr.h"
#ifdef BLUETOOTH_SD #ifdef BLUETOOTH_SD
#include "nrf_sdm.h" #include "nrf_sdm.h"
#endif #endif
#include "nrf.h" #include "nrf_rng.h"
STATIC const qstr os_uname_info_fields[] = { STATIC const qstr os_uname_info_fields[] = {
MP_QSTR_sysname, MP_QSTR_nodename, 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_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 const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME);
STATIC MP_DEFINE_ATTRTUPLE( STATIC MP_DEFINE_ATTRTUPLE(
os_uname_info_obj, os_uname_info_obj,
os_uname_info_fields, os_uname_info_fields,
@ -63,28 +61,26 @@ mp_obj_t common_hal_os_uname(void) {
return (mp_obj_t)&os_uname_info_obj; 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 #ifdef BLUETOOTH_SD
uint8_t sd_en = 0; uint8_t sd_en = 0;
(void) sd_softdevice_is_enabled(&sd_en); (void) sd_softdevice_is_enabled(&sd_en);
if (sd_en) { if (sd_en)
return NRF_SUCCESS == sd_rand_application_vector_get(buffer,length); return NRF_SUCCESS == sd_rand_application_vector_get(buffer, length);
}
#endif #endif
NRF_RNG->EVENTS_VALRDY = 0; nrf_rng_event_clear(NRF_RNG_EVENT_VALRDY);
NRF_RNG->TASKS_START = 1; nrf_rng_task_trigger(NRF_RNG_TASK_START);
for (uint32_t i = 0; i < length; i++) { for (uint32_t i = 0; i < length; i++) {
while (NRF_RNG->EVENTS_VALRDY == 0) { while (nrf_rng_event_get(NRF_RNG_EVENT_VALRDY) == 0);
; nrf_rng_event_clear(NRF_RNG_EVENT_VALRDY);
}
NRF_RNG->EVENTS_VALRDY = 0; buffer[i] = nrf_rng_random_value_get();
buffer[i] = (uint8_t) NRF_RNG->VALUE;
} }
NRF_RNG->TASKS_STOP = 1; nrf_rng_task_trigger(NRF_RNG_TASK_STOP);
return true; return true;
} }