Skip to content

Platform: Add sleep/deepsleep user facing functions #3607

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

Merged
merged 4 commits into from
Jan 26, 2017
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// In this case, bits which are equal to 0 are the bits reserved in this register
#define SCB_ICSR_RESERVED_BITS_MASK 0x9E43F03F

void sleep(void)
void hal_sleep(void)
{
// ensure debug is disconnected if semihost is enabled....

Expand Down Expand Up @@ -64,7 +64,7 @@ void sleep(void)
}
}

void deepsleep(void)
void hal_deepsleep(void)
{
sleep();
// NRF_POWER->SYSTEMOFF=1;
Expand Down
4 changes: 2 additions & 2 deletions hal/sleep_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {
* Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
* able to access the LocalFileSystem
*/
void sleep(void);
void hal_sleep(void);

/** Send the microcontroller to deep sleep
*
Expand All @@ -56,7 +56,7 @@ void sleep(void);
* Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
* able to access the LocalFileSystem
*/
void deepsleep(void);
void hal_deepsleep(void);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions mbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
#include "drivers/InterruptIn.h"
#include "platform/wait_api.h"
#include "hal/sleep_api.h"
#include "platform/sleep.h"
#include "platform/rtc_time.h"

// mbed Non-hardware components
Expand Down
85 changes: 85 additions & 0 deletions platform/sleep.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

/** \addtogroup platform */
/** @{*/
/* mbed Microcontroller Library
* Copyright (c) 2006-2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_SLEEP_H
#define MBED_SLEEP_H

#include "sleep_api.h"

#ifdef __cplusplus
extern "C" {
#endif

/** Send the microcontroller to sleep
*
* @note This function can be a noop if not implemented by the platform.
* @note This function will only put device to sleep in release mode (small profile or when NDEBUG is defined).
*
* The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the
* system clock to the core is stopped until a reset or an interrupt occurs. This eliminates
* dynamic power used by the processor, memory systems and buses. The processor, peripheral and
* memory state are maintained, and the peripherals continue to work and can generate interrupts.
*
* The processor can be woken up by any internal peripheral interrupt or external pin interrupt.
*
* @note
* The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
* Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
* able to access the LocalFileSystem
*/
__INLINE static void sleep(void)
{
#ifdef NDEBUG
#if DEVICE_SLEEP
hal_sleep();
#endif /* DEVICE_SLEEP */
#endif /* NDEBUG */
}

/** Send the microcontroller to deep sleep
*
* @note This function can be a noop if not implemented by the platform.
* @note This function will only put device to sleep in release mode (small profile or when NDEBUG is defined).
*
* This processor is setup ready for deep sleep, and sent to sleep using __WFI(). This mode
* has the same sleep features as sleep plus it powers down peripherals and clocks. All state
* is still maintained.
*
* The processor can only be woken up by an external interrupt on a pin or a watchdog timer.
*
* @note
* The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
* Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
* able to access the LocalFileSystem
*/
__INLINE static void deepsleep(void)
{
#ifdef NDEBUG
#if DEVICE_SLEEP
hal_deepsleep();
#endif /* DEVICE_SLEEP */
#endif /* NDEBUG */
}

#ifdef __cplusplus
}
#endif

#endif

/** @}*/
4 changes: 2 additions & 2 deletions targets/TARGET_ARM_SSG/TARGET_BEETLE/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
#include "sleep_api.h"
#include "cmsis.h"

void sleep(void)
void hal_sleep(void)
{
SystemPowerSuspend(POWER_MODE_SLEEP);
SystemPowerResume(POWER_MODE_SLEEP);
}

void deepsleep(void)
void hal_deepsleep(void)
{
SystemPowerSuspend(POWER_MODE_DEEP_SLEEP);
SystemPowerResume(POWER_MODE_DEEP_SLEEP);
Expand Down
4 changes: 2 additions & 2 deletions targets/TARGET_Atmel/TARGET_SAM_CortexM0P/sleep_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @param[void] void
* @return void
*/
void sleep(void)
void hal_sleep(void)
{
#if (SAMD21) || (SAMR21)
system_set_sleepmode(SYSTEM_SLEEPMODE_IDLE_2);
Expand All @@ -43,7 +43,7 @@ void sleep(void)
* @param[void] void
* @return void
*/
void deepsleep(void)
void hal_deepsleep(void)
{
system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY);
system_sleep();
Expand Down
6 changes: 3 additions & 3 deletions targets/TARGET_Atmel/TARGET_SAM_CortexM4/sleep_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @param[void] void
* @return void
*/
void sleep(void)
void hal_sleep(void)
{
enum sleepmgr_mode sleep_mode;

Expand All @@ -40,10 +40,10 @@ void sleep(void)
* @param[void] void
* @return void
*/
void deepsleep(void)
void hal_deepsleep(void)
{
enum sleepmgr_mode sleep_mode;

sleep_mode = SLEEPMGR_SLEEP_WFE;
sleepmgr_sleep(sleep_mode);
}
}
4 changes: 2 additions & 2 deletions targets/TARGET_Freescale/TARGET_K20XX/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "cmsis.h"

//Normal wait mode
void sleep(void)
void hal_sleep(void)
{
SMC->PMPROT = SMC_PMPROT_AVLLS_MASK | SMC_PMPROT_ALLS_MASK | SMC_PMPROT_AVLP_MASK;

Expand All @@ -27,7 +27,7 @@ void sleep(void)
}

//Very low-power stop mode
void deepsleep(void)
void hal_deepsleep(void)
{
//Check if ADC is enabled and HS mode is set, if yes disable it (lowers power consumption by 60uA)
uint8_t ADC_HSC = 0;
Expand Down
4 changes: 2 additions & 2 deletions targets/TARGET_Freescale/TARGET_KLXX/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "PeripheralPins.h"

//Normal wait mode
void sleep(void)
void hal_sleep(void)
{
SMC->PMPROT = SMC_PMPROT_AVLLS_MASK | SMC_PMPROT_ALLS_MASK | SMC_PMPROT_AVLP_MASK;

Expand All @@ -28,7 +28,7 @@ void sleep(void)
}

//Very low-power stop mode
void deepsleep(void)
void hal_deepsleep(void)
{
//Check if ADC is enabled and HS mode is set, if yes disable it (lowers power consumption by 60uA)
uint8_t ADC_HSC = 0;
Expand Down
4 changes: 2 additions & 2 deletions targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
#include "fsl_smc.h"
#include "fsl_clock_config.h"

void sleep(void)
void hal_sleep(void)
{
SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);

SMC_SetPowerModeWait(SMC);
}

void deepsleep(void)
void hal_deepsleep(void)
{
#if (defined(FSL_FEATURE_SOC_MCG_COUNT) && FSL_FEATURE_SOC_MCG_COUNT)
mcg_mode_t mode = CLOCK_GetMode();
Expand Down
4 changes: 2 additions & 2 deletions targets/TARGET_Maxim/TARGET_MAX32600/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
static mxc_uart_regs_t *stdio_uart = (mxc_uart_regs_t*)STDIO_UART;

// Normal wait mode
void sleep(void)
void hal_sleep(void)
{
// Normal sleep mode for ARM core
SCB->SCR = 0;
Expand Down Expand Up @@ -70,7 +70,7 @@ static void clearAllGPIOWUD(void)
}

// Low-power stop mode
void deepsleep(void)
void hal_deepsleep(void)
{
__disable_irq();

Expand Down
4 changes: 2 additions & 2 deletions targets/TARGET_Maxim/TARGET_MAX32610/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
static mxc_uart_regs_t *stdio_uart = (mxc_uart_regs_t*)STDIO_UART;

// Normal wait mode
void sleep(void)
void hal_sleep(void)
{
// Normal sleep mode for ARM core
SCB->SCR = 0;
Expand Down Expand Up @@ -70,7 +70,7 @@ static void clearAllGPIOWUD(void)
}

// Low-power stop mode
void deepsleep(void)
void hal_deepsleep(void)
{
__disable_irq();

Expand Down
4 changes: 2 additions & 2 deletions targets/TARGET_Maxim/TARGET_MAX32620/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static mxc_uart_regs_t *stdio_uart = (mxc_uart_regs_t*)STDIO_UART;
static int restore_usb;
static usb_state_t usb_state;

void sleep(void)
void hal_sleep(void)
{
// Normal sleep mode for ARM core
SCB->SCR = 0;
Expand Down Expand Up @@ -109,7 +109,7 @@ static void usb_wakeup(void)
}

// Low-power stop mode
void deepsleep(void)
void hal_deepsleep(void)
{
unsigned int part_rev = MXC_PWRMAN->mask_id0 & MXC_F_PWRMAN_MASK_ID0_REVISION_ID;

Expand Down
6 changes: 3 additions & 3 deletions targets/TARGET_Maxim/TARGET_MAX32625/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
#include "sleep_api.h"
#include "lp.h"

void sleep(void)
void hal_sleep(void)
{
LP_EnterLP2();
}

// Low-power stop mode
void deepsleep(void)
void hal_deepsleep(void)
{
sleep();
hal_sleep();
}
6 changes: 3 additions & 3 deletions targets/TARGET_NORDIC/TARGET_MCU_NRF51822/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
#include "mbed_interface.h"
#include "toolchain.h"

MBED_WEAK void sleep(void)
void hal_sleep(void)
{
// ensure debug is disconnected if semihost is enabled....
NRF_POWER->TASKS_LOWPWR = 1;
// wait for interrupt
__WFE();
}

MBED_WEAK void deepsleep(void)
void hal_deepsleep(void)
{
sleep();
hal_sleep();
// NRF_POWER->SYSTEMOFF=1;
}
6 changes: 3 additions & 3 deletions targets/TARGET_NORDIC/TARGET_NRF5/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#define FPU_EXCEPTION_MASK 0x0000009F

void sleep(void)
void hal_sleep(void)
{
// ensure debug is disconnected if semihost is enabled....

Expand Down Expand Up @@ -73,8 +73,8 @@ void sleep(void)
}
}

void deepsleep(void)
void hal_deepsleep(void)
{
sleep();
hal_sleep();
// NRF_POWER->SYSTEMOFF=1;
}
4 changes: 2 additions & 2 deletions targets/TARGET_NUVOTON/TARGET_M451/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int pwmout_allow_powerdown(void);
/**
* Enter Idle mode.
*/
void sleep(void)
void hal_sleep(void)
{
struct sleep_s sleep_obj;
sleep_obj.powerdown = 0;
Expand All @@ -49,7 +49,7 @@ void sleep(void)
/**
* Enter Power-down mode while no peripheral is active; otherwise, enter Idle mode.
*/
void deepsleep(void)
void hal_deepsleep(void)
{
struct sleep_s sleep_obj;
sleep_obj.powerdown = 1;
Expand Down
4 changes: 2 additions & 2 deletions targets/TARGET_NUVOTON/TARGET_NUC472/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int pwmout_allow_powerdown(void);
/**
* Enter Idle mode.
*/
void sleep(void)
void hal_sleep(void)
{
struct sleep_s sleep_obj;
sleep_obj.powerdown = 0;
Expand All @@ -49,7 +49,7 @@ void sleep(void)
/**
* Enter Power-down mode while no peripheral is active; otherwise, enter Idle mode.
*/
void deepsleep(void)
void hal_deepsleep(void)
{
struct sleep_s sleep_obj;
sleep_obj.powerdown = 1;
Expand Down
Loading