Skip to content

Commit

Permalink
Add tmr_continue() and tmr_continue_dbg()
Browse files Browse the repository at this point in the history
to allow jiffie-accurate interval timer continuation
usually called from within the handler function
  • Loading branch information
vanrein authored and sreimers committed Apr 7, 2023
1 parent 69f817c commit 0fe696c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
16 changes: 16 additions & 0 deletions include/re_tmr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand All @@ -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);

Expand Down
21 changes: 19 additions & 2 deletions src/tmr/tmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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
*
Expand Down

0 comments on commit 0fe696c

Please sign in to comment.