Lines Matching refs:trickle
27 static inline bool is_suppression_disabled(struct net_trickle *trickle) in is_suppression_disabled() argument
29 return trickle->k == NET_TRICKLE_INFINITE_REDUNDANCY; in is_suppression_disabled()
32 static inline bool is_tx_allowed(struct net_trickle *trickle) in is_tx_allowed() argument
34 return is_suppression_disabled(trickle) || in is_tx_allowed()
35 (trickle->c < trickle->k); in is_tx_allowed()
38 static inline uint32_t get_end(struct net_trickle *trickle) in get_end() argument
40 return trickle->Istart + trickle->I; in get_end()
53 static void double_interval_timeout(struct net_trickle *trickle) in double_interval_timeout() argument
56 uint32_t last_end = get_end(trickle); in double_interval_timeout()
58 trickle->c = 0U; in double_interval_timeout()
63 if (trickle->I <= (trickle->Imax_abs >> 1)) { in double_interval_timeout()
65 trickle->I <<= 1; in double_interval_timeout()
67 NET_DBG("double I %u", trickle->I); in double_interval_timeout()
69 trickle->I = trickle->Imax_abs; in double_interval_timeout()
71 NET_DBG("I %u", trickle->I); in double_interval_timeout()
75 rand_time = get_t(trickle->I); in double_interval_timeout()
79 trickle->Istart = k_uptime_get_32() + rand_time; in double_interval_timeout()
80 trickle->double_to = false; in double_interval_timeout()
82 k_work_reschedule(&trickle->timer, K_MSEC(rand_time)); in double_interval_timeout()
85 last_end, get_end(trickle), trickle->Istart, trickle->I); in double_interval_timeout()
88 static inline void reschedule(struct net_trickle *trickle) in reschedule() argument
91 uint32_t diff = get_end(trickle) - now; in reschedule()
101 trickle->double_to = true; in reschedule()
103 k_work_reschedule(&trickle->timer, K_MSEC(diff)); in reschedule()
106 static void interval_timeout(struct net_trickle *trickle) in interval_timeout() argument
110 if (trickle->cb) { in interval_timeout()
112 is_tx_allowed(trickle), trickle->c, trickle->k); in interval_timeout()
114 trickle->cb(trickle, is_tx_allowed(trickle), in interval_timeout()
115 trickle->user_data); in interval_timeout()
118 if (net_trickle_is_running(trickle)) { in interval_timeout()
119 reschedule(trickle); in interval_timeout()
126 struct net_trickle *trickle = CONTAINER_OF(dwork, in trickle_timeout() local
130 if (trickle->double_to) { in trickle_timeout()
131 double_interval_timeout(trickle); in trickle_timeout()
133 interval_timeout(trickle); in trickle_timeout()
137 static void setup_new_interval(struct net_trickle *trickle) in setup_new_interval() argument
141 trickle->c = 0U; in setup_new_interval()
143 t = get_t(trickle->I); in setup_new_interval()
145 trickle->Istart = k_uptime_get_32(); in setup_new_interval()
147 k_work_reschedule(&trickle->timer, K_MSEC(t)); in setup_new_interval()
150 trickle->Istart, in setup_new_interval()
151 get_end(trickle), in setup_new_interval()
153 trickle->I); in setup_new_interval()
159 int net_trickle_create(struct net_trickle *trickle, in net_trickle_create() argument
164 if (!(trickle && Imax > 0 && k > 0 && !CHECK_IMIN(Imin))) { in net_trickle_create()
168 (void)memset(trickle, 0, sizeof(struct net_trickle)); in net_trickle_create()
170 trickle->Imin = Imin; in net_trickle_create()
171 trickle->Imax = Imax; in net_trickle_create()
172 trickle->Imax_abs = Imin << Imax; in net_trickle_create()
173 trickle->k = k; in net_trickle_create()
175 if (!trickle->Imax_abs) { in net_trickle_create()
180 trickle->Imin, trickle->Imax, trickle->k, in net_trickle_create()
181 trickle->Imax_abs); in net_trickle_create()
183 k_work_init_delayable(&trickle->timer, trickle_timeout); in net_trickle_create()
188 int net_trickle_start(struct net_trickle *trickle, in net_trickle_start() argument
192 if (!(trickle && cb)) { in net_trickle_start()
196 trickle->cb = cb; in net_trickle_start()
197 trickle->user_data = user_data; in net_trickle_start()
198 trickle->double_to = false; in net_trickle_start()
201 trickle->I = trickle->Imin + in net_trickle_start()
202 (sys_rand32_get() % (trickle->Imax_abs - trickle->Imin + 1)); in net_trickle_start()
204 setup_new_interval(trickle); in net_trickle_start()
207 trickle->Istart, get_end(trickle), in net_trickle_start()
208 trickle->I >> 1, trickle->I); in net_trickle_start()
213 int net_trickle_stop(struct net_trickle *trickle) in net_trickle_stop() argument
215 if (trickle == NULL) { in net_trickle_stop()
219 k_work_cancel_delayable(&trickle->timer); in net_trickle_stop()
221 trickle->I = 0U; in net_trickle_stop()
226 void net_trickle_consistency(struct net_trickle *trickle) in net_trickle_consistency() argument
228 if (trickle == NULL) { in net_trickle_consistency()
232 if (trickle->c < 0xFF) { in net_trickle_consistency()
233 trickle->c++; in net_trickle_consistency()
236 NET_DBG("consistency %u", trickle->c); in net_trickle_consistency()
239 void net_trickle_inconsistency(struct net_trickle *trickle) in net_trickle_inconsistency() argument
241 if (trickle == NULL) { in net_trickle_inconsistency()
245 if (trickle->I != trickle->Imin) { in net_trickle_inconsistency()
248 trickle->I = trickle->Imin; in net_trickle_inconsistency()
251 setup_new_interval(trickle); in net_trickle_inconsistency()