File tree Expand file tree Collapse file tree 3 files changed +24
-11
lines changed
Expand file tree Collapse file tree 3 files changed +24
-11
lines changed Original file line number Diff line number Diff line change @@ -7,3 +7,7 @@ package machine
77func GetRNG () (ret uint32 , err error ) {
88 return getRNG ()
99}
10+
11+ func isSoftDeviceEnabled () bool {
12+ return false
13+ }
Original file line number Diff line number Diff line change @@ -11,9 +11,8 @@ import (
1111
1212// avoid a heap allocation in GetRNG.
1313var (
14- softdeviceEnabled uint8
15- bytesAvailable uint8
16- buf [4 ]uint8
14+ bytesAvailable uint8
15+ buf [4 ]uint8
1716
1817 errNoSoftDeviceSupport = errors .New ("rng: softdevice not supported on this device" )
1918 errNotEnoughRandomData = errors .New ("rng: not enough random data available" )
2423func GetRNG () (ret uint32 , err error ) {
2524 // First check whether the SoftDevice is enabled.
2625 // sd_rand_application_bytes_available_get cannot be called when the SoftDevice is not enabled.
27- arm .SVCall1 (0x12 , & softdeviceEnabled ) // sd_softdevice_is_enabled
28-
29- if softdeviceEnabled == 0 {
26+ if ! isSoftDeviceEnabled () {
3027 return getRNG ()
3128 }
3229
@@ -57,3 +54,8 @@ func GetRNG() (ret uint32, err error) {
5754
5855 return uint32 (buf [0 ]) | uint32 (buf [1 ])<< 8 | uint32 (buf [2 ])<< 16 | uint32 (buf [3 ])<< 24 , nil
5956}
57+
58+ // This function is defined in the runtime, but we need it too.
59+ //
60+ //go:linkname isSoftDeviceEnabled runtime.isSoftDeviceEnabled
61+ func isSoftDeviceEnabled () bool
Original file line number Diff line number Diff line change @@ -13,17 +13,24 @@ func sd_app_evt_wait()
1313// This is a global variable to avoid a heap allocation in waitForEvents.
1414var softdeviceEnabled uint8
1515
16+ // Check whether the SoftDevice is currently enabled.
17+ // This function is also called from the machine package, so the signature has
18+ // to stay consistent.
19+ func isSoftDeviceEnabled () bool {
20+ // First check whether the SoftDevice is enabled. Unfortunately,
21+ // sd_app_evt_wait cannot be called when the SoftDevice is not enabled.
22+ arm .SVCall1 (0x12 , & softdeviceEnabled ) // sd_softdevice_is_enabled
23+
24+ return softdeviceEnabled != 0
25+ }
26+
1627func waitForEvents () {
1728 // Call into the SoftDevice to sleep. This is necessary here because a
1829 // normal wfe will not put the chip in low power mode (it still consumes
1930 // 500µA-1mA). It is really needed to call sd_app_evt_wait for low power
2031 // consumption.
2132
22- // First check whether the SoftDevice is enabled. Unfortunately,
23- // sd_app_evt_wait cannot be called when the SoftDevice is not enabled.
24- arm .SVCall1 (0x12 , & softdeviceEnabled ) // sd_softdevice_is_enabled
25-
26- if softdeviceEnabled != 0 {
33+ if isSoftDeviceEnabled () {
2734 // Now pick the appropriate SVCall number. Hopefully they won't change
2835 // in the future with a different SoftDevice version.
2936 if nrf .Device == "nrf51" {
You can’t perform that action at this time.
0 commit comments