SatCat5
satcat5::util::TimeVal Struct Reference

Detailed Description

Timestamp for measuring elapsed time.

SatCat5 system timer concepts.

Timestamp value returned by TimeRef::now() and other methods. Represents a moment in time, either now or in the near future.

Definition at line 48 of file timeref.h.

#include <timeref.h>

Collaboration diagram for satcat5::util::TimeVal:
[legend]

Public Member Functions

 TimeVal (const TimeVal &t)=default
 
TimeValoperator= (const TimeVal &t)=default
 
unsigned elapsed_tick () const
 Measure elapsed time in ticks. More...
 
unsigned elapsed_usec () const
 Elapsed time in microseconds. More...
 
unsigned elapsed_msec () const
 Elapsed time in milliseconds. More...
 
unsigned increment_usec ()
 Measure elapsed time in microseconds, then increment by the returned quantized value. More...
 
unsigned increment_msec ()
 Measure elapsed time in milliseconds, then increment by the returned quantized value. More...
 
bool interval_tick (u32 ticks)
 Test an interval measured in ticks. More...
 
bool interval_usec (unsigned usec)
 Test an interval measured in microseconds. More...
 
bool interval_msec (unsigned msec)
 Test an interval measured in milliseconds. More...
 
bool checkpoint_elapsed ()
 Test if an oven-timer checkpoint has elapsed. More...
 

Public Attributes

TimeRefclk
 Pointer to the parent time reference.
 
u32 tval
 The value of this timestamp, measured in ticks.
 

Member Function Documentation

◆ checkpoint_elapsed()

bool TimeVal::checkpoint_elapsed ( )

Test if an oven-timer checkpoint has elapsed.

If so, disable it (set to zero) and return true.

To create a checkpoint, use methods TimeRef::checkpoint_usec() or TimeRef::checkpoint_msec().

This example polls an object until a timeout has elapsed:

TimeVal timeout = SATCAT5_CLOCK->checkpoint_msec(100);
while (!timeout.checkpoint_elapsed()) {
do_thing();
}

Definition at line 77 of file timeref.cc.

◆ elapsed_msec()

unsigned TimeVal::elapsed_msec ( ) const

Elapsed time in milliseconds.

See also
elapsed_tick

Definition at line 29 of file timeref.cc.

◆ elapsed_tick()

unsigned TimeVal::elapsed_tick ( ) const

Measure elapsed time in ticks.

This example measures time spent in the "do_thing()" function:

TimeVal ref = SATCAT5_CLOCK->now(); // Create timestamp
do_thing(); // Delay 42.7 usec
unsigned elapsed = ref.elapsed_usec(); // Returns 42

Definition at line 19 of file timeref.cc.

◆ elapsed_usec()

unsigned TimeVal::elapsed_usec ( ) const

Elapsed time in microseconds.

See also
elapsed_tick

Definition at line 25 of file timeref.cc.

◆ increment_msec()

unsigned TimeVal::increment_msec ( )

Measure elapsed time in milliseconds, then increment by the returned quantized value.

Measure elapsed time since the timestamp, then increment the timestamp by that integer quantity. This is typically used to avoid cumulative rounding error for recurring events.

This example measures time spent in the "do_thing()" function:

TimeVal ref = SATCAT5_CLOCK->now(); // Create timestamp
do_thing(); // Delay 3.7 usec
unsigned t1 = ref.increment_usec(); // Returns 3
do_thing(); // Delay 3.7 usec
unsigned t2 = ref.increment_msec(); // Returns 4
do_thing(); // Delay 3.7 usec
unsigned t3 = ref.increment_msec(); // Returns 4

Definition at line 39 of file timeref.cc.

◆ increment_usec()

unsigned TimeVal::increment_usec ( )

Measure elapsed time in microseconds, then increment by the returned quantized value.

Measure elapsed time since the timestamp, then increment the timestamp by that integer quantity. This is typically used to avoid cumulative rounding error for recurring events.

This example measures time spent in the "do_thing()" function:

TimeVal ref = SATCAT5_CLOCK->now(); // Create timestamp
do_thing(); // Delay 3.7 usec
unsigned t1 = ref.increment_usec(); // Returns 3
do_thing(); // Delay 3.7 usec
unsigned t2 = ref.increment_msec(); // Returns 4
do_thing(); // Delay 3.7 usec
unsigned t3 = ref.increment_msec(); // Returns 4

Definition at line 33 of file timeref.cc.

◆ interval_msec()

bool TimeVal::interval_msec ( unsigned  msec)

Test an interval measured in milliseconds.

Measure elapsed time since the timestamp. If that exceeds the designated interval, then return true and increment the timestamp by the designated amount. Otherwise, return false. This is typically used to measure repeating events.

This example prints a message once every second:

TimeVal ref = SATCAT5_CLOCK->now(); // Create timestamp
while (1) { // Poll forever...
if (ref.interval_msec(1000)) printf("Tock\n");
}

Definition at line 60 of file timeref.cc.

◆ interval_tick()

bool TimeVal::interval_tick ( u32  ticks)

Test an interval measured in ticks.

Measure elapsed time since the timestamp. If that exceeds the designated interval, then return true and increment the timestamp by the designated amount. Otherwise, return false. This is typically used to measure repeating events.

This example prints a message once every second:

TimeVal ref = SATCAT5_CLOCK->now(); // Create timestamp
while (1) { // Poll forever...
if (ref.interval_msec(1000)) printf("Tock\n");
}

Definition at line 45 of file timeref.cc.

◆ interval_usec()

bool TimeVal::interval_usec ( unsigned  usec)

Test an interval measured in microseconds.

Measure elapsed time since the timestamp. If that exceeds the designated interval, then return true and increment the timestamp by the designated amount. Otherwise, return false. This is typically used to measure repeating events.

This example prints a message once every second:

TimeVal ref = SATCAT5_CLOCK->now(); // Create timestamp
while (1) { // Poll forever...
if (ref.interval_msec(1000)) printf("Tock\n");
}

Definition at line 55 of file timeref.cc.


The documentation for this struct was generated from the following files: