Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu: PM_NUM_MODES must only count non-IDLE modes #13475

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpu/kinetis/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ typedef uint16_t gpio_t;
/**
* @brief number of usable power modes
*/
#define PM_NUM_MODES (1U)
#define PM_NUM_MODES (0U)

#ifdef RTC
/* All Kinetis CPUs have exactly one RTC hardware module, except for the KL02
Expand Down
2 changes: 1 addition & 1 deletion cpu/lpc2387/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern "C" {
* @name Power mode configuration
* @{
*/
#define PM_NUM_MODES (4)
#define PM_NUM_MODES (3)
/** @} */

/**
Expand Down
11 changes: 0 additions & 11 deletions cpu/sam0_common/include/periph_cpu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,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
Expand Down
7 changes: 7 additions & 0 deletions cpu/samd21/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions cpu/samd5x/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
* @{
Expand Down
7 changes: 7 additions & 0 deletions cpu/saml1x/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 16 additions & 18 deletions cpu/saml1x/periph/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 7 additions & 0 deletions cpu/saml21/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
* @{
Expand Down
44 changes: 21 additions & 23 deletions cpu/saml21/periph/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
5 changes: 0 additions & 5 deletions cpu/stm32f1/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ extern "C" {
*/
#define GPIO_MODE(mode, cnf, odr) (mode | (cnf << 2) | (odr << 4))

/**
* @brief Define the number of available PM modes
*/
#define PM_NUM_MODES (2U)

/**
* @brief Define the config flag for stop mode
*/
Expand Down