mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
nrf: refactor SoftDevice enabled check
Share the code with the runtime.
This commit is contained in:
committed by
Ron Evans
parent
5690204224
commit
484ccf830a
@@ -13,17 +13,24 @@ func sd_app_evt_wait()
|
||||
// This is a global variable to avoid a heap allocation in waitForEvents.
|
||||
var softdeviceEnabled uint8
|
||||
|
||||
// Check whether the SoftDevice is currently enabled.
|
||||
// This function is also called from the machine package, so the signature has
|
||||
// to stay consistent.
|
||||
func isSoftDeviceEnabled() bool {
|
||||
// First check whether the SoftDevice is enabled. Unfortunately,
|
||||
// sd_app_evt_wait cannot be called when the SoftDevice is not enabled.
|
||||
arm.SVCall1(0x12, &softdeviceEnabled) // sd_softdevice_is_enabled
|
||||
|
||||
return softdeviceEnabled != 0
|
||||
}
|
||||
|
||||
func waitForEvents() {
|
||||
// Call into the SoftDevice to sleep. This is necessary here because a
|
||||
// normal wfe will not put the chip in low power mode (it still consumes
|
||||
// 500µA-1mA). It is really needed to call sd_app_evt_wait for low power
|
||||
// consumption.
|
||||
|
||||
// First check whether the SoftDevice is enabled. Unfortunately,
|
||||
// sd_app_evt_wait cannot be called when the SoftDevice is not enabled.
|
||||
arm.SVCall1(0x12, &softdeviceEnabled) // sd_softdevice_is_enabled
|
||||
|
||||
if softdeviceEnabled != 0 {
|
||||
if isSoftDeviceEnabled() {
|
||||
// Now pick the appropriate SVCall number. Hopefully they won't change
|
||||
// in the future with a different SoftDevice version.
|
||||
if nrf.Device == "nrf51" {
|
||||
|
||||
Reference in New Issue
Block a user