mbed
Fork of mbed-dev by
Diff: targets/TARGET_NUVOTON/TARGET_M480/sleep.c
- Revision:
- 177:447f873cad2f
- Parent:
- 173:7d866c31b3c5
--- a/targets/TARGET_NUVOTON/TARGET_M480/sleep.c Wed Oct 11 12:45:49 2017 +0100 +++ b/targets/TARGET_NUVOTON/TARGET_M480/sleep.c Wed Oct 25 14:53:38 2017 +0100 @@ -15,8 +15,6 @@ */ #include "sleep_api.h" -#include "serial_api.h" -#include "lp_ticker_api.h" #if DEVICE_SLEEP @@ -25,74 +23,24 @@ #include "objects.h" #include "PeripheralPins.h" -static void mbed_enter_sleep(struct sleep_s *obj); -static void mbed_exit_sleep(struct sleep_s *obj); - -int serial_allow_powerdown(void); -int spi_allow_powerdown(void); -int i2c_allow_powerdown(void); -int pwmout_allow_powerdown(void); - /** - * Enter Idle mode. + * Enter idle mode, in which just CPU is halted. */ void hal_sleep(void) { - struct sleep_s sleep_obj; - sleep_obj.powerdown = 0; - mbed_enter_sleep(&sleep_obj); - mbed_exit_sleep(&sleep_obj); + SYS_UnlockReg(); + CLK_Idle(); + SYS_LockReg(); } /** - * Enter Power-down mode while no peripheral is active; otherwise, enter Idle mode. + * Enter power-down mode, in which HXT/HIRC are halted. */ void hal_deepsleep(void) { - struct sleep_s sleep_obj; - sleep_obj.powerdown = 1; - mbed_enter_sleep(&sleep_obj); - mbed_exit_sleep(&sleep_obj); -} - -static void mbed_enter_sleep(struct sleep_s *obj) -{ - // Check if serial allows entering power-down mode - if (obj->powerdown) { - obj->powerdown = serial_allow_powerdown(); - } - // Check if spi allows entering power-down mode - if (obj->powerdown) { - obj->powerdown = spi_allow_powerdown(); - } - // Check if i2c allows entering power-down mode - if (obj->powerdown) { - obj->powerdown = i2c_allow_powerdown(); - } - // Check if pwmout allows entering power-down mode - if (obj->powerdown) { - obj->powerdown = pwmout_allow_powerdown(); - } - // TODO: Check if other peripherals allow entering power-down mode - - if (obj->powerdown) { // Power-down mode (HIRC/HXT disabled, LIRC/LXT enabled) - SYS_UnlockReg(); - CLK_PowerDown(); - SYS_LockReg(); - } else { // CPU halt mode (HIRC/HXT enabled, LIRC/LXT enabled) - SYS_UnlockReg(); - CLK_Idle(); - SYS_LockReg(); - } - __NOP(); - __NOP(); - __NOP(); - __NOP(); -} - -static void mbed_exit_sleep(struct sleep_s *obj) -{ - (void)obj; + SYS_UnlockReg(); + CLK_PowerDown(); + SYS_LockReg(); } #endif