mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Revision:
188:bcfe06ba3d64
Parent:
184:08ed48f1de7f
Child:
189:f392fc9709a3
--- a/targets/TARGET_NUVOTON/TARGET_NUC472/serial_api.c	Thu Sep 06 13:40:20 2018 +0100
+++ b/targets/TARGET_NUVOTON/TARGET_NUC472/serial_api.c	Thu Nov 08 11:46:34 2018 +0000
@@ -25,6 +25,7 @@
 #include "nu_modutil.h"
 #include "nu_bitutil.h"
 #include <string.h>
+#include <stdbool.h>
 
 #if DEVICE_SERIAL_ASYNCH
 #include "dma_api.h"
@@ -87,6 +88,8 @@
 static int serial_is_irq_en(serial_t *obj, SerialIrq irq);
 #endif
 
+bool serial_can_deep_sleep(void);
+
 static struct nu_uart_var uart0_var = {
     .ref_cnt            =   0,
     .obj                =   NULL,
@@ -1136,4 +1139,23 @@
 }
 
 #endif  // #if DEVICE_SERIAL_ASYNCH
+
+bool serial_can_deep_sleep(void)
+{
+    bool sleep_allowed = 1;
+    const struct nu_modinit_s *modinit = uart_modinit_tab;
+    while (modinit->var != NULL) {
+        struct nu_uart_var *uart_var = (struct nu_uart_var *) modinit->var;
+        UART_T *uart_base = (UART_T *) NU_MODBASE(modinit->modname);
+        if (uart_var->ref_cnt > 0) {
+            if (!UART_IS_TX_EMPTY(uart_base)) {
+                sleep_allowed = 0;
+                break;
+            }
+        }
+        modinit++;
+    }
+    return sleep_allowed;
+}
+
 #endif  // #if DEVICE_SERIAL