2019-01-21 17:05:04 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2019-11-22 20:00:35 +01:00
|
|
|
* @ingroup cpu_saml1x
|
2019-01-21 17:05:04 +01:00
|
|
|
* @ingroup drivers_periph_pm
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Implementation of the kernels power management interface
|
|
|
|
*
|
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "periph/pm.h"
|
|
|
|
|
2020-10-22 11:34:00 +02:00
|
|
|
#define ENABLE_DEBUG 0
|
2019-01-21 17:05:04 +01:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
void pm_set(unsigned mode)
|
|
|
|
{
|
2020-05-20 17:17:11 +02:00
|
|
|
int deep = 0;
|
2020-02-25 18:47:16 +01:00
|
|
|
uint32_t _mode;
|
2019-01-21 17:05:04 +01:00
|
|
|
|
2020-02-25 18:47:16 +01:00
|
|
|
switch (mode) {
|
|
|
|
case 0:
|
|
|
|
DEBUG_PUTS("pm_set(): setting STANDBY mode.");
|
|
|
|
_mode = PM_SLEEPCFG_SLEEPMODE_STANDBY;
|
2020-05-20 17:17:11 +02:00
|
|
|
deep = 1;
|
2020-02-25 18:47:16 +01:00
|
|
|
break;
|
|
|
|
default: /* Falls through */
|
|
|
|
case 1:
|
|
|
|
DEBUG_PUTS("pm_set(): setting IDLE mode.");
|
|
|
|
_mode = PM_SLEEPCFG_SLEEPMODE_IDLE;
|
|
|
|
break;
|
2019-01-21 17:05:04 +01:00
|
|
|
}
|
|
|
|
|
2020-02-25 18:47:16 +01:00
|
|
|
/* write sleep configuration */
|
2024-05-29 17:45:25 +02:00
|
|
|
PM->SLEEPCFG.reg = _mode;
|
2020-02-25 18:47:16 +01:00
|
|
|
/* make sure value has been set */
|
2024-05-29 17:45:25 +02:00
|
|
|
while ((PM->SLEEPCFG.reg & PM_SLEEPCFG_SLEEPMODE_Msk) != _mode) {}
|
2020-02-25 18:47:16 +01:00
|
|
|
|
2020-05-20 17:17:11 +02:00
|
|
|
sam0_cortexm_sleep(deep);
|
2019-01-21 17:05:04 +01:00
|
|
|
}
|