1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

trickle: switch to xtimer

This commit is contained in:
Cenk Gündoğan 2015-09-04 10:50:11 +02:00 committed by Kaspar Schleiser
parent 4b7a3ed236
commit 052ad7cd51
2 changed files with 27 additions and 26 deletions

View File

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

View File

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