28
28
#include "py/mpconfig.h"
29
29
#include "py/objstr.h"
30
30
#include "py/objtuple.h"
31
- #include "py/qstr.h"
32
31
33
32
#ifdef BLUETOOTH_SD
34
33
#include "nrf_sdm.h"
35
34
#endif
36
35
37
- #include "nrf .h"
36
+ #include "nrf_rng .h"
38
37
39
38
STATIC const qstr os_uname_info_fields [] = {
40
39
MP_QSTR_sysname , MP_QSTR_nodename ,
@@ -47,7 +46,6 @@ STATIC const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING
47
46
STATIC const MP_DEFINE_STR_OBJ (os_uname_info_version_obj , MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE );
48
47
STATIC const MP_DEFINE_STR_OBJ (os_uname_info_machine_obj , MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME );
49
48
50
-
51
49
STATIC MP_DEFINE_ATTRTUPLE (
52
50
os_uname_info_obj ,
53
51
os_uname_info_fields ,
@@ -63,28 +61,26 @@ mp_obj_t common_hal_os_uname(void) {
63
61
return (mp_obj_t )& os_uname_info_obj ;
64
62
}
65
63
66
- bool common_hal_os_urandom (uint8_t * buffer , uint32_t length ) {
64
+ bool common_hal_os_urandom (uint8_t * buffer , uint32_t length ) {
67
65
#ifdef BLUETOOTH_SD
68
66
uint8_t sd_en = 0 ;
69
67
(void ) sd_softdevice_is_enabled (& sd_en );
70
68
71
- if (sd_en ) {
72
- return NRF_SUCCESS == sd_rand_application_vector_get (buffer ,length );
73
- }
69
+ if (sd_en )
70
+ return NRF_SUCCESS == sd_rand_application_vector_get (buffer , length );
74
71
#endif
75
72
76
- NRF_RNG -> EVENTS_VALRDY = 0 ;
77
- NRF_RNG -> TASKS_START = 1 ;
73
+ nrf_rng_event_clear ( NRF_RNG_EVENT_VALRDY ) ;
74
+ nrf_rng_task_trigger ( NRF_RNG_TASK_START ) ;
78
75
79
76
for (uint32_t i = 0 ; i < length ; i ++ ) {
80
- while (NRF_RNG -> EVENTS_VALRDY == 0 ) {
81
- ;
82
- }
83
- NRF_RNG -> EVENTS_VALRDY = 0 ;
84
- buffer [i ] = (uint8_t ) NRF_RNG -> VALUE ;
77
+ while (nrf_rng_event_get (NRF_RNG_EVENT_VALRDY ) == 0 );
78
+ nrf_rng_event_clear (NRF_RNG_EVENT_VALRDY );
79
+
80
+ buffer [i ] = nrf_rng_random_value_get ();
85
81
}
86
82
87
- NRF_RNG -> TASKS_STOP = 1 ;
83
+ nrf_rng_task_trigger ( NRF_RNG_TASK_STOP ) ;
88
84
89
85
return true;
90
86
}
0 commit comments