From 7555d7411c88d332803bfe341f4fa9dd5b6df957 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Fri, 15 Aug 2014 13:17:00 +0100 Subject: [PATCH] add a cachedInterruptTimestamp to us_ticker_set_interrupt() to short-circuit duplicate calls. --- .../hal/TARGET_NORDIC/TARGET_MCU_NRF51822/us_ticker.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/us_ticker.c b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/us_ticker.c index f7b1b28b9b..ed763eb652 100644 --- a/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/us_ticker.c +++ b/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/us_ticker.c @@ -58,6 +58,8 @@ static void us_ticker_app_timer_callback(void *context) void us_ticker_set_interrupt(unsigned int timestamp) { + static unsigned cachedInterruptTimestamp; + if (!us_ticker_inited) { us_ticker_init(); } @@ -67,7 +69,13 @@ void us_ticker_set_interrupt(unsigned int timestamp) /* placeholder to do something to recover from error */ return; } + } else { + /* we want to avoid taking action on duplicate requests */ + if (timestamp == cachedInterruptTimestamp) { + return; + } } + cachedInterruptTimestamp = timestamp; uint32_t currentCounter; app_timer_cnt_get(¤tCounter);