diff --git a/boards/airfy-beacon/include/board.h b/boards/airfy-beacon/include/board.h index a94b061e8eb335352456cc8c686067ae48813952..49b17c03e7ce7f16a76df69e40e56e18d5bcfc78 100644 --- a/boards/airfy-beacon/include/board.h +++ b/boards/airfy-beacon/include/board.h @@ -34,7 +34,6 @@ #define XTIMER (0) #define XTIMER_CHAN (0) #define XTIMER_MASK (0xff000000) -#define XTIMER_SHIFT_ON_COMPARE (2) #define XTIMER_BACKOFF (40) /** @} */ diff --git a/boards/arduino-mega2560/include/board.h b/boards/arduino-mega2560/include/board.h index fb5fc9b57a1e82a7c1799a9075c1c539d2e898c9..8bd917f531fb81230b4e1f26b6b37b7557cc2116 100644 --- a/boards/arduino-mega2560/include/board.h +++ b/boards/arduino-mega2560/include/board.h @@ -53,7 +53,6 @@ extern "C" { */ #define XTIMER_MASK (0xffff0000) #define XTIMER_SHIFT (2) -#define XTIMER_SHIFT_ON_COMPARE (8) #define XTIMER_BACKOFF (40) /** @} */ diff --git a/boards/chronos/include/board.h b/boards/chronos/include/board.h index 319eb4f81773a973fd99748be5e6ff2d0532e069..00dab1df8a694eb8b69265fb22de61ec918fb147 100644 --- a/boards/chronos/include/board.h +++ b/boards/chronos/include/board.h @@ -41,7 +41,6 @@ extern "C" { #define XTIMER (0) #define XTIMER_CHAN (0) #define XTIMER_MASK (0xffff0000) -#define XTIMER_SHIFT_ON_COMPARE (4) /** @} */ /** diff --git a/boards/msb-430-common/include/board_common.h b/boards/msb-430-common/include/board_common.h index 24953643ae9c990681fabd7c7a54d22f528cfa14..72d856dcb78b21cfd0773bf7a4b209a2332e62ab 100644 --- a/boards/msb-430-common/include/board_common.h +++ b/boards/msb-430-common/include/board_common.h @@ -40,7 +40,6 @@ extern "C" { #define XTIMER (0) #define XTIMER_CHAN (0) #define XTIMER_MASK (0xffff0000) -#define XTIMER_SHIFT_ON_COMPARE (4) #define XTIMER_BACKOFF (40) /** @} */ diff --git a/boards/nrf51dongle/include/board.h b/boards/nrf51dongle/include/board.h index 39223c8db024f6a4a87aa821bd07645b3e4b1368..3e3ee91c6671b64a1aa9cf94d9070aab2a97708d 100644 --- a/boards/nrf51dongle/include/board.h +++ b/boards/nrf51dongle/include/board.h @@ -35,7 +35,6 @@ extern "C" { #define XTIMER (0) #define XTIMER_CHAN (0) #define XTIMER_MASK (0xff000000) -#define XTIMER_SHIFT_ON_COMPARE (2) #define XTIMER_BACKOFF (40) /** @} */ diff --git a/boards/pca10000/include/board.h b/boards/pca10000/include/board.h index 67e31bbbd34b9a5066c708e343dbc3006dd2d369..11ee1dcbb3f88609e3a28a2eb975eef1c81c5926 100644 --- a/boards/pca10000/include/board.h +++ b/boards/pca10000/include/board.h @@ -35,7 +35,6 @@ extern "C" { #define XTIMER (0) #define XTIMER_CHAN (0) #define XTIMER_MASK (0xff000000) -#define XTIMER_SHIFT_ON_COMPARE (2) #define XTIMER_BACKOFF (40) /** @} */ diff --git a/boards/pca10005/include/board.h b/boards/pca10005/include/board.h index a5ce739b6db5b2a8fc3816ee3f529d2c228934ae..ab8a291f774aad9f99e7ef096f3abfb0e2465f9f 100644 --- a/boards/pca10005/include/board.h +++ b/boards/pca10005/include/board.h @@ -35,7 +35,6 @@ extern "C" { #define XTIMER (0) #define XTIMER_CHAN (0) #define XTIMER_MASK (0xff000000) -#define XTIMER_SHIFT_ON_COMPARE (2) #define XTIMER_BACKOFF (40) /** @} */ diff --git a/boards/telosb/include/board.h b/boards/telosb/include/board.h index 78c67772f30bcf41fd3368b1b3e803a5c8454164..a3e36ab4738be26100b94309a3771fb79b3907ff 100644 --- a/boards/telosb/include/board.h +++ b/boards/telosb/include/board.h @@ -57,7 +57,6 @@ extern "C" { #define XTIMER (0) #define XTIMER_CHAN (0) #define XTIMER_MASK (0xffff0000) -#define XTIMER_SHIFT_ON_COMPARE (4) #define XTIMER_BACKOFF (40) /** @} */ diff --git a/boards/wsn430-common/include/board_common.h b/boards/wsn430-common/include/board_common.h index 56a0b6b5c6a6024004490c210a6e1ea4cf962a8b..1942986328c6b11cc912aeaafadd27e47c33f358 100644 --- a/boards/wsn430-common/include/board_common.h +++ b/boards/wsn430-common/include/board_common.h @@ -40,7 +40,6 @@ extern "C" { #define XTIMER (0) #define XTIMER_CHAN (0) #define XTIMER_MASK (0xffff0000) -#define XTIMER_SHIFT_ON_COMPARE (4) #define XTIMER_BACKOFF (40) /** @} */ diff --git a/boards/yunjia-nrf51822/include/board.h b/boards/yunjia-nrf51822/include/board.h index 4b5509d560d9d700bea9bb548c8f90cac15fa095..22f21e99054bb3a8b28043323085a09fe01397e0 100644 --- a/boards/yunjia-nrf51822/include/board.h +++ b/boards/yunjia-nrf51822/include/board.h @@ -34,7 +34,6 @@ extern "C" { #define XTIMER (0) #define XTIMER_CHAN (0) #define XTIMER_MASK (0xff000000) -#define XTIMER_SHIFT_ON_COMPARE (2) #define XTIMER_BACKOFF (40) /** @} */ diff --git a/boards/z1/include/board.h b/boards/z1/include/board.h index 431931cd916544594a4368ab1d7f155e484c8c4f..4698181e049a315f6aeae8579ba7f1b4205e5eaa 100644 --- a/boards/z1/include/board.h +++ b/boards/z1/include/board.h @@ -51,7 +51,6 @@ extern "C" { #define XTIMER (0) #define XTIMER_CHAN (0) #define XTIMER_MASK (0xffff0000) -#define XTIMER_SHIFT_ON_COMPARE (4) #define XTIMER_BACKOFF (40) /** @} */ diff --git a/sys/include/xtimer.h b/sys/include/xtimer.h index 05c68270b9cee29359a17204998d308ddfa478b3..a600777c802df859d2f2b337d949cda3db951fdf 100644 --- a/sys/include/xtimer.h +++ b/sys/include/xtimer.h @@ -432,25 +432,6 @@ void _xtimer_sleep(uint32_t offset, uint32_t long_offset); static inline void xtimer_spin_until(uint32_t value); /** @} */ -#if XTIMER_MASK -#ifndef XTIMER_SHIFT_ON_COMPARE -/** - * @brief ignore some bits when comparing timer values - * - * (only relevant when XTIMER_MASK != 0, e.g., timers < 32bit.) - * - * When combining _lltimer_now() and _high_cnt, we have to get the same value in - * order to work around a race between overflowing _lltimer_now() and OR'ing the - * resulting values. - * But some platforms are too slow to get the same timer - * value twice, so we use this define to ignore some of the bits. - * - * Use tests/xtimer_shift_on_compare to find the correct value for your MCU. - */ -#define XTIMER_SHIFT_ON_COMPARE (0) -#endif -#endif - #ifndef XTIMER_MIN_SPIN /** * @brief Minimal value xtimer_spin() can spin @@ -461,12 +442,18 @@ static inline void xtimer_spin_until(uint32_t value); static inline uint32_t xtimer_now(void) { #if XTIMER_MASK - uint32_t a, b; + uint32_t latched_high_cnt, now; + + /* _high_cnt can change at any time, so check the value before + * and after reading the low-level timer. If it hasn't changed, + * then it can be safely applied to the timer count. */ + do { - a = _lltimer_now() | _high_cnt; - b = _lltimer_now() | _high_cnt; - } while ((a >> XTIMER_SHIFT_ON_COMPARE) != (b >> XTIMER_SHIFT_ON_COMPARE)); - return b; + latched_high_cnt = _high_cnt; + now = _lltimer_now(); + } while (_high_cnt != latched_high_cnt); + + return latched_high_cnt | now; #else return _lltimer_now(); #endif