ChibiOS/RT  6.0.3
Collaboration diagram for Virtual Timers:

Detailed Description

Time and Virtual Timers related APIs and services.

Functions

void _vt_init (void)
 Virtual Timers initialization. More...
 
void chVTDoSetI (virtual_timer_t *vtp, sysinterval_t delay, vtfunc_t vtfunc, void *par)
 Enables a virtual timer. More...
 
void chVTDoResetI (virtual_timer_t *vtp)
 Disables a Virtual Timer. More...
 
static void chVTObjectInit (virtual_timer_t *vtp)
 Initializes a virtual_timer_t object. More...
 
static systime_t chVTGetSystemTimeX (void)
 Current system time. More...
 
static systime_t chVTGetSystemTime (void)
 Current system time. More...
 
static sysinterval_t chVTTimeElapsedSinceX (systime_t start)
 Returns the elapsed time since the specified start time. More...
 
static bool chVTIsSystemTimeWithinX (systime_t start, systime_t end)
 Checks if the current system time is within the specified time window. More...
 
static bool chVTIsSystemTimeWithin (systime_t start, systime_t end)
 Checks if the current system time is within the specified time window. More...
 
static bool chVTGetTimersStateI (sysinterval_t *timep)
 Returns the time interval until the next timer event. More...
 
static bool chVTIsArmedI (const virtual_timer_t *vtp)
 Returns true if the specified timer is armed. More...
 
static bool chVTIsArmed (const virtual_timer_t *vtp)
 Returns true if the specified timer is armed. More...
 
static void chVTResetI (virtual_timer_t *vtp)
 Disables a Virtual Timer. More...
 
static void chVTReset (virtual_timer_t *vtp)
 Disables a Virtual Timer. More...
 
static void chVTSetI (virtual_timer_t *vtp, sysinterval_t delay, vtfunc_t vtfunc, void *par)
 Enables a virtual timer. More...
 
static void chVTSet (virtual_timer_t *vtp, sysinterval_t delay, vtfunc_t vtfunc, void *par)
 Enables a virtual timer. More...
 
static void chVTDoTickI (void)
 Virtual timers ticker. More...
 

Function Documentation

void _vt_init ( void  )

Virtual Timers initialization.

Note
Internal use only.
Function Class:
Not an API, this function is for internal use only.

Definition at line 61 of file chvt.c.

References ch, ch_virtual_timers_list::delta, ch_virtual_timers_list::lasttime, ch_virtual_timers_list::next, ch_virtual_timers_list::prev, ch_virtual_timers_list::systime, and ch_system::vtlist.

Referenced by chSysInit().

void chVTDoSetI ( virtual_timer_t vtp,
sysinterval_t  delay,
vtfunc_t  vtfunc,
void *  par 
)

Enables a virtual timer.

The timer is enabled and programmed to trigger after the delay specified as parameter.

Precondition
The timer must not be already armed before calling this function.
Note
The callback function is invoked from interrupt context.
Parameters
[out]vtpthe virtual_timer_t structure pointer
[in]delaythe number of ticks before the operation timeouts, the special values are handled as follow:
  • TIME_INFINITE is allowed but interpreted as a normal time specification.
  • TIME_IMMEDIATE this value is not allowed.
[in]vtfuncthe timer callback function. After invoking the callback the timer is disabled and the structure can be disposed or reused.
[in]para parameter that will be passed to the callback function
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 95 of file chvt.c.

References ch, CH_CFG_ST_TIMEDELTA, chDbgAssert, chDbgCheck, chDbgCheckClassI(), chTimeAddX(), chTimeDiffX(), chVTGetSystemTimeX(), ch_virtual_timer::delta, ch_virtual_timers_list::delta, ch_virtual_timer::func, ch_virtual_timers_list::lasttime, ch_virtual_timer::next, ch_virtual_timers_list::next, ch_virtual_timer::par, ch_virtual_timer::prev, ch_virtual_timers_list::prev, TIME_IMMEDIATE, TIME_MAX_SYSTIME, and ch_system::vtlist.

Referenced by chSchGoSleepTimeoutS(), and chVTSetI().

Here is the call graph for this function:

void chVTDoResetI ( virtual_timer_t vtp)

Disables a Virtual Timer.

Precondition
The timer must be in armed state before calling this function.
Parameters
[in]vtpthe virtual_timer_t structure pointer
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 211 of file chvt.c.

