From 58e381979fe025dd9ca0e349a9e43a1d17551f3e Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Thu, 13 Feb 2020 15:37:14 +0100 Subject: [PATCH 1/2] xtimer: add xtimer_set_timeout_flag64() --- sys/include/xtimer.h | 12 ++++++++++++ sys/xtimer/xtimer.c | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/sys/include/xtimer.h b/sys/include/xtimer.h index aea20cc029..269e499077 100644 --- a/sys/include/xtimer.h +++ b/sys/include/xtimer.h @@ -398,6 +398,7 @@ static inline bool xtimer_less64(xtimer_ticks64_t a, xtimer_ticks64_t b); */ int xtimer_mutex_lock_timeout(mutex_t *mutex, uint64_t us); +#if defined(MODULE_CORE_THREAD_FLAGS) || defined(DOXYGEN) /** * @brief Set timeout thread flag after @p timeout * @@ -409,6 +410,17 @@ int xtimer_mutex_lock_timeout(mutex_t *mutex, uint64_t us); */ void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout); +/** + * @brief Set timeout thread flag after @p timeout + * + * See xtimer_set_timeout_flag() for more information. + * + * @param[in] t timer struct to use + * @param[in] timeout timeout in usec + */ +void xtimer_set_timeout_flag64(xtimer_t *t, uint64_t timeout); +#endif + #if defined(MODULE_CORE_MSG) || defined(DOXYGEN) /** * @brief Set a timer that sends a message diff --git a/sys/xtimer/xtimer.c b/sys/xtimer/xtimer.c index 6341f7617a..d51e03f5b3 100644 --- a/sys/xtimer/xtimer.c +++ b/sys/xtimer/xtimer.c @@ -255,11 +255,22 @@ static void _set_timeout_flag_callback(void* arg) thread_flags_set(arg, THREAD_FLAG_TIMEOUT); } -void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout) +static void _set_timeout_flag_prepare(xtimer_t *t) { t->callback = _set_timeout_flag_callback; t->arg = (thread_t *)sched_active_thread; thread_flags_clear(THREAD_FLAG_TIMEOUT); +} + +void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout) +{ + _set_timeout_flag_prepare(t); xtimer_set(t, timeout); } + +void xtimer_set_timeout_flag64(xtimer_t *t, uint64_t timeout) +{ + _set_timeout_flag_prepare(t); + xtimer_set64(t, timeout); +} #endif From 0bcef73067ea92f99ea668d6c89cb0cc321cf882 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Thu, 13 Feb 2020 15:37:30 +0100 Subject: [PATCH 2/2] tests/thread_flags: add call to set_timeout_flag64 --- tests/thread_flags/main.c | 8 ++++++++ tests/thread_flags/tests/01-run.py | 2 ++ 2 files changed, 10 insertions(+) diff --git a/tests/thread_flags/main.c b/tests/thread_flags/main.c index 153668073f..86ab454ab3 100644 --- a/tests/thread_flags/main.c +++ b/tests/thread_flags/main.c @@ -98,6 +98,14 @@ int main(void) uint32_t diff = xtimer_now_usec() - before; printf("main: timeout triggered. time passed: %"PRIu32"us\n", diff); + puts("main: setting 100ms timeout (using uint64)..."); + uint64_t timeout64 = TIMEOUT; + before = xtimer_now_usec(); + xtimer_set_timeout_flag64(&t, timeout64); + thread_flags_wait_any(THREAD_FLAG_TIMEOUT); + diff = xtimer_now_usec() - before; + printf("main: timeout triggered. time passed: %"PRIu32"us\n", diff); + if (diff < (TIMEOUT + THRESHOLD)) { puts("SUCCESS"); return 0; diff --git a/tests/thread_flags/tests/01-run.py b/tests/thread_flags/tests/01-run.py index 063a7dd55d..73e71eb017 100755 --- a/tests/thread_flags/tests/01-run.py +++ b/tests/thread_flags/tests/01-run.py @@ -24,6 +24,8 @@ def testfunc(child): child.expect_exact("thread(): received flags: 0x0008") child.expect_exact("main: setting 100ms timeout...") child.expect("main: timeout triggered. time passed: [0-9]{6}us") + child.expect_exact("main: setting 100ms timeout (using uint64)...") + child.expect("main: timeout triggered. time passed: [0-9]{6}us") child.expect("SUCCESS")