flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
timeutils.c File Reference
#include "timeutils.h"
#include <flexptp_options.h>

Go to the source code of this file.

Functions

TimestampItsUToI (TimestampI *ti, const TimestampU *tu)
 
TimestampIaddTime (TimestampI *r, const TimestampI *a, const TimestampI *b)
 
TimestampIsubTime (TimestampI *r, const TimestampI *a, const TimestampI *b)
 
TimestampIdivTime (TimestampI *r, const TimestampI *a, int divisor)
 
uint64_t nsU (const TimestampU *t)
 
int64_t nsI (const TimestampI *t)
 
void normTime (TimestampI *t)
 
int64_t tsToTick (const TimestampI *ts, uint32_t tps)
 
TimestampInsToTsI (TimestampI *r, int64_t ns)
 
bool nonZeroI (const TimestampI *a)
 
void tsPrint (char *str, const TimestampI *ts)
 

Variables

static unsigned FIRST_DAY_OF_MONTH [] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }
 

Function Documentation

◆ addTime()

TimestampI * addTime ( TimestampI r,
const TimestampI a,
const TimestampI b 
)

Add up timestamps. r = a + b;

Parameters
rresult
afirst operand
bsecond operand
Returns
r

Definition at line 16 of file timeutils.c.

◆ divTime()

TimestampI * divTime ( TimestampI r,
const TimestampI a,
int  divisor 
)

Divide (inversely scale) a time value by an integer.

Parameters
rpointer to the result field
adividend
divisordivisor
Returns
r

Definition at line 31 of file timeutils.c.

◆ nonZeroI()

bool nonZeroI ( const TimestampI a)

Does the timestamp differ from zero?

Parameters
atimestamp
Returns
a != 0

Definition at line 67 of file timeutils.c.

◆ normTime()

void normTime ( TimestampI t)

Normalize time. Move whole seconds from the nanoseconds field to the seconds.

Parameters
tTime. It will be overwritten.

Definition at line 49 of file timeutils.c.

◆ nsI()

int64_t nsI ( const TimestampI t)

Convert signed time into nanoseconds.

Parameters
ttime
Returns
time in nanoseconds

Definition at line 44 of file timeutils.c.

◆ nsToTsI()

TimestampI * nsToTsI ( TimestampI r,
int64_t  ns 
)

Convert nanoseconds to time.

Parameters
rresults
nstime in nanoseconds
Returns
r

Definition at line 61 of file timeutils.c.

◆ nsU()

uint64_t nsU ( const TimestampU t)

Convert unsigned time into nanoseconds.

Parameters
ttime
Returns
time in nanoseconds

Definition at line 39 of file timeutils.c.

◆ subTime()

TimestampI * subTime ( TimestampI r,
const TimestampI a,
const TimestampI b 
)

Substract timestamps. r = a - b;

Parameters
rresult
afirst operand
bsecond operand
Returns
r

Definition at line 24 of file timeutils.c.

◆ tsPrint()

void tsPrint ( char *  str,
const TimestampI ts 
)

Print datetime to string.

Parameters
strdestination area, must provide at least 20 consecutive bytes!
tspointer to timestamp object holding the time value

Definition at line 73 of file timeutils.c.

◆ tsToTick()

int64_t tsToTick ( const TimestampI ts,
uint32_t  tps 
)

Convert duration (~time value) to hardware ticks.

Parameters
tstime
tpsticks per second
Returns
duration in ticks (rounded to floor during division)

Definition at line 55 of file timeutils.c.

◆ tsUToI()

TimestampI * tsUToI ( TimestampI ti,
const TimestampU tu 
)

Convert unsigned timestamp to signed.

Parameters
tidestination (signed) timestamp
tusource (unsigned) timestamp

Definition at line 8 of file timeutils.c.

Variable Documentation

◆ FIRST_DAY_OF_MONTH

unsigned FIRST_DAY_OF_MONTH[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }
static

Definition at line 71 of file timeutils.c.