File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 31
31
32
32
#ifdef BLUETOOTH_SD
33
33
#include "nrf_sdm.h"
34
+ #include "tick.h"
34
35
#endif
35
36
36
37
#include "nrf_rng.h"
@@ -66,8 +67,25 @@ bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) {
66
67
uint8_t sd_en = 0 ;
67
68
(void ) sd_softdevice_is_enabled (& sd_en );
68
69
69
- if (sd_en )
70
- return NRF_SUCCESS == sd_rand_application_vector_get (buffer , length );
70
+ if (sd_en ) {
71
+ while (length != 0 ) {
72
+ uint8_t available = 0 ;
73
+ sd_rand_application_bytes_available_get (& available );
74
+ if (available ) {
75
+ uint32_t request = MIN (length , available );
76
+ uint32_t result = sd_rand_application_vector_get (buffer , request );
77
+ if (result != NRF_SUCCESS ) {
78
+ return false;
79
+ }
80
+ buffer += request ;
81
+ length -= request ;
82
+ } else {
83
+ RUN_BACKGROUND_TASKS ;
84
+ tick_delay (500 );
85
+ }
86
+ }
87
+ return true;
88
+ }
71
89
#endif
72
90
73
91
nrf_rng_event_clear (NRF_RNG , NRF_RNG_EVENT_VALRDY );
You can’t perform that action at this time.
0 commit comments