1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/lpc2387: implement periph/pm

Enable IDLE and Deep Powerdown mode.

IDLE is pretty straightforward - insteady of busy waiting, the CPU will
enter an idle state from which it will resume on any event.

Deep Power Down shuts off the entite system except for the battery backup
power domain.
That means the CPU will reset on resume and can be woken by e.g. RTC.

SLEEP and POWERDOWN disable the PLL and the PLL and Flash respectively.
This requires some proper wake-up handling.

Since this turned out to be a major time sink and those modes are never
currently never used in RIOT outside of tests, I left this as an exercise
for a future reader.
This commit is contained in:
Benjamin Valentin 2019-11-07 20:21:02 +01:00 committed by benpicco
parent 3eae474e74
commit a9d1825e2e
4 changed files with 68 additions and 3 deletions

View File

@ -72,9 +72,10 @@ extern "C" {
#define BORD (BIT4)
#define PM2 (BIT7)
#define PM_IDLE (PM0)
#define PM_SLEEP (PM2|PM0)
#define PM_POWERDOWN (PM1)
#define PM_IDLE (PM0)
#define PM_SLEEP (PM2|PM0)
#define PM_POWERDOWN (PM1)
#define PM_DEEP_POWERDOWN (PM2|PM1)
/** @} */
/**

View File

@ -1,3 +1,4 @@
include $(RIOTCPU)/arm7_common/Makefile.include
USEMODULE += arm7_common periph bitfield newlib
USEMODULE += pm_layered

View File

@ -32,6 +32,13 @@ extern "C" {
*/
#define __IO volatile
/**
* @name Power mode configuration
* @{
*/
#define PM_NUM_MODES (4)
/** @} */
/**
* @brief Fast GPIO register definition struct
*/

56
cpu/lpc2387/periph/pm.c Normal file
View File

@ -0,0 +1,56 @@
/*
* Copyright (C) 2019 Beuth Hochschule für Technik Berlin
*
* 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.
*/
/**
* @ingroup cpu_lpc2387
* @ingroup drivers_periph_pm
* @{
*
* @file
* @brief Implementation of the kernels power management interface
*
* @note Handling of wake-up from POWERDOWN & SLEEP is not implemented
* yet, so those states are disabled.
*
* @author Benjamin Valentin <benpicco@beuth-hochschule.de>
*
* @}
*/
#include "periph/pm.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
void pm_set(unsigned mode)
{
switch (mode) {
case 0:
/* Everything except battery backup is powered down */
DEBUG_PUTS("pm_set(): setting Deep Power Down mode.");
PCON |= PM_DEEP_POWERDOWN;
break;
case 1:
/* PLL & Flash are powered down */
DEBUG_PUTS("pm_set(): setting Power Down mode.");
/* PCON |= PM_POWERDOWN; */
PCON |= PM_IDLE; /* fixme */
break;
case 2:
/* PLL is powered down */
DEBUG_PUTS("pm_set(): setting Sleep mode.");
/* PCON |= PM_SLEEP; */
PCON |= PM_IDLE; /* fixme */
break;
default: /* Falls through */
case 3:
DEBUG_PUTS("pm_set(): setting Idle mode.");
PCON |= PM_IDLE;
break;
}
}