diff --git a/os/rt/src/chvt.c b/os/rt/src/chvt.c index 292f0b84d..46d18f8b5 100644 --- a/os/rt/src/chvt.c +++ b/os/rt/src/chvt.c @@ -264,13 +264,16 @@ void chVTDoResetI(virtual_timer_t *vtp) { (void) ch_dlist_dequeue(&vtp->dlist); /* Adding delta to the next element, if it is not the last one.*/ - if (is_timer(&vtlp->dlist, vtp->dlist.next)) { - vtp->dlist.next->delta += vtp->dlist.delta; - } + vtp->dlist.next->delta += vtp->dlist.delta; /* Marking timer as not armed.*/ vtp->dlist.next = NULL; + /* Special case when the removed element from the last position in the list, + the value in the header must be restored, just doing it is faster than + checking then doing.*/ + vtlp->dlist.delta = (sysinterval_t)-1; + return; } @@ -416,6 +419,7 @@ void chVTDoTickI(void) { lasttime = chTimeAddX(vtlp->lasttime, dlp->delta); vtlp->lasttime = lasttime; + // TODO, remove this assert, it is triggered also by some valid cases. chDbgAssert((int)chTimeDiffX(vtlp->lasttime, now) >= 0, "back in time"); /* Removing the timer from the list, marking it as not armed.*/ @@ -434,7 +438,7 @@ void chVTDoTickI(void) { vtp->func(vtp, vtp->par); chSysLockFromISR(); - /* Delta between current time after callback and last execution time.*/ + /* Delta between current time after callback execution time.*/ now = chVTGetSystemTimeX(); nowdelta = chTimeDiffX(lasttime, now);