diff --git a/cpu/sam0_common/include/periph_cpu_common.h b/cpu/sam0_common/include/periph_cpu_common.h index 9ee96a6f81..8516c56b6b 100644 --- a/cpu/sam0_common/include/periph_cpu_common.h +++ b/cpu/sam0_common/include/periph_cpu_common.h @@ -598,6 +598,20 @@ typedef struct { */ void gpio_init_mux(gpio_t pin, gpio_mux_t mux); +#ifdef PM_SLEEPCFG_SLEEPMODE_OFF + +/** + * @brief CPU provides own pm_off() function + */ +# define PROVIDES_PM_OFF + +/** + * @brief CPU provides own pm_off() function + */ +# define PROVIDES_PM_LAYERED_OFF + +#endif /* PM_SLEEPCFG_SLEEPMODE_OFF */ + /** * @brief Called before the power management enters a power mode * diff --git a/cpu/sam0_common/periph/pm.c b/cpu/sam0_common/periph/pm.c new file mode 100644 index 0000000000..fdf74f818b --- /dev/null +++ b/cpu/sam0_common/periph/pm.c @@ -0,0 +1,31 @@ +/* + * SPDX-FileCopyrightText: 2020 ML!PA Consulting GmbH + * SPDX-License-Identifier: LGPL-2.1-only + */ + +/** + * @ingroup cpu_sam0_common + * @ingroup drivers_periph_pm + * @{ + * + * @file + * @brief Implementation of pm_off() + * + * @author Benjamin Valentin + * + * @} + */ + +#include "periph/pm.h" + +#ifdef PM_SLEEPCFG_SLEEPMODE_OFF +void pm_off(void) +{ + irq_disable(); + + PM->SLEEPCFG.bit.SLEEPMODE = PM_SLEEPCFG_SLEEPMODE_OFF; + while (PM->SLEEPCFG.bit.SLEEPMODE != PM_SLEEPCFG_SLEEPMODE_OFF) {} + + cortexm_sleep(1); +} +#endif