From 882e9afb959e5ecc8800a79bb3cf3dabf1a7ccc6 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 13 Oct 2017 09:25:38 +0000 Subject: Now it is APPARENTLY working for intervals larger than system time. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rt5_dev_point1@10817 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/STM32/RT-STM32F746G-DISCOVERY/chconf.h | 2 +- os/rt/include/chvt.h | 62 ++++++++++++++-------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/demos/STM32/RT-STM32F746G-DISCOVERY/chconf.h b/demos/STM32/RT-STM32F746G-DISCOVERY/chconf.h index 206f1d11d..bba658831 100644 --- a/demos/STM32/RT-STM32F746G-DISCOVERY/chconf.h +++ b/demos/STM32/RT-STM32F746G-DISCOVERY/chconf.h @@ -42,7 +42,7 @@ * @brief System time counter resolution. * @note Allowed values are 16 or 32 bits. */ -#define CH_CFG_ST_RESOLUTION 32 +#define CH_CFG_ST_RESOLUTION 16 /** * @brief System tick frequency. diff --git a/os/rt/include/chvt.h b/os/rt/include/chvt.h index ea4493df3..b3a803c1a 100644 --- a/os/rt/include/chvt.h +++ b/os/rt/include/chvt.h @@ -398,48 +398,48 @@ static inline void chVTDoTickI(void) { /* Looping through timers.*/ vtp = ch.vtlist.next; while (true) { - vtfunc_t fn; + sysinterval_t nowdelta; - /* The loop is stopped by the timers header having - "ch.vtlist.vt_delta == (sysinterval_t)-1" which - is greater than all deltas.*/ + /* Getting the system time as reference.*/ now = chVTGetSystemTimeX(); - if (vtp->delta > chTimeDiffX(ch.vtlist.lasttime, now)) { + nowdelta = chTimeDiffX(ch.vtlist.lasttime, now); + + /* The list scan is limited by the timers header having + "ch.vtlist.vt_delta == (sysinterval_t)-1" which is + greater than all deltas.*/ + if (vtp->delta > nowdelta) { break; } -#if 0 - /* The "last time" becomes this timer's expiration time.*/ - ch.vtlist.lasttime = chTimeAddX(ch.vtlist.lasttime, vtp->delta); -#else - /* The "last time" is set to the current time.*/ - ch.vtlist.lasttime = now; -#endif + /* Consuming all timers between "vtp->lasttime" and now.*/ + do { + vtfunc_t fn; - vtp->next->prev = (virtual_timer_t *)&ch.vtlist; - ch.vtlist.next = vtp->next; - fn = vtp->func; - vtp->func = NULL; + /* Recalculated delta.*/ + nowdelta = nowdelta - vtp->delta; - /* if the list becomes empty then the timer is stopped.*/ - if (ch.vtlist.next == (virtual_timer_t *)&ch.vtlist) { - port_timer_stop_alarm(); - } + vtp->next->prev = (virtual_timer_t *)&ch.vtlist; + ch.vtlist.next = vtp->next; + fn = vtp->func; + vtp->func = NULL; - /* Leaving the system critical zone in order to execute the callback - and in order to give a preemption chance to higher priority - interrupts.*/ - chSysUnlockFromISR(); + /* if the list becomes empty then the timer is stopped.*/ + if (ch.vtlist.next == (virtual_timer_t *)&ch.vtlist) { + port_timer_stop_alarm(); + } - /* The callback is invoked outside the kernel critical zone.*/ - fn(vtp->par); + /* The callback is invoked outside the kernel critical zone.*/ + chSysUnlockFromISR(); + fn(vtp->par); + chSysLockFromISR(); - /* Re-entering the critical zone in order to continue the exploration - of the list.*/ - chSysLockFromISR(); + /* Next element in the list.*/ + vtp = ch.vtlist.next; + } + while (vtp->delta <= nowdelta); - /* Next element in the list.*/ - vtp = ch.vtlist.next; + /* The "last time" is set to the current time.*/ + ch.vtlist.lasttime = now; } /* if the list is empty, nothing else to do.*/ -- cgit v1.2.3