Reintegrated RT5 point1 branch.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10833 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
Giovanni Di Sirio 2017-10-16 09:31:32 +00:00
commit 6bbfd2126f
45 changed files with 944 additions and 586 deletions

View File

@ -5,7 +5,7 @@
# Compiler options here.
ifeq ($(USE_OPT),)
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
USE_OPT = -O0 -ggdb -fomit-frame-pointer -falign-functions=16
endif
# C specific options here (added to USE_OPT).
@ -103,7 +103,7 @@ include $(CHIBIOS)/os/hal/osal/rt/osal.mk
include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
# Other files (optional).
include $(CHIBIOS)/test/rt/test.mk
#include $(CHIBIOS)/test/rt/test.mk
# Define linker script file here
LDSCRIPT= $(STARTUPLD)/STM32F746xG.ld

View File

@ -42,14 +42,26 @@
* @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.
* @details Frequency of the system timer that drives the system ticks. This
* setting also defines the system tick time unit.
*/
#define CH_CFG_ST_FREQUENCY 10000
#define CH_CFG_ST_FREQUENCY 100000
/**
* @brief Time intervals data size.
* @note Allowed values are 16, 32 or 64 bits.
*/
#define CH_CFG_INTERVALS_SIZE 32
/**
* @brief Time types data size.
* @note Allowed values are 16 or 32 bits.
*/
#define CH_CFG_TIME_TYPES_SIZE 32
/**
* @brief Time delta constant for the tick-less mode.

View File

@ -33,7 +33,7 @@
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList/&gt;"/>
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;delta-next-vtlist-null-_idle_thread.lto_priv.25-(format)&quot; val=&quot;4&quot;/&gt;&lt;/contentList&gt;"/>
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;globalVariableList/&gt;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;memoryBlockExpressionList&gt;&#10;&lt;memoryBlockExpressionItem&gt;&#10;&lt;expression text=&quot;0x0&quot;/&gt;&#10;&lt;/memoryBlockExpressionItem&gt;&#10;&lt;/memoryBlockExpressionList&gt;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>

View File

@ -33,7 +33,7 @@
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;vt_delta-null-chVTDoSetI-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;r3-(format)&quot; val=&quot;4&quot;/&gt;&lt;/contentList&gt;"/>
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;r3-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;vt_delta-null-chVTDoSetI-(format)&quot; val=&quot;4&quot;/&gt;&lt;/contentList&gt;"/>
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;globalVariableList/&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList/&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>

View File

@ -16,7 +16,7 @@
#include "ch.h"
#include "hal.h"
#include "ch_test.h"
//#include "ch_test.h"
/*
* This is a periodic thread that does absolutely nothing except flashing
@ -29,9 +29,9 @@ static THD_FUNCTION(Thread1, arg) {
chRegSetThreadName("blinker");
while (true) {
palSetLine(LINE_ARD_D13);
chThdSleepMilliseconds(500);
chThdSleepMilliseconds(1000);
palClearLine(LINE_ARD_D13);
chThdSleepMilliseconds(500);
chThdSleepMilliseconds(1000);
}
}
@ -64,15 +64,15 @@ int main(void) {
/*
* Creates the example thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+1, Thread1, NULL);
/*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and check the button state.
*/
while (true) {
if (palReadLine(LINE_BUTTON_USER))
test_execute((BaseSequentialStream *)&SD1);
chThdSleepMilliseconds(500);
// if (palReadLine(LINE_BUTTON_USER))
// test_execute((BaseSequentialStream *)&SD1);
chThdSleepMilliseconds(2000);
}
}

View File

@ -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);
}
/**

View File

@ -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);
}

View File

@ -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
}

View File

@ -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

View File

@ -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();

View File

@ -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();

View File

@ -284,14 +284,14 @@ extern "C" {
uint8_t *ibqGetEmptyBufferI(input_buffers_queue_t *ibqp);
void ibqPostFullBufferI(input_buffers_queue_t *ibqp, size_t size);
msg_t ibqGetFullBufferTimeout(input_buffers_queue_t *ibqp,
systime_t timeout);
sysinterval_t timeout);
msg_t ibqGetFullBufferTimeoutS(input_buffers_queue_t *ibqp,
systime_t timeout);
sysinterval_t timeout);
void ibqReleaseEmptyBuffer(input_buffers_queue_t *ibqp);
void ibqReleaseEmptyBufferS(input_buffers_queue_t *ibqp);
msg_t ibqGetTimeout(input_buffers_queue_t *ibqp, systime_t timeout);
msg_t ibqGetTimeout(input_buffers_queue_t *ibqp, sysinterval_t timeout);
size_t ibqReadTimeout(input_buffers_queue_t *ibqp, uint8_t *bp,
size_t n, systime_t timeout);
size_t n, sysinterval_t timeout);
void obqObjectInit(output_buffers_queue_t *obqp, bool suspended, uint8_t *bp,
size_t size, size_t n, bqnotify_t onfy, void *link);
void obqResetI(output_buffers_queue_t *obqp);
@ -299,15 +299,15 @@ extern "C" {
size_t *sizep);
void obqReleaseEmptyBufferI(output_buffers_queue_t *obqp);
msg_t obqGetEmptyBufferTimeout(output_buffers_queue_t *obqp,
systime_t timeout);
sysinterval_t timeout);
msg_t obqGetEmptyBufferTimeoutS(output_buffers_queue_t *obqp,
systime_t timeout);
sysinterval_t timeout);
void obqPostFullBuffer(output_buffers_queue_t *obqp, size_t size);
void obqPostFullBufferS(output_buffers_queue_t *obqp, size_t size);
msg_t obqPutTimeout(output_buffers_queue_t *obqp, uint8_t b,
systime_t timeout);
sysinterval_t timeout);
size_t obqWriteTimeout(output_buffers_queue_t *obqp, const uint8_t *bp,
size_t n, systime_t timeout);
size_t n, sysinterval_t timeout);
bool obqTryFlushI(output_buffers_queue_t *obqp);
void obqFlush(output_buffers_queue_t *obqp);
#ifdef __cplusplus

View File

@ -152,11 +152,11 @@ extern "C" {
msg_t canTransmitTimeout(CANDriver *canp,
canmbx_t mailbox,
const CANTxFrame *ctfp,
systime_t timeout);
sysinterval_t timeout);
msg_t canReceiveTimeout(CANDriver *canp,
canmbx_t mailbox,
CANRxFrame *crfp,
systime_t timeout);
sysinterval_t timeout);
#if CAN_USE_SLEEP_MODE
void canSleep(CANDriver *canp);
void canWakeup(CANDriver *canp);

View File

@ -51,14 +51,15 @@
#define _base_channel_methods \
_base_sequential_stream_methods \
/* Channel put method with timeout specification.*/ \
msg_t (*putt)(void *instance, uint8_t b, systime_t time); \
msg_t (*putt)(void *instance, uint8_t b, sysinterval_t time); \
/* Channel get method with timeout specification.*/ \
msg_t (*gett)(void *instance, systime_t time); \
msg_t (*gett)(void *instance, sysinterval_t time); \
/* Channel write method with timeout specification.*/ \
size_t (*writet)(void *instance, const uint8_t *bp, \
size_t n, systime_t time); \
size_t n, sysinterval_t time); \
/* Channel read method with timeout specification.*/ \
size_t (*readt)(void *instance, uint8_t *bp, size_t n, systime_t time); \
size_t (*readt)(void *instance, uint8_t *bp, size_t n, \
sysinterval_t time); \
/* Channel put method with timeout specification.*/ \
msg_t (*ctl)(void *instance, unsigned int operation, void *arg);

