Force inline Timer::attach() to get rid of floating-point instruction

Calls to Timer::attach() are inlined in order not to use floating-point
library functions calls given Timer::attach_us() expects an integer
for the callback interval.
pull/11236/head
Hugues Kamba 2019-08-16 09:39:44 +01:00
parent b0d4b69123
commit 5635e94af5
5 changed files with 13 additions and 38 deletions

View File

@ -142,11 +142,11 @@ void test_detach(void)
{
LowPowerTicker ticker;
bool ret;
const s_timestamp_t ticker_time_s = 1;
const uint32_t wait_time_ms = 5000;
const float ticker_time_s = 0.1f;
const uint32_t wait_time_ms = 500;
Semaphore sem(0, 1);
ticker.attach_s(callback(sem_release, &sem), ticker_time_s);
ticker.attach(callback(sem_release, &sem), ticker_time_s);
sem.acquire();
@ -171,7 +171,7 @@ void test_attach_time(void)
gtimer.reset();
gtimer.start();
ticker.attach_s(callback(stop_gtimer_set_flag), MICROSECONDS_TO_SECONDS(DELAY_US));
ticker.attach(callback(stop_gtimer_set_flag), ((float)DELAY_US) / 1000000.0f);
while (!ticker_callback_flag);
ticker.detach();
const int time_diff = gtimer.read_us();

View File

@ -264,11 +264,11 @@ void test_detach(void)
{
Ticker ticker;
bool ret;
const s_timestamp_t ticker_time_s = 1;
const uint32_t wait_time_ms = 5000;
const float ticker_time_s = 0.1f;
const uint32_t wait_time_ms = 500;
Semaphore sem(0, 1);
ticker.attach_s(callback(sem_release, &sem), ticker_time_s);
ticker.attach(callback(sem_release, &sem), ticker_time_s);
sem.acquire();
@ -293,7 +293,7 @@ void test_attach_time(void)
gtimer.reset();
gtimer.start();
ticker.attach_s(callback(stop_gtimer_set_flag), MICROSECONDS_TO_SECONDS(DELAY_US));
ticker.attach(callback(stop_gtimer_set_flag), ((float)DELAY_US) / 1000000.0f);
while (!ticker_callback_flag);
ticker.detach();
const int time_diff = gtimer.read_us();

View File

@ -23,21 +23,6 @@
#include "platform/NonCopyable.h"
#include "hal/lp_ticker_api.h"
/**
* Number of microseconds in a second
*/
#define MICROSECONDS_IN_SECOND (us_timestamp_t)1000000
/**
* Converts seconds to microseconds
*/
#define SECONDS_TO_MICROSECONDS(SECONDS) (us_timestamp_t)(MICROSECONDS_IN_SECOND * SECONDS)
/**
* Converts microseconds to seconds
*/
#define MICROSECONDS_TO_SECONDS(MICROSECONDS) (s_timestamp_t)(MICROSECONDS / MICROSECONDS_IN_SECOND)
namespace mbed {
/**
* \addtogroup drivers_Ticker Ticker class
@ -89,17 +74,12 @@ public:
Ticker(const ticker_data_t *data);
/** Attach a function to be called by the Ticker, specifying the interval in seconds
*
* The method must be inlined to convert to not use floating-point operations
* 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_s(Callback<void()> func, const s_timestamp_t t)
{
attach_us(func, SECONDS_TO_MICROSECONDS(t));
}
MBED_DEPRECATED("This function has been deprecated, use attach_s(Callback<void()> func, const s_timestamp_t t)")
void attach(Callback<void()> func, float t)
MBED_FORCEINLINE void attach(Callback<void()> func, float t)
{
attach_us(func, t * 1000000.0f);
}
@ -119,7 +99,7 @@ public:
"attach(callback(obj, method), t).")
void attach(T *obj, M method, float t)
{
attach_s(callback(obj, method), (s_timestamp_t)t);
attach(callback(obj, method), t);
}
/** Attach a function to be called by the Ticker, specifying the interval in microseconds

View File

@ -183,7 +183,7 @@ void NFCController::scheduler_process(bool hw_interrupt)
// Process stack events
uint32_t timeout = nfc_scheduler_iteration(_scheduler, hw_interrupt ? EVENT_HW_INTERRUPT : EVENT_NONE);
_timeout.attach_s(callback(this, &NFCController::on_timeout), timeout);
_timeout.attach(callback(this, &NFCController::on_timeout), timeout);
}
void NFCController::on_hw_interrupt()

View File

@ -38,11 +38,6 @@ typedef uint32_t timestamp_t;
*/
typedef uint64_t us_timestamp_t;
/**
* A second timestamp stored in a 64 bit integer.
*/
typedef uint64_t s_timestamp_t;
/** Ticker's event structure
*/
typedef struct ticker_event_s {