AFBR-S50 API Reference Manual v1.5.6
AFBR-S50 Time-of-Flight Sensor SDK for Embedded Software
Loading...
Searching...
No Matches
Time Utility

Timer utilities for time measurement duties. More...

Collaboration diagram for Time Utility:

Data Structures

struct  ltc_t
 A data structure to represent current time. More...
 

Functions

uint32_t Time_ToUSec (ltc_t const *t)
 Converts ltc_t to microseconds (uint32_t).
 
uint32_t Time_ToMSec (ltc_t const *t)
 Converts ltc_t to milliseconds (uint32_t).
 
uint32_t Time_ToSec (ltc_t const *t)
 Converts ltc_t to seconds (uint32_t).
 
void Time_FromUSec (ltc_t *t, uint32_t t_usec)
 Converts microseconds (uint32_t) to ltc_t.
 
void Time_FromMSec (ltc_t *t, uint32_t t_msec)
 Converts milliseconds (uint32_t) to ltc_t.
 
void Time_FromSec (ltc_t *t, uint32_t t_sec)
 Converts seconds (uint32_t) to ltc_t.
 
bool Time_GreaterEqual (ltc_t const *t1, ltc_t const *t2)
 Checks if /p t1 is greater or equal that /p t2.
 
void Time_GetNow (ltc_t *t_now)
 Obtains the elapsed time since MCU startup.
 
ltc_t Time_Now (void)
 Obtains the elapsed time since MCU startup.
 
uint32_t Time_GetNowUSec (void)
 Obtains the elapsed microseconds since MCU startup.
 
uint32_t Time_GetNowMSec (void)
 Obtains the elapsed milliseconds (rounded) since MCU startup.
 
uint32_t Time_GetNowSec (void)
 Obtains the elapsed seconds (rounded) since MCU startup.
 
void Time_Diff (ltc_t *t_diff, ltc_t const *t_start, ltc_t const *t_end)
 Obtains the time difference between two given time points.
 
uint32_t Time_DiffUSec (ltc_t const *t_start, ltc_t const *t_end)
 Obtains the time difference between two given time points in microseconds.
 
uint32_t Time_DiffMSec (ltc_t const *t_start, ltc_t const *t_end)
 Obtains the time difference between two given time points in milliseconds.
 
uint32_t Time_DiffSec (ltc_t const *t_start, ltc_t const *t_end)
 Obtains the time difference between two given time points in seconds.
 
void Time_GetElapsed (ltc_t *t_elapsed, ltc_t const *t_start)
 Obtains the elapsed time since a given time point.
 
uint32_t Time_GetElapsedUSec (ltc_t const *t_start)
 Obtains the elapsed microseconds since a given time point.
 
uint32_t Time_GetElapsedMSec (ltc_t const *t_start)
 Obtains the elapsed milliseconds since a given time point.
 
uint32_t Time_GetElapsedSec (ltc_t const *t_start)
 Obtains the elapsed seconds since a given time point.
 
void Time_Add (ltc_t *t, ltc_t const *t1, ltc_t const *t2)
 Adds two ltc_t values.
 
void Time_AddUSec (ltc_t *t, ltc_t const *t1, uint32_t t2_usec)
 Adds a given time in microseconds to an ltc_t value.
 
void Time_AddMSec (ltc_t *t, ltc_t const *t1, uint32_t t2_msec)
 Adds a given time in milliseconds to an ltc_t value.
 
void Time_AddSec (ltc_t *t, ltc_t const *t1, uint32_t t2_sec)
 Adds a given time in seconds to an ltc_t value.
 
bool Time_CheckWithin (ltc_t const *t_start, ltc_t const *t_end, ltc_t const *t)
 Checks if /p t is within the time interval /p t_start and /p t_end.
 
bool Time_CheckTimeout (ltc_t const *t_start, ltc_t const *t_timeout)
 Checks if timeout is reached from a given starting time.
 
bool Time_CheckTimeoutUSec (ltc_t const *t_start, uint32_t const t_timeout_usec)
 Checks if timeout is reached from a given starting time.
 
