aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2017-10-13 12:35:40 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2017-10-13 12:35:40 +0000
commitcb725828056b9564ab5d723bd0738375a83c077c (patch)
tree1db3326fe3ea3b0103830c5dfdf16518aec9e404 /os
parent882e9afb959e5ecc8800a79bb3cf3dabf1a7ccc6 (diff)
downloadChibiOS-cb725828056b9564ab5d723bd0738375a83c077c.tar.gz
ChibiOS-cb725828056b9564ab5d723bd0738375a83c077c.tar.bz2
ChibiOS-cb725828056b9564ab5d723bd0738375a83c077c.zip
Fixed and optimizations, NOW it seems to work for intervals larger than system time.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rt5_dev_point1@10818 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/rt/include/chtime.h4
-rw-r--r--os/rt/include/chvt.h20
2 files changed, 13 insertions, 11 deletions
diff --git a/os/rt/include/chtime.h b/os/rt/include/chtime.h
index e2e3402ef..701dfb4d5 100644
--- a/os/rt/include/chtime.h
+++ b/os/rt/include/chtime.h
@@ -488,7 +488,7 @@ static inline systime_t chTimeAddX(systime_t systime,
*/
static inline sysinterval_t chTimeDiffX(systime_t start, systime_t end) {
- return (sysinterval_t)(end - start);
+ return (sysinterval_t)((systime_t)(end - start));
}
@@ -509,7 +509,7 @@ static inline bool chTimeIsInRangeX(systime_t time,
systime_t start,
systime_t end) {
- return (bool)((systime_t)(time - start) < (systime_t)(end - start));
+ return (bool)((time - start) < (end - start));
}
/** @} */
diff --git a/os/rt/include/chvt.h b/os/rt/include/chvt.h
index b3a803c1a..e115bec63 100644
--- a/os/rt/include/chvt.h
+++ b/os/rt/include/chvt.h
@@ -393,12 +393,11 @@ static inline void chVTDoTickI(void) {
#else /* CH_CFG_ST_TIMEDELTA > 0 */
virtual_timer_t *vtp;
systime_t now;
- sysinterval_t delta;
+ sysinterval_t delta, nowdelta;
/* Looping through timers.*/
vtp = ch.vtlist.next;
while (true) {
- sysinterval_t nowdelta;
/* Getting the system time as reference.*/
now = chVTGetSystemTimeX();
@@ -407,7 +406,7 @@ static inline void chVTDoTickI(void) {
/* 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) {
+ if (nowdelta < vtp->delta) {
break;
}
@@ -415,8 +414,9 @@ static inline void chVTDoTickI(void) {
do {
vtfunc_t fn;
- /* Recalculated delta.*/
- nowdelta = nowdelta - vtp->delta;
+ /* The "last time" becomes this timer's expiration time.*/
+ ch.vtlist.lasttime += vtp->delta;
+ nowdelta -= vtp->delta;
vtp->next->prev = (virtual_timer_t *)&ch.vtlist;
ch.vtlist.next = vtp->next;
@@ -437,9 +437,6 @@ static inline void chVTDoTickI(void) {
vtp = ch.vtlist.next;
}
while (vtp->delta <= nowdelta);
-
- /* The "last time" is set to the current time.*/
- ch.vtlist.lasttime = now;
}
/* if the list is empty, nothing else to do.*/
@@ -447,6 +444,11 @@ static inline void chVTDoTickI(void) {
return;
}
+ /* The "unprocessed nowdelta" time slice is added to "last time"
+ and subtracted to next timer's delta.*/
+ ch.vtlist.lasttime += nowdelta;
+ ch.vtlist.next->delta -= nowdelta;
+
/* Recalculating the next alarm time.*/
delta = chTimeDiffX(now, chTimeAddX(ch.vtlist.lasttime, vtp->delta));
if (delta < (sysinterval_t)CH_CFG_ST_TIMEDELTA) {
@@ -454,7 +456,7 @@ static inline void chVTDoTickI(void) {
}
#if CH_CFG_INTERVALS_SIZE > CH_CFG_ST_RESOLUTION
/* The delta could be too large for the physical timer to handle.*/
- if (delta > (sysinterval_t)TIME_MAX_SYSTIME) {
+ else if (delta > (sysinterval_t)TIME_MAX_SYSTIME) {
delta = (sysinterval_t)TIME_MAX_SYSTIME;
}
#endif