embeddedlibrary
reusable software modules for embedded systems
Timing module

Modules

 (HAL) Timing module
 

Macros

#define tint_t   uint32_t
 
#define TIME_MAX   0xFFFFFFFFU
 

Functions

void Timing_Init (void)
 Initialize the timing module. More...
 
uint32_t TimeNow (void)
 Returns the current system time in milliseconds. More...
 
uint32_t TimeSince (tint_t t)
 Get the elapsed time. More...
 
void DelayMs (tint_t delay)
 Delay a specific number of milliseconds. More...
 
void Timing_Roll (void)
 

Detailed Description

This module provides some very basic functions to make timing easier. Several other modules rely on the services provided by this module.

The module uses the HAL layer to provide the hardware specific functionality for the timing module. In this module, the hal_timing.c file is included to allow the ISR to access the time variable without externing the variable or making a function call. This allows the ISR to be very efficient.

Macro Definition Documentation

#define TIME_MAX   0xFFFFFFFFU

Max time that can be held with the tint_t type.

#define tint_t   uint32_t

type for timer, change override this to uint16_t for better efficiency on a 8 or 16 bit system.

Note: a define is used instead of a typedef so that the define can be overriden.

Function Documentation

void DelayMs ( tint_t  delay)

Delay a specific number of milliseconds.

DelayMs uses TimeNow() and TimeSince() to implement the delay

Parameters
delayspecifies the number of milliseconds to delay
uint32_t TimeNow ( void  )

Returns the current system time in milliseconds.

Returns
the current system time in milliseconds
See also
TimeSince
uint32_t TimeSince ( tint_t  t)

Get the elapsed time.

Calculate and return the time elapsed since a given time. Typically used with TimeNow(). See the example usage.

1 uint32_t t;
2 t = TimeNow();
3 while(TimeSince(t) < 5000){
4  //Insert code here
5 }
See also
TimeNow
Parameters
t- The time in milliseconds to calculate the elapsed time since
Returns
- The time elapsed since the time given in milliseconds
void Timing_Init ( void  )

Initialize the timing module.

Call the HAL layer to initialize a timer to interrupt every 1ms. Clears the timing count

void Timing_Roll ( void  )

Reset the system time

Reset system time (e.g. TimeNow() will return 0) and set appropriate rollover times so TimeSince will work properly.

Warning
Timing discrepancies will occur if TimerRoll is called and not called again for the next timer rollover. TimeSince() will result in a shorter time than expected if the timer is allowed to naturally roll over after calling TimerRoll. The difference will be MAX_TIME - the time when TimerRoll was last called. This could be fixed by adding a check for the timer rolling over naturally and setting rollover_time to TIME_MAX in timing.c. Note: This is handled by the task management system which typically will be the only user of Timing_Roll()