From 052ad7cd5149fdd8b5be9b5c34422f302f8c9cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cenk=20G=C3=BCndo=C4=9Fan?= Date: Fri, 4 Sep 2015 10:50:11 +0200 Subject: [PATCH] trickle: switch to xtimer --- sys/include/trickle.h | 20 +++++++++++--------- sys/trickle/trickle.c | 33 ++++++++++++++++----------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/sys/include/trickle.h b/sys/include/trickle.h index f7178b97d7..bbd027dbfb 100644 --- a/sys/include/trickle.h +++ b/sys/include/trickle.h @@ -29,7 +29,7 @@ extern "C" { #endif -#include "vtimer.h" +#include "xtimer.h" #include "thread.h" /** @brief a generic callback function with arguments that is called by trickle periodically */ @@ -41,20 +41,22 @@ typedef struct { /** @brief all state variables for a trickle timer */ typedef struct { uint8_t k; /**< redundancy constant */ + uint8_t Imax; /**< maximum interval size, described as doublings */ + uint16_t c; /**< counter */ uint32_t Imin; /**< minimum interval size */ - uint8_t Imax; /**< maximum interval size, described as a number of doublings */ uint32_t I; /**< current interval size */ uint32_t t; /**< time within the current interval */ - uint16_t c; /**< counter */ kernel_pid_t pid; /**< pid of trickles target thread */ trickle_callback_t callback; /**< the callback function and parameter that trickle is calling after each interval */ - uint16_t interval_msg_type; /**< the msg_t.type that trickle should use after an interval */ - timex_t msg_interval_time; /**< interval represented as timex_t */ - vtimer_t msg_interval_timer; /**< vtimer to send a msg_t to the target thread for a new interval */ - uint16_t callback_msg_type; /**< the msg_t.type that trickle should use after a callback */ - timex_t msg_callback_time; /**< callback interval represented as timex_t */ - vtimer_t msg_callback_timer; /**< vtimer to send a msg_t to the target thread for a callback */ + msg_t msg_interval; /**< the msg_t to use for intervals */ + uint64_t msg_interval_time; /**< interval in ms */ + xtimer_t msg_interval_timer; /**< xtimer to send a msg_t to the target thread + for a new interval */ + msg_t msg_callback; /**< the msg_t to use for callbacks */ + uint64_t msg_callback_time; /**< callback interval in ms */ + xtimer_t msg_callback_timer; /**< xtimer to send a msg_t to the target thread + for a callback */ } trickle_t; /** diff --git a/sys/trickle/trickle.c b/sys/trickle/trickle.c index 2453b516e5..877fe7c291 100644 --- a/sys/trickle/trickle.c +++ b/sys/trickle/trickle.c @@ -53,27 +53,24 @@ void trickle_interval(trickle_t *trickle) trickle->c = 0; trickle->t = (trickle->I / 2) + (rand() % ((trickle->I / 2) + 1)); - vtimer_remove(&trickle->msg_callback_timer); - trickle->msg_callback_time = timex_set(0, trickle->t * 1000); - vtimer_set_msg(&trickle->msg_callback_timer, trickle->msg_callback_time, trickle->pid, - trickle->callback_msg_type, trickle); + trickle->msg_callback_time = trickle->t * SEC_IN_MS; + xtimer_set_msg64(&trickle->msg_callback_timer, trickle->msg_callback_time, + &trickle->msg_callback, trickle->pid); - vtimer_remove(&trickle->msg_interval_timer); - trickle->msg_interval_time = timex_set(0, trickle->I * 1000); - vtimer_set_msg(&trickle->msg_interval_timer, trickle->msg_interval_time, trickle->pid, - trickle->interval_msg_type, trickle); + trickle->msg_interval_time = trickle->I * SEC_IN_MS; + xtimer_set_msg64(&trickle->msg_interval_timer, trickle->msg_interval_time, + &trickle->msg_interval, trickle->pid); } void trickle_reset_timer(trickle_t *trickle) { - vtimer_remove(&trickle->msg_interval_timer); - vtimer_remove(&trickle->msg_callback_timer); - trickle_start(trickle->pid, trickle, trickle->interval_msg_type, trickle->callback_msg_type, - trickle->Imin, trickle->Imax, trickle->k); + trickle_stop(trickle); + trickle_start(trickle->pid, trickle, trickle->msg_interval.type, trickle->msg_callback.type, + trickle->Imin, trickle->Imax, trickle->k); } void trickle_start(kernel_pid_t pid, trickle_t *trickle, uint16_t interval_msg_type, - uint16_t callback_msg_type, uint32_t Imin, uint8_t Imax, uint8_t k) + uint16_t callback_msg_type, uint32_t Imin, uint8_t Imax, uint8_t k) { trickle->pid = pid; @@ -83,16 +80,18 @@ void trickle_start(kernel_pid_t pid, trickle_t *trickle, uint16_t interval_msg_t trickle->Imax = Imax; trickle->I = trickle->Imin + (rand() % (4 * trickle->Imin)); trickle->pid = pid; - trickle->interval_msg_type = interval_msg_type; - trickle->callback_msg_type = callback_msg_type; + trickle->msg_interval.content.ptr = (char *)trickle; + trickle->msg_interval.type = interval_msg_type; + trickle->msg_callback.content.ptr = (char *)trickle; + trickle->msg_callback.type = callback_msg_type; trickle_interval(trickle); } void trickle_stop(trickle_t *trickle) { - vtimer_remove(&trickle->msg_interval_timer); - vtimer_remove(&trickle->msg_callback_timer); + xtimer_remove(&trickle->msg_interval_timer); + xtimer_remove(&trickle->msg_callback_timer); } void trickle_increment_counter(trickle_t *trickle)