From eb79646ab11ac2d63f9e7e025eb44ec5d73c8c86 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Tue, 1 Mar 2016 23:13:55 +0100 Subject: [PATCH] cpu/cortexm_common: added sleep_until_event --- cpu/cortexm_common/cortexm_init.c | 3 +++ cpu/cortexm_common/include/cpu.h | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/cpu/cortexm_common/cortexm_init.c b/cpu/cortexm_common/cortexm_init.c index 5419d92db7..39ff3a9081 100644 --- a/cpu/cortexm_common/cortexm_init.c +++ b/cpu/cortexm_common/cortexm_init.c @@ -49,4 +49,7 @@ void cortexm_init(void) for (IRQn_Type i = 0; i < (int) CPU_IRQ_NUMOF; i++) { NVIC_SetPriority(i, CPU_DEFAULT_IRQ_PRIO); } + + /* enable wake up on events for __WFE CPU sleep */ + SCB->SCR |= SCB_SCR_SEVONPEND_Msk; } diff --git a/cpu/cortexm_common/include/cpu.h b/cpu/cortexm_common/include/cpu.h index c2a79cbacd..fbffb0f2da 100644 --- a/cpu/cortexm_common/include/cpu.h +++ b/cpu/cortexm_common/include/cpu.h @@ -102,6 +102,18 @@ static inline void cpu_print_last_instruction(void) printf("%p\n", (void*) lr_ptr); } +/** + * @brief Put the CPU into the 'wait for event' sleep mode + * + * This function is meant to be used for short periods of time, where it is not + * feasible to switch to the idle thread and back. + */ +static inline void cpu_sleep_until_event(void) +{ + __SEV(); + __WFE(); +} + #ifdef __cplusplus } #endif