Merge pull request #13371 from haukepetersen/add_xtimer_settimeoutflag64

xtimer: add xtimer_set_timeout_flag64()
This commit is contained in:
Kaspar Schleiser 2020-02-13 16:16:45 +01:00 committed by GitHub
commit fc40b54cae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 1 deletions

View File

@ -407,6 +407,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
*
@ -418,6 +419,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

View File

@ -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

View File

@ -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;

View File

@ -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")