diff --git a/include/re_tmr.h b/include/re_tmr.h index 013d101df..77ce25fc0 100644 --- a/include/re_tmr.h +++ b/include/re_tmr.h @@ -40,6 +40,9 @@ int tmr_status(struct re_printf *pf, void *unused); void tmr_init(struct tmr *tmr); void tmr_start_dbg(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg, const char *file, int line); +void tmr_continue_dbg(struct tmr *tmr, uint64_t delay, + tmr_h *th, void *arg, + const char *file, int line); uint32_t tmrl_count(struct tmrl *tmrl); @@ -56,6 +59,19 @@ uint32_t tmrl_count(struct tmrl *tmrl); #define tmr_start(tmr, delay, th, arg) \ tmr_start_dbg(tmr, delay, th, arg, __FILE__, __LINE__) +/** + * @def tmr_continue(tmr, delay, th, arg) + * + * Continue a previously started timer with exactly added delay + * + * @param tmr Timer to start + * @param delay Timer delay in [ms] + * @param th Timeout handler + * @param arg Handler argument + */ +#define tmr_continue(tmr, delay, th, arg) \ + tmr_continue_dbg(tmr, delay, th, arg, __FILE__, __LINE__) + void tmr_cancel(struct tmr *tmr); uint64_t tmr_get_expire(const struct tmr *tmr); diff --git a/src/tmr/tmr.c b/src/tmr/tmr.c index 524cb2272..3c1bdc780 100644 --- a/src/tmr/tmr.c +++ b/src/tmr/tmr.c @@ -382,7 +382,8 @@ void tmr_init(struct tmr *tmr) } -void tmr_start_dbg(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg, +static void tmr_startcont_dbg(struct tmr *tmr, uint64_t delay, bool syncnow, + tmr_h *th, void *arg, const char *file, int line) { struct tmrl *tmrl = re_tmrl_get(); @@ -420,7 +421,9 @@ void tmr_start_dbg(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg, return; } - tmr->jfs = delay + tmr_jiffies(); + if (syncnow) + tmr->jfs = tmr_jiffies(); + tmr->jfs += delay; if (delay == 0) { le = list_apply(&tmrl->list, true, inspos_handler_0, @@ -446,6 +449,20 @@ void tmr_start_dbg(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg, } +void tmr_start_dbg(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg, + const char *file, int line) +{ + tmr_startcont_dbg(tmr, delay, true, th, arg, file, line); +} + + +void tmr_continue_dbg(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg, + const char *file, int line) +{ + tmr_startcont_dbg(tmr, delay, false, th, arg, file, line); +} + + /** * Cancel an active timer *