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