orcus
Macros | Functions
timer.h File Reference

Timer. More...

#include <stdint.h>

Macros

#define TIMER_NS_PER_TICK   135
 Nanoseconds per timer tick. More...
 

Functions

uint32_t timerGet ()
 Get current timer tick. More...
 
unsigned long timerNsSince (uint32_t lastTick, uint32_t *storeCurrent)
 Calculate nanoseconds elapsed since a given tick. More...
 
uint32_t timerSet (uint32_t count)
 Reset timer to count from specific tick. More...
 
void timerSleepNs (unsigned long ns)
 Wait for a given number of nanoseconds. More...
 

Macro Definition Documentation

◆ TIMER_NS_PER_TICK

#define TIMER_NS_PER_TICK   135

Nanoseconds per timer tick. Timer ticks once every 0.135uS.

Function Documentation

◆ timerGet()

uint32_t timerGet ( )

Get current timer tick.

Timer ticks every 0.135uS and overflows at 0xFFFFFFFF then carries on counting.

Returns
Current timer tick

◆ timerNsSince()

unsigned long timerNsSince ( uint32_t  lastTick,
uint32_t *  storeCurrent 
)

Calculate nanoseconds elapsed since a given tick. Optionally store the current tick.

Useful for timeouts, or calculating time between frames.

Note
This function won't work correctly for periods longer than 579.82s due to timer overflow.

◆ timerSet()

uint32_t timerSet ( uint32_t  count)

Reset timer to count from specific tick.

Note
There is a bug in the MMSP2 silicon which prevents starting the timer from 0, so this function will start it from 1 if you try to pass 0.
Parameters
countTick to start counting from
Returns
Tick the timer was at before being reset

◆ timerSleepNs()

void timerSleepNs ( unsigned long  ns)

Wait for a given number of nanoseconds.

Note
This function won't work correctly if you try to wait for longer than 579.82s due to timer overflow.
Parameters
nsNanoseconds to wait