nrf: call sd_app_evt_wait when the SoftDevice is enabled
This reduces current consumption from 500-1000µA to very low (<10µA) current consumption. This change is important for battery powered devices, especially devices that may be running for long periods of time.
Этот коммит содержится в:
родитель
b75f042c23
коммит
9d625a1ccb
8 изменённых файлов: 71 добавлений и 4 удалений
|
@ -102,7 +102,3 @@ func procPin() {
|
|||
func procUnpin() {
|
||||
arm.EnableInterrupts(procPinnedMask)
|
||||
}
|
||||
|
||||
func waitForEvents() {
|
||||
arm.Asm("wfe")
|
||||
}
|
||||
|
|
|
@ -345,3 +345,7 @@ func initADCClock() {
|
|||
sam.GCLK_CLKCTRL_CLKEN)
|
||||
waitForSync()
|
||||
}
|
||||
|
||||
func waitForEvents() {
|
||||
arm.Asm("wfe")
|
||||
}
|
||||
|
|
|
@ -332,3 +332,7 @@ func initADCClock() {
|
|||
sam.GCLK.PCHCTRL[41].Set((sam.GCLK_PCHCTRL_GEN_GCLK1 << sam.GCLK_PCHCTRL_GEN_Pos) |
|
||||
sam.GCLK_PCHCTRL_CHEN)
|
||||
}
|
||||
|
||||
func waitForEvents() {
|
||||
arm.Asm("wfe")
|
||||
}
|
||||
|
|
|
@ -50,3 +50,7 @@ var stdoutWrite = (*volatile.Register8)(unsafe.Pointer(uintptr(0x4000c000)))
|
|||
func putchar(c byte) {
|
||||
stdoutWrite.Set(uint8(c))
|
||||
}
|
||||
|
||||
func waitForEvents() {
|
||||
arm.Asm("wfe")
|
||||
}
|
||||
|
|
9
src/runtime/runtime_nrf_bare.go
Обычный файл
9
src/runtime/runtime_nrf_bare.go
Обычный файл
|
@ -0,0 +1,9 @@
|
|||
// +build nrf,!softdevice
|
||||
|
||||
package runtime
|
||||
|
||||
import "device/arm"
|
||||
|
||||
func waitForEvents() {
|
||||
arm.Asm("wfe")
|
||||
}
|
40
src/runtime/runtime_nrf_softdevice.go
Обычный файл
40
src/runtime/runtime_nrf_softdevice.go
Обычный файл
|
@ -0,0 +1,40 @@
|
|||
// +build nrf,softdevice
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"device/arm"
|
||||
"device/nrf"
|
||||
)
|
||||
|
||||
//export sd_app_evt_wait
|
||||
func sd_app_evt_wait()
|
||||
|
||||
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.
|
||||
var enabled uint8
|
||||
arm.SVCall1(0x12, &enabled) // sd_softdevice_is_enabled
|
||||
|
||||
if enabled != 0 {
|
||||
// Now pick the appropriate SVCall number. Hopefully they won't change
|
||||
// in the future with a different SoftDevice version.
|
||||
if nrf.DEVICE == "nrf51" {
|
||||
// sd_app_evt_wait: SOC_SVC_BASE_NOT_AVAILABLE + 29
|
||||
arm.SVCall0(0x2B + 29)
|
||||
} else if nrf.DEVICE == "nrf52" || nrf.DEVICE == "nrf52840" {
|
||||
// sd_app_evt_wait: SOC_SVC_BASE_NOT_AVAILABLE + 21
|
||||
arm.SVCall0(0x2C + 21)
|
||||
} else {
|
||||
sd_app_evt_wait()
|
||||
}
|
||||
} else {
|
||||
// SoftDevice is disabled so we can sleep normally.
|
||||
arm.Asm("wfe")
|
||||
}
|
||||
}
|
|
@ -265,3 +265,7 @@ func abort() {
|
|||
machine.PollUART(&machine.UART2)
|
||||
}
|
||||
}
|
||||
|
||||
func waitForEvents() {
|
||||
arm.Asm("wfe")
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
package runtime
|
||||
|
||||
import "device/arm"
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
func postinit() {}
|
||||
|
@ -12,3 +14,7 @@ func main() {
|
|||
run()
|
||||
abort()
|
||||
}
|
||||
|
||||
func waitForEvents() {
|
||||
arm.Asm("wfe")
|
||||
}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче