ChibiOS/RT  6.0.3
Time and Intervals
Collaboration diagram for Time and Intervals:

Detailed Description

This module is responsible for handling of system time and time intervals.

Special time constants

#define TIME_IMMEDIATE   ((sysinterval_t)0)
 Zero interval specification for some functions with a timeout specification. More...
 
#define TIME_INFINITE   ((sysinterval_t)-1)
 Infinite interval specification for all functions with a timeout specification. More...
 
#define TIME_MAX_INTERVAL   ((sysinterval_t)-2)
 Maximum interval constant usable as timeout. More...
 
#define TIME_MAX_SYSTIME   ((systime_t)-1)
 Maximum system of system time before it wraps. More...
 

Fast time conversion utilities

#define TIME_S2I(secs)   ((sysinterval_t)((time_conv_t)(secs) * (time_conv_t)CH_CFG_ST_FREQUENCY))
 Seconds to time interval. More...
 
#define TIME_MS2I(msecs)
 Milliseconds to time interval. More...
 
#define TIME_US2I(usecs)
 Microseconds to time interval. More...
 
#define TIME_I2S(interval)
 Time interval to seconds. More...
 
#define TIME_I2MS(interval)
 Time interval to milliseconds. More...
 
#define TIME_I2US(interval)
 Time interval to microseconds. More...
 

Secure time conversion utilities

static sysinterval_t chTimeS2I (time_secs_t secs)
 Seconds to time interval. More...
 
static sysinterval_t chTimeMS2I (time_msecs_t msec)
 Milliseconds to time interval. More...
 
static sysinterval_t chTimeUS2I (time_usecs_t usec)
 Microseconds to time interval. More...
 
static time_secs_t chTimeI2S (sysinterval_t interval)
 Time interval to seconds. More...
 
static time_msecs_t chTimeI2MS (sysinterval_t interval)
 Time interval to milliseconds. More...
 
static time_usecs_t chTimeI2US (sysinterval_t interval)
 Time interval to microseconds. More...
 
static systime_t chTimeAddX (systime_t systime, sysinterval_t interval)
 Adds an interval to a system time returning a system time. More...
 
static sysinterval_t chTimeDiffX (systime_t start, systime_t end)
 Subtracts two system times returning an interval. More...
 
static bool chTimeIsInRangeX (systime_t time, systime_t start, systime_t end)
 Checks if the specified time is within the specified time range. More...
 

Typedefs

typedef uint64_t systime_t
 Type of system time. More...
 
typedef uint64_t sysinterval_t
 Type of time interval. More...
 
typedef uint32_t time_secs_t
 Type of seconds. More...
 
typedef uint32_t time_msecs_t
 Type of milliseconds. More...
 
typedef uint32_t time_usecs_t
 Type of microseconds. More...
 
typedef uint64_t time_conv_t
 Type of time conversion variable. More...
 

Macro Definition Documentation

#define TIME_IMMEDIATE   ((sysinterval_t)0)

Zero interval specification for some functions with a timeout specification.

Note
Not all functions accept TIME_IMMEDIATE as timeout parameter, see the specific function documentation.

Definition at line 47 of file chtime.h.

Referenced by chCondWaitTimeoutS(), chEvtWaitAllTimeout(), chEvtWaitAnyTimeout(), chEvtWaitOneTimeout(), chFifoSendObject(), chFifoSendObjectAhead(), chFifoSendObjectAheadS(), chFifoSendObjectS(), chSemWaitTimeoutS(), chThdEnqueueTimeoutS(), chThdSleepS(), chThdSuspendTimeoutS(), and chVTDoSetI().

#define TIME_INFINITE   ((sysinterval_t)-1)

Infinite interval specification for all functions with a timeout specification.

Note
Not all functions accept TIME_INFINITE as timeout parameter, see the specific function documentation.

Definition at line 55 of file chtime.h.

Referenced by chSchGoSleepTimeoutS().

#define TIME_MAX_INTERVAL   ((sysinterval_t)-2)

Maximum interval constant usable as timeout.

Definition at line 60 of file chtime.h.

Referenced by chTimeMS2I(), chTimeS2I(), and chTimeUS2I().

#define TIME_MAX_SYSTIME   ((systime_t)-1)

Maximum system of system time before it wraps.

Definition at line 65 of file chtime.h.

Referenced by chTimeAddX(), chVTDoResetI(), chVTDoSetI(), and chVTDoTickI().

#define TIME_S2I (   secs)    ((sysinterval_t)((time_conv_t)(secs) * (time_conv_t)CH_CFG_ST_FREQUENCY))

Seconds to time interval.

Converts from seconds to system ticks number.

Note
The result is rounded upward to the next tick boundary.
Use of this macro for large values is not secure because integer overflows, make sure your value can be correctly converted.
Parameters
[in]secsnumber of seconds
Returns
The number of ticks.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 180 of file chtime.h.

#define TIME_MS2I (   msecs)
Value:
((sysinterval_t)((((time_conv_t)(msecs) * \
(time_conv_t)999) / (time_conv_t)1000))
uint64_t sysinterval_t
Type of time interval.
Definition: chtime.h:119
uint64_t time_conv_t
Type of time conversion variable.
Definition: chtime.h:150
#define CH_CFG_ST_FREQUENCY
System tick frequency.
Definition: chconf.h:55

Milliseconds to time interval.

Converts from milliseconds to system ticks number.

Note
The result is rounded upward to the next tick boundary.
Use of this macro for large values is not secure because integer overflows, make sure your value can be correctly converted.
Parameters
[in]msecsnumber of milliseconds
Returns
The number of ticks.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 196 of file chtime.h.

#define TIME_US2I (   usecs)
Value:
((sysinterval_t)((((time_conv_t)(usecs) * \
(time_conv_t)999999) / (time_conv_t)1000000))
uint64_t sysinterval_t
Type of time interval.
Definition: chtime.h:119
uint64_t time_conv_t
Type of time conversion variable.
Definition: chtime.h:150
#define CH_CFG_ST_FREQUENCY
System tick frequency.
Definition: chconf.h:55

Microseconds to time interval.

Converts from microseconds to system ticks number.

Note
The result is rounded upward to the next tick boundary.
Use of this macro for large values is not secure because integer overflows, make sure your value can be correctly converted.
Parameters
[in]usecsnumber of microseconds
Returns
The number of ticks.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 214 of file chtime.h.

#define TIME_I2S (   interval)
Value:
(time_secs_t)(((time_conv_t)(interval) + \
uint32_t time_secs_t
Type of seconds.
Definition: chtime.h:131
uint64_t time_conv_t
Type of time conversion variable.
Definition: chtime.h:150
#define CH_CFG_ST_FREQUENCY
System tick frequency.
Definition: chconf.h:55

Time interval to seconds.

Converts from system ticks number to seconds.

Note
The result is rounded up to the next second boundary.
Use of this macro for large values is not secure because integer overflows, make sure your value can be correctly converted.
Parameters
[in]intervalinterval in ticks
Returns
The number of seconds.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 232 of file chtime.h.

#define TIME_I2MS (   interval)
Value:
(time_msecs_t)((((time_conv_t)(interval) * (time_conv_t)1000) + \
uint64_t time_conv_t
Type of time conversion variable.
Definition: chtime.h:150
uint32_t time_msecs_t
Type of milliseconds.
Definition: chtime.h:137
#define CH_CFG_ST_FREQUENCY
System tick frequency.
Definition: chconf.h:55

Time interval to milliseconds.

Converts from system ticks number to milliseconds.

Note
The result is rounded up to the next millisecond boundary.
Use of this macro for large values is not secure because integer overflows, make sure your value can be correctly converted.
Parameters
[in]intervalinterval in ticks
Returns
The number of milliseconds.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 250 of file chtime.h.

#define TIME_I2US (   interval)
Value:
(time_msecs_t)((((time_conv_t)(interval) * (time_conv_t)1000000) + \
uint64_t time_conv_t
Type of time conversion variable.
Definition: chtime.h:150
uint32_t time_msecs_t
Type of milliseconds.
Definition: chtime.h:137
#define CH_CFG_ST_FREQUENCY
System tick frequency.
Definition: chconf.h:55

Time interval to microseconds.

Converts from system ticks number to microseconds.

Note
The result is rounded up to the next microsecond boundary.
Use of this macro for large values is not secure because integer overflows, make sure your value can be correctly converted.
Parameters
[in]intervalinterval in ticks
Returns
The number of microseconds.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 268 of file chtime.h.

Typedef Documentation

typedef uint64_t systime_t

Type of system time.

Note
It is selectable in configuration between 16, 32 or 64 bits.

Definition at line 107 of file chtime.h.

typedef uint64_t sysinterval_t

Type of time interval.

Note
It is selectable in configuration between 16, 32 or 64 bits.

Definition at line 119 of file chtime.h.

typedef uint32_t time_secs_t

Type of seconds.

Note
It is selectable in configuration between 16 or 32 bits.

Definition at line 131 of file chtime.h.

typedef uint32_t time_msecs_t

Type of milliseconds.

Note
It is selectable in configuration between 16 or 32 bits.

Definition at line 137 of file chtime.h.

typedef uint32_t time_usecs_t

Type of microseconds.

Note
It is selectable in configuration between 16 or 32 bits.

Definition at line 143 of file chtime.h.

typedef uint64_t time_conv_t

Type of time conversion variable.

Note
This type must have double width than other time types, it is only used internally for conversions.

Definition at line 150 of file chtime.h.

Function Documentation

static sysinterval_t chTimeS2I ( time_secs_t  secs)
inlinestatic

Seconds to time interval.

Converts from seconds to system ticks number.

Note
The result is rounded upward to the next tick boundary.
Parameters
[in]secsnumber of seconds
Returns
The number of ticks.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 307 of file chtime.h.

References CH_CFG_ST_FREQUENCY, chDbgAssert, and TIME_MAX_INTERVAL.

static sysinterval_t chTimeMS2I ( time_msecs_t  msec)
inlinestatic

Milliseconds to time interval.

Converts from milliseconds to system ticks number.

Note
The result is rounded upward to the next tick boundary.
Parameters
[in]msecnumber of milliseconds
Returns
The number of ticks.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 328 of file chtime.h.

References CH_CFG_ST_FREQUENCY, chDbgAssert, and TIME_MAX_INTERVAL.

static sysinterval_t chTimeUS2I ( time_usecs_t  usec)
inlinestatic

Microseconds to time interval.

Converts from microseconds to system ticks number.

Note
The result is rounded upward to the next tick boundary.
Parameters
[in]usecnumber of microseconds
Returns
The number of ticks.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 350 of file chtime.h.

References CH_CFG_ST_FREQUENCY, chDbgAssert, and TIME_MAX_INTERVAL.

static time_secs_t chTimeI2S ( sysinterval_t  interval)
inlinestatic

Time interval to seconds.

Converts from system interval to seconds.

Note
The result is rounded up to the next second boundary.
Parameters
[in]intervalinterval in ticks
Returns
The number of seconds.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 372 of file chtime.h.

References CH_CFG_ST_FREQUENCY, and chDbgAssert.

static time_msecs_t chTimeI2MS ( sysinterval_t  interval)
inlinestatic

Time interval to milliseconds.

Converts from system interval to milliseconds.

Note
The result is rounded up to the next millisecond boundary.
Parameters
[in]intervalinterval in ticks
Returns
The number of milliseconds.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 395 of file chtime.h.

References CH_CFG_ST_FREQUENCY, and chDbgAssert.

static time_usecs_t chTimeI2US ( sysinterval_t  interval)
inlinestatic

Time interval to microseconds.

Converts from system interval to microseconds.

Note
The result is rounded up to the next microsecond boundary.
Parameters
[in]intervalinterval in ticks
Returns
The number of microseconds.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 418 of file chtime.h.

References CH_CFG_ST_FREQUENCY, and chDbgAssert.

static systime_t chTimeAddX ( systime_t  systime,
sysinterval_t  interval 
)
inlinestatic

Adds an interval to a system time returning a system time.

Parameters
[in]systimebase system time
[in]intervalinterval to be added
Returns
The new system time.
Function Class:
This is an X-Class API, this function can be invoked from any context.

Definition at line 440 of file chtime.h.

References chDbgCheck, and TIME_MAX_SYSTIME.

Referenced by chVTDoResetI(), chVTDoSetI(), and chVTDoTickI().

static sysinterval_t chTimeDiffX ( systime_t  start,
systime_t  end 
)
inlinestatic

Subtracts two system times returning an interval.

Parameters
[in]startfirst system time
[in]endsecond system time
Returns
The interval representing the time difference.
Function Class:
This is an X-Class API, this function can be invoked from any context.

Definition at line 459 of file chtime.h.

Referenced by chThdSleepUntil(), chThdSleepUntilWindowed(), chVTDoResetI(), chVTDoSetI(), chVTDoTickI(), chVTGetTimersStateI(), and chVTTimeElapsedSinceX().

static bool chTimeIsInRangeX ( systime_t  time,
systime_t  start,
systime_t  end 
)
inlinestatic

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.
Parameters
[in]timethe time to be verified
[in]startthe start of the time window (inclusive)
[in]endthe end of the time window (non inclusive)
Return values
truecurrent time within the specified time window.
falsecurrent time not within the specified time window.
Function Class:
This is an X-Class API, this function can be invoked from any context.

Definition at line 480 of file chtime.h.

Referenced by chThdSleepUntilWindowed(), chVTIsSystemTimeWithin(), and chVTIsSystemTimeWithinX().