aboutsummaryrefslogtreecommitdiffstats
path: root/os/rt/src
diff options
context:
space:
mode:
Diffstat (limited to 'os/rt/src')
-rw-r--r--os/rt/src/chcond.c14
-rw-r--r--os/rt/src/chevents.c24
-rw-r--r--os/rt/src/chschd.c8
-rw-r--r--os/rt/src/chsem.c14
-rw-r--r--os/rt/src/chthreads.c17
-rw-r--r--os/rt/src/chvt.c62
6 files changed, 82 insertions, 57 deletions
diff --git a/os/rt/src/chcond.c b/os/rt/src/chcond.c
index cecd2d874..d11ae93bf 100644
--- a/os/rt/src/chcond.c
+++ b/os/rt/src/chcond.c
@@ -239,7 +239,7 @@ msg_t chCondWaitS(condition_variable_t *cp) {
* mutex, the mutex ownership is lost.
*
* @param[in] cp pointer to the @p condition_variable_t structure
- * @param[in] time the number of ticks before the operation timeouts, the
+ * @param[in] timeout the number of ticks before the operation timeouts, the
* special values are handled as follow:
* - @a TIME_INFINITE no timeout.
* - @a TIME_IMMEDIATE this value is not allowed.
@@ -255,11 +255,11 @@ msg_t chCondWaitS(condition_variable_t *cp) {
*
* @api
*/
-msg_t chCondWaitTimeout(condition_variable_t *cp, systime_t time) {
+msg_t chCondWaitTimeout(condition_variable_t *cp, sysinterval_t timeout) {
msg_t msg;
chSysLock();
- msg = chCondWaitTimeoutS(cp, time);
+ msg = chCondWaitTimeoutS(cp, timeout);
chSysUnlock();
return msg;
@@ -277,7 +277,7 @@ msg_t chCondWaitTimeout(condition_variable_t *cp, systime_t time) {
* mutex, the mutex ownership is lost.
*
* @param[in] cp pointer to the @p condition_variable_t structure
- * @param[in] time the number of ticks before the operation timeouts, the
+ * @param[in] timeout the number of ticks before the operation timeouts, the
* special values are handled as follow:
* - @a TIME_INFINITE no timeout.
* - @a TIME_IMMEDIATE this value is not allowed.
@@ -293,12 +293,12 @@ msg_t chCondWaitTimeout(condition_variable_t *cp, systime_t time) {
*
* @sclass
*/
-msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) {
+msg_t chCondWaitTimeoutS(condition_variable_t *cp, sysinterval_t timeout) {
mutex_t *mp;
msg_t msg;
chDbgCheckClassS();
- chDbgCheck((cp != NULL) && (time != TIME_IMMEDIATE));
+ chDbgCheck((cp != NULL) && (timeout != TIME_IMMEDIATE));
chDbgAssert(currp->mtxlist != NULL, "not owning a mutex");
/* Getting "current" mutex and releasing it.*/
@@ -309,7 +309,7 @@ msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) {
again.*/
currp->u.wtobjp = cp;
queue_prio_insert(currp, &cp->queue);
- msg = chSchGoSleepTimeoutS(CH_STATE_WTCOND, time);
+ msg = chSchGoSleepTimeoutS(CH_STATE_WTCOND, timeout);
if (msg != MSG_TIMEOUT) {
chMtxLockS(mp);
}
diff --git a/os/rt/src/chevents.c b/os/rt/src/chevents.c
index 63740d50b..a4338d70a 100644
--- a/os/rt/src/chevents.c
+++ b/os/rt/src/chevents.c
@@ -482,7 +482,7 @@ eventmask_t chEvtWaitAll(eventmask_t events) {
*
* @param[in] events events that the function should wait
* for, @p ALL_EVENTS enables all the events
- * @param[in] time the number of ticks before the operation timeouts,
+ * @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
@@ -492,19 +492,19 @@ eventmask_t chEvtWaitAll(eventmask_t events) {
*
* @api
*/
-eventmask_t chEvtWaitOneTimeout(eventmask_t events, systime_t time) {
+eventmask_t chEvtWaitOneTimeout(eventmask_t events, sysinterval_t timeout) {
thread_t *ctp = currp;
eventmask_t m;
chSysLock();
m = ctp->epending & events;
if (m == (eventmask_t)0) {
- if (TIME_IMMEDIATE == time) {
+ if (TIME_IMMEDIATE == timeout) {
chSysUnlock();
return (eventmask_t)0;
}
ctp->u.ewmask = events;
- if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, time) < MSG_OK) {
+ if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, timeout) < MSG_OK) {
chSysUnlock();
return (eventmask_t)0;
}
@@ -525,7 +525,7 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t events, systime_t time) {
*
* @param[in] events events that the function should wait
* for, @p ALL_EVENTS enables all the events
- * @param[in] time the number of ticks before the operation timeouts,
+ * @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
@@ -535,19 +535,19 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t events, systime_t time) {
*
* @api
*/
-eventmask_t chEvtWaitAnyTimeout(eventmask_t events, systime_t time) {
+eventmask_t chEvtWaitAnyTimeout(eventmask_t events, sysinterval_t timeout) {
thread_t *ctp = currp;
eventmask_t m;
chSysLock();
m = ctp->epending & events;
if (m == (eventmask_t)0) {
- if (TIME_IMMEDIATE == time) {
+ if (TIME_IMMEDIATE == timeout) {
chSysUnlock();
return (eventmask_t)0;
}
ctp->u.ewmask = events;
- if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, time) < MSG_OK) {
+ if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, timeout) < MSG_OK) {
chSysUnlock();
return (eventmask_t)0;
}
@@ -566,7 +566,7 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t events, systime_t time) {
*
* @param[in] events events that the function should wait
* for, @p ALL_EVENTS requires all the events
- * @param[in] time the number of ticks before the operation timeouts,
+ * @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
@@ -576,17 +576,17 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t events, systime_t time) {
*
* @api
*/
-eventmask_t chEvtWaitAllTimeout(eventmask_t events, systime_t time) {
+eventmask_t chEvtWaitAllTimeout(eventmask_t events, sysinterval_t timeout) {
thread_t *ctp = currp;
chSysLock();
if ((ctp->epending & events) != events) {
- if (TIME_IMMEDIATE == time) {
+ if (TIME_IMMEDIATE == timeout) {
chSysUnlock();
return (eventmask_t)0;
}
ctp->u.ewmask = events;
- if (chSchGoSleepTimeoutS(CH_STATE_WTANDEVT, time) < MSG_OK) {
+ if (chSchGoSleepTimeoutS(CH_STATE_WTANDEVT, timeout) < MSG_OK) {
chSysUnlock();
return (eventmask_t)0;
}
diff --git a/os/rt/src/chschd.c b/os/rt/src/chschd.c
index aed9aa8a7..d4bf1cafa 100644
--- a/os/rt/src/chschd.c
+++ b/os/rt/src/chschd.c
@@ -360,7 +360,7 @@ static void wakeup(void *p) {
* @ref thread_states are defined into @p threads.h.
*
* @param[in] newstate the new thread state
- * @param[in] time the number of ticks before the operation timeouts, the
+ * @param[in] timeout the number of ticks before the operation timeouts, the
* special values are handled as follow:
* - @a TIME_INFINITE the thread enters an infinite sleep
* state, this is equivalent to invoking
@@ -372,14 +372,14 @@ static void wakeup(void *p) {
*
* @sclass
*/
-msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) {
+msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout) {
chDbgCheckClassS();
- if (TIME_INFINITE != time) {
+ if (TIME_INFINITE != timeout) {
virtual_timer_t vt;
- chVTDoSetI(&vt, time, wakeup, currp);
+ chVTDoSetI(&vt, timeout, wakeup, currp);
chSchGoSleepS(newstate);
if (chVTIsArmedI(&vt)) {
chVTDoResetI(&vt);
diff --git a/os/rt/src/chsem.c b/os/rt/src/chsem.c
index 90df0dd73..c41ff4d78 100644
--- a/os/rt/src/chsem.c
+++ b/os/rt/src/chsem.c
@@ -217,7 +217,7 @@ msg_t chSemWaitS(semaphore_t *sp) {
* @brief Performs a wait operation on a semaphore with timeout specification.
*
* @param[in] sp pointer to a @p semaphore_t structure
- * @param[in] time the number of ticks before the operation timeouts,
+ * @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
@@ -232,11 +232,11 @@ msg_t chSemWaitS(semaphore_t *sp) {
*
* @api
*/
-msg_t chSemWaitTimeout(semaphore_t *sp, systime_t time) {
+msg_t chSemWaitTimeout(semaphore_t *sp, sysinterval_t timeout) {
msg_t msg;
chSysLock();
- msg = chSemWaitTimeoutS(sp, time);
+ msg = chSemWaitTimeoutS(sp, timeout);
chSysUnlock();
return msg;
@@ -246,7 +246,7 @@ msg_t chSemWaitTimeout(semaphore_t *sp, systime_t time) {
* @brief Performs a wait operation on a semaphore with timeout specification.
*
* @param[in] sp pointer to a @p semaphore_t structure
- * @param[in] time the number of ticks before the operation timeouts,
+ * @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
@@ -261,7 +261,7 @@ msg_t chSemWaitTimeout(semaphore_t *sp, systime_t time) {
*
* @sclass
*/
-msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) {
+msg_t chSemWaitTimeoutS(semaphore_t *sp, sysinterval_t timeout) {
chDbgCheckClassS();
chDbgCheck(sp != NULL);
@@ -270,7 +270,7 @@ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) {
"inconsistent semaphore");
if (--sp->cnt < (cnt_t)0) {
- if (TIME_IMMEDIATE == time) {
+ if (TIME_IMMEDIATE == timeout) {
sp->cnt++;
return MSG_TIMEOUT;
@@ -278,7 +278,7 @@ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) {
currp->u.wtsemp = sp;
sem_insert(currp, &sp->queue);
- return chSchGoSleepTimeoutS(CH_STATE_WTSEM, time);
+ return chSchGoSleepTimeoutS(CH_STATE_WTSEM, timeout);
}
return MSG_OK;
diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c
index 6ca99904b..49abadb2d 100644
--- a/os/rt/src/chthreads.c
+++ b/os/rt/src/chthreads.c
@@ -646,7 +646,7 @@ void chThdTerminate(thread_t *tp) {
*
* @api
*/
-void chThdSleep(systime_t time) {
+void chThdSleep(sysinterval_t time) {
chSysLock();
chThdSleepS(time);
@@ -667,11 +667,12 @@ void chThdSleep(systime_t time) {
* @api
*/
void chThdSleepUntil(systime_t time) {
+ sysinterval_t interval;
chSysLock();
- time -= chVTGetSystemTimeX();
- if (time > (systime_t)0) {
- chThdSleepS(time);
+ interval = chTimeDiffX(time, chVTGetSystemTimeX());
+ if (interval > (sysinterval_t)0) {
+ chThdSleepS(interval);
}
chSysUnlock();
}
@@ -695,8 +696,8 @@ systime_t chThdSleepUntilWindowed(systime_t prev, systime_t next) {
chSysLock();
time = chVTGetSystemTimeX();
- if (chVTIsTimeWithinX(time, prev, next)) {
- chThdSleepS(next - time);
+ if (chTimeIsInRangeX(time, prev, next)) {
+ chThdSleepS(chTimeDiffX(next, time));
}
chSysUnlock();
@@ -758,7 +759,7 @@ msg_t chThdSuspendS(thread_reference_t *trp) {
*
* @sclass
*/
-msg_t chThdSuspendTimeoutS(thread_reference_t *trp, systime_t timeout) {
+msg_t chThdSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout) {
thread_t *tp = chThdGetSelfX();
chDbgAssert(*trp == NULL, "not NULL");
@@ -858,7 +859,7 @@ void chThdResume(thread_reference_t *trp, msg_t msg) {
*
* @sclass
*/
-msg_t chThdEnqueueTimeoutS(threads_queue_t *tqp, systime_t timeout) {
+msg_t chThdEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout) {
if (TIME_IMMEDIATE == timeout) {
return MSG_TIMEOUT;
diff --git a/os/rt/src/chvt.c b/os/rt/src/chvt.c
index 51db54cc3..0667bf7c3 100644
--- a/os/rt/src/chvt.c
+++ b/os/rt/src/chvt.c
@@ -62,7 +62,7 @@ void _vt_init(void) {
ch.vtlist.next = (virtual_timer_t *)&ch.vtlist;
ch.vtlist.prev = (virtual_timer_t *)&ch.vtlist;
- ch.vtlist.delta = (systime_t)-1;
+ ch.vtlist.delta = (sysinterval_t)-1;
#if CH_CFG_ST_TIMEDELTA == 0
ch.vtlist.systime = (systime_t)0;
#else /* CH_CFG_ST_TIMEDELTA > 0 */
@@ -92,10 +92,10 @@ void _vt_init(void) {
*
* @iclass
*/
-void chVTDoSetI(virtual_timer_t *vtp, systime_t delay,
+void chVTDoSetI(virtual_timer_t *vtp, sysinterval_t delay,
vtfunc_t vtfunc, void *par) {
virtual_timer_t *p;
- systime_t delta;
+ sysinterval_t delta;
chDbgCheckClassI();
chDbgCheck((vtp != NULL) && (vtfunc != NULL) && (delay != TIME_IMMEDIATE));
@@ -109,8 +109,8 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay,
/* If the requested delay is lower than the minimum safe delta then it
is raised to the minimum safe value.*/
- if (delay < (systime_t)CH_CFG_ST_TIMEDELTA) {
- delay = (systime_t)CH_CFG_ST_TIMEDELTA;
+ if (delay < (sysinterval_t)CH_CFG_ST_TIMEDELTA) {
+ delay = (sysinterval_t)CH_CFG_ST_TIMEDELTA;
}
/* Special case where the timers list is empty.*/
@@ -125,8 +125,15 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay,
vtp->prev = (virtual_timer_t *)&ch.vtlist;
vtp->delta = delay;
+#if CH_CFG_INTERVALS_SIZE > CH_CFG_ST_RESOLUTION
+ /* The delta could be too large for the physical timer to handle.*/
+ if (delay > (sysinterval_t)TIME_MAX_SYSTIME) {
+ delay = (sysinterval_t)TIME_MAX_SYSTIME;
+ }
+#endif
+
/* Being the first element in the list the alarm timer is started.*/
- port_timer_start_alarm(ch.vtlist.lasttime + delay);
+ port_timer_start_alarm(chTimeAddX(ch.vtlist.lasttime, delay));
return;
}
@@ -136,9 +143,9 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay,
/* Delay as delta from 'lasttime'. Note, it can overflow and the value
becomes lower than 'now'.*/
- delta = now - ch.vtlist.lasttime + delay;
+ delta = chTimeDiffX(ch.vtlist.lasttime, now) + delay;
- if (delta < now - ch.vtlist.lasttime) {
+ if (delta < chTimeDiffX(ch.vtlist.lasttime, now)) {
/* Scenario where a very large delay excedeed the numeric range, it
requires a special handling. We need to skip the first element and
adjust the delta to wrap back in the previous numeric range.*/
@@ -146,9 +153,18 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_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(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 */
@@ -176,7 +192,7 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay,
/* Special case when the timer is in last position in the list, the
value in the header must be restored.*/;
p->delta -= delta;
- ch.vtlist.delta = (systime_t)-1;
+ ch.vtlist.delta = (sysinterval_t)-1;
}
/**
@@ -205,9 +221,9 @@ void chVTDoResetI(virtual_timer_t *vtp) {
/* The above code changes the value in the header when the removed element
is the last of the list, restoring it.*/
- ch.vtlist.delta = (systime_t)-1;
+ ch.vtlist.delta = (sysinterval_t)-1;
#else /* CH_CFG_ST_TIMEDELTA > 0 */
- systime_t nowdelta, delta;
+ sysinterval_t nowdelta, delta;
/* If the timer is not the first of the list then it is simply unlinked
else the operation is more complex.*/
@@ -246,7 +262,7 @@ void chVTDoResetI(virtual_timer_t *vtp) {
}*/
/* Distance in ticks between the last alarm event and current time.*/
- nowdelta = chVTGetSystemTimeX() - ch.vtlist.lasttime;
+ nowdelta = chTimeDiffX(ch.vtlist.lasttime, chVTGetSystemTimeX());
/* If the current time surpassed the time of the next element in list
then the event interrupt is already pending, just return.*/
@@ -259,11 +275,19 @@ void chVTDoResetI(virtual_timer_t *vtp) {
/* Making sure to not schedule an event closer than CH_CFG_ST_TIMEDELTA
ticks from now.*/
- if (delta < (systime_t)CH_CFG_ST_TIMEDELTA) {
- delta = (systime_t)CH_CFG_ST_TIMEDELTA;
+ if (delta < (sysinterval_t)CH_CFG_ST_TIMEDELTA) {
+ delta = nowdelta + (sysinterval_t)CH_CFG_ST_TIMEDELTA;
}
-
- port_timer_set_alarm(ch.vtlist.lasttime + nowdelta + delta);
+ else {
+ 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 (delta > (sysinterval_t)TIME_MAX_SYSTIME) {
+ delta = (sysinterval_t)TIME_MAX_SYSTIME;
+ }
+#endif
+ }
+ port_timer_set_alarm(chTimeAddX(ch.vtlist.lasttime, delta));
#endif /* CH_CFG_ST_TIMEDELTA > 0 */
}