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.
#define TIME_MAX 0xFFFFFFFFU |
Max time that can be held.
void DelayMs |
( |
uint32_t |
delay | ) |
|
Delay a specific number of milliseconds.
DelayMs uses TimeNow() and TimeSince() to implement the delay
- Parameters
-
delay | specifies the number of milliseconds to delay |
void DelayUs |
( |
uint32_t |
us | ) |
|
uint32_t TimeNow |
( |
void |
| ) |
|
Returns the current system time in milliseconds.
- Returns
- the current system time in milliseconds
- See Also
- TimeSince
uint32_t TimeNowUs |
( |
void |
| ) |
|
uint32_t TimeSince |
( |
uint32_t |
t | ) |
|
Get the elapsed time.
Calculate and return the time elapsed since a given time. Typically used with TimeNow(). See the example usage.
- 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
uint32_t TimeSinceUs |
( |
uint32_t |
t | ) |
|
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()