From 787d69c6769cdf1531d1be284426fe25a68cb508 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Fri, 19 Jan 2018 22:17:48 +0100 Subject: [PATCH] cpu/nrf52: add CPU specific sleep function This function is supposed to be used for putting the CPU into sleep mode for short amounts of time (e.g. in typical polling loops used in periph drivers). --- cpu/nrf52/cpu.c | 3 +++ cpu/nrf52/include/cpu_conf.h | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/cpu/nrf52/cpu.c b/cpu/nrf52/cpu.c index 1a0d6672d4..2d01ff28ff 100644 --- a/cpu/nrf52/cpu.c +++ b/cpu/nrf52/cpu.c @@ -78,6 +78,9 @@ void cpu_init(void) NVIC_SetPriority(SWI0_EGU0_IRQn, 6); #endif + /* enable wake up on events for __WFE CPU sleep */ + SCB->SCR |= SCB_SCR_SEVONPEND_Msk; + /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/nrf52/include/cpu_conf.h b/cpu/nrf52/include/cpu_conf.h index 0ef8d767f5..32d9b9da65 100644 --- a/cpu/nrf52/include/cpu_conf.h +++ b/cpu/nrf52/include/cpu_conf.h @@ -75,6 +75,16 @@ extern "C" { #endif /* SOFTDEVICE_PRESENT */ /** @} */ +/** + * @brief Put the CPU in the low-power 'wait for event' state + */ +static inline void nrf52_sleep(void) +{ + __SEV(); + __WFE(); + __asm("nop"); +} + #ifdef __cplusplus } #endif