mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

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?

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