mbed library sources. Supersedes mbed-src.

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

Revision:
188:bcfe06ba3d64
Parent:
187:0387e8f68319
diff -r 0387e8f68319 -r bcfe06ba3d64 hal/mbed_sleep_manager.c
--- a/hal/mbed_sleep_manager.c	Thu Sep 06 13:40:20 2018 +0100
+++ b/hal/mbed_sleep_manager.c	Thu Nov 08 11:46:34 2018 +0000
@@ -14,17 +14,18 @@
  * limitations under the License.
  */
 
-#include "mbed_assert.h"
-#include "mbed_power_mgmt.h"
-#include "mbed_critical.h"
+#include "platform/mbed_assert.h"
+#include "platform/mbed_power_mgmt.h"
+#include "platform/mbed_critical.h"
 #include "sleep_api.h"
-#include "mbed_error.h"
-#include "mbed_debug.h"
-#include "mbed_stats.h"
+#include "platform/mbed_error.h"
+#include "platform/mbed_debug.h"
+#include "platform/mbed_stats.h"
+#include "us_ticker_api.h"
 #include "lp_ticker_api.h"
 #include <limits.h>
 #include <stdio.h>
-#include "mbed_stats.h"
+#include "platform/mbed_stats.h"
 
 
 #if DEVICE_SLEEP
@@ -162,6 +163,10 @@
     if (deep_sleep_lock == USHRT_MAX) {
         core_util_critical_section_exit();
         MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_HAL, MBED_ERROR_CODE_OVERFLOW), "DeepSleepLock overflow (> USHRT_MAX)", deep_sleep_lock);
+        // When running sleep_manager tests, the mbed_error() is overridden
+        // and no longer calls mbed_halt_system(). Return to prevent
+        // execution of the following code.
+        return;
     }
     core_util_atomic_incr_u16(&deep_sleep_lock, 1);
     core_util_critical_section_exit();
@@ -173,6 +178,10 @@
     if (deep_sleep_lock == 0) {
         core_util_critical_section_exit();
         MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_HAL, MBED_ERROR_CODE_UNDERFLOW), "DeepSleepLock underflow (< 0)", deep_sleep_lock);
+        // When running sleep_manager tests, the mbed_error() is overridden
+        // and no longer calls mbed_halt_system(). Return to prevent
+        // execution of the following code.
+        return;
     }
     core_util_atomic_decr_u16(&deep_sleep_lock, 1);
     core_util_critical_section_exit();
@@ -183,6 +192,19 @@
     return deep_sleep_lock == 0 ? true : false;
 }
 
+bool sleep_manager_can_deep_sleep_test_check()
+{
+    const uint32_t check_time_us = 2000;
+    const ticker_data_t *const ticker = get_us_ticker_data();
+    uint32_t start = ticker_read(ticker);
+    while ((ticker_read(ticker) - start) < check_time_us) {
+        if (sleep_manager_can_deep_sleep()) {
+            return true;
+        }
+    }
+    return false;
+}
+
 void sleep_manager_sleep_auto(void)
 {
 #ifdef MBED_SLEEP_TRACING_ENABLED