From 68e884613985d02db868fd52987b14bea6c58ed5 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Mon, 18 Feb 2019 14:53:45 +0100 Subject: [PATCH 1/2] Do not refresh watchdog in rtimer busy-wait macros --- os/sys/rtimer.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/os/sys/rtimer.h b/os/sys/rtimer.h index 260f08950..1b401a203 100644 --- a/os/sys/rtimer.h +++ b/os/sys/rtimer.h @@ -57,6 +57,11 @@ #include "dev/watchdog.h" #include +#if CONTIKI_TARGET_COOJA +#include "lib/simEnvChange.h" +#include "sys/cooja_mt.h" +#endif + /** \brief The rtimer size (in bytes) */ #ifdef RTIMER_CONF_CLOCK_SIZE #define RTIMER_CLOCK_SIZE RTIMER_CONF_CLOCK_SIZE @@ -189,14 +194,24 @@ void rtimer_arch_schedule(rtimer_clock_t t); #endif /* RTIMER_CONF_GUARD_TIME */ /** \brief Busy-wait until a condition. Start time is t0, max wait time is max_time */ +#if CONTIKI_TARGET_COOJA #define RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time) \ ({ \ bool c; \ while(!(c = cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (max_time))) { \ - watchdog_periodic(); \ + simProcessRunValue = 1; \ + cooja_mt_yield(); \ } \ c; \ }) +#else /* CONTIKI_TARGET_COOJA */ +#define RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time) \ + ({ \ + bool c; \ + while(!(c = cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (max_time))); \ + c; \ + }) +#endif /* CONTIKI_TARGET_COOJA */ /** \brief Busy-wait until a condition for at most max_time */ #define RTIMER_BUSYWAIT_UNTIL(cond, max_time) \ From 11346c5bdaedecb7ea7d5fc6d87e206ddd5fa3fc Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Mon, 4 Mar 2019 09:17:09 +0100 Subject: [PATCH 2/2] RTIMER_BUSYWAIT_UNTIL_ABS: move cooja-specific implem to cooja platform directory --- arch/platform/cooja/rtimer-arch.h | 15 +++++++++++++++ os/sys/rtimer.h | 19 ++----------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/arch/platform/cooja/rtimer-arch.h b/arch/platform/cooja/rtimer-arch.h index 072333bc1..35bd892b4 100644 --- a/arch/platform/cooja/rtimer-arch.h +++ b/arch/platform/cooja/rtimer-arch.h @@ -35,6 +35,8 @@ #include "contiki.h" #include "sys/clock.h" +#include "lib/simEnvChange.h" +#include "sys/cooja_mt.h" #define RTIMER_ARCH_SECOND UINT64_C(1000000) @@ -47,4 +49,17 @@ int rtimer_arch_check(void); int rtimer_arch_pending(void); rtimer_clock_t rtimer_arch_next(void); +/** \brief A platform-specific implementation that calls cooja_mt_yield() + * periodically. Without this, Cooja will get stuck in the busy-loop + * without ever updating the current rtimer time. */ +#define RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time) \ + ({ \ + bool c; \ + while(!(c = cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (max_time))) { \ + simProcessRunValue = 1; \ + cooja_mt_yield(); \ + } \ + c; \ + }) + #endif /* RTIMER_ARCH_H_ */ diff --git a/os/sys/rtimer.h b/os/sys/rtimer.h index 1b401a203..783e1569b 100644 --- a/os/sys/rtimer.h +++ b/os/sys/rtimer.h @@ -57,11 +57,6 @@ #include "dev/watchdog.h" #include -#if CONTIKI_TARGET_COOJA -#include "lib/simEnvChange.h" -#include "sys/cooja_mt.h" -#endif - /** \brief The rtimer size (in bytes) */ #ifdef RTIMER_CONF_CLOCK_SIZE #define RTIMER_CLOCK_SIZE RTIMER_CONF_CLOCK_SIZE @@ -194,24 +189,14 @@ void rtimer_arch_schedule(rtimer_clock_t t); #endif /* RTIMER_CONF_GUARD_TIME */ /** \brief Busy-wait until a condition. Start time is t0, max wait time is max_time */ -#if CONTIKI_TARGET_COOJA -#define RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time) \ - ({ \ - bool c; \ - while(!(c = cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (max_time))) { \ - simProcessRunValue = 1; \ - cooja_mt_yield(); \ - } \ - c; \ - }) -#else /* CONTIKI_TARGET_COOJA */ +#ifndef RTIMER_BUSYWAIT_UNTIL_ABS #define RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time) \ ({ \ bool c; \ while(!(c = cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (max_time))); \ c; \ }) -#endif /* CONTIKI_TARGET_COOJA */ +#endif /* RTIMER_BUSYWAIT_UNTIL_ABS */ /** \brief Busy-wait until a condition for at most max_time */ #define RTIMER_BUSYWAIT_UNTIL(cond, max_time) \