bool Time_CheckTimeoutMSec (ltc_t const *t_start, uint32_t const t_timeout_msec)
 Checks if timeout is reached from a given starting time.
 
bool Time_CheckTimeoutSec (ltc_t const *t_start, uint32_t const t_timeout_sec)
 Checks if timeout is reached from a given starting time.
 
void Time_Delay (ltc_t const *dt)
 Time delay for a given time period.
 
void Time_DelayUSec (uint32_t dt_usec)
 Time delay for a given time period in microseconds.
 
void Time_DelayMSec (uint32_t dt_msec)
 Time delay for a given time period in milliseconds.
 
void Time_DelaySec (uint32_t dt_sec)
 Time delay for a given time period in seconds.
 

Detailed Description

Timer utilities for time measurement duties.


This module provides time measurement utility functions like delay or time measurement methods, or time math functions.

Function Documentation

◆ Time_Add()

void Time_Add ( ltc_t t,
ltc_t const *  t1,
ltc_t const *  t2 
)
inline

Adds two ltc_t values.


Result is defined as t = t1 + t2. The results are wrapped around at maximum values just like integers. The references for t, t1 and t2 may point to the same instance(s).

Parameters
tReturn value: t = t1 + t2.
t11st operand.
t22nd operand.

◆ Time_AddMSec()

void Time_AddMSec ( ltc_t t,
ltc_t const *  t1,
uint32_t  t2_msec 
)
inline

Adds a given time in milliseconds to an ltc_t value.


Result is defined as t = t1 + t2. The results are wrapped around at maximum values just like integers. The references for t and t1 may point to the same instance.

Parameters
tReturn value: t = t1 + t2.
t11st operand.
t2_msec2nd operand in milliseconds.

◆ Time_AddSec()

void Time_AddSec ( ltc_t t,
ltc_t const *  t1,
uint32_t  t2_sec 
)
inline

Adds a given time in seconds to an ltc_t value.


Result is defined as t = t1 + t2. The results are wrapped around at maximum values just like integers. The references for t and t1 may point to the same instance.

Parameters
tReturn value: t = t1 + t2.
t11st operand.
t2_sec2nd operand in seconds.

◆ Time_AddUSec()

void Time_AddUSec ( ltc_t t,
ltc_t const *  t1,
uint32_t  t2_usec 
)
inline

Adds a given time in microseconds to an ltc_t value.


Result is defined as t = t1 + t2. The results are wrapped around at maximum values just like integers. The references for t and t1 may point to the same instance.

Parameters
tReturn value: t = t1 + t2.
t11st operand.
t2_usec2nd operand in microseconds.

◆ Time_CheckTimeout()

bool Time_CheckTimeout ( ltc_t const *  t_start,
ltc_t const *  t_timeout 
)
inline

Checks if timeout is reached from a given starting time.


Checks if a specified time (/p t_timeout) has elapsed since a specified start time (/p t_start). Handles overflow/wraparound of time values at the maximum value.

Parameters
t_startStart time.
t_timeoutTimeout period.
Returns
Timeout elapsed? True/False (boolean value)

◆ Time_CheckTimeoutMSec()

bool Time_CheckTimeoutMSec ( ltc_t const *  t_start,
uint32_t const  t_timeout_msec 
)
inline

Checks if timeout is reached from a given starting time.


Handles overflow.

Parameters
t_startStart time.
t_timeout_msecTimeout period in milliseconds.
Returns
Timeout elapsed? True/False (boolean value)

◆ Time_CheckTimeoutSec()

bool Time_CheckTimeoutSec ( ltc_t const *  t_start,
uint32_t const  t_timeout_sec 
)
inline

Checks if timeout is reached from a given starting time.


Handles overflow.

Parameters
t_startStart time.
t_timeout_secTimeout period in seconds.
Returns
Timeout elapsed? True/False (boolean value)

◆ Time_CheckTimeoutUSec()

bool Time_CheckTimeoutUSec ( ltc_t const *  t_start,
uint32_t const  t_timeout_usec 
)
inline

Checks if timeout is reached from a given starting time.


Handles overflow.

