From 286deccd1280b0d66ccc6d9b2617719582607f0d Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 12 Oct 2017 08:37:47 +0000 Subject: EXPERIMENTAL: Introduced sysinterval_t in RT, now system time and intervals are different types and could have different sizes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rt5_dev_point1@10812 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/common/oslib/include/chbsem.h | 12 +- os/common/oslib/include/chfifo.h | 8 +- os/common/oslib/include/chmboxes.h | 12 +- os/common/oslib/include/chmempools.h | 4 +- os/common/oslib/src/chmboxes.c | 12 +- os/common/oslib/src/chmempools.c | 4 +- os/hal/osal/rt/osal.h | 4 +- os/rt/include/ch.h | 19 +- os/rt/include/chcond.h | 4 +- os/rt/include/chevents.h | 6 +- os/rt/include/chschd.h | 2 +- os/rt/include/chsem.h | 4 +- os/rt/include/chsystypes.h | 11 - os/rt/include/chthreads.h | 22 +- os/rt/include/chtime.h | 515 +++++++++++++++++++++++++++++++++++ os/rt/include/chvt.h | 277 ------------------- os/rt/src/chcond.c | 14 +- os/rt/src/chevents.c | 24 +- os/rt/src/chschd.c | 8 +- os/rt/src/chsem.c | 14 +- os/rt/src/chthreads.c | 17 +- 21 files changed, 614 insertions(+), 379 deletions(-) create mode 100644 os/rt/include/chtime.h (limited to 'os') diff --git a/os/common/oslib/include/chbsem.h b/os/common/oslib/include/chbsem.h index 3a6956017..bf77700d1 100644 --- a/os/common/oslib/include/chbsem.h +++ b/os/common/oslib/include/chbsem.h @@ -166,7 +166,7 @@ static inline msg_t chBSemWaitS(binary_semaphore_t *bsp) { * @brief Wait operation on the binary semaphore. * * @param[in] bsp pointer to a @p binary_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. @@ -182,18 +182,18 @@ static inline msg_t chBSemWaitS(binary_semaphore_t *bsp) { * @sclass */ static inline msg_t chBSemWaitTimeoutS(binary_semaphore_t *bsp, - systime_t time) { + sysinterval_t timeout) { chDbgCheckClassS(); - return chSemWaitTimeoutS(&bsp->sem, time); + return chSemWaitTimeoutS(&bsp->sem, timeout); } /** * @brief Wait operation on the binary semaphore. * * @param[in] bsp pointer to a @p binary_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. @@ -209,9 +209,9 @@ static inline msg_t chBSemWaitTimeoutS(binary_semaphore_t *bsp, * @api */ static inline msg_t chBSemWaitTimeout(binary_semaphore_t *bsp, - systime_t time) { + sysinterval_t timeout) { - return chSemWaitTimeout(&bsp->sem, time); + return chSemWaitTimeout(&bsp->sem, timeout); } /** diff --git a/os/common/oslib/include/chfifo.h b/os/common/oslib/include/chfifo.h index 1df57ef41..78ba16132 100644 --- a/os/common/oslib/include/chfifo.h +++ b/os/common/oslib/include/chfifo.h @@ -164,7 +164,7 @@ static inline void *chFifoTakeObjectI(objects_fifo_t *ofp) { * @sclass */ static inline void *chFifoTakeObjectTimeoutS(objects_fifo_t *ofp, - systime_t timeout) { + sysinterval_t timeout) { return chGuardedPoolAllocTimeoutS(&ofp->free, timeout); } @@ -185,7 +185,7 @@ static inline void *chFifoTakeObjectTimeoutS(objects_fifo_t *ofp, * @api */ static inline void *chFifoTakeObjectTimeout(objects_fifo_t *ofp, - systime_t timeout) { + sysinterval_t timeout) { return chGuardedPoolAllocTimeout(&ofp->free, timeout); } @@ -304,7 +304,7 @@ static inline msg_t chFifoReceiveObjectI(objects_fifo_t *ofp, */ static inline msg_t chFifoReceiveObjectTimeoutS(objects_fifo_t *ofp, void **objpp, - systime_t timeout) { + sysinterval_t timeout) { return chMBFetchTimeoutS(&ofp->mbx, (msg_t *)objpp, timeout); } @@ -327,7 +327,7 @@ static inline msg_t chFifoReceiveObjectTimeoutS(objects_fifo_t *ofp, */ static inline msg_t chFifoReceiveObjectTimeout(objects_fifo_t *ofp, void **objpp, - systime_t timeout) { + sysinterval_t timeout) { return chMBFetchTimeout(&ofp->mbx, (msg_t *)objpp, timeout); } diff --git a/os/common/oslib/include/chmboxes.h b/os/common/oslib/include/chmboxes.h index e6ffd7b82..2c9d09296 100644 --- a/os/common/oslib/include/chmboxes.h +++ b/os/common/oslib/include/chmboxes.h @@ -112,14 +112,14 @@ extern "C" { void chMBObjectInit(mailbox_t *mbp, msg_t *buf, size_t n); void chMBReset(mailbox_t *mbp); void chMBResetI(mailbox_t *mbp); - msg_t chMBPostTimeout(mailbox_t *mbp, msg_t msg, systime_t timeout); - msg_t chMBPostTimeoutS(mailbox_t *mbp, msg_t msg, systime_t timeout); + msg_t chMBPostTimeout(mailbox_t *mbp, msg_t msg, sysinterval_t timeout); + msg_t chMBPostTimeoutS(mailbox_t *mbp, msg_t msg, sysinterval_t timeout); msg_t chMBPostI(mailbox_t *mbp, msg_t msg); - msg_t chMBPostAheadTimeout(mailbox_t *mbp, msg_t msg, systime_t timeout); - msg_t chMBPostAheadTimeoutS(mailbox_t *mbp, msg_t msg, systime_t timeout); + msg_t chMBPostAheadTimeout(mailbox_t *mbp, msg_t msg, sysinterval_t timeout); + msg_t chMBPostAheadTimeoutS(mailbox_t *mbp, msg_t msg, sysinterval_t timeout); msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg); - msg_t chMBFetchTimeout(mailbox_t *mbp, msg_t *msgp, systime_t timeout); - msg_t chMBFetchTimeoutS(mailbox_t *mbp, msg_t *msgp, systime_t timeout); + msg_t chMBFetchTimeout(mailbox_t *mbp, msg_t *msgp, sysinterval_t timeout); + msg_t chMBFetchTimeoutS(mailbox_t *mbp, msg_t *msgp, sysinterval_t timeout); msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp); #ifdef __cplusplus } diff --git a/os/common/oslib/include/chmempools.h b/os/common/oslib/include/chmempools.h index 0e9773374..1923404b3 100644 --- a/os/common/oslib/include/chmempools.h +++ b/os/common/oslib/include/chmempools.h @@ -164,9 +164,9 @@ extern "C" { unsigned align); void chGuardedPoolLoadArray(guarded_memory_pool_t *gmp, void *p, size_t n); void *chGuardedPoolAllocTimeoutS(guarded_memory_pool_t *gmp, - systime_t timeout); + sysinterval_t timeout); void *chGuardedPoolAllocTimeout(guarded_memory_pool_t *gmp, - systime_t timeout); + sysinterval_t timeout); void chGuardedPoolFreeI(guarded_memory_pool_t *gmp, void *objp); void chGuardedPoolFree(guarded_memory_pool_t *gmp, void *objp); #endif diff --git a/os/common/oslib/src/chmboxes.c b/os/common/oslib/src/chmboxes.c index 5f2f9b6a3..48b5b4f01 100644 --- a/os/common/oslib/src/chmboxes.c +++ b/os/common/oslib/src/chmboxes.c @@ -162,7 +162,7 @@ void chMBResetI(mailbox_t *mbp) { * * @api */ -msg_t chMBPostTimeout(mailbox_t *mbp, msg_t msg, systime_t timeout) { +msg_t chMBPostTimeout(mailbox_t *mbp, msg_t msg, sysinterval_t timeout) { msg_t rdymsg; chSysLock(); @@ -191,7 +191,7 @@ msg_t chMBPostTimeout(mailbox_t *mbp, msg_t msg, systime_t timeout) { * * @sclass */ -msg_t chMBPostTimeoutS(mailbox_t *mbp, msg_t msg, systime_t timeout) { +msg_t chMBPostTimeoutS(mailbox_t *mbp, msg_t msg, sysinterval_t timeout) { msg_t rdymsg; chDbgCheckClassS(); @@ -287,7 +287,7 @@ msg_t chMBPostI(mailbox_t *mbp, msg_t msg) { * * @api */ -msg_t chMBPostAheadTimeout(mailbox_t *mbp, msg_t msg, systime_t timeout) { +msg_t chMBPostAheadTimeout(mailbox_t *mbp, msg_t msg, sysinterval_t timeout) { msg_t rdymsg; chSysLock(); @@ -316,7 +316,7 @@ msg_t chMBPostAheadTimeout(mailbox_t *mbp, msg_t msg, systime_t timeout) { * * @sclass */ -msg_t chMBPostAheadTimeoutS(mailbox_t *mbp, msg_t msg, systime_t timeout) { +msg_t chMBPostAheadTimeoutS(mailbox_t *mbp, msg_t msg, sysinterval_t timeout) { msg_t rdymsg; chDbgCheckClassS(); @@ -412,7 +412,7 @@ msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg) { * * @api */ -msg_t chMBFetchTimeout(mailbox_t *mbp, msg_t *msgp, systime_t timeout) { +msg_t chMBFetchTimeout(mailbox_t *mbp, msg_t *msgp, sysinterval_t timeout) { msg_t rdymsg; chSysLock(); @@ -441,7 +441,7 @@ msg_t chMBFetchTimeout(mailbox_t *mbp, msg_t *msgp, systime_t timeout) { * * @sclass */ -msg_t chMBFetchTimeoutS(mailbox_t *mbp, msg_t *msgp, systime_t timeout) { +msg_t chMBFetchTimeoutS(mailbox_t *mbp, msg_t *msgp, sysinterval_t timeout) { msg_t rdymsg; chDbgCheckClassS(); diff --git a/os/common/oslib/src/chmempools.c b/os/common/oslib/src/chmempools.c index aec47400c..5e23273f5 100644 --- a/os/common/oslib/src/chmempools.c +++ b/os/common/oslib/src/chmempools.c @@ -268,7 +268,7 @@ void chGuardedPoolLoadArray(guarded_memory_pool_t *gmp, void *p, size_t n) { * @sclass */ void *chGuardedPoolAllocTimeoutS(guarded_memory_pool_t *gmp, - systime_t timeout) { + sysinterval_t timeout) { msg_t msg; msg = chSemWaitTimeoutS(&gmp->sem, timeout); @@ -295,7 +295,7 @@ void *chGuardedPoolAllocTimeoutS(guarded_memory_pool_t *gmp, * @api */ void *chGuardedPoolAllocTimeout(guarded_memory_pool_t *gmp, - systime_t timeout) { + sysinterval_t timeout) { void *p; chSysLock(); diff --git a/os/hal/osal/rt/osal.h b/os/hal/osal/rt/osal.h index c99b4c92a..727cea623 100644 --- a/os/hal/osal/rt/osal.h +++ b/os/hal/osal/rt/osal.h @@ -321,7 +321,7 @@ typedef struct { * * @api */ -#define OSAL_MS2ST(msec) MS2ST(msec) +#define OSAL_MS2ST(msec) TIME_MS2I(msec) /** * @brief Microseconds to system ticks. @@ -333,7 +333,7 @@ typedef struct { * * @api */ -#define OSAL_US2ST(usec) US2ST(usec) +#define OSAL_US2ST(usec) TIME_US2I(usec) /** @} */ /** diff --git a/os/rt/include/ch.h b/os/rt/include/ch.h index e11a049ac..d3bd8217b 100644 --- a/os/rt/include/ch.h +++ b/os/rt/include/ch.h @@ -66,7 +66,7 @@ #define CH_KERNEL_PATCH 0 /** @} */ -/* Core headers.*/ +/* Configuration headers and checks.*/ #include "chtypes.h" #include "chconf.h" @@ -78,12 +78,23 @@ #error "obsolete or unknown configuration file" #endif +/* Early function prototypes required by the following headers.*/ +#ifdef __cplusplus +extern "C" { +#endif + void chSysHalt(const char *reason); +#ifdef __cplusplus +} +#endif + +/* Including everything else.*/ #include "chlicense.h" #include "chchecks.h" #include "chsystypes.h" +#include "chdebug.h" +#include "chtime.h" #include "chalign.h" #include "chcore.h" -#include "chdebug.h" #include "chtrace.h" #include "chtm.h" #include "chstats.h" @@ -108,10 +119,6 @@ #include "chfactory.h" #include "chdynamic.h" -#if !defined(_CHIBIOS_RT_CONF_) -#error "missing or wrong configuration file" -#endif - #endif /* CH_H */ /** @} */ diff --git a/os/rt/include/chcond.h b/os/rt/include/chcond.h index bf1e02cd5..9b753f274 100644 --- a/os/rt/include/chcond.h +++ b/os/rt/include/chcond.h @@ -98,8 +98,8 @@ extern "C" { msg_t chCondWait(condition_variable_t *cp); msg_t chCondWaitS(condition_variable_t *cp); #if CH_CFG_USE_CONDVARS_TIMEOUT == TRUE - msg_t chCondWaitTimeout(condition_variable_t *cp, systime_t time); - msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time); + msg_t chCondWaitTimeout(condition_variable_t *cp, sysinterval_t timeout); + msg_t chCondWaitTimeoutS(condition_variable_t *cp, sysinterval_t timeout); #endif #ifdef __cplusplus } diff --git a/os/rt/include/chevents.h b/os/rt/include/chevents.h index 8b14ed112..d155e0e6d 100644 --- a/os/rt/include/chevents.h +++ b/os/rt/include/chevents.h @@ -141,9 +141,9 @@ extern "C" { eventmask_t chEvtWaitAll(eventmask_t events); #endif #if CH_CFG_USE_EVENTS_TIMEOUT == TRUE - eventmask_t chEvtWaitOneTimeout(eventmask_t events, systime_t time); - eventmask_t chEvtWaitAnyTimeout(eventmask_t events, systime_t time); - eventmask_t chEvtWaitAllTimeout(eventmask_t events, systime_t time); + eventmask_t chEvtWaitOneTimeout(eventmask_t events, sysinterval_t timeout); + eventmask_t chEvtWaitAnyTimeout(eventmask_t events, sysinterval_t timeout); + eventmask_t chEvtWaitAllTimeout(eventmask_t events, sysinterval_t timeout); #endif #ifdef __cplusplus } diff --git a/os/rt/include/chschd.h b/os/rt/include/chschd.h index 79ff437a1..7f25279a9 100644 --- a/os/rt/include/chschd.h +++ b/os/rt/include/chschd.h @@ -476,7 +476,7 @@ extern "C" { thread_t *chSchReadyI(thread_t *tp); thread_t *chSchReadyAheadI(thread_t *tp); void chSchGoSleepS(tstate_t newstate); - msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time); + msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout); void chSchWakeupS(thread_t *ntp, msg_t msg); void chSchRescheduleS(void); bool chSchIsPreemptionRequired(void); diff --git a/os/rt/include/chsem.h b/os/rt/include/chsem.h index ef2848b16..d8958eeeb 100644 --- a/os/rt/include/chsem.h +++ b/os/rt/include/chsem.h @@ -93,8 +93,8 @@ extern "C" { void chSemResetI(semaphore_t *sp, cnt_t n); msg_t chSemWait(semaphore_t *sp); msg_t chSemWaitS(semaphore_t *sp); - msg_t chSemWaitTimeout(semaphore_t *sp, systime_t time); - msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time); + msg_t chSemWaitTimeout(semaphore_t *sp, sysinterval_t timeout); + msg_t chSemWaitTimeoutS(semaphore_t *sp, sysinterval_t timeout); void chSemSignal(semaphore_t *sp); void chSemSignalI(semaphore_t *sp); void chSemAddCounterI(semaphore_t *sp, cnt_t n); diff --git a/os/rt/include/chsystypes.h b/os/rt/include/chsystypes.h index 527ff2e8b..dac7d297b 100644 --- a/os/rt/include/chsystypes.h +++ b/os/rt/include/chsystypes.h @@ -44,17 +44,6 @@ /* Module data structures and types. */ /*===========================================================================*/ -/** - * @brief Type of system time. - */ -#if (CH_CFG_ST_RESOLUTION == 32) || defined(__DOXYGEN__) -typedef uint32_t systime_t; -#elif CH_CFG_ST_RESOLUTION == 16 -typedef uint16_t systime_t; -#else -#error "invalid CH_CFG_ST_RESOLUTION setting" -#endif - /** * @extends threads_queue_t * diff --git a/os/rt/include/chthreads.h b/os/rt/include/chthreads.h index 6ac40d3b8..ade7dc30b 100644 --- a/os/rt/include/chthreads.h +++ b/os/rt/include/chthreads.h @@ -190,7 +190,7 @@ typedef struct { * * @api */ -#define chThdSleepSeconds(sec) chThdSleep(S2ST(sec)) +#define chThdSleepSeconds(sec) chThdSleep(TIME_S2I(sec)) /** * @brief Delays the invoking thread for the specified number of @@ -206,7 +206,7 @@ typedef struct { * * @api */ -#define chThdSleepMilliseconds(msec) chThdSleep(MS2ST(msec)) +#define chThdSleepMilliseconds(msec) chThdSleep(TIME_MS2I(msec)) /** * @brief Delays the invoking thread for the specified number of @@ -222,7 +222,7 @@ typedef struct { * * @api */ -#define chThdSleepMicroseconds(usec) chThdSleep(US2ST(usec)) +#define chThdSleepMicroseconds(usec) chThdSleep(TIME_US2I(usec)) /** @} */ /*===========================================================================*/ @@ -255,14 +255,14 @@ extern "C" { tprio_t chThdSetPriority(tprio_t newprio); void chThdTerminate(thread_t *tp); msg_t chThdSuspendS(thread_reference_t *trp); - msg_t chThdSuspendTimeoutS(thread_reference_t *trp, systime_t timeout); + msg_t chThdSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout); void chThdResumeI(thread_reference_t *trp, msg_t msg); void chThdResumeS(thread_reference_t *trp, msg_t msg); void chThdResume(thread_reference_t *trp, msg_t msg); - msg_t chThdEnqueueTimeoutS(threads_queue_t *tqp, systime_t timeout); + msg_t chThdEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout); void chThdDequeueNextI(threads_queue_t *tqp, msg_t msg); void chThdDequeueAllI(threads_queue_t *tqp, msg_t msg); - void chThdSleep(systime_t time); + void chThdSleep(sysinterval_t time); void chThdSleepUntil(systime_t time); systime_t chThdSleepUntilWindowed(systime_t prev, systime_t next); void chThdYield(void); @@ -376,9 +376,9 @@ static inline thread_t *chThdStartI(thread_t *tp) { } /** - * @brief Suspends the invoking thread for the specified time. + * @brief Suspends the invoking thread for the specified number of ticks. * - * @param[in] time the delay in system ticks, the special values are + * @param[in] ticks the delay in system ticks, the special values are * handled as follow: * - @a TIME_INFINITE the thread enters an infinite sleep * state. @@ -387,11 +387,11 @@ static inline thread_t *chThdStartI(thread_t *tp) { * * @sclass */ -static inline void chThdSleepS(systime_t time) { +static inline void chThdSleepS(sysinterval_t ticks) { - chDbgCheck(time != TIME_IMMEDIATE); + chDbgCheck(ticks != TIME_IMMEDIATE); - (void) chSchGoSleepTimeoutS(CH_STATE_SLEEPING, time); + (void) chSchGoSleepTimeoutS(CH_STATE_SLEEPING, ticks); } /** diff --git a/os/rt/include/chtime.h b/os/rt/include/chtime.h new file mode 100644 index 000000000..5a09735eb --- /dev/null +++ b/os/rt/include/chtime.h @@ -0,0 +1,515 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file chtime.h + * @brief Time and intervals macros and structures. + * + * @addtogroup time_intervals + * @{ + */ + +#ifndef CHTIME_H +#define CHTIME_H + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +/** + * @name Special time constants + * @{ + */ +/** + * @brief Zero interval specification for some functions with a timeout + * specification. + * @note Not all functions accept @p TIME_IMMEDIATE as timeout parameter, + * see the specific function documentation. + */ +#define TIME_IMMEDIATE ((sysinterval_t)0) + +/** + * @brief Infinite interval specification for all functions with a timeout + * specification. + * @note Not all functions accept @p TIME_INFINITE as timeout parameter, + * see the specific function documentation. + */ +#define TIME_INFINITE ((sysinterval_t)-1) + +/** + * @brief Maximum interval constant usable as timeout. + */ +#define TIME_MAXIMUM ((sysinterval_t)-2) +/** @} */ + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/** + * @brief System time counter resolution. + * @note Allowed values are 16, 32 or 64 bits. + */ +#if !defined(CH_CFG_ST_RESOLUTION) || defined(__DOXYGEN__) +#define CH_CFG_ST_RESOLUTION 32 +#endif + +/** + * @brief System tick frequency. + * @details Frequency of the system timer that drives the system ticks. This + * setting also defines the system tick time unit. + */ +#if !defined(CH_CFG_ST_FREQUENCY) || defined(__DOXYGEN__) +#define CH_CFG_ST_FREQUENCY 1000 +#endif + +/** + * @brief Time intervals data size. + * @note Allowed values are 16, 32 or 64 bits. + */ +#if !defined(CH_CFG_INTERVALS_SIZE) || defined(__DOXYGEN__) +#define CH_CFG_INTERVALS_SIZE 32 +#endif + +/** + * @brief Time types data size. + * @note Allowed values are 16 or 32 bits. + */ +#if !defined(CH_CFG_TIME_TYPES_SIZE) || defined(__DOXYGEN__) +#define CH_CFG_TIME_TYPES_SIZE 32 +#endif + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +#if (CH_CFG_ST_RESOLUTION != 16) && (CH_CFG_ST_RESOLUTION != 32) && \ + (CH_CFG_ST_RESOLUTION != 64) +#error "invalid CH_CFG_ST_RESOLUTION specified, must be 16, 32 or 64" +#endif + +#if CH_CFG_ST_FREQUENCY < 10 +#error "invalid CH_CFG_ST_FREQUENCY specified, must be >= 10" +#endif + +#if (CH_CFG_INTERVALS_SIZE != 16) && (CH_CFG_INTERVALS_SIZE != 32) && \ + (CH_CFG_INTERVALS_SIZE != 64) +#error "invalid CH_CFG_INTERVALS_SIZE specified, must be 16, 32 or 64" +#endif + +#if (CH_CFG_TIME_TYPES_SIZE != 16) && (CH_CFG_TIME_TYPES_SIZE != 32) +#error "invalid CH_CFG_TIME_TYPES_SIZE specified, must be 16 or 32" +#endif + +#if CH_CFG_INTERVALS_SIZE < CH_CFG_ST_RESOLUTION +#error "CH_CFG_INTERVALS_SIZE must be >= CH_CFG_ST_RESOLUTION" +#endif + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ + +/** + * @brief Type of system time. + * @note It is selectable in configuration between 16, 32 or 64 bits + */ +#if (CH_CFG_ST_RESOLUTION == 64) || defined(__DOXYGEN__) +typedef uint64_t systime_t; +#elif CH_CFG_ST_RESOLUTION == 32 +typedef uint32_t systime_t; +#elif CH_CFG_ST_RESOLUTION == 16 +typedef uint16_t systime_t; +#endif + +/** + * @brief Type of time interval. + * @note It is selectable in configuration between 16, 32 or 64 bits + */ +#if (CH_CFG_ST_RESOLUTION == 64) || defined(__DOXYGEN__) +typedef uint64_t sysinterval_t; +#elif CH_CFG_ST_RESOLUTION == 32 +typedef uint32_t sysinterval_t; +#elif CH_CFG_ST_RESOLUTION == 16 +typedef uint16_t sysinterval_t; +#endif + +#if (CH_CFG_TIME_TYPES_SIZE == 32) || defined(__DOXYGEN__) +/** + * @brief Type of seconds. + * @note It is selectable in configuration between 16 or 32 bits + */ +typedef uint32_t time_secs_t; + +/** + * @brief Type of milliseconds. + * @note It is selectable in configuration between 16 or 32 bits + */ +typedef uint32_t time_msecs_t; + +/** + * @brief Type of microseconds. + * @note It is selectable in configuration between 16 or 32 bits + */ +typedef uint32_t time_usecs_t; + +/** + * @brief Type of time conversion variable. + * @note This type must have double width than other time types, it is + * only used internally for conversions. + */ +typedef uint64_t time_conv_t; + +#else +typedef uint16_t time_secs_t; +typedef uint16_t time_msecs_t; +typedef uint16_t time_usecs_t; +typedef uint32_t time_conv_t; +#endif + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + + +/** + * @name Fast time conversion utilities + * @{ + */ +/** + * @brief Seconds to time interval. + * @details Converts from seconds to system ticks number. + * @note The result is rounded upward to the next tick boundary. + * @note Use of this macro for large values is not secure because + * integer overflows, make sure your value can be correctly + * converted. + * + * @param[in] secs number of seconds + * @return The number of ticks. + * + * @api + */ +#define TIME_S2I(secs) \ + ((sysinterval_t)((time_conv_t)(secs) * (time_conv_t)CH_CFG_ST_FREQUENCY)) + +/** + * @brief Milliseconds to time interval. + * @details Converts from milliseconds to system ticks number. + * @note The result is rounded upward to the next tick boundary. + * @note Use of this macro for large values is not secure because + * integer overflows, make sure your value can be correctly + * converted. + * + * @param[in] msecs number of milliseconds + * @return The number of ticks. + * + * @api + */ +#define TIME_MS2I(msecs) \ + ((sysinterval_t)((((time_conv_t)(msecs) * \ + (time_conv_t)CH_CFG_ST_FREQUENCY) + \ + (time_conv_t)999) / (time_conv_t)1000)) + +/** + * @brief Microseconds to time interval. + * @details Converts from microseconds to system ticks number. + * @note The result is rounded upward to the next tick boundary. + * @note Use of this macro for large values is not secure because + * integer overflows, make sure your value can be correctly + * converted. + * + * @param[in] usecs number of microseconds + * @return The number of ticks. + * + * @api + */ +#define TIME_US2I(usecs) \ + ((sysinterval_t)((((time_conv_t)(usecs) * \ + (time_conv_t)CH_CFG_ST_FREQUENCY) + \ + (time_conv_t)999999) / (time_conv_t)1000000)) + +/** + * @brief Time interval to seconds. + * @details Converts from system ticks number to seconds. + * @note The result is rounded up to the next second boundary. + * @note Use of this macro for large values is not secure because + * integer overflows, make sure your value can be correctly + * converted. + * + * @param[in] interval interval in ticks + * @return The number of seconds. + * + * @api + */ +#define TIME_I2S(interval) \ + (time_secs_t)(((time_conv_t)(interval) + \ + (time_conv_t)CH_CFG_ST_FREQUENCY - \ + (time_conv_t)1) / (time_conv_t)CH_CFG_ST_FREQUENCY) + +/** + * @brief Time interval to milliseconds. + * @details Converts from system ticks number to milliseconds. + * @note The result is rounded up to the next millisecond boundary. + * @note Use of this macro for large values is not secure because + * integer overflows, make sure your value can be correctly + * converted. + * + * @param[in] interval interval in ticks + * @return The number of milliseconds. + * + * @api + */ +#define TIME_I2MS(interval) \ + (time_msecs_t)((((time_conv_t)(interval) * (time_conv_t)1000) + \ + (time_conv_t)CH_CFG_ST_FREQUENCY - (time_conv_t)1) / \ + (time_conv_t)CH_CFG_ST_FREQUENCY) + +/** + * @brief Time interval to microseconds. + * @details Converts from system ticks number to microseconds. + * @note The result is rounded up to the next microsecond boundary. + * @note Use of this macro for large values is not secure because + * integer overflows, make sure your value can be correctly + * converted. + * + * @param[in] interval interval in ticks + * @return The number of microseconds. + * + * @api + */ +#define TIME_I2US(interval) \ + (time_msecs_t)((((time_conv_t)(interval) * (time_conv_t)1000000) + \ + (time_conv_t)CH_CFG_ST_FREQUENCY - (time_conv_t)1) / \ + (time_conv_t)CH_CFG_ST_FREQUENCY) +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +/* + * Virtual Timers APIs. + */ +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +/** + * @name Secure time conversion utilities + * @{ + */ +/** + * @brief Seconds to time interval. + * @details Converts from seconds to system ticks number. + * @note The result is rounded upward to the next tick boundary. + * + * @param[in] sec number of seconds + * @return The number of ticks. + * + * @special + */ +static inline sysinterval_t chTimeS2I(time_secs_t secs) { + time_conv_t ticks; + + ticks = (time_conv_t)secs * (time_conv_t)CH_CFG_ST_FREQUENCY; + + chDbgAssert(ticks <= (time_conv_t)TIME_MAXIMUM, + "conversion overflow"); + + return (sysinterval_t)ticks; +} + +/** + * @brief Milliseconds to time interval. + * @details Converts from milliseconds to system ticks number. + * @note The result is rounded upward to the next tick boundary. + * + * @param[in] msec number of milliseconds + * @return The number of ticks. + * + * @special + */ +static inline sysinterval_t chTimeMS2I(time_msecs_t msec) { + time_conv_t ticks; + + ticks = (((time_conv_t)msec * (time_conv_t)CH_CFG_ST_FREQUENCY) + + (time_conv_t)999) / (time_conv_t)1000; + + chDbgAssert(ticks <= (time_conv_t)TIME_MAXIMUM, + "conversion overflow"); + + return (sysinterval_t)ticks; +} + +/** + * @brief Microseconds to time interval. + * @details Converts from microseconds to system ticks number. + * @note The result is rounded upward to the next tick boundary. + * + * @param[in] usec number of microseconds + * @return The number of ticks. + * + * @special + */ +static inline sysinterval_t chTimeUS2I(time_usecs_t usec) { + time_conv_t ticks; + + ticks = (((time_conv_t)usec * (time_conv_t)CH_CFG_ST_FREQUENCY) + + (time_conv_t)999999) / (time_conv_t)1000000; + + chDbgAssert(ticks <= (time_conv_t)TIME_MAXIMUM, + "conversion overflow"); + + return (sysinterval_t)ticks; +} + +/** + * @brief Time interval to seconds. + * @details Converts from system interval to seconds. + * @note The result is rounded up to the next second boundary. + * + * @param[in] interval interval in ticks + * @return The number of seconds. + * + * @special + */ +static inline time_secs_t chTimeI2S(sysinterval_t interval) { + time_conv_t secs; + + secs = ((time_conv_t)interval + + (time_conv_t)CH_CFG_ST_FREQUENCY - + (time_conv_t)1) / (time_conv_t)CH_CFG_ST_FREQUENCY; + + chDbgAssert(secs < (time_conv_t)((time_secs_t)-1), + "conversion overflow"); + + return (time_secs_t)secs; +} + +/** + * @brief Time interval to milliseconds. + * @details Converts from system interval to milliseconds. + * @note The result is rounded up to the next millisecond boundary. + * + * @param[in] interval interval in ticks + * @return The number of milliseconds. + * + * @special + */ +static inline time_msecs_t chTimeI2MS(sysinterval_t interval) { + time_conv_t msecs; + + msecs = (((time_conv_t)interval * (time_conv_t)1000) + + (time_conv_t)CH_CFG_ST_FREQUENCY - (time_conv_t)1) / + (time_conv_t)CH_CFG_ST_FREQUENCY; + + chDbgAssert(msecs < (time_conv_t)((time_msecs_t)-1), + "conversion overflow"); + + return (time_msecs_t)msecs; +} + +/** + * @brief Time interval to microseconds. + * @details Converts from system interval to microseconds. + * @note The result is rounded up to the next microsecond boundary. + * + * @param[in] interval interval in ticks + * @return The number of microseconds. + * + * @special + */ +static inline time_usecs_t chTimeI2US(sysinterval_t interval) { + time_conv_t usecs; + + usecs = (((time_conv_t)interval * (time_conv_t)1000000) + + (time_conv_t)CH_CFG_ST_FREQUENCY - (time_conv_t)1) / + (time_conv_t)CH_CFG_ST_FREQUENCY; + + chDbgAssert(usecs <= (time_conv_t)((time_usecs_t)-1), + "conversion overflow"); + + return (time_usecs_t)usecs; +} + +/** + * @brief Adds an interval to a system time returning a system time. + * + * @param[in] systime base system time + * @param[in] interval interval to be added + * @return The new system time. + * + * @xclass + */ +static inline systime_t chTimeAddX(systime_t systime, + sysinterval_t interval) { + + chDbgCheck(interval <= (sysinterval_t)((systime_t)-1)); + + return systime + (systime_t)interval; +} + +/** + * @brief Subtracts two system times returning an interval. + * + * @param[in] start first system time + * @param[in] end second system time + * @return The interval representing the time difference. + * + * @xclass + */ +static inline sysinterval_t chTimeSubtractX(systime_t start, + systime_t end) { + + return (sysinterval_t)(end - start); +} + + +/** + * @brief Checks if the specified time is within the specified time range. + * @note When start==end then the function returns always true because the + * whole time range is specified. + * + * @param[in] time the time to be verified + * @param[in] start the start of the time window (inclusive) + * @param[in] end the end of the time window (non inclusive) + * @retval true current time within the specified time window. + * @retval false current time not within the specified time window. + * + * @xclass + */ +static inline bool chTimeIsInRangeX(systime_t time, + systime_t start, + systime_t end) { + + return (bool)((systime_t)(time - start) < (systime_t)(end - start)); +} + +/** @} */ + +#endif /* CHTIME_H */ + +/** @} */ diff --git a/os/rt/include/chvt.h b/os/rt/include/chvt.h index dc08dbe07..92adaaf7b 100644 --- a/os/rt/include/chvt.h +++ b/os/rt/include/chvt.h @@ -32,37 +32,6 @@ /* Module constants. */ /*===========================================================================*/ -/** - * @name Special time constants - * @{ - */ -/** - * @brief Zero time specification for some functions with a timeout - * specification. - * @note Not all functions accept @p TIME_IMMEDIATE as timeout parameter, - * see the specific function documentation. - */ -#define TIME_IMMEDIATE ((systime_t)0) - -/** - * @brief Infinite time specification for all functions with a timeout - * specification. - * @note Not all functions accept @p TIME_INFINITE as timeout parameter, - * see the specific function documentation. - */ -#define TIME_INFINITE ((systime_t)-1) - -/** - * @brief Maximum time constant. - */ -#define TIME_MAXIMUM ((systime_t)-2) -/** @} */ - -/** - * @brief Maximum unsigned integer. - */ -#define __UINT_MAX ((unsigned int)-1) - /*===========================================================================*/ /* Module pre-compile time settings. */ /*===========================================================================*/ @@ -71,14 +40,6 @@ /* Derived constants and error checks. */ /*===========================================================================*/ -#if (CH_CFG_ST_RESOLUTION != 16) && (CH_CFG_ST_RESOLUTION != 32) -#error "invalid CH_CFG_ST_RESOLUTION specified, must be 16 or 32" -#endif - -#if CH_CFG_ST_FREQUENCY <= 0 -#error "invalid CH_CFG_ST_FREQUENCY specified, must be greater than zero" -#endif - #if (CH_CFG_ST_TIMEDELTA < 0) || (CH_CFG_ST_TIMEDELTA == 1) #error "invalid CH_CFG_ST_TIMEDELTA specified, must " \ "be zero or greater than one" @@ -100,108 +61,6 @@ /* Module macros. */ /*===========================================================================*/ -/** - * @name Fast time conversion utilities - * @{ - */ -/** - * @brief Seconds to system ticks. - * @details Converts from seconds to system ticks number. - * @note The result is rounded upward to the next tick boundary. - * @note Use of this macro for large values is not secure because - * integer overflows, make sure your value can be correctly - * converted. - * - * @param[in] sec number of seconds - * @return The number of ticks. - * - * @api - */ -#define S2ST(sec) \ - ((systime_t)((uint32_t)(sec) * (uint32_t)CH_CFG_ST_FREQUENCY)) - -/** - * @brief Milliseconds to system ticks. - * @details Converts from milliseconds to system ticks number. - * @note The result is rounded upward to the next tick boundary. - * @note Use of this macro for large values is not secure because - * integer overflows, make sure your value can be correctly - * converted. - * - * @param[in] msec number of milliseconds - * @return The number of ticks. - * - * @api - */ -#define MS2ST(msec) \ - ((systime_t)(((((uint32_t)(msec)) * \ - ((uint32_t)CH_CFG_ST_FREQUENCY)) + 999UL) / 1000UL)) - -/** - * @brief Microseconds to system ticks. - * @details Converts from microseconds to system ticks number. - * @note The result is rounded upward to the next tick boundary. - * @note Use of this macro for large values is not secure because - * integer overflows, make sure your value can be correctly - * converted. - * - * @param[in] usec number of microseconds - * @return The number of ticks. - * - * @api - */ -#define US2ST(usec) \ - ((systime_t)(((((uint32_t)(usec)) * \ - ((uint32_t)CH_CFG_ST_FREQUENCY)) + 999999UL) / 1000000UL)) - -/** - * @brief System ticks to seconds. - * @details Converts from system ticks number to seconds. - * @note The result is rounded up to the next second boundary. - * @note Use of this macro for large values is not secure because - * integer overflows, make sure your value can be correctly - * converted. - * - * @param[in] n number of system ticks - * @return The number of seconds. - * - * @api - */ -#define ST2S(n) (((n) + CH_CFG_ST_FREQUENCY - 1UL) / CH_CFG_ST_FREQUENCY) - -/** - * @brief System ticks to milliseconds. - * @details Converts from system ticks number to milliseconds. - * @note The result is rounded up to the next millisecond boundary. - * @note Use of this macro for large values is not secure because - * integer overflows, make sure your value can be correctly - * converted. - * - * @param[in] n number of system ticks - * @return The number of milliseconds. - * - * @api - */ -#define ST2MS(n) (((n) * 1000UL + CH_CFG_ST_FREQUENCY - 1UL) / \ - CH_CFG_ST_FREQUENCY) - -/** - * @brief System ticks to microseconds. - * @details Converts from system ticks number to microseconds. - * @note The result is rounded up to the next microsecond boundary. - * @note Use of this macro for large values is not secure because - * integer overflows, make sure your value can be correctly - * converted. - * - * @param[in] n number of system ticks - * @return The number of microseconds. - * - * @api - */ -#define ST2US(n) (((n) * 1000000UL + CH_CFG_ST_FREQUENCY - 1UL) / \ - CH_CFG_ST_FREQUENCY) -/** @} */ - /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ @@ -224,142 +83,6 @@ extern "C" { /* Module inline functions. */ /*===========================================================================*/ -/** - * @name Secure time conversion utilities - * @{ - */ -/** - * @brief Seconds to system ticks. - * @details Converts from seconds to system ticks number. - * @note The result is rounded upward to the next tick boundary. - * @note This function uses a 64 bits internal representation, - * use with non-constant parameters can lead to inefficient - * code because 64 bits arithmetic would be used at runtime. - * - * @param[in] sec number of seconds - * @return The number of ticks. - * - * @api - */ -static inline systime_t LL_S2ST(unsigned int sec) { - uint64_t ticks = (uint64_t)sec * (uint64_t)CH_CFG_ST_FREQUENCY; - - chDbgAssert(ticks <= (uint64_t)TIME_MAXIMUM, "conversion overflow"); - - return (systime_t)ticks; -} - -/** - * @brief Milliseconds to system ticks. - * @details Converts from milliseconds to system ticks number. - * @note The result is rounded upward to the next tick boundary. - * @note This function uses a 64 bits internal representation, - * use with non-constant parameters can lead to inefficient - * code because 64 bits arithmetic would be used at runtime. - * - * @param[in] msec number of milliseconds - * @return The number of ticks. - * - * @api - */ -static inline systime_t LL_MS2ST(unsigned int msec) { - uint64_t ticks = (((uint64_t)msec * (uint64_t)CH_CFG_ST_FREQUENCY) + 999ULL) - / 1000ULL; - - chDbgAssert(ticks <= (uint64_t)TIME_MAXIMUM, "conversion overflow"); - - return (systime_t)ticks; -} - -/** - * @brief Microseconds to system ticks. - * @details Converts from microseconds to system ticks number. - * @note The result is rounded upward to the next tick boundary. - * @note This function uses a 64 bits internal representation, - * use with non-constant parameters can lead to inefficient - * code because 64 bits arithmetic would be used at runtime. - * - * @param[in] usec number of microseconds - * @return The number of ticks. - * - * @api - */ -static inline systime_t LL_US2ST(unsigned int usec) { - uint64_t ticks = (((uint64_t)usec * (uint64_t)CH_CFG_ST_FREQUENCY) + 999999ULL) - / 1000000ULL; - - chDbgAssert(ticks <= (uint64_t)TIME_MAXIMUM, "conversion overflow"); - - return (systime_t)ticks; -} - -/** - * @brief System ticks to seconds. - * @details Converts from system ticks number to seconds. - * @note The result is rounded up to the next second boundary. - * @note This function uses a 64 bits internal representation, - * use with non-constant parameters can lead to inefficient - * code because 64 bits arithmetic would be used at runtime. - * - * @param[in] n number of system ticks - * @return The number of seconds. - * - * @api - */ -static inline unsigned int LL_ST2S(systime_t n) { - uint64_t sec = ((uint64_t)n + (uint64_t)CH_CFG_ST_FREQUENCY - 1ULL) - / (uint64_t)CH_CFG_ST_FREQUENCY; - - chDbgAssert(sec < (uint64_t)__UINT_MAX, "conversion overflow"); - - return (unsigned int)sec; -} - -/** - * @brief System ticks to milliseconds. - * @details Converts from system ticks number to milliseconds. - * @note The result is rounded up to the next millisecond boundary. - * @note This function uses a 64 bits internal representation, - * use with non-constant parameters can lead to inefficient - * code because 64 bits arithmetic would be used at runtime. - * - * @param[in] n number of system ticks - * @return The number of milliseconds. - * - * @api - */ -static inline unsigned int LL_ST2MS(systime_t n) { - uint64_t msec = (((uint64_t)n * 1000ULL) + (uint64_t)CH_CFG_ST_FREQUENCY - 1ULL) - / (uint64_t)CH_CFG_ST_FREQUENCY; - - chDbgAssert(msec < (uint64_t)__UINT_MAX, "conversion overflow"); - - return (unsigned int)msec; -} - -/** - * @brief System ticks to microseconds. - * @details Converts from system ticks number to microseconds. - * @note The result is rounded up to the next microsecond boundary. - * @note This function uses a 64 bits internal representation, - * use with non-constant parameters can lead to inefficient - * code because 64 bits arithmetic would be used at runtime. - * - * @param[in] n number of system ticks - * @return The number of microseconds. - * - * @api - */ -static inline unsigned int LL_ST2US(systime_t n) { - uint64_t usec = (((uint64_t)n * 1000000ULL) + (uint64_t)CH_CFG_ST_FREQUENCY - 1ULL) - / (uint64_t)CH_CFG_ST_FREQUENCY; - - chDbgAssert(usec < (uint64_t)__UINT_MAX, "conversion overflow"); - - return (unsigned int)usec; -} -/** @} */ - /** * @brief Initializes a @p virtual_timer_t object. * @note Initializing a timer object is not strictly required because 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..b462df09f 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 = chTimeSubtractX(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(chTimeSubtractX(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; -- cgit v1.2.3