From 4d0b8bdf6e8c27242b38f69c0831eb2a0ddb689f Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 12 Oct 2017 13:31:42 +0000 Subject: Added support for "large virtual timers", those allows for intervals greater than the system time capability. To be tested. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rt5_dev_point1@10814 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/src/chvt.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'os/rt/src') diff --git a/os/rt/src/chvt.c b/os/rt/src/chvt.c index 4d887b8c4..f627436b4 100644 --- a/os/rt/src/chvt.c +++ b/os/rt/src/chvt.c @@ -146,9 +146,18 @@ void chVTDoSetI(virtual_timer_t *vtp, sysinterval_t delay, p = p->next; } else if (delta < p->delta) { - /* A small delay that will become the first element in the delta list - and next deadline.*/ - port_timer_set_alarm(chTimeAddX(ch.vtlist.lasttime, delta)); + sysinterval_t deadline_delta; + + /* A small delay that will become the first element in the delta list + and next deadline.*/ + deadline_delta = delta; +#if CH_CFG_INTERVALS_SIZE > CH_CFG_ST_RESOLUTION + /* The delta could be too large for the physical timer to handle.*/ + if (deadline_delta > (sysinterval_t)TIME_MAX_SYSTIME) { + deadline_delta = (sysinterval_t)TIME_MAX_SYSTIME; + } +#endif + port_timer_set_alarm(chTimeAddX(ch.vtlist.lasttime, deadline_delta)); } } #else /* CH_CFG_ST_TIMEDELTA == 0 */ @@ -207,7 +216,7 @@ void chVTDoResetI(virtual_timer_t *vtp) { is the last of the list, restoring it.*/ ch.vtlist.delta = (sysinterval_t)-1; #else /* CH_CFG_ST_TIMEDELTA > 0 */ - sysinterval_t nowdelta, delta; + sysinterval_t nowdelta, delta, deadline_delta; /* If the timer is not the first of the list then it is simply unlinked else the operation is more complex.*/ @@ -263,7 +272,15 @@ void chVTDoResetI(virtual_timer_t *vtp) { delta = (systime_t)CH_CFG_ST_TIMEDELTA; } - port_timer_set_alarm(chTimeAddX(ch.vtlist.lasttime, nowdelta + delta)); + /* Next deadline.*/ + deadline_delta = nowdelta + delta; +#if CH_CFG_INTERVALS_SIZE > CH_CFG_ST_RESOLUTION + /* The delta could be too large for the physical timer to handle.*/ + if (deadline_delta > (sysinterval_t)TIME_MAX_SYSTIME) { + deadline_delta = (sysinterval_t)TIME_MAX_SYSTIME; + } +#endif + port_timer_set_alarm(chTimeAddX(ch.vtlist.lasttime, deadline_delta)); #endif /* CH_CFG_ST_TIMEDELTA > 0 */ } -- cgit v1.2.3