From ca719a96a8d3e61666b70a9f4fb19ab2fb5b6f7d Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Mon, 14 Jun 2021 14:49:31 +0100 Subject: [PATCH] mbedtls: Use LowPowerTimeout for mbedtls_set_alarm() if available The function `mbedtls_set_alarm()` is only precise to seconds, so `LowPowerTimeout` is enough and saves power. --- connectivity/mbedtls/platform/src/timing_mbed.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/connectivity/mbedtls/platform/src/timing_mbed.cpp b/connectivity/mbedtls/platform/src/timing_mbed.cpp index 17acf6c9b9..dd35cb415e 100644 --- a/connectivity/mbedtls/platform/src/timing_mbed.cpp +++ b/connectivity/mbedtls/platform/src/timing_mbed.cpp @@ -29,6 +29,7 @@ #include "mbedtls/timing.h" #include "drivers/Timeout.h" +#include "drivers/LowPowerTimeout.h" #include "drivers/Timer.h" #include "drivers/LowPowerTimer.h" #include @@ -44,7 +45,14 @@ static void handle_alarm(void) extern "C" void mbedtls_set_alarm(int seconds) { +#if DEVICE_LPTICKER + static mbed::LowPowerTimeout t; +#elif DEVICE_USTICKER static mbed::Timeout t; +#else +#error "MBEDTLS_TIMING_C requires either LPTICKER or USTICKER" +#endif + mbedtls_timing_alarmed = 0; t.attach(handle_alarm, std::chrono::seconds(seconds));