1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-27 15:31:17 +01:00

Merge pull request #13210 from kaspar030/add_xtimer_left

sys/xtimer: remove uses of xtimer internal struct members
This commit is contained in:
Koen Zandberg 2020-04-21 12:15:41 +02:00 committed by GitHub
commit 5293e5400c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 57 additions and 55 deletions

View File

@ -1,7 +1,7 @@
From 22f5984e32bec116e3449ebad1b29b2a18f4d93e Mon Sep 17 00:00:00 2001
From 1534f82714a2a11bb338e14ed9dd18a24799cd38 Mon Sep 17 00:00:00 2001
From: Michel Rottleuthner <michel.rottleuthner@haw-hamburg.de>
Date: Thu, 9 Jan 2020 11:16:38 +0100
Subject: [PATCH] update xtimer_t member names
Subject: [PATCH] update xtimer_t struct clearing
---
app.c | 2 +-
@ -10,43 +10,44 @@ Subject: [PATCH] update xtimer_t member names
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/app.c b/app.c
index 8d37bd9..da9fc3c 100644
index 8d37bd970af..bc4718d31b9 100644
--- a/app.c
+++ b/app.c
@@ -380,7 +380,7 @@ int ndn_app_schedule(ndn_app_t* handle, ndn_app_sched_cb_t cb, void* context,
if (entry == NULL) return -1;
// initialize the timer
- entry->timer.target = entry->timer.long_target = 0;
+ entry->timer.offset = entry->timer.long_offset = 0;
+ entry->timer = (xtimer_t) {0};
// initialize the msg struct
entry->timer_msg.type = MSG_XTIMER;
diff --git a/l2.c b/l2.c
index 77d6be4..b64b9df 100644
index 77d6be49cd9..a0546b5e4a2 100644
--- a/l2.c
+++ b/l2.c
@@ -155,7 +155,7 @@ ndn_shared_block_t* ndn_l2_frag_receive(kernel_pid_t iface,
entry->id = id;
// initialize timer
- entry->timer.target = entry->timer.long_target = 0;
+ entry->timer.offset = entry->timer.long_offset = 0;
+ entry->timer = (xtimer_t) {0};
entry->timer_msg.type = NDN_L2_FRAG_MSG_TYPE_TIMEOUT;
entry->timer_msg.content.ptr = (char*)(&entry->timer_msg);
diff --git a/pit.c b/pit.c
index 644cf08..944a07c 100644
index 644cf089d9c..692105ea1ed 100644
--- a/pit.c
+++ b/pit.c
@@ -155,7 +155,7 @@ int ndn_pit_add(kernel_pid_t face_id, int face_type, ndn_shared_block_t* si,
*pit_entry = entry;
/* initialize the timer */
- entry->timer.target = entry->timer.long_target = 0;
+ entry->timer.offset = entry->timer.long_offset = 0;
+ entry->timer = (xtimer_t) {0};
/* initialize the msg struct */
entry->timer_msg.type = NDN_PIT_MSG_TYPE_TIMEOUT;
--
2.24.1
2.25.0

View File

@ -27,10 +27,7 @@ extern kernel_pid_t semtech_loramac_pid;
void TimerInit(TimerEvent_t *obj, void (*cb)(void))
{
obj->dev.start_time = 0;
obj->dev.long_start_time = 0;
obj->dev.offset = 0;
obj->dev.long_offset = 0;
obj->dev = (xtimer_t) { 0 };
obj->running = 0;
obj->cb = cb;
}

View File

@ -114,20 +114,9 @@ static void _update_timer(evtimer_t *evtimer)
static uint32_t _get_offset(xtimer_t *timer)
{
uint64_t now_us = xtimer_now_usec64();
uint64_t start_us = _xtimer_usec_from_ticks64(
((uint64_t)timer->long_start_time << 32) | timer->start_time);
uint64_t target_us = start_us + _xtimer_usec_from_ticks64(
((uint64_t)timer->long_offset) << 32 | timer->offset);
if (target_us <= now_us) {
return 0;
}
else {
target_us -= now_us;
/* add half of 125 so integer division rounds to nearest */
return div_u64_by_125((target_us >> 3) + 62);
}
uint64_t left = xtimer_left_usec(timer);
/* add half of 125 so integer division rounds to nearest */
return div_u64_by_125((left >> 3) + 62);
}
static void _update_head_offset(evtimer_t *evtimer)

View File

@ -436,6 +436,16 @@ void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout);
void xtimer_set_timeout_flag64(xtimer_t *t, uint64_t timeout);
#endif
/**
* @brief Get remaining time of timer
*
* @param[in] timer timer struct to use
*
* @returns time in usec until timer triggers
* @returns 0 if timer is not set (or has already passed)
*/
uint64_t xtimer_left_usec(const xtimer_t *timer);
#if defined(MODULE_CORE_MSG) || defined(DOXYGEN)
/**
* @brief Set a timer that sends a message

View File

@ -278,7 +278,7 @@ int _gnrc_rpl_dodag_show(void)
gnrc_rpl_dodag_t *dodag = NULL;
char addr_str[IPV6_ADDR_MAX_STR_LEN];
uint64_t tc, xnow = xtimer_now_usec64();
uint64_t tc;
for (uint8_t i = 0; i < GNRC_RPL_INSTANCES_NUMOF; ++i) {
if (gnrc_rpl_instances[i].state == 0) {
@ -292,11 +292,8 @@ int _gnrc_rpl_dodag_show(void)
gnrc_rpl_instances[i].mop, gnrc_rpl_instances[i].of->ocp,
gnrc_rpl_instances[i].min_hop_rank_inc, gnrc_rpl_instances[i].max_rank_inc);
tc = _xtimer_usec_from_ticks64(((uint64_t) dodag->trickle.msg_timer.long_offset << 32)
| dodag->trickle.msg_timer.offset)
- (xnow - _xtimer_usec_from_ticks64(
(uint64_t)dodag->trickle.msg_timer.long_start_time << 32 | dodag->trickle.msg_timer.start_time));
tc = (int64_t) tc < 0 ? 0 : tc / US_PER_SEC;
tc = xtimer_left_usec(&dodag->trickle.msg_timer);
tc = (int64_t) tc == 0 ? 0 : tc / US_PER_SEC;
printf("\tdodag [%s | R: %d | OP: %s | PIO: %s | "
"TR(I=[%d,%d], k=%d, c=%d, TC=%" PRIu32 "s)]\n",

View File

@ -295,3 +295,26 @@ void xtimer_set_timeout_flag64(xtimer_t *t, uint64_t timeout)
xtimer_set64(t, timeout);
}
#endif
uint64_t xtimer_left_usec(const xtimer_t *timer)
{
unsigned state = irq_disable();
/* ensure we're working on valid data by making a local copy of timer */
xtimer_t t = *timer;
uint64_t now_us = xtimer_now_usec64();
irq_restore(state);
uint64_t start_us = _xtimer_usec_from_ticks64(
((uint64_t)t.long_start_time << 32) | t.start_time);
uint64_t target_us = start_us + _xtimer_usec_from_ticks64(
((uint64_t)t.long_offset) << 32 | t.offset);
/* Let's assume that 64bit won't overflow anytime soon. There'd be >580
* years when counting nanoseconds. With microseconds, there are 580000
* years of space in 2**64... */
if (now_us > target_us) {
return 0;
}
return target_us - now_us;
}

View File

@ -375,18 +375,10 @@ static void run_test(test_ctx_t *ctx, uint32_t interval, unsigned int variant)
interval += TEST_MIN;
unsigned int interval_ref = TIM_TEST_TO_REF(interval);
xtimer_t xt = {
.start_time = 0,
.long_start_time = 0,
.offset = 0,
.long_offset = 0,
.callback = cb,
.arg = ctx,
};
xtimer_t xt_parallel = {
.start_time = 0,
.long_start_time = 0,
.offset = 0,
.long_offset = 0,
.callback = nop,
.arg = NULL,
};

View File

@ -7,6 +7,7 @@ BOARD_INSUFFICIENT_MEMORY := \
atmega328p \
chronos \
msb-430 \
msb-430h \
nucleo-f031k6 \
nucleo-f042k6 \
nucleo-l031k6 \

View File

@ -412,10 +412,6 @@ void test_speed(uint32_t duration)
/* collect samples as long as timer has not expired */
unsigned running = 1;
xtimer_t xt = {
.start_time = 0,
.long_start_time = 0,
.offset = 0,
.long_offset = 0,
.callback = cb_speed_timeout,
.arg = &running,
};
@ -446,10 +442,6 @@ void test_speed_range(uint32_t duration, uint32_t low_thresh, uint32_t high_thre
/* collect samples as long as timer has not expired */
unsigned running = 1;
xtimer_t xt = {
.start_time = 0,
.long_start_time = 0,
.offset = 0,
.long_offset = 0,
.callback = cb_speed_timeout,
.arg = &running,
};