ChibiOS/RT Logo ChibiOS/RT

Architecture - Reference Manual - Guides

Data Structures | Defines | Typedefs | Functions | Variables

Time and Virtual Timers
[Base Kernel Services]

Collaboration diagram for Time and Virtual Timers:


Description

Time and Virtual Timers related APIs and services.

Data Structures

struct  VirtualTimer
 Virtual Timer descriptor structure. More...
struct  VTList
 Virtual timers list header. More...

Defines

#define S2ST(sec)   ((systime_t)((sec) * CH_FREQUENCY))
 Time conversion utility.
#define MS2ST(msec)   ((systime_t)(((((msec) - 1L) * CH_FREQUENCY) / 1000L) + 1L))
 Time conversion utility.
#define US2ST(usec)   ((systime_t)(((((usec) - 1L) * CH_FREQUENCY) / 1000000L) + 1L))
 Time conversion utility.
#define chVTDoTickI()
 Virtual timers ticker.
#define chVTIsArmedI(vtp)   ((vtp)->vt_func != NULL)
 Returns TRUE if the speciified timer is armed.
#define chTimeNow()   (vtlist.vt_systime)
 Current system time.

Typedefs

typedef void(* vtfunc_t )(void *)
 Virtual Timer callback function.
typedef struct VirtualTimer VirtualTimer
 Virtual Timer structure type.

Functions

void vt_init (void)
 Virtual Timers initialization.
void chVTSetI (VirtualTimer *vtp, systime_t time, vtfunc_t vtfunc, void *par)
 Enables a virtual timer.
void chVTResetI (VirtualTimer *vtp)
 Disables a Virtual Timer.
bool_t chTimeIsWithin (systime_t start, systime_t end)
 Checks if the current system time is within the specified time window.

Variables

VTList vtlist
 Virtual timers delta list header.
VTList vtlist
 Virtual timers delta list header.

Define Documentation

#define S2ST (   sec  )     ((systime_t)((sec) * CH_FREQUENCY))

Time conversion utility.

Converts from seconds to system ticks number.

Note:
The result is rounded upward to the next tick boundary.

Definition at line 43 of file chvt.h.

#define MS2ST (   msec  )     ((systime_t)(((((msec) - 1L) * CH_FREQUENCY) / 1000L) + 1L))

Time conversion utility.

Converts from milliseconds to system ticks number.

Note:
The result is rounded upward to the next tick boundary.

Definition at line 50 of file chvt.h.

Referenced by mmcStart(), and tmrfunc().

#define US2ST (   usec  )     ((systime_t)(((((usec) - 1L) * CH_FREQUENCY) / 1000000L) + 1L))

Time conversion utility.

Converts from microseconds to system ticks number.

Note:
The result is rounded upward to the next tick boundary.

Definition at line 57 of file chvt.h.

#define chVTDoTickI (  ) 
Value:
{                                                 \
  vtlist.vt_systime++;                                                  \
  if (&vtlist != (VTList *)vtlist.vt_next) {                            \
    VirtualTimer *vtp;                                                  \
                                                                        \
    --vtlist.vt_next->vt_time;                                          \
    while (!(vtp = vtlist.vt_next)->vt_time) {                          \
      vtfunc_t fn = vtp->vt_func;                                       \
      vtp->vt_func = (vtfunc_t)NULL;                                    \
      vtp->vt_next->vt_prev = (void *)&vtlist;                          \
      (&vtlist)->vt_next = vtp->vt_next;                                \
      fn(vtp->vt_par);                                                  \
    }                                                                   \
  }                                                                     \
}

Virtual timers ticker.

Definition at line 106 of file chvt.h.

Referenced by chSysTimerHandlerI().

#define chVTIsArmedI (   vtp  )     ((vtp)->vt_func != NULL)

Returns TRUE if the speciified timer is armed.

Definition at line 139 of file chvt.h.

Referenced by chSchGoSleepTimeoutS(), and chibios_rt::Timer::IsArmed().

#define chTimeNow (  )     (vtlist.vt_systime)

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 is designed to work with the chThdSleepUntil().
Returns:
The system time in ticks.r

Definition at line 150 of file chvt.h.

Referenced by chDbgTrace(), chThdSleepUntil(), chTimeIsWithin(), chibios_rt::System::GetTime(), macWaitReceiveDescriptor(), and macWaitTransmitDescriptor().


Typedef Documentation

typedef void(* vtfunc_t)(void *)

Virtual Timer callback function.

Definition at line 62 of file chvt.h.

typedef struct VirtualTimer VirtualTimer

Virtual Timer structure type.

Definition at line 67 of file chvt.h.


Function Documentation

void vt_init ( void   ) 

Virtual Timers initialization.

Note:
Internal use only.

Definition at line 47 of file chvt.c.

References VTList::vt_next, VTList::vt_prev, VTList::vt_systime, and VTList::vt_time.

Referenced by chSysInit().

void chVTSetI ( VirtualTimer vtp,
systime_t  time,
vtfunc_t  vtfunc,
void *  par 
)

Enables a virtual timer.

Note:
The associated function is invoked by an interrupt handler within the I-Locked state, see System States.
Parameters:
[out] vtp the VirtualTimer structure pointer
[in] time the number of time ticks, the value TIME_INFINITE is notallowed. The value TIME_IMMEDIATE is allowed but interpreted as a normal time specification not as an immediate timeout specification.
[in] vtfunc the timer callback function. After invoking the callback the timer is disabled and the structure can be disposed or reused.
[in] par a parameter that will be passed to the callback function

Definition at line 70 of file chvt.c.

References chDbgCheck, TIME_INFINITE, VirtualTimer::vt_func, VirtualTimer::vt_next, VTList::vt_next, VirtualTimer::vt_par, VirtualTimer::vt_prev, and VirtualTimer::vt_time.

Referenced by chSchGoSleepTimeoutS(), mmcStart(), chibios_rt::Timer::Set(), and tmrfunc().

void chVTResetI ( VirtualTimer vtp  ) 

Disables a Virtual Timer.

Note:
The timer MUST be active when this function is invoked.
Parameters:
[in] vtp the VirtualTimer structure pointer

Definition at line 97 of file chvt.c.

References chDbgAssert, chDbgCheck, VirtualTimer::vt_func, VirtualTimer::vt_next, VirtualTimer::vt_prev, and VirtualTimer::vt_time.

Referenced by chSchGoSleepTimeoutS(), mmcStop(), and chibios_rt::Timer::Reset().

bool_t chTimeIsWithin ( systime_t  start,
systime_t  end 
)

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] start the start of the time window (inclusive)
[in] end the end of the time window (non inclusive)
Return values:
TRUE current time within the specified time window.
FALSE current time not within the specified time window.

Definition at line 122 of file chvt.c.

References chTimeNow.


Variable Documentation

Virtual timers delta list header.

Definition at line 41 of file chvt.c.

Virtual timers delta list header.

Definition at line 41 of file chvt.c.


Generated on Sun Nov 28 2010 14:09:56 for ChibiOS/RT by doxygen 1.7.1