View File

@ -145,11 +145,11 @@ extern "C" {
i2caddr_t addr,
const uint8_t *txbuf, size_t txbytes,
uint8_t *rxbuf, size_t rxbytes,
systime_t timeout);
sysinterval_t timeout);
msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp,
i2caddr_t addr,
uint8_t *rxbuf, size_t rxbytes,
systime_t timeout);
sysinterval_t timeout);
#if I2C_USE_MUTUAL_EXCLUSION == TRUE
void i2cAcquireBus(I2CDriver *i2cp);
void i2cReleaseBus(I2CDriver *i2cp);

View File

@ -184,11 +184,11 @@ extern "C" {
void macSetAddress(MACDriver *macp, const uint8_t *p);
msg_t macWaitTransmitDescriptor(MACDriver *macp,
MACTransmitDescriptor *tdp,
systime_t timeout);
sysinterval_t timeout);
void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp);
msg_t macWaitReceiveDescriptor(MACDriver *macp,
MACReceiveDescriptor *rdp,
systime_t timeout);
sysinterval_t timeout);
void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp);
bool macPollLinkStatus(MACDriver *macp);
#ifdef __cplusplus

View File

@ -1006,8 +1006,9 @@ extern "C" {
void palSetLineCallbackI(ioline_t line, palcallback_t cb, void *arg);
#endif /* PAL_USE_CALLBACKS */
#if PAL_USE_WAIT || defined(__DOXYGEN__)
msg_t palWaitPadTimeoutS(ioportid_t port, iopadid_t pad, systime_t timeout);
msg_t palWaitLineTimeoutS(ioline_t line, systime_t timeout);
msg_t palWaitPadTimeoutS(ioportid_t port, iopadid_t pad,
sysinterval_t timeout);
msg_t palWaitLineTimeoutS(ioline_t line, sysinterval_t timeout);
#endif /* PAL_USE_WAIT */
#ifdef __cplusplus
}

View File

@ -278,17 +278,17 @@ extern "C" {
qnotify_t infy, void *link);
void iqResetI(input_queue_t *iqp);
msg_t iqPutI(input_queue_t *iqp, uint8_t b);
msg_t iqGetTimeout(input_queue_t *iqp, systime_t timeout);
msg_t iqGetTimeout(input_queue_t *iqp, sysinterval_t timeout);
size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp,
size_t n, systime_t timeout);
size_t n, sysinterval_t timeout);
void oqObjectInit(output_queue_t *oqp, uint8_t *bp, size_t size,
qnotify_t onfy, void *link);
void oqResetI(output_queue_t *oqp);
msg_t oqPutTimeout(output_queue_t *oqp, uint8_t b, systime_t timeout);
msg_t oqPutTimeout(output_queue_t *oqp, uint8_t b, sysinterval_t timeout);
msg_t oqGetI(output_queue_t *oqp);
size_t oqWriteTimeout(output_queue_t *oqp, const uint8_t *bp,
size_t n, systime_t timeout);
size_t n, sysinterval_t timeout);
#ifdef __cplusplus
}
#endif

View File

@ -359,11 +359,11 @@ extern "C" {
size_t uartStopReceiveI(UARTDriver *uartp);
#if UART_USE_WAIT == TRUE
msg_t uartSendTimeout(UARTDriver *uartp, size_t *np,
const void *txbuf, systime_t timeout);
const void *txbuf, sysinterval_t timeout);
msg_t uartSendFullTimeout(UARTDriver *uartp, size_t *np,
const void *txbuf, systime_t timeout);
const void *txbuf, sysinterval_t timeout);
msg_t uartReceiveTimeout(UARTDriver *uartp, size_t *np,
void *rxbuf, systime_t timeout);
void *rxbuf, sysinterval_t timeout);
#endif
#if UART_USE_MUTUAL_EXCLUSION == TRUE
void uartAcquireBus(UARTDriver *uartp);

