Merge pull request #11236 from hugueskamba/hk-iotcore-1315-remove-floating-point-ticker

Force inline Timer::attach() to get rid of floating-point instructions
pull/11266/head
Martin Kojtal 2019-08-20 11:47:54 +02:00 committed by GitHub
commit 398515a367
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -42,7 +42,7 @@ static const uint32_t TOLERANCE_ACCURACY_US = (DELAY_10S *US_PER_SEC / ACCURACY_
#if DEVICE_LPTICKER
volatile bool expired;
void callback(void)
void set_flag_true(void)
{
expired = true;
}
@ -72,7 +72,7 @@ void rtc_sleep_test_support(bool deepsleep_mode)
rtc_write(start);
timeout.attach(callback, DELAY_4S);
timeout.attach(set_flag_true, DELAY_4S);
TEST_ASSERT(sleep_manager_can_deep_sleep_test_check() == deepsleep_mode);

View File

@ -17,6 +17,7 @@
#ifndef MBED_TICKER_H
#define MBED_TICKER_H
#include <mstd_utility>
#include "drivers/TimerEvent.h"
#include "platform/Callback.h"
#include "platform/mbed_toolchain.h"
@ -75,12 +76,17 @@ public:
/** Attach a function to be called by the Ticker, specifying the interval in seconds
*
* The method forwards its arguments to attach_us() rather than copying them which
* may not be trivial depending on the callback copied.
* The function is forcibly inlined to not use floating-point operations. This is
* possible given attach_us() expects an integer value for the callback interval.
* @param func pointer to the function to be called
* @param t the time between calls in seconds
*/
void attach(Callback<void()> func, float t)
template <typename F>
MBED_FORCEINLINE void attach(F &&func, float t)
{
attach_us(func, t * 1000000.0f);
attach_us(std::forward<F>(func), t * 1000000.0f);
}
/** Attach a member function to be called by the Ticker, specifying the interval in seconds