Skip to content

Commit

Permalink
cpu/cortexm_common: added sleep_until_event
Browse files Browse the repository at this point in the history
  • Loading branch information
haukepetersen committed Mar 1, 2016
1 parent a182a44 commit eb79646
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cpu/cortexm_common/cortexm_init.c
Expand Up @@ -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;
}
12 changes: 12 additions & 0 deletions cpu/cortexm_common/include/cpu.h
Expand Up @@ -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
Expand Down

0 comments on commit eb79646

Please sign in to comment.