Merge pull request #13371 from haukepetersen/add_xtimer_settimeoutflag64
xtimer: add xtimer_set_timeout_flag64()
This commit is contained in:
commit
fc40b54cae
@ -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);
|
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
|
* @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);
|
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)
|
#if defined(MODULE_CORE_MSG) || defined(DOXYGEN)
|
||||||
/**
|
/**
|
||||||
* @brief Set a timer that sends a message
|
* @brief Set a timer that sends a message
|
||||||
|
|||||||
@ -255,11 +255,22 @@ static void _set_timeout_flag_callback(void* arg)
|
|||||||
thread_flags_set(arg, THREAD_FLAG_TIMEOUT);
|
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->callback = _set_timeout_flag_callback;
|
||||||
t->arg = (thread_t *)sched_active_thread;
|
t->arg = (thread_t *)sched_active_thread;
|
||||||
thread_flags_clear(THREAD_FLAG_TIMEOUT);
|
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);
|
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
|
#endif
|
||||||
|
|||||||
@ -98,6 +98,14 @@ int main(void)
|
|||||||
uint32_t diff = xtimer_now_usec() - before;
|
uint32_t diff = xtimer_now_usec() - before;
|
||||||
printf("main: timeout triggered. time passed: %"PRIu32"us\n", diff);
|
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)) {
|
if (diff < (TIMEOUT + THRESHOLD)) {
|
||||||
puts("SUCCESS");
|
puts("SUCCESS");
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -24,6 +24,8 @@ def testfunc(child):
|
|||||||
child.expect_exact("thread(): received flags: 0x0008")
|
child.expect_exact("thread(): received flags: 0x0008")
|
||||||
child.expect_exact("main: setting 100ms timeout...")
|
child.expect_exact("main: setting 100ms timeout...")
|
||||||
child.expect("main: timeout triggered. time passed: [0-9]{6}us")
|
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")
|
child.expect("SUCCESS")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user