Parameters
t_startStart time.
t_timeout_usecTimeout period in microseconds.
Returns
Timeout elapsed? True/False (boolean value)

◆ Time_CheckWithin()

bool Time_CheckWithin ( ltc_t const *  t_start,
ltc_t const *  t_end,
ltc_t const *  t 
)
inline

Checks if /p t is within the time interval /p t_start and /p t_end.


The interval is from /p t_start to /p t_end. The function returns true if /p t >= /p t_start AND /p t < /p t_end. If /p t_end is before /p t_start, /p t_end is consider to be wrapped around and the condition inverts (i.e. the function returns true if /p < /p t_end OR /p t >= t_start.

Parameters
t_startThe start of the time interval.
t_endThe end of the time interval.
tThe time to be checked if it is with the interval.
Returns
True if t is within t_start and t_stop.

◆ Time_Delay()

void Time_Delay ( ltc_t const *  dt)
inline

Time delay for a given time period.


Parameters
dtDelay time.

◆ Time_DelayMSec()

void Time_DelayMSec ( uint32_t  dt_msec)
inline

Time delay for a given time period in milliseconds.


Parameters
dt_msecDelay time in milliseconds.

◆ Time_DelaySec()

void Time_DelaySec ( uint32_t  dt_sec)
inline

Time delay for a given time period in seconds.


Parameters
dt_secDelay time in seconds.

◆ Time_DelayUSec()

void Time_DelayUSec ( uint32_t  dt_usec)
inline

Time delay for a given time period in microseconds.


Parameters
dt_usecDelay time in microseconds.

◆ Time_Diff()

void Time_Diff ( ltc_t t_diff,
ltc_t const *  t_start,
ltc_t const *  t_end 
)
inline

Obtains the time difference between two given time points.


Result is defined as t_diff = t_end - t_start. Note: since no negative time differences are supported, t_end has to be later/larger than t_start. Otherwise, the result is undefined!

Parameters
t_diffReturned time difference.
t_startStart time point.
t_endEnd time point.

◆ Time_DiffMSec()

uint32_t Time_DiffMSec ( ltc_t const *  t_start,
ltc_t const *  t_end 
)
inline

Obtains the time difference between two given time points in milliseconds.


Result is defined as t_diff = t_end - t_start. Refers to Time_Diff() and handles overflow. Wrap around effect due to uint32_t result format!!

Parameters
t_startStart time point.
t_endEnd time point.
Returns
Time difference in milliseconds.

◆ Time_DiffSec()

uint32_t Time_DiffSec ( ltc_t const *  t_start,
ltc_t const *  t_end 
)
inline

Obtains the time difference between two given time points in seconds.


Result is defined as t_diff = t_end - t_start. Refers to Time_Diff() and handles overflow.

Parameters
t_startStart time point.
t_endEnd time point.
Returns
Time difference in seconds.

◆ Time_DiffUSec()

uint32_t Time_DiffUSec ( ltc_t const *  t_start,
ltc_t const *  t_end 
)
inline

Obtains the time difference between two given time points in microseconds.


Result is defined as t_diff = t_end - t_start. Refers to Time_Diff() and handles overflow such that to large values are limited by 0xFFFFFFFF µs.

Parameters
t_startStart time point.
t_endEnd time point.
Returns
Time difference in microseconds.
Examples
03_high_speed_example.c.

◆ Time_FromMSec()

void Time_FromMSec ( ltc_t t,
uint32_t  t_msec 
)
inline

Converts milliseconds (uint32_t) to ltc_t.


The specified time value in milliseconds is converted to type ltc_t.

Parameters
tOutput ltc_t structure.
t_msecInput time in milliseconds.

◆ Time_FromSec()

void Time_FromSec ( ltc_t t,
uint32_t  t_sec 
)
inline

Converts seconds (uint32_t) to ltc_t.


The specified time value in seconds is converted to type ltc_t.

Parameters
tOutput ltc_t structure.
t_secInput time in seconds.

◆ Time_FromUSec()

void Time_FromUSec ( ltc_t t,
uint32_t  t_usec 
)
inline

Converts microseconds (uint32_t) to ltc_t.


The specified time value in microseconds is converted to type ltc_t.

Parameters
tOutput ltc_t structure.
t_usecInput time in microseconds.

◆ Time_GetElapsed()

void Time_GetElapsed ( ltc_t t_elapsed,
ltc_t const *  t_start 
)
inline

Obtains the elapsed time since a given time point.


Calculates the currently elapsed time since a specified start time (/p t_start).

Note that /p t_start must be in the past! Otherwise, the behavior is undefined!

Parameters
t_elapsedReturns the elapsed time since /p t_start.
t_startStart time point.

◆ Time_GetElapsedMSec()

uint32_t Time_GetElapsedMSec ( ltc_t const *  t_start)
inline

Obtains the elapsed milliseconds since a given time point.


Wrap around effect due to uint32_t result format!!

Parameters
t_startStart time point.
Returns
Elapsed milliseconds since t_start as uint32_t.

◆ Time_GetElapsedSec()

uint32_t Time_GetElapsedSec ( ltc_t const *  t_start)
inline

Obtains the elapsed seconds since a given time point.


Parameters
t_startStart time point.
Returns
Elapsed seconds since t_start as uint32_t.

◆ Time_GetElapsedUSec()

uint32_t Time_GetElapsedUSec ( ltc_t const *  t_start)
inline

Obtains the elapsed microseconds since a given time point.


Wrap around effect due to uint32_t result format!!

Parameters
t_startStart time point.
Returns
Elapsed microseconds since t_start as uint32_t.

◆ Time_GetNow()

void Time_GetNow ( ltc_t t_now)
inline

Obtains the elapsed time since MCU startup.


Parameters
t_nowreturned current time

◆ Time_GetNowMSec()

uint32_t Time_GetNowMSec ( void  )
inline

Obtains the elapsed milliseconds (rounded) since MCU startup.


Wrap around effect due to uint32_t result format!!

Returns
Elapsed milliseconds since MCU startup as uint32_t.

◆ Time_GetNowSec()

uint32_t Time_GetNowSec ( void  )
inline

Obtains the elapsed seconds (rounded) since MCU startup.


Returns
Elapsed seconds since MCU startup as uint32_t.

◆ Time_GetNowUSec()

uint32_t Time_GetNowUSec ( void  )
inline

Obtains the elapsed microseconds since MCU startup.


Wrap around effect due to uint32_t result format!!

Returns
Elapsed microseconds since MCU startup as uint32_t.

◆ Time_GreaterEqual()

bool Time_GreaterEqual ( ltc_t const *  t1,
ltc_t const *  t2 
)
inline

Checks if /p t1 is greater or equal that /p t2.


Handles overflow.

Parameters
t11st operand.
t22nd operand.
Returns
Returns (t1 >= t2);

◆ Time_Now()

ltc_t Time_Now ( void  )
inline

Obtains the elapsed time since MCU startup.


Returns
Returns the current time.

◆ Time_ToMSec()

uint32_t Time_ToMSec ( ltc_t const *  t)
inline

Converts ltc_t to milliseconds (uint32_t).


The specified time value (type ltc_t) is converted to milliseconds. The value is truncated to UINT32_MAX value if the result would exceed UINT32_MAX milliseconds. The returned value is correctly rounded to the nearest value.

Parameters
tInput ltc_t structure.
Returns
Time value in milliseconds.

◆ Time_ToSec()

uint32_t Time_ToSec ( ltc_t const *  t)
inline

Converts ltc_t to seconds (uint32_t).


The specified time value (type ltc_t) is converted to seconds. The returned value is correctly rounded to the nearest value.

Parameters
tInput ltc_t structure.
Returns
Time value in seconds.

◆ Time_ToUSec()

uint32_t Time_ToUSec ( ltc_t const *  t)
inline

Converts ltc_t to microseconds (uint32_t).


The specified time value (type ltc_t) is converted to microseconds. The value is truncated to UINT32_MAX value if the result would exceed UINT32_MAX microseconds.

Parameters
tInput ltc_t structure.
Returns
Time value in microseconds.