fb11e647
vrobic
reseau statique a...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*
* Trickle constants and prototypes
*
* Copyright (C) 2013, 2014 INRIA.
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup sys_trickle Trickle Timer
* @ingroup sys
* @{
*/
/**
* @file
* @brief Implementation of a generic Trickle Algorithm (RFC 6206)
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Cenk Gündoğan <cnkgndgn@gmail.com>
*/
#ifndef TRICKLE_H
#define TRICKLE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "xtimer.h"
#include "thread.h"
/** @brief a generic callback function with arguments that is called by trickle periodically */
typedef struct {
void (*func)(void *); /**< a generic callback function pointer */
void *args; /**< a generic parameter for the callback function pointer */
} trickle_callback_t;
/** @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 */
uint32_t I; /**< current interval size */
uint32_t t; /**< time within the current interval */
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 */
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;
/**
* @brief resets the trickle timer
*
* @param[in] trickle the trickle timer
*/
void trickle_reset_timer(trickle_t *trickle);
/**
* @brief start the trickle timer
*
* @param[in] pid target thread
* @param[in] trickle trickle timer
* @param[in] interval_msg_type msg_t.type for interval messages
* @param[in] callback_msg_type msg_t.type for callback messages
* @param[in] Imin minimum interval
* @param[in] Imax maximum interval
* @param[in] k redundancy constant
*/
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);
/**
* @brief stops the trickle timer
*
* @param[in] trickle trickle timer
*/
void trickle_stop(trickle_t *trickle);
/**
* @brief increments the counter by one
*
* @param[in] trickle trickle timer
*/
void trickle_increment_counter(trickle_t *trickle);
/**
* @brief is called after the interval is over and calculates the next interval
*
* @param[in] trickle trickle timer
*/
void trickle_interval(trickle_t *trickle);
/**
* @brief is called after the callback interval is over and calls the callback function
*
* @param[in] trickle trickle timer
*/
void trickle_callback(trickle_t *trickle);
#ifdef __cplusplus
}
#endif
#endif /* TRICKLE_H */
/** @} */
|