View File

@ -875,8 +875,9 @@ static inline void osalEventBroadcastFlags(event_source_t *esp,
osalDbgCheck(esp != NULL);
chSysLock();
osalEventBroadcastFlagsI(esp, flags);
chSchRescheduleS();
esp->flags |= flags;
if (esp->cb != NULL) {
esp->cb(esp);
chSysUnlock();
}

View File

@ -67,8 +67,8 @@
* @name Special time constants
* @{
*/
#define TIME_IMMEDIATE ((systime_t)0)
#define TIME_INFINITE ((systime_t)-1)
#define TIME_IMMEDIATE ((sysinterval_t)0)
#define TIME_INFINITE ((sysinterval_t)-1)
/** @} */
#endif
@ -148,6 +148,13 @@ typedef int32_t msg_t;
typedef uint32_t systime_t;
#endif
#if 0
/**
* @brief Type of system time counter.
*/
typedef uint32_t sysinterval_t;
#endif
#if 0
/**
* @brief Type of realtime counter.
@ -179,14 +186,15 @@ typedef uint32_t eventflags_t;
* API and are implementation-dependent.
*/
typedef struct {
volatile eventflags_t flags; /**< @brief Flags stored into the
object. */
volatile eventflags_t flags; /**< @brief Stored event flags. */
eventcallback_t cb; /**< @brief Event source callback. */
void *param; /**< @brief User defined field. */
} event_source_t;
#endif
/**
* @brief Type of a mutex.
* @note If the OS does not support mutexes or there is no OS then them
* @note If the OS does not support mutexes or there is no OS then the
* mechanism can be simulated.
*/
#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__)
@ -304,36 +312,36 @@ typedef struct {
* @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
* @param[in] secs number of seconds
* @return The number of ticks.
*
* @api
*/
#define OSAL_S2ST(sec) S2ST(sec)
#define OSAL_S2I(secs) TIME_S2I(secs)
/**
* @brief Milliseconds to system ticks.
* @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
* @param[in] msecs number of milliseconds
* @return The number of ticks.
*
* @api
*/
#define OSAL_MS2ST(msec) MS2ST(msec)
#define OSAL_MS2I(msecs) TIME_MS2I(msecs)
/**
* @brief Microseconds to system ticks.
* @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
* @param[in] usecs number of microseconds
* @return The number of ticks.
*
* @api
*/
#define OSAL_US2ST(usec) US2ST(usec)
#define OSAL_US2I(usecs) TIME_US2I(usecs)
/** @} */
/**
@ -392,11 +400,11 @@ typedef struct {
* system tick clock.
* @note The maximum specifiable value is implementation dependent.
*
* @param[in] sec time in seconds, must be different from zero
* @param[in] secs time in seconds, must be different from zero
*
* @api
*/
#define osalThreadSleepSeconds(sec) osalThreadSleep(OSAL_S2ST(sec))
#define osalThreadSleepSeconds(secs) osalThreadSleep(OSAL_S2I(secs))
/**
* @brief Delays the invoking thread for the specified number of
@ -405,11 +413,11 @@ typedef struct {
* system tick clock.
* @note The maximum specifiable value is implementation dependent.
*
* @param[in] msec time in milliseconds, must be different from zero
* @param[in] msecs time in milliseconds, must be different from zero
*
* @api
*/
#define osalThreadSleepMilliseconds(msec) osalThreadSleep(OSAL_MS2ST(msec))
#define osalThreadSleepMilliseconds(msecs) osalThreadSleep(OSAL_MS2I(msecs))
/**
* @brief Delays the invoking thread for the specified number of
@ -418,11 +426,11 @@ typedef struct {
* system tick clock.
* @note The maximum specifiable value is implementation dependent.
*
* @param[in] usec time in microseconds, must be different from zero
* @param[in] usecs time in microseconds, must be different from zero
*
* @api
*/
#define osalThreadSleepMicroseconds(usec) osalThreadSleep(OSAL_US2ST(usec))
#define osalThreadSleepMicroseconds(usecs) osalThreadSleep(OSAL_US2I(usecs))
/** @} */
/*===========================================================================*/
@ -618,6 +626,35 @@ static inline systime_t osalOsGetSystemTimeX(void) {
return chVTGetSystemTimeX();
}
/**
* @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 osalTimeAddX(systime_t systime,
sysinterval_t interval) {
return chTimeAddX(systime, 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 osalTimeDiffX(systime_t start, systime_t end) {
return chTimeDiffX(start, end);
}
/**
* @brief Checks if the specified time is within the specified time window.
* @note When start==end then the function returns always true because the
@ -632,17 +669,17 @@ static inline systime_t osalOsGetSystemTimeX(void) {
*
* @xclass
*/
static inline bool osalOsIsTimeWithinX(systime_t time,
systime_t start,
systime_t end) {
static inline bool osalTimeIsInRangeX(systime_t time,
systime_t start,
systime_t end) {
return chVTIsTimeWithinX(time, start, end);
return chTimeIsInRangeX(time, start, end);
}
/**
* @brief Suspends the invoking thread for the specified time.
*
* @param[in] time the delay in system ticks, the special values are
* @param[in] delay the delay in system ticks, the special values are
* handled as follow:
* - @a TIME_INFINITE is allowed but interpreted as a
* normal time specification.
@ -651,15 +688,15 @@ static inline bool osalOsIsTimeWithinX(systime_t time,
*
* @sclass
*/
static inline void osalThreadSleepS(systime_t time) {
static inline void osalThreadSleepS(sysinterval_t delay) {
chThdSleepS(time);
chThdSleepS(delay);
}
/**
* @brief Suspends the invoking thread for the specified time.
*
* @param[in] time the delay in system ticks, the special values are
* @param[in] delay the delay in system ticks, the special values are
* handled as follow:
* - @a TIME_INFINITE is allowed but interpreted as a
* normal time specification.
@ -668,9 +705,9 @@ static inline void osalThreadSleepS(systime_t time) {
*
* @api
*/
static inline void osalThreadSleep(systime_t time) {
static inline void osalThreadSleep(sysinterval_t delay) {
chThdSleep(time);
chThdSleep(delay);
}
/**
@ -708,7 +745,7 @@ static inline msg_t osalThreadSuspendS(thread_reference_t *trp) {
* @sclass
*/
static inline msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp,
systime_t timeout) {
sysinterval_t timeout) {
return chThdSuspendTimeoutS(trp, timeout);
}
@ -761,7 +798,7 @@ static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) {
* dequeued or the specified timeouts expires.
*
* @param[in] tqp pointer to the threads queue object
* @param[in] time the timeout in system ticks, the special values are
* @param[in] timeout the timeout in system ticks, the special values are
* handled as follow:
* - @a TIME_INFINITE the thread enters an infinite sleep
* state.
@ -779,9 +816,9 @@ static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) {
* @sclass
*/
static inline msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp,
systime_t time) {
sysinterval_t timeout) {
return chThdEnqueueTimeoutS(tqp, time);
return chThdEnqueueTimeoutS(tqp, timeout);
}
/**
@ -823,9 +860,13 @@ static inline void osalEventObjectInit(event_source_t *esp) {
chEvtObjectInit(esp);
}
#else
static inline void osalEventObjectInit(event_source_t *esp) {
static inline void osalEventObjectInit(osal_event_source_t *esp) {
osalDbgCheck(esp != NULL);
esp->flags = 0;
esp->cb = NULL;
esp->param = NULL;
}
#endif
@ -847,7 +888,12 @@ static inline void osalEventBroadcastFlagsI(event_source_t *esp,
static inline void osalEventBroadcastFlagsI(event_source_t *esp,
eventflags_t flags) {
osalDbgCheck(esp != NULL);
esp->flags |= flags;
if (esp->cb != NULL) {
esp->cb(esp);
}
}
#endif
@ -868,12 +914,42 @@ static inline void osalEventBroadcastFlags(event_source_t *esp,
#else
static inline void osalEventBroadcastFlags(event_source_t *esp,
eventflags_t flags) {
osalDbgCheck(esp != NULL);
osalSysLock();
esp->flags |= flags;
if (esp->cb != NULL) {
esp->cb(esp);
osalSysUnlock();
}
#endif
#if !CH_CFG_USE_EVENTS || defined(__DOXYGEN__)
/**
* @brief Event callback setup.
* @note The callback is invoked from ISR context and can
* only invoke I-Class functions. The callback is meant
* to wakeup the task that will handle the event by
* calling @p osalEventGetAndClearFlagsI().
*
* @param[in] esp pointer to the event flags object
* @param[in] cb pointer to the callback function
* @param[in] param parameter to be passed to the callback function
*
* @api
*/
static inline void osalEventSetCallback(event_source_t *esp,
eventcallback_t cb,
void *param) {
osalDbgCheck(esp != NULL);
esp->cb = cb;
esp->param = param;
}
#endif
/**
* @brief Initializes s @p mutex_t object.
*

View File

@ -188,7 +188,7 @@ void ibqPostFullBufferI(input_buffers_queue_t *ibqp, size_t size) {
* @api
*/
msg_t ibqGetFullBufferTimeout(input_buffers_queue_t *ibqp,
systime_t timeout) {
sysinterval_t timeout) {
msg_t msg;
osalSysLock();
@ -220,7 +220,7 @@ msg_t ibqGetFullBufferTimeout(input_buffers_queue_t *ibqp,
* @sclass
*/
msg_t ibqGetFullBufferTimeoutS(input_buffers_queue_t *ibqp,
systime_t timeout) {
sysinterval_t timeout) {
osalDbgCheckClassS();
@ -306,7 +306,7 @@ void ibqReleaseEmptyBuffer(input_buffers_queue_t *ibqp) {
*
* @api
*/
msg_t ibqGetTimeout(input_buffers_queue_t *ibqp, systime_t timeout) {
msg_t ibqGetTimeout(input_buffers_queue_t *ibqp, sysinterval_t timeout) {
msg_t msg;
osalSysLock();
@ -356,9 +356,9 @@ msg_t ibqGetTimeout(input_buffers_queue_t *ibqp, systime_t timeout) {
* @api
*/
size_t ibqReadTimeout(input_buffers_queue_t *ibqp, uint8_t *bp,
size_t n, systime_t timeout) {
size_t n, sysinterval_t timeout) {
size_t r = 0;
systime_t deadline;
sysinterval_t deadline;
osalDbgCheck(n > 0U);
@ -380,7 +380,7 @@ size_t ibqReadTimeout(input_buffers_queue_t *ibqp, uint8_t *bp,
msg = ibqGetFullBufferTimeoutS(ibqp, timeout);
}
else {
systime_t next_timeout = deadline - osalOsGetSystemTimeX();
sysinterval_t next_timeout = deadline - osalOsGetSystemTimeX();
/* Handling the case where the system time went past the deadline,
in this case next becomes a very high number because the system
@ -562,7 +562,7 @@ void obqReleaseEmptyBufferI(output_buffers_queue_t *obqp) {
* @api
*/
msg_t obqGetEmptyBufferTimeout(output_buffers_queue_t *obqp,
systime_t timeout) {
sysinterval_t timeout) {
msg_t msg;
osalSysLock();
@ -594,7 +594,7 @@ msg_t obqGetEmptyBufferTimeout(output_buffers_queue_t *obqp,
* @sclass
*/
msg_t obqGetEmptyBufferTimeoutS(output_buffers_queue_t *obqp,
systime_t timeout) {
sysinterval_t timeout) {
osalDbgCheckClassS();
@ -688,7 +688,7 @@ void obqPostFullBufferS(output_buffers_queue_t *obqp, size_t size) {
* @api
*/
msg_t obqPutTimeout(output_buffers_queue_t *obqp, uint8_t b,
systime_t timeout) {
sysinterval_t timeout) {
msg_t msg;
osalSysLock();
@ -738,9 +738,9 @@ msg_t obqPutTimeout(output_buffers_queue_t *obqp, uint8_t b,
* @api
*/
size_t obqWriteTimeout(output_buffers_queue_t *obqp, const uint8_t *bp,
size_t n, systime_t timeout) {
size_t n, sysinterval_t timeout) {
size_t w = 0;
systime_t deadline;
sysinterval_t deadline;
osalDbgCheck(n > 0U);
@ -762,7 +762,7 @@ size_t obqWriteTimeout(output_buffers_queue_t *obqp, const uint8_t *bp,
msg = obqGetEmptyBufferTimeoutS(obqp, timeout);
}
else {
systime_t next_timeout = deadline - osalOsGetSystemTimeX();
sysinterval_t next_timeout = deadline - osalOsGetSystemTimeX();
/* Handling the case where the system time went past the deadline,
in this case next becomes a very high number because the system

View File

@ -233,7 +233,7 @@ bool canTryReceiveI(CANDriver *canp,
msg_t canTransmitTimeout(CANDriver *canp,
canmbx_t mailbox,
const CANTxFrame *ctfp,
systime_t timeout) {
sysinterval_t timeout) {
osalDbgCheck((canp != NULL) && (ctfp != NULL) &&
(mailbox <= (canmbx_t)CAN_TX_MAILBOXES));
@ -281,7 +281,7 @@ msg_t canTransmitTimeout(CANDriver *canp,
msg_t canReceiveTimeout(CANDriver *canp,
canmbx_t mailbox,
CANRxFrame *crfp,
systime_t timeout) {
sysinterval_t timeout) {
osalDbgCheck((canp != NULL) && (crfp != NULL) &&
(mailbox <= (canmbx_t)CAN_RX_MAILBOXES));

View File

@ -173,7 +173,7 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp,
size_t txbytes,
uint8_t *rxbuf,
size_t rxbytes,
systime_t timeout) {
sysinterval_t timeout) {
msg_t rdymsg;
osalDbgCheck((i2cp != NULL) && (addr != 0U) &&
@ -222,7 +222,7 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp,
i2caddr_t addr,
uint8_t *rxbuf,
size_t rxbytes,
systime_t timeout){
sysinterval_t timeout) {
msg_t rdymsg;

View File

@ -149,7 +149,7 @@ void macStop(MACDriver *macp) {
*/
msg_t macWaitTransmitDescriptor(MACDriver *macp,
MACTransmitDescriptor *tdp,
systime_t timeout) {
sysinterval_t timeout) {
msg_t msg;
systime_t now;
@ -157,7 +157,7 @@ msg_t macWaitTransmitDescriptor(MACDriver *macp,
osalDbgAssert(macp->state == MAC_ACTIVE, "not active");
while (((msg = mac_lld_get_transmit_descriptor(macp, tdp)) != MSG_OK) &&
(timeout > (systime_t)0)) {
(timeout > (sysinterval_t)0)) {
osalSysLock();
now = osalOsGetSystemTimeX();
msg = osalThreadEnqueueTimeoutS(&macp->tdqueue, timeout);
@ -209,7 +209,7 @@ void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) {
*/
msg_t macWaitReceiveDescriptor(MACDriver *macp,
MACReceiveDescriptor *rdp,
systime_t timeout) {
sysinterval_t timeout) {
msg_t msg;
systime_t now;
@ -217,7 +217,7 @@ msg_t macWaitReceiveDescriptor(MACDriver *macp,
osalDbgAssert(macp->state == MAC_ACTIVE, "not active");
while (((msg = mac_lld_get_receive_descriptor(macp, rdp)) != MSG_OK) &&
(timeout > (systime_t)0)) {
(timeout > (sysinterval_t)0)) {
osalSysLock();
now = osalOsGetSystemTimeX();
msg = osalThreadEnqueueTimeoutS(&macp->rdqueue, timeout);

View File

@ -167,7 +167,9 @@ void palSetLineCallbackI(ioline_t line, palcallback_t cb, void *arg) {
*
* @sclass
*/
msg_t palWaitPadTimeoutS(ioportid_t port, iopadid_t pad, systime_t timeout) {
msg_t palWaitPadTimeoutS(ioportid_t port,
iopadid_t pad,
sysinterval_t timeout) {
palevent_t *pep = pal_lld_get_pad_event(port, pad);
return osalThreadEnqueueTimeoutS(&pep->threads, timeout);
@ -186,7 +188,8 @@ msg_t palWaitPadTimeoutS(ioportid_t port, iopadid_t pad, systime_t timeout) {
*
* @sclass
*/
msg_t palWaitLineTimeoutS(ioline_t line, systime_t timeout) {
msg_t palWaitLineTimeoutS(ioline_t line,
sysinterval_t timeout) {
palevent_t *pep = pal_lld_get_line_event(line);
return osalThreadEnqueueTimeoutS(&pep->threads, timeout);

View File

@ -138,7 +138,7 @@ msg_t iqPutI(input_queue_t *iqp, uint8_t b) {
*
* @api
*/
msg_t iqGetTimeout(input_queue_t *iqp, systime_t timeout) {
msg_t iqGetTimeout(input_queue_t *iqp, sysinterval_t timeout) {
uint8_t b;
osalSysLock();
@ -194,7 +194,7 @@ msg_t iqGetTimeout(input_queue_t *iqp, systime_t timeout) {
* @api
*/
size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp,
size_t n, systime_t timeout) {
size_t n, sysinterval_t timeout) {
systime_t deadline;
qnotify_t nfy = iqp->q_notify;
size_t r = 0;
@ -206,7 +206,7 @@ size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp,
/* Time deadline for the whole operation, note the result is invalid
when timeout is TIME_INFINITE or TIME_IMMEDIATE but in that case
the deadline is not used.*/
deadline = osalOsGetSystemTimeX() + timeout;
deadline = osalTimeAddX(osalOsGetSystemTimeX(), timeout);
while (true) {
/* Waiting until there is a character available or a timeout occurs.*/
@ -219,7 +219,8 @@ size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp,
msg = osalThreadEnqueueTimeoutS(&iqp->q_waiting, timeout);
}
else {
systime_t next_timeout = deadline - osalOsGetSystemTimeX();
sysinterval_t next_timeout = osalTimeDiffX(osalOsGetSystemTimeX(),
deadline);
/* Handling the case where the system time went past the deadline,
in this case next becomes a very high number because the system
@ -334,7 +335,7 @@ void oqResetI(output_queue_t *oqp) {
*
* @api
*/
msg_t oqPutTimeout(output_queue_t *oqp, uint8_t b, systime_t timeout) {
msg_t oqPutTimeout(output_queue_t *oqp, uint8_t b, sysinterval_t timeout) {
osalSysLock();
@ -419,7 +420,7 @@ msg_t oqGetI(output_queue_t *oqp) {
* @api
*/
size_t oqWriteTimeout(output_queue_t *oqp, const uint8_t *bp,
size_t n, systime_t timeout) {
size_t n, sysinterval_t timeout) {
systime_t deadline;
qnotify_t nfy = oqp->q_notify;
size_t w = 0;
@ -431,7 +432,7 @@ size_t oqWriteTimeout(output_queue_t *oqp, const uint8_t *bp,
/* Time deadline for the whole operation, note the result is invalid
when timeout is TIME_INFINITE or TIME_IMMEDIATE but in that case
the deadline is not used.*/
deadline = osalOsGetSystemTimeX() + timeout;
deadline = osalTimeAddX(osalOsGetSystemTimeX(), timeout);
while (true) {
msg_t msg;
@ -443,7 +444,8 @@ size_t oqWriteTimeout(output_queue_t *oqp, const uint8_t *bp,
msg = osalThreadEnqueueTimeoutS(&oqp->q_waiting, timeout);
}
else {
systime_t next_timeout = deadline - osalOsGetSystemTimeX();
sysinterval_t next_timeout = osalTimeDiffX(osalOsGetSystemTimeX(),
deadline);
/* Handling the case where the system time went past the deadline,
in this case next becomes a very high number because the system

View File

@ -69,22 +69,24 @@ static msg_t _get(void *ip) {
return iqGetTimeout(&((SerialDriver *)ip)->iqueue, TIME_INFINITE);
}
static msg_t _putt(void *ip, uint8_t b, systime_t timeout) {
static msg_t _putt(void *ip, uint8_t b, sysinterval_t timeout) {
return oqPutTimeout(&((SerialDriver *)ip)->oqueue, b, timeout);
}
static msg_t _gett(void *ip, systime_t timeout) {
static msg_t _gett(void *ip, sysinterval_t timeout) {
return iqGetTimeout(&((SerialDriver *)ip)->iqueue, timeout);
}
static size_t _writet(void *ip, const uint8_t *bp, size_t n, systime_t timeout) {
static size_t _writet(void *ip, const uint8_t *bp, size_t n,
sysinterval_t timeout) {
return oqWriteTimeout(&((SerialDriver *)ip)->oqueue, bp, n, timeout);
}
static size_t _readt(void *ip, uint8_t *bp, size_t n, systime_t timeout) {
static size_t _readt(void *ip, uint8_t *bp, size_t n,
sysinterval_t timeout) {
return iqReadTimeout(&((SerialDriver *)ip)->iqueue, bp, n, timeout);
}

View File

@ -104,22 +104,24 @@ static msg_t _get(void *ip) {
return ibqGetTimeout(&((SerialUSBDriver *)ip)->ibqueue, TIME_INFINITE);
}
static msg_t _putt(void *ip, uint8_t b, systime_t timeout) {
static msg_t _putt(void *ip, uint8_t b, sysinterval_t timeout) {
return obqPutTimeout(&((SerialUSBDriver *)ip)->obqueue, b, timeout);
}
static msg_t _gett(void *ip, systime_t timeout) {
static msg_t _gett(void *ip, sysinterval_t timeout) {
return ibqGetTimeout(&((SerialUSBDriver *)ip)->ibqueue, timeout);
}
static size_t _writet(void *ip, const uint8_t *bp, size_t n, systime_t timeout) {
static size_t _writet(void *ip, const uint8_t *bp, size_t n,
sysinterval_t timeout) {
return obqWriteTimeout(&((SerialUSBDriver *)ip)->obqueue, bp, n, timeout);
}
static size_t _readt(void *ip, uint8_t *bp, size_t n, systime_t timeout) {
static size_t _readt(void *ip, uint8_t *bp, size_t n,
sysinterval_t timeout) {
return ibqReadTimeout(&((SerialUSBDriver *)ip)->ibqueue, bp, n, timeout);
}

View File

@ -367,7 +367,7 @@ size_t uartStopReceiveI(UARTDriver *uartp) {
* @api
*/
msg_t uartSendTimeout(UARTDriver *uartp, size_t *np,
const void *txbuf, systime_t timeout) {
const void *txbuf, sysinterval_t timeout) {
msg_t msg;
osalDbgCheck((uartp != NULL) && (*np > 0U) && (txbuf != NULL));
@ -412,7 +412,7 @@ msg_t uartSendTimeout(UARTDriver *uartp, size_t *np,
* @api
*/
msg_t uartSendFullTimeout(UARTDriver *uartp, size_t *np,
const void *txbuf, systime_t timeout) {
const void *txbuf, sysinterval_t timeout) {
msg_t msg;
osalDbgCheck((uartp != NULL) && (*np > 0U) && (txbuf != NULL));
@ -459,7 +459,7 @@ msg_t uartSendFullTimeout(UARTDriver *uartp, size_t *np,
* @api
*/
msg_t uartReceiveTimeout(UARTDriver *uartp, size_t *np,
void *rxbuf, systime_t timeout) {
void *rxbuf, sysinterval_t timeout) {
msg_t msg;
osalDbgCheck((uartp != NULL) && (*np > 0U) && (rxbuf != NULL));

View File

@ -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 */
/** @} */

View File

@ -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
}

View File

@ -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
}

View File

@ -325,7 +325,7 @@ struct ch_thread {
struct ch_virtual_timer {
virtual_timer_t *next; /**< @brief Next timer in the list. */
virtual_timer_t *prev; /**< @brief Previous timer in the list. */
systime_t delta; /**< @brief Time delta before timeout. */
sysinterval_t delta; /**< @brief Time delta before timeout. */
vtfunc_t func; /**< @brief Timer callback function
pointer. */
void *par; /**< @brief Timer callback function
@ -343,7 +343,7 @@ struct ch_virtual_timers_list {
list. */
virtual_timer_t *prev; /**< @brief Last timer in the delta
list. */
systime_t delta; /**< @brief Must be initialized to -1. */
sysinterval_t delta; /**< @brief Must be initialized to -1. */
#if (CH_CFG_ST_TIMEDELTA == 0) || defined(__DOXYGEN__)
volatile systime_t systime; /**< @brief System Time counter. */
#endif
@ -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);

View File

@ -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);

View File

@ -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
*

View File

@ -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);
}
/**

519
os/rt/include/chtime.h Normal file
View File

@ -0,0 +1,519 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
/**
* @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_MAX_INTERVAL ((sysinterval_t)-2)
/**
* @brief Maximum system of system time before it wraps.
*/
#define TIME_MAX_SYSTIME ((systime_t)-1)
/** @} */
/*===========================================================================*/
/* 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_INTERVALS_SIZE == 64) || defined(__DOXYGEN__)
typedef uint64_t sysinterval_t;
#elif CH_CFG_INTERVALS_SIZE == 32
typedef uint32_t sysinterval_t;
#elif CH_CFG_INTERVALS_SIZE == 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_MAX_INTERVAL,
"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_MAX_INTERVAL,
"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_MAX_INTERVAL,
"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 chTimeDiffX(systime_t start, systime_t end) {
return (sysinterval_t)((systime_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)((time - start) < (end - start));
}
/** @} */
#endif /* CHTIME_H */
/** @} */

View File

@ -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. */
/*===========================================================================*/
@ -213,7 +72,7 @@
extern "C" {
#endif
void _vt_init(void);
void chVTDoSetI(virtual_timer_t *vtp, systime_t delay,
void chVTDoSetI(virtual_timer_t *vtp, sysinterval_t delay,
vtfunc_t vtfunc, void *par);
void chVTDoResetI(virtual_timer_t *vtp);
#ifdef __cplusplus
@ -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
@ -426,30 +149,9 @@ static inline systime_t chVTGetSystemTime(void) {
*
* @xclass
*/
static inline systime_t chVTTimeElapsedSinceX(systime_t start) {
static inline sysinterval_t chVTTimeElapsedSinceX(systime_t start) {
return chVTGetSystemTimeX() - start;
}
/**
* @brief Checks if the specified time is within the specified time window.
* @note When start==end then the function returns always true because the
* whole time range is specified.
* @note This function can be called from any context.
*
* @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 chVTIsTimeWithinX(systime_t time,
systime_t start,
systime_t end) {
return (bool)((systime_t)(time - start) < (systime_t)(end - start));
return chTimeDiffX(chVTGetSystemTimeX(), start);
}
/**
@ -467,7 +169,7 @@ static inline bool chVTIsTimeWithinX(systime_t time,
*/
static inline bool chVTIsSystemTimeWithinX(systime_t start, systime_t end) {
return chVTIsTimeWithinX(chVTGetSystemTimeX(), start, end);
return chTimeIsInRangeX(chVTGetSystemTimeX(), start, end);
}
/**
@ -485,7 +187,7 @@ static inline bool chVTIsSystemTimeWithinX(systime_t start, systime_t end) {
*/
static inline bool chVTIsSystemTimeWithin(systime_t start, systime_t end) {
return chVTIsTimeWithinX(chVTGetSystemTime(), start, end);
return chTimeIsInRangeX(chVTGetSystemTime(), start, end);
}
/**
@ -504,7 +206,7 @@ static inline bool chVTIsSystemTimeWithin(systime_t start, systime_t end) {
*
* @iclass
*/
static inline bool chVTGetTimersStateI(systime_t *timep) {
static inline bool chVTGetTimersStateI(sysinterval_t *timep) {
chDbgCheckClassI();
@ -516,8 +218,10 @@ static inline bool chVTGetTimersStateI(systime_t *timep) {
#if CH_CFG_ST_TIMEDELTA == 0
*timep = ch.vtlist.next->delta;
#else
*timep = ch.vtlist.lasttime + ch.vtlist.next->delta +
CH_CFG_ST_TIMEDELTA - chVTGetSystemTimeX();
*timep = chTimeDiffX(chVTGetSystemTimeX(),
chTimeAddX(ch.vtlist.lasttime,
ch.vtlist.next->delta +
(sysinterval_t)CH_CFG_ST_TIMEDELTA));
#endif
}
@ -617,7 +321,7 @@ static inline void chVTReset(virtual_timer_t *vtp) {
*
* @iclass
*/
static inline void chVTSetI(virtual_timer_t *vtp, systime_t delay,
static inline void chVTSetI(virtual_timer_t *vtp, sysinterval_t delay,
vtfunc_t vtfunc, void *par) {
chVTResetI(vtp);
@ -646,7 +350,7 @@ static inline void chVTSetI(virtual_timer_t *vtp, systime_t delay,
*
* @api
*/
static inline void chVTSet(virtual_timer_t *vtp, systime_t delay,
static inline void chVTSet(virtual_timer_t *vtp, sysinterval_t delay,
vtfunc_t vtfunc, void *par) {
chSysLock();
@ -672,7 +376,7 @@ static inline void chVTDoTickI(void) {
if (&ch.vtlist != (virtual_timers_list_t *)ch.vtlist.next) {
/* The list is not empty, processing elements on top.*/
--ch.vtlist.next->delta;
while (ch.vtlist.next->delta == (systime_t)0) {
while (ch.vtlist.next->delta == (sysinterval_t)0) {
virtual_timer_t *vtp;
vtfunc_t fn;
@ -688,48 +392,51 @@ static inline void chVTDoTickI(void) {
}
#else /* CH_CFG_ST_TIMEDELTA > 0 */
virtual_timer_t *vtp;
systime_t now, delta;
systime_t now;
sysinterval_t delta, nowdelta;
/* First timer to be processed.*/
/* Looping through timers.*/
vtp = ch.vtlist.next;
now = chVTGetSystemTimeX();
while (true) {
/* All timers within the time window are triggered and removed,
note that the loop is stopped by the timers header having
"ch.vtlist.vt_delta == (systime_t)-1" which is greater than
all deltas.*/
while (vtp->delta <= (systime_t)(now - ch.vtlist.lasttime)) {
vtfunc_t fn;
/* Getting the system time as reference.*/
now = chVTGetSystemTimeX();
nowdelta = chTimeDiffX(ch.vtlist.lasttime, now);
/* The "last time" becomes this timer's expiration time.*/
ch.vtlist.lasttime += vtp->delta;
vtp->next->prev = (virtual_timer_t *)&ch.vtlist;
ch.vtlist.next = vtp->next;
fn = vtp->func;
vtp->func = NULL;
/* if the list becomes empty then the timer is stopped.*/
if (ch.vtlist.next == (virtual_timer_t *)&ch.vtlist) {
port_timer_stop_alarm();
/* The list scan is limited by the timers header having
"ch.vtlist.vt_delta == (sysinterval_t)-1" which is
greater than all deltas.*/
if (nowdelta < vtp->delta) {
break;
}
/* Leaving the system critical zone in order to execute the callback
and in order to give a preemption chance to higher priority
interrupts.*/
chSysUnlockFromISR();
/* Consuming all timers between "vtp->lasttime" and now.*/
do {
vtfunc_t fn;
/* The callback is invoked outside the kernel critical zone.*/
fn(vtp->par);
/* The "last time" becomes this timer's expiration time.*/
ch.vtlist.lasttime += vtp->delta;
nowdelta -= vtp->delta;
/* Re-entering the critical zone in order to continue the exploration
of the list.*/
chSysLockFromISR();
vtp->next->prev = (virtual_timer_t *)&ch.vtlist;
ch.vtlist.next = vtp->next;
fn = vtp->func;
vtp->func = NULL;
/* Next element in the list, the current time could have advanced so
recalculating the time window.*/
vtp = ch.vtlist.next;
now = chVTGetSystemTimeX();
/* 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.*/
chSysUnlockFromISR();
fn(vtp->par);
chSysLockFromISR();
/* Next element in the list.*/
vtp = ch.vtlist.next;
}
while (vtp->delta <= nowdelta);
}
/* if the list is empty, nothing else to do.*/
@ -737,15 +444,26 @@ static inline void chVTDoTickI(void) {
return;
}
/* Recalculating the next alarm time.*/
delta = ch.vtlist.lasttime + vtp->delta - now;
if (delta < (systime_t)CH_CFG_ST_TIMEDELTA) {
delta = (systime_t)CH_CFG_ST_TIMEDELTA;
}
port_timer_set_alarm(now + delta);
/* 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;
chDbgAssert((chVTGetSystemTimeX() - ch.vtlist.lasttime) <=
(now + delta - ch.vtlist.lasttime),
/* Recalculating the next alarm time.*/
delta = chTimeDiffX(now, chTimeAddX(ch.vtlist.lasttime, vtp->delta));
if (delta < (sysinterval_t)CH_CFG_ST_TIMEDELTA) {
delta = (sysinterval_t)CH_CFG_ST_TIMEDELTA;
}
#if CH_CFG_INTERVALS_SIZE > CH_CFG_ST_RESOLUTION
/* The delta could be too large for the physical timer to handle.*/
else if (delta > (sysinterval_t)TIME_MAX_SYSTIME) {
delta = (sysinterval_t)TIME_MAX_SYSTIME;
}
#endif
port_timer_set_alarm(chTimeAddX(now, delta));
chDbgAssert(chTimeDiffX(ch.vtlist.lasttime, chVTGetSystemTimeX()) <=
chTimeDiffX(ch.vtlist.lasttime, chTimeAddX(now, delta)),
"exceeding delta");
#endif /* CH_CFG_ST_TIMEDELTA > 0 */
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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 */
}