diff --git a/include/nanokernel.h b/include/nanokernel.h index d79bde67ef..68857ad1fb 100644 --- a/include/nanokernel.h +++ b/include/nanokernel.h @@ -59,11 +59,16 @@ struct _nano_queue { #include +struct _nano_timeout; + +typedef void (*_nano_timeout_func_t)(struct _nano_timeout *t); + struct _nano_timeout { sys_dlist_t node; struct tcs *tcs; struct _nano_queue *wait_q; int32_t delta_ticks_from_prev; + _nano_timeout_func_t func; }; /** * @endcond diff --git a/kernel/nanokernel/include/timeout_q.h b/kernel/nanokernel/include/timeout_q.h index 2ae5cf161d..619728ffbe 100644 --- a/kernel/nanokernel/include/timeout_q.h +++ b/kernel/nanokernel/include/timeout_q.h @@ -35,7 +35,8 @@ static inline void _do_nano_timeout_add(struct tcs *tcs, struct _nano_queue *wait_q, int32_t timeout); -static inline void _nano_timeout_init(struct _nano_timeout *t) +static inline void _nano_timeout_init(struct _nano_timeout *t, + _nano_timeout_func_t func) { /* * Must be initialized here and when dequeueing a timeout so that code @@ -55,6 +56,11 @@ static inline void _nano_timeout_init(struct _nano_timeout *t) * routine can check if there is a fiber waiting on this timeout */ t->tcs = NULL; + + /* + * Set callback function + */ + t->func = func; } #if defined(CONFIG_NANO_TIMEOUTS) @@ -63,7 +69,7 @@ static inline void _nano_timeout_init(struct _nano_timeout *t) static inline void _nano_timeout_tcs_init(struct tcs *tcs) { - _nano_timeout_init(&tcs->nano_timeout); + _nano_timeout_init(&tcs->nano_timeout, NULL); /* * These are initialized when enqueing on the timeout queue: @@ -131,6 +137,8 @@ static inline struct _nano_timeout *_nano_timeout_handle_one_timeout( } else { _nano_fiber_ready(tcs); } + } else if (t->func) { + t->func(t); } t->delta_ticks_from_prev = -1; diff --git a/kernel/nanokernel/nano_timer.c b/kernel/nanokernel/nano_timer.c index 06c89ec99e..14a23bcd3f 100644 --- a/kernel/nanokernel/nano_timer.c +++ b/kernel/nanokernel/nano_timer.c @@ -23,7 +23,7 @@ void nano_timer_init(struct nano_timer *timer, void *data) { /* initialize timeout_data */ - _nano_timeout_init(&timer->timeout_data); + _nano_timeout_init(&timer->timeout_data, NULL); /* nano_timer_test() returns NULL on timer that was not started */ timer->user_data = NULL;