mbed library sources. Supersedes mbed-src.

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

Revision:
188:bcfe06ba3d64
Parent:
187:0387e8f68319
--- a/targets/TARGET_NUVOTON/TARGET_M2351/sleep.c	Thu Sep 06 13:40:20 2018 +0100
+++ b/targets/TARGET_NUVOTON/TARGET_M2351/sleep.c	Thu Nov 08 11:46:34 2018 +0000
@@ -22,30 +22,48 @@
 #include "device.h"
 #include "objects.h"
 #include "PeripheralPins.h"
+#include <stdbool.h>
 
-#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
+#if DEVICE_SERIAL
+bool serial_can_deep_sleep(void);
+#endif
 
 /**
  * Enter idle mode, in which just CPU is halted.
  */
-__NONSECURE_ENTRY
 void hal_sleep(void)
 {
+#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
     SYS_UnlockReg();
     CLK_Idle();
     SYS_LockReg();
+#else
+    SYS_UnlockReg_S();
+    CLK_Idle_S();
+    SYS_LockReg_S();
+#endif
 }
 
 /**
  * Enter power-down mode, in which HXT/HIRC are halted.
  */
-__NONSECURE_ENTRY
 void hal_deepsleep(void)
 {
+#if DEVICE_SERIAL
+    if (!serial_can_deep_sleep()) {
+        return;
+    }
+#endif
+
+#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
     SYS_UnlockReg();
     CLK_PowerDown();
     SYS_LockReg();
+#else
+    SYS_UnlockReg_S();
+    CLK_PowerDown_S();
+    SYS_LockReg_S();
+#endif
 }
 
 #endif
-#endif