71 #ifndef TRICKLE_TIMER_H_ 72 #define TRICKLE_TIMER_H_ 87 #define TRICKLE_TIMER_INFINITE_REDUNDANCY 0x00 89 #define TRICKLE_TIMER_ERROR 0 90 #define TRICKLE_TIMER_SUCCESS 1 96 #define TRICKLE_TIMER_MAX_IMAX_GENERIC 0 101 #define TRICKLE_TIMER_MAX_IMAX_16_BIT 1 106 #define TRICKLE_TIMER_MAX_IMAX_32_BIT 2 112 #define TRICKLE_TIMER_TX_SUPPRESS 0 113 #define TRICKLE_TIMER_TX_OK 1 123 #define TRICKLE_TIMER_IS_STOPPED 0 138 #ifdef TRICKLE_TIMER_CONF_COMPENSATE_DRIFT 139 #define TRICKLE_TIMER_COMPENSATE_DRIFT TRICKLE_TIMER_CONF_COMPENSATE_DRIFT 141 #define TRICKLE_TIMER_COMPENSATE_DRIFT 1 155 #ifdef TRICKLE_TIMER_CONF_WIDE_RAND 156 #define TRICKLE_TIMER_WIDE_RAND TRICKLE_TIMER_CONF_WIDE_RAND 158 #define TRICKLE_TIMER_WIDE_RAND 1 189 #ifdef TRICKLE_TIMER_CONF_MAX_IMAX_WIDTH 190 #define TRICKLE_TIMER_MAX_IMAX_WIDTH TRICKLE_TIMER_CONF_MAX_IMAX_WIDTH 192 #define TRICKLE_TIMER_MAX_IMAX_WIDTH TRICKLE_TIMER_MAX_IMAX_GENERIC 201 #ifdef TRICKLE_TIMER_CONF_ERROR_CHECKING 202 #define TRICKLE_TIMER_ERROR_CHECKING TRICKLE_TIMER_CONF_ERROR_CHECKING 204 #define TRICKLE_TIMER_ERROR_CHECKING 1 216 #define TRICKLE_TIMER_CLOCK_MAX ((clock_time_t)~0) 227 #define TRICKLE_TIMER_SUPPRESSION_ENABLED(tt) \ 228 ((tt)->k != TRICKLE_TIMER_INFINITE_REDUNDANCY) 238 #define TRICKLE_TIMER_SUPPRESSION_DISABLED(tt) \ 239 ((tt)->k == TRICKLE_TIMER_INFINITE_REDUNDANCY) 249 #define TRICKLE_TIMER_PROTO_TX_ALLOW(tt) \ 250 (TRICKLE_TIMER_SUPPRESSION_DISABLED(tt) || ((tt)->c < (tt)->k)) 260 #define TRICKLE_TIMER_PROTO_TX_SUPPRESS(tt) \ 261 (TRICKLE_TIMER_SUPPRESSION_ENABLED(tt) && ((tt)->c >= (tt)->k)) 271 #define TRICKLE_TIMER_INTERVAL_MAX(tt) ((tt)->i_max_abs) 281 #define TRICKLE_TIMER_INTERVAL_END(tt) ((tt)->i_start + (tt)->i_cur) 292 #define TRICKLE_TIMER_IMIN_IS_OK(imin) \ 293 ((imin > 1) && (i_min <= (TRICKLE_TIMER_CLOCK_MAX >> 1))) 304 #define TRICKLE_TIMER_IMIN_IS_BAD(imin) \ 305 ((imin < 2) || (i_min > (TRICKLE_TIMER_CLOCK_MAX >> 1))) 321 #define TRICKLE_TIMER_IPAIR_IS_BAD(i_min, i_max) \ 322 ((TRICKLE_TIMER_CLOCK_MAX >> (i_max + 1)) < i_min - 1) 414 uint8_t
i_max, uint8_t
k);
450 #define trickle_timer_stop(tt) do { \ 451 ctimer_stop(&((tt)->ct)); \ 452 (tt)->i_cur = TRICKLE_TIMER_IS_STOPPED; \ 498 #define trickle_timer_reset_event(tt) trickle_timer_inconsistency(tt) 508 #define trickle_timer_is_running(tt) ((tt)->i_cur != TRICKLE_TIMER_IS_STOPPED)
uint8_t trickle_timer_set(struct trickle_timer *tt, trickle_timer_cb_t proto_cb, void *ptr)
Start a previously configured trickle timer.
void trickle_timer_consistency(struct trickle_timer *tt)
To be called by the protocol when it hears a consistent transmission.
void(* trickle_timer_cb_t)(void *ptr, uint8_t suppress)
typedef for a callback function to be defined in the protocol's implementation.
void trickle_timer_inconsistency(struct trickle_timer *tt)
To be called by the protocol when it hears an inconsistent transmission.
struct ctimer ct
A Callback timer used internally.
clock_time_t i_max_abs
Maximum interval size in clock ticks (and not in number of doublings).
uint8_t trickle_timer_config(struct trickle_timer *tt, clock_time_t i_min, uint8_t i_max, uint8_t k)
Configure a trickle timer.
clock_time_t i_start
Start of this interval (absolute clock_time)
trickle_timer_cb_t cb
Protocol's own callback, invoked at time t within the current interval.
clock_time_t i_min
Imin: Clock ticks.
Header file for the callback timer
clock_time_t i_cur
I: Current interval in clock_ticks.
uint8_t i_max
Imax: Max number of doublings.
void * cb_arg
Opaque pointer to be used as the argument of the protocol's callback.
uint8_t c
c: Consistency Counter
uint8_t k
k: Redundancy Constant