OLE Developer Guide  Latest Git
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Coarse Timer

Detailed Description

A coarse global timer that can be used to track time intervals.

The timer is accurate to 10ths of a millisecond.

Files

file  coarse_timer.h
 Provides a coarse timer for determining the elapsed time between two events.
 

Data Structures

struct  CoarseTimer_Settings
 Settings for the CoarseTimer module. More...
 

Typedefs

typedef uint32_t CoarseTimer_Value
 An opaque type used to represent a time stamp.
 

Functions

void CoarseTimer_Initialize (const CoarseTimer_Settings *settings)
 Initialize the timer. More...
 
void CoarseTimer_TimerEvent ()
 Update the timer. More...
 
CoarseTimer_Value CoarseTimer_GetTime ()
 Get the current value of the timer. More...
 
uint32_t CoarseTimer_ElapsedTime (CoarseTimer_Value start_time)
 Return the interval since the start_time. More...
 
uint32_t CoarseTimer_Delta (CoarseTimer_Value start_time, CoarseTimer_Value end_time)
 Return the interval between two times. More...
 
bool CoarseTimer_HasElapsed (CoarseTimer_Value start_time, uint32_t interval)
 Check if a time interval has passed. More...
 
void CoarseTimer_SetCounter (uint32_t count)
 Manually set the internal counter. More...
 

Function Documentation

uint32_t CoarseTimer_Delta ( CoarseTimer_Value  start_time,
CoarseTimer_Value  end_time 
)

Return the interval between two times.

Parameters
start_timeThe time to measure from.
end_timeThe time to measure to.
Returns
The time between the start and end time, measured in 10ths of a millisecond.

Accuracy is to within 10ths of a millisecond. Be careful if using this to trigger events. as the events may then trigger up to 0.1ms before they were supposed to.

uint32_t CoarseTimer_ElapsedTime ( CoarseTimer_Value  start_time)

Return the interval since the start_time.

Parameters
start_timeThe time to measure from.
Returns
The time since the start_time, measured in 10ths of a millisecond.

Accuracy is to within 10ths of a millisecond. Be careful if using this to trigger events. as the events may then trigger up to 0.1ms before they were supposed to.

CoarseTimer_Value CoarseTimer_GetTime ( )

Get the current value of the timer.

Returns
The current value of the timer counter.

The value returned can be later passed to CoarseTimer_HasElapsed() and CoarseTimer_ElapsedTime().

bool CoarseTimer_HasElapsed ( CoarseTimer_Value  start_time,
uint32_t  interval 
)

Check if a time interval has passed.

Parameters
start_timeThe time to measure from.
intervalThe time interval in 10ths of a millisecond.
Returns
true if the interval has elapsed since the start_time.
void CoarseTimer_Initialize ( const CoarseTimer_Settings settings)

Initialize the timer.

Parameters
settingsThe timer settings.

The settings should match the interrupt vector used to call CoarseTimer_TimerEvent().

Example
1 CoarseTimer_Settings timer_settings = {
2  .timer_id = TMR_ID_2,
3  .interrupt_source = INT_SOURCE_TIMER_2
4 };
5 
6 CoarseTimer_Initialize(&timer_settings);
void CoarseTimer_SetCounter ( uint32_t  count)

Manually set the internal counter.

Parameters
countthe new value of the internal counter.
Note
This function should be used for testing only.
void CoarseTimer_TimerEvent ( )

Update the timer.

This should be called from within an ISR.

Example
1 void __ISR(_TIMER_2_VECTOR, ipl6) TimerEvent() {
2  CoarseTimer_TimerEvent();
3 }

The interrupt vector should match what was supplied to CoarseTimer_Initialize().