Forked.
Fork of mbed-dev by
targets/TARGET_NUVOTON/TARGET_M480/sleep.c@172:7d866c31b3c5, 2017-08-31 (annotated)
- Committer:
- AnnaBridge
- Date:
- Thu Aug 31 17:27:04 2017 +0100
- Revision:
- 172:7d866c31b3c5
This updates the lib to the mbed lib v 150
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 172:7d866c31b3c5 | 1 | /* mbed Microcontroller Library |
AnnaBridge | 172:7d866c31b3c5 | 2 | * Copyright (c) 2015-2016 Nuvoton |
AnnaBridge | 172:7d866c31b3c5 | 3 | * |
AnnaBridge | 172:7d866c31b3c5 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
AnnaBridge | 172:7d866c31b3c5 | 5 | * you may not use this file except in compliance with the License. |
AnnaBridge | 172:7d866c31b3c5 | 6 | * You may obtain a copy of the License at |
AnnaBridge | 172:7d866c31b3c5 | 7 | * |
AnnaBridge | 172:7d866c31b3c5 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
AnnaBridge | 172:7d866c31b3c5 | 9 | * |
AnnaBridge | 172:7d866c31b3c5 | 10 | * Unless required by applicable law or agreed to in writing, software |
AnnaBridge | 172:7d866c31b3c5 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AnnaBridge | 172:7d866c31b3c5 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AnnaBridge | 172:7d866c31b3c5 | 13 | * See the License for the specific language governing permissions and |
AnnaBridge | 172:7d866c31b3c5 | 14 | * limitations under the License. |
AnnaBridge | 172:7d866c31b3c5 | 15 | */ |
AnnaBridge | 172:7d866c31b3c5 | 16 | |
AnnaBridge | 172:7d866c31b3c5 | 17 | #include "sleep_api.h" |
AnnaBridge | 172:7d866c31b3c5 | 18 | #include "serial_api.h" |
AnnaBridge | 172:7d866c31b3c5 | 19 | #include "lp_ticker_api.h" |
AnnaBridge | 172:7d866c31b3c5 | 20 | |
AnnaBridge | 172:7d866c31b3c5 | 21 | #if DEVICE_SLEEP |
AnnaBridge | 172:7d866c31b3c5 | 22 | |
AnnaBridge | 172:7d866c31b3c5 | 23 | #include "cmsis.h" |
AnnaBridge | 172:7d866c31b3c5 | 24 | #include "device.h" |
AnnaBridge | 172:7d866c31b3c5 | 25 | #include "objects.h" |
AnnaBridge | 172:7d866c31b3c5 | 26 | #include "PeripheralPins.h" |
AnnaBridge | 172:7d866c31b3c5 | 27 | |
AnnaBridge | 172:7d866c31b3c5 | 28 | static void mbed_enter_sleep(struct sleep_s *obj); |
AnnaBridge | 172:7d866c31b3c5 | 29 | static void mbed_exit_sleep(struct sleep_s *obj); |
AnnaBridge | 172:7d866c31b3c5 | 30 | |
AnnaBridge | 172:7d866c31b3c5 | 31 | int serial_allow_powerdown(void); |
AnnaBridge | 172:7d866c31b3c5 | 32 | int spi_allow_powerdown(void); |
AnnaBridge | 172:7d866c31b3c5 | 33 | int i2c_allow_powerdown(void); |
AnnaBridge | 172:7d866c31b3c5 | 34 | int pwmout_allow_powerdown(void); |
AnnaBridge | 172:7d866c31b3c5 | 35 | |
AnnaBridge | 172:7d866c31b3c5 | 36 | /** |
AnnaBridge | 172:7d866c31b3c5 | 37 | * Enter Idle mode. |
AnnaBridge | 172:7d866c31b3c5 | 38 | */ |
AnnaBridge | 172:7d866c31b3c5 | 39 | void hal_sleep(void) |
AnnaBridge | 172:7d866c31b3c5 | 40 | { |
AnnaBridge | 172:7d866c31b3c5 | 41 | struct sleep_s sleep_obj; |
AnnaBridge | 172:7d866c31b3c5 | 42 | sleep_obj.powerdown = 0; |
AnnaBridge | 172:7d866c31b3c5 | 43 | mbed_enter_sleep(&sleep_obj); |
AnnaBridge | 172:7d866c31b3c5 | 44 | mbed_exit_sleep(&sleep_obj); |
AnnaBridge | 172:7d866c31b3c5 | 45 | } |
AnnaBridge | 172:7d866c31b3c5 | 46 | |
AnnaBridge | 172:7d866c31b3c5 | 47 | /** |
AnnaBridge | 172:7d866c31b3c5 | 48 | * Enter Power-down mode while no peripheral is active; otherwise, enter Idle mode. |
AnnaBridge | 172:7d866c31b3c5 | 49 | */ |
AnnaBridge | 172:7d866c31b3c5 | 50 | void hal_deepsleep(void) |
AnnaBridge | 172:7d866c31b3c5 | 51 | { |
AnnaBridge | 172:7d866c31b3c5 | 52 | struct sleep_s sleep_obj; |
AnnaBridge | 172:7d866c31b3c5 | 53 | sleep_obj.powerdown = 1; |
AnnaBridge | 172:7d866c31b3c5 | 54 | mbed_enter_sleep(&sleep_obj); |
AnnaBridge | 172:7d866c31b3c5 | 55 | mbed_exit_sleep(&sleep_obj); |
AnnaBridge | 172:7d866c31b3c5 | 56 | } |
AnnaBridge | 172:7d866c31b3c5 | 57 | |
AnnaBridge | 172:7d866c31b3c5 | 58 | static void mbed_enter_sleep(struct sleep_s *obj) |
AnnaBridge | 172:7d866c31b3c5 | 59 | { |
AnnaBridge | 172:7d866c31b3c5 | 60 | // Check if serial allows entering power-down mode |
AnnaBridge | 172:7d866c31b3c5 | 61 | if (obj->powerdown) { |
AnnaBridge | 172:7d866c31b3c5 | 62 | obj->powerdown = serial_allow_powerdown(); |
AnnaBridge | 172:7d866c31b3c5 | 63 | } |
AnnaBridge | 172:7d866c31b3c5 | 64 | // Check if spi allows entering power-down mode |
AnnaBridge | 172:7d866c31b3c5 | 65 | if (obj->powerdown) { |
AnnaBridge | 172:7d866c31b3c5 | 66 | obj->powerdown = spi_allow_powerdown(); |
AnnaBridge | 172:7d866c31b3c5 | 67 | } |
AnnaBridge | 172:7d866c31b3c5 | 68 | // Check if i2c allows entering power-down mode |
AnnaBridge | 172:7d866c31b3c5 | 69 | if (obj->powerdown) { |
AnnaBridge | 172:7d866c31b3c5 | 70 | obj->powerdown = i2c_allow_powerdown(); |
AnnaBridge | 172:7d866c31b3c5 | 71 | } |
AnnaBridge | 172:7d866c31b3c5 | 72 | // Check if pwmout allows entering power-down mode |
AnnaBridge | 172:7d866c31b3c5 | 73 | if (obj->powerdown) { |
AnnaBridge | 172:7d866c31b3c5 | 74 | obj->powerdown = pwmout_allow_powerdown(); |
AnnaBridge | 172:7d866c31b3c5 | 75 | } |
AnnaBridge | 172:7d866c31b3c5 | 76 | // TODO: Check if other peripherals allow entering power-down mode |
AnnaBridge | 172:7d866c31b3c5 | 77 | |
AnnaBridge | 172:7d866c31b3c5 | 78 | if (obj->powerdown) { // Power-down mode (HIRC/HXT disabled, LIRC/LXT enabled) |
AnnaBridge | 172:7d866c31b3c5 | 79 | SYS_UnlockReg(); |
AnnaBridge | 172:7d866c31b3c5 | 80 | CLK_PowerDown(); |
AnnaBridge | 172:7d866c31b3c5 | 81 | SYS_LockReg(); |
AnnaBridge | 172:7d866c31b3c5 | 82 | } else { // CPU halt mode (HIRC/HXT enabled, LIRC/LXT enabled) |
AnnaBridge | 172:7d866c31b3c5 | 83 | SYS_UnlockReg(); |
AnnaBridge | 172:7d866c31b3c5 | 84 | CLK_Idle(); |
AnnaBridge | 172:7d866c31b3c5 | 85 | SYS_LockReg(); |
AnnaBridge | 172:7d866c31b3c5 | 86 | } |
AnnaBridge | 172:7d866c31b3c5 | 87 | __NOP(); |
AnnaBridge | 172:7d866c31b3c5 | 88 | __NOP(); |
AnnaBridge | 172:7d866c31b3c5 | 89 | __NOP(); |
AnnaBridge | 172:7d866c31b3c5 | 90 | __NOP(); |
AnnaBridge | 172:7d866c31b3c5 | 91 | } |
AnnaBridge | 172:7d866c31b3c5 | 92 | |
AnnaBridge | 172:7d866c31b3c5 | 93 | static void mbed_exit_sleep(struct sleep_s *obj) |
AnnaBridge | 172:7d866c31b3c5 | 94 | { |
AnnaBridge | 172:7d866c31b3c5 | 95 | (void)obj; |
AnnaBridge | 172:7d866c31b3c5 | 96 | } |
AnnaBridge | 172:7d866c31b3c5 | 97 | |
AnnaBridge | 172:7d866c31b3c5 | 98 | #endif |