From 95b66657aab656e3ca9b2a44d3c2e8cf093ff4d2 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Mon, 25 Apr 2016 17:57:46 +0300 Subject: [PATCH] cc26xx: add TSCH-related rtimer defines --- cpu/cc26xx-cc13xx/rtimer-arch.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cpu/cc26xx-cc13xx/rtimer-arch.h b/cpu/cc26xx-cc13xx/rtimer-arch.h index 0d54d227c..128461c8d 100644 --- a/cpu/cc26xx-cc13xx/rtimer-arch.h +++ b/cpu/cc26xx-cc13xx/rtimer-arch.h @@ -50,6 +50,21 @@ #define RTIMER_ARCH_SECOND 65536 /*---------------------------------------------------------------------------*/ rtimer_clock_t rtimer_arch_now(void); + +/* HW oscillator frequency is 32 kHz, not 64 kHz and RTIMER_NOW() never returns + * an odd value; so US_TO_RTIMERTICKS always rounds to the nearest even number. + */ +#define US_TO_RTIMERTICKS(US) (2 * ((US) >= 0 ? \ + (((int32_t)(US) * (RTIMER_ARCH_SECOND / 2) + 500000) / 1000000L) : \ + ((int32_t)(US) * (RTIMER_ARCH_SECOND / 2) - 500000) / 1000000L)) + +#define RTIMERTICKS_TO_US(T) ((T) >= 0 ? \ + (((int32_t)(T) * 1000000L + ((RTIMER_ARCH_SECOND) / 2)) / (RTIMER_ARCH_SECOND)) : \ + ((int32_t)(T) * 1000000L - ((RTIMER_ARCH_SECOND) / 2)) / (RTIMER_ARCH_SECOND)) + +/* A 64-bit version because the 32-bit one cannot handle T >= 4295 ticks. + Intended only for positive values of T. */ +#define RTIMERTICKS_TO_US_64(T) ((uint32_t)(((uint64_t)(T) * 1000000 + ((RTIMER_ARCH_SECOND) / 2)) / (RTIMER_ARCH_SECOND))) /*---------------------------------------------------------------------------*/ #endif /* RTIMER_ARCH_H_ */ /*---------------------------------------------------------------------------*/