1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 14:33:52 +01:00

Merge pull request #13751 from benpicco/sam0-pm

cpu/sam0_common: fix handling of PM_NUM_MODES
This commit is contained in:
Dylan Laduranty 2020-04-02 17:14:39 +02:00 committed by GitHub
commit 4eb9b9b9df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 65 additions and 52 deletions

View File

@ -96,17 +96,6 @@ enum {
*/
#define GPIO_MODE(pr, ie, pe) (pr | (ie << 1) | (pe << 2))
/**
* @name Power mode configuration
* @{
*/
#ifdef CPU_SAML1X
#define PM_NUM_MODES (2)
#else
#define PM_NUM_MODES (3)
#endif
/** @} */
#ifndef DOXYGEN
/**
* @brief Override GPIO modes

View File

@ -28,6 +28,13 @@
extern "C" {
#endif
/**
* @name Power mode configuration
* @{
*/
#define PM_NUM_MODES (3)
/** @} */
/**
* @brief Override the default initial PM blocker
* @todo Idle modes are enabled by default, deep sleep mode blocked

View File

@ -43,6 +43,13 @@ extern "C" {
*/
#define SAM0_DPLL_FREQ_MAX_HZ (200000000U)
/**
* @name Power mode configuration
* @{
*/
#define PM_NUM_MODES (3)
/** @} */
/**
* @name SAMD5x GCLK definitions
* @{

View File

@ -26,6 +26,13 @@
extern "C" {
#endif
/**
* @name Power mode configuration
* @{
*/
#define PM_NUM_MODES (1)
/** @} */
/**
* @brief Override the default initial PM blocker
* @todo Idle modes are enabled by default, deep sleep mode blocked

View File

@ -26,26 +26,24 @@
void pm_set(unsigned mode)
{
if (mode < PM_NUM_MODES) {
uint32_t _mode;
uint32_t _mode;
switch (mode) {
case 0:
DEBUG_PUTS("pm_set(): setting STANDBY mode.");
_mode = PM_SLEEPCFG_SLEEPMODE_STANDBY;
break;
default: /* Falls through */
case 1:
DEBUG_PUTS("pm_set(): setting IDLE mode.");
_mode = PM_SLEEPCFG_SLEEPMODE_IDLE;
break;
}
/* write sleep configuration */
PM->SLEEPCFG.bit.SLEEPMODE = _mode;
/* make sure value has been set */
while (PM->SLEEPCFG.bit.SLEEPMODE != _mode) {}
switch (mode) {
case 0:
DEBUG_PUTS("pm_set(): setting STANDBY mode.");
_mode = PM_SLEEPCFG_SLEEPMODE_STANDBY;
break;
default: /* Falls through */
case 1:
DEBUG_PUTS("pm_set(): setting IDLE mode.");
_mode = PM_SLEEPCFG_SLEEPMODE_IDLE;
break;
}
/* write sleep configuration */
PM->SLEEPCFG.bit.SLEEPMODE = _mode;
/* make sure value has been set */
while (PM->SLEEPCFG.bit.SLEEPMODE != _mode) {}
sam0_cortexm_sleep(0);
}

View File

@ -31,6 +31,13 @@ extern "C" {
*/
#define CPU_BACKUP_RAM_NOT_RETAINED (1)
/**
* @name Power mode configuration
* @{
*/
#define PM_NUM_MODES (2)
/** @} */
/**
* @name SAML21 GCLK definitions
* @{

View File

@ -26,34 +26,32 @@
void pm_set(unsigned mode)
{
if (mode < PM_NUM_MODES) {
uint32_t _mode;
uint32_t _mode;
switch (mode) {
case 0:
DEBUG_PUTS("pm_set(): setting BACKUP mode.");
_mode = PM_SLEEPCFG_SLEEPMODE_BACKUP;
break;
case 1:
DEBUG_PUTS("pm_set(): setting STANDBY mode.");
_mode = PM_SLEEPCFG_SLEEPMODE_STANDBY;
break;
default: /* Falls through */
case 2:
DEBUG_PUTS("pm_set(): setting IDLE mode.");
switch (mode) {
case 0:
DEBUG_PUTS("pm_set(): setting BACKUP mode.");
_mode = PM_SLEEPCFG_SLEEPMODE_BACKUP;
break;
case 1:
DEBUG_PUTS("pm_set(): setting STANDBY mode.");
_mode = PM_SLEEPCFG_SLEEPMODE_STANDBY;
break;
default: /* Falls through */
case 2:
DEBUG_PUTS("pm_set(): setting IDLE mode.");
#if !defined(PM_SLEEPCFG_SLEEPMODE_IDLE2)
_mode = PM_SLEEPCFG_SLEEPMODE_IDLE;
_mode = PM_SLEEPCFG_SLEEPMODE_IDLE;
#else
_mode = PM_SLEEPCFG_SLEEPMODE_IDLE2;
_mode = PM_SLEEPCFG_SLEEPMODE_IDLE2;
#endif
break;
}
/* write sleep configuration */
PM->SLEEPCFG.bit.SLEEPMODE = _mode;
/* make sure value has been set */
while (PM->SLEEPCFG.bit.SLEEPMODE != _mode) {}
break;
}
/* write sleep configuration */
PM->SLEEPCFG.bit.SLEEPMODE = _mode;
/* make sure value has been set */
while (PM->SLEEPCFG.bit.SLEEPMODE != _mode) {}
sam0_cortexm_sleep(0);
}