References ch, CH_CFG_ST_TIMEDELTA, chDbgAssert, chDbgCheck, chDbgCheckClassI(), chTimeAddX(), chTimeDiffX(), chVTGetSystemTimeX(), ch_virtual_timer::delta, ch_virtual_timers_list::delta, ch_virtual_timer::func, ch_virtual_timers_list::lasttime, ch_virtual_timer::next, ch_virtual_timers_list::next, ch_virtual_timer::prev, TIME_MAX_SYSTIME, and ch_system::vtlist.

Referenced by chSchGoSleepTimeoutS(), and chVTResetI().

Here is the call graph for this function:

static void chVTObjectInit ( virtual_timer_t vtp)
inlinestatic

Initializes a virtual_timer_t object.

Note
Initializing a timer object is not strictly required because the function chVTSetI() initializes the object too. This function is only useful if you need to perform a chVTIsArmed() check before calling chVTSetI().
Parameters
[out]vtpthe virtual_timer_t structure pointer
Function Class:
Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 97 of file chvt.h.

References ch_virtual_timer::func.

static systime_t chVTGetSystemTimeX ( void  )
inlinestatic

Current system time.

Returns the number of system ticks since the chSysInit() invocation.

Note
The counter can reach its maximum and then restart from zero.
This function can be called from any context but its atomicity is not guaranteed on architectures whose word size is less than systime_t size.
Returns
The system time in ticks.
Function Class:
This is an X-Class API, this function can be invoked from any context.

Definition at line 115 of file chvt.h.

References ch, ch_virtual_timers_list::systime, and ch_system::vtlist.

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

static systime_t chVTGetSystemTime ( void  )
inlinestatic

Current system time.

Returns the number of system ticks since the chSysInit() invocation.

Note
The counter can reach its maximum and then restart from zero.
Returns
The system time in ticks.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 134 of file chvt.h.

References chSysLock(), chSysUnlock(), and chVTGetSystemTimeX().

Referenced by chVTIsSystemTimeWithin().

Here is the call graph for this function:

static sysinterval_t chVTTimeElapsedSinceX ( systime_t  start)
inlinestatic

Returns the elapsed time since the specified start time.

Parameters
[in]startstart time
Returns
The elapsed time.
Function Class:
This is an X-Class API, this function can be invoked from any context.

Definition at line 152 of file chvt.h.

References chTimeDiffX(), and chVTGetSystemTimeX().

Here is the call graph for this function:

static bool chVTIsSystemTimeWithinX ( systime_t  start,
systime_t  end 
)
inlinestatic

Checks if the current system time is within the specified time window.

Note
When start==end then the function returns always true because the whole time range is specified.
Parameters
[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 170 of file chvt.h.

References chTimeIsInRangeX(), and chVTGetSystemTimeX().

Here is the call graph for this function:

static bool chVTIsSystemTimeWithin ( systime_t  start,
systime_t  end 
)
inlinestatic

Checks if the current system time is within the specified time window.

Note
When start==end then the function returns always true because the whole time range is specified.
Parameters
[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:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 188 of file chvt.h.

References chTimeIsInRangeX(), and chVTGetSystemTime().

Here is the call graph for this function:

static bool chVTGetTimersStateI ( sysinterval_t timep)
inlinestatic

Returns the time interval until the next timer event.

Note
The return value is not perfectly accurate and can report values in excess of CH_CFG_ST_TIMEDELTA ticks.
The interval returned by this function is only meaningful if more timers are not added to the list until the returned time.
Parameters
[out]timeppointer to a variable that will contain the time interval until the next timer elapses. This pointer can be NULL if the information is not required.
Returns
The time, in ticks, until next time event.
Return values
falseif the timers list is empty.
trueif the timers list contains at least one timer.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 209 of file chvt.h.

References ch, CH_CFG_ST_TIMEDELTA, chDbgCheckClassI(), chTimeDiffX(), chVTGetSystemTimeX(), ch_virtual_timer::delta, ch_virtual_timers_list::lasttime, ch_virtual_timers_list::next, and ch_system::vtlist.

Here is the call graph for this function:

static bool chVTIsArmedI ( const virtual_timer_t vtp)
inlinestatic

Returns true if the specified timer is armed.

Precondition
The timer must have been initialized using chVTObjectInit() or chVTDoSetI().
Parameters
[in]vtpthe virtual_timer_t structure pointer
Returns
true if the timer is armed.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 239 of file chvt.h.

References chDbgCheckClassI(), and ch_virtual_timer::func.

Referenced by chSchGoSleepTimeoutS(), chVTIsArmed(), and chVTResetI().

Here is the call graph for this function:

static bool chVTIsArmed ( const virtual_timer_t vtp)
inlinestatic

Returns true if the specified timer is armed.

Precondition
The timer must have been initialized using chVTObjectInit() or chVTDoSetI().
Parameters
[in]vtpthe virtual_timer_t structure pointer
Returns
true if the timer is armed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 256 of file chvt.h.

References chSysLock(), chSysUnlock(), and chVTIsArmedI().

Here is the call graph for this function:

static void chVTResetI ( virtual_timer_t vtp)
inlinestatic

Disables a Virtual Timer.

Note
The timer is first checked and disabled only if armed.
Precondition
The timer must have been initialized using chVTObjectInit() or chVTDoSetI().
Parameters
[in]vtpthe virtual_timer_t structure pointer
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 276 of file chvt.h.

References chVTDoResetI(), and chVTIsArmedI().

Referenced by chVTReset(), and chVTSetI().

Here is the call graph for this function:

static void chVTReset ( virtual_timer_t vtp)
inlinestatic

Disables a Virtual Timer.

Note
The timer is first checked and disabled only if armed.
Precondition
The timer must have been initialized using chVTObjectInit() or chVTDoSetI().
Parameters
[in]vtpthe virtual_timer_t structure pointer
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 293 of file chvt.h.

References chSysLock(), chSysUnlock(), and chVTResetI().

Here is the call graph for this function:

static void chVTSetI ( virtual_timer_t vtp,
sysinterval_t  delay,
vtfunc_t  vtfunc,
void *  par 
)
inlinestatic

Enables a virtual timer.

If the virtual timer was already enabled then it is re-enabled using the new parameters.

Precondition
The timer must have been initialized using chVTObjectInit() or chVTDoSetI().
Parameters
[in]vtpthe virtual_timer_t structure pointer
[in]delaythe number of ticks before the operation timeouts, the special values are handled as follow:
  • TIME_INFINITE is allowed but interpreted as a normal time specification.
  • TIME_IMMEDIATE this value is not allowed.
[in]vtfuncthe timer callback function. After invoking the callback the timer is disabled and the structure can be disposed or reused.
[in]para parameter that will be passed to the callback function
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 322 of file chvt.h.

References chVTDoSetI(), and chVTResetI().

Referenced by chVTSet().

Here is the call graph for this function:

static void chVTSet ( virtual_timer_t vtp,
sysinterval_t  delay,
vtfunc_t  vtfunc,
void *  par 
)
inlinestatic

Enables a virtual timer.

If the virtual timer was already enabled then it is re-enabled using the new parameters.

Precondition
The timer must have been initialized using chVTObjectInit() or chVTDoSetI().
Parameters
[in]vtpthe virtual_timer_t structure pointer
[in]delaythe number of ticks before the operation timeouts, the special values are handled as follow:
  • TIME_INFINITE is allowed but interpreted as a normal time specification.
  • TIME_IMMEDIATE this value is not allowed.
[in]vtfuncthe timer callback function. After invoking the callback the timer is disabled and the structure can be disposed or reused.
[in]para parameter that will be passed to the callback function
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 351 of file chvt.h.

References chSysLock(), chSysUnlock(), and chVTSetI().

Here is the call graph for this function:

static void chVTDoTickI ( void  )
inlinestatic

Virtual timers ticker.

Note
The system lock is released before entering the callback and re-acquired immediately after. It is callback's responsibility to acquire the lock if needed. This is done in order to reduce interrupts jitter when many timers are in use.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 368 of file chvt.h.

References ch, CH_CFG_ST_TIMEDELTA, chDbgAssert, chDbgCheckClassI(), chSysLockFromISR(), chSysUnlockFromISR(), chTimeAddX(), chTimeDiffX(), chVTGetSystemTimeX(), ch_virtual_timer::delta, ch_virtual_timer::func, ch_virtual_timers_list::lasttime, ch_virtual_timer::next, ch_virtual_timers_list::next, ch_virtual_timer::par, ch_virtual_timer::prev, ch_virtual_timers_list::systime, TIME_MAX_SYSTIME, and ch_system::vtlist.

Referenced by chSysTimerHandlerI().

Here is the call graph for this function: