![]() |
flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
|
This module defines storage classes for timestamps and operations on time values. More...
#include <stdbool.h>
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | TimestampU |
Timestamp (unsigned) More... | |
struct | TimestampI |
Timestamp (signed) More... | |
Macros | |
#define | NANO_PREFIX (1000000000) |
Integer nano prefix. | |
#define | NANO_PREFIX_F (1000000000.0f) |
Float nanno prefix. | |
#define | T_SEC_PER_MINUTE (60) |
seconds per minute | |
#define | T_SEC_PER_HOUR (60 * T_SEC_PER_MINUTE) |
seconds per hour | |
#define | T_SEC_PER_DAY (24 * T_SEC_PER_HOUR) |
seconds per day | |
#define | T_SEC_PER_YEAR (365 * T_SEC_PER_DAY) |
seconds per year | |
#define | T_SEC_PER_LEAPYEAR (366 * T_SEC_PER_DAY) |
seconds per leapyear | |
#define | T_SEC_PER_FOURYEAR (3 * T_SEC_PER_YEAR + T_SEC_PER_LEAPYEAR) |
seconds per four years | |
Functions | |
TimestampI * | tsUToI (TimestampI *ti, const TimestampU *tu) |
TimestampI * | addTime (TimestampI *r, const TimestampI *a, const TimestampI *b) |
TimestampI * | subTime (TimestampI *r, const TimestampI *a, const TimestampI *b) |
TimestampI * | divTime (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) |
TimestampI * | nsToTsI (TimestampI *r, int64_t ns) |
bool | nonZeroI (const TimestampI *a) |
void | tsPrint (char *str, const TimestampI *ts) |
This module defines storage classes for timestamps and operations on time values.
Definition in file timeutils.h.
#define NANO_PREFIX (1000000000) |
Integer nano prefix.
Definition at line 34 of file timeutils.h.
#define NANO_PREFIX_F (1000000000.0f) |
Float nanno prefix.
Definition at line 35 of file timeutils.h.
#define T_SEC_PER_DAY (24 * T_SEC_PER_HOUR) |
seconds per day
Definition at line 39 of file timeutils.h.
#define T_SEC_PER_FOURYEAR (3 * T_SEC_PER_YEAR + T_SEC_PER_LEAPYEAR) |
seconds per four years
Definition at line 42 of file timeutils.h.
#define T_SEC_PER_HOUR (60 * T_SEC_PER_MINUTE) |
seconds per hour
Definition at line 38 of file timeutils.h.
#define T_SEC_PER_LEAPYEAR (366 * T_SEC_PER_DAY) |
seconds per leapyear
Definition at line 41 of file timeutils.h.
#define T_SEC_PER_MINUTE (60) |
seconds per minute
Definition at line 37 of file timeutils.h.
#define T_SEC_PER_YEAR (365 * T_SEC_PER_DAY) |
seconds per year
Definition at line 40 of file timeutils.h.
TimestampI * addTime | ( | TimestampI * | r, |
const TimestampI * | a, | ||
const TimestampI * | b | ||
) |
Add up timestamps. r = a + b;
r | result |
a | first operand |
b | second operand |
Definition at line 16 of file timeutils.c.
TimestampI * divTime | ( | TimestampI * | r, |
const TimestampI * | a, | ||
int | divisor | ||
) |
Divide (inversely scale) a time value by an integer.
r | pointer to the result field |
a | dividend |
divisor | divisor |
Definition at line 31 of file timeutils.c.
bool nonZeroI | ( | const TimestampI * | a | ) |
Does the timestamp differ from zero?
a | timestamp |
Definition at line 67 of file timeutils.c.
void normTime | ( | TimestampI * | t | ) |
Normalize time. Move whole seconds from the nanoseconds field to the seconds.
t | Time. It will be overwritten. |
Definition at line 49 of file timeutils.c.
int64_t nsI | ( | const TimestampI * | t | ) |
Convert signed time into nanoseconds.
t | time |
Definition at line 44 of file timeutils.c.
TimestampI * nsToTsI | ( | TimestampI * | r, |
int64_t | ns | ||
) |
Convert nanoseconds to time.
r | results |
ns | time in nanoseconds |
Definition at line 61 of file timeutils.c.
uint64_t nsU | ( | const TimestampU * | t | ) |
Convert unsigned time into nanoseconds.
t | time |
Definition at line 39 of file timeutils.c.
TimestampI * subTime | ( | TimestampI * | r, |
const TimestampI * | a, | ||
const TimestampI * | b | ||
) |
Substract timestamps. r = a - b;
r | result |
a | first operand |
b | second operand |
Definition at line 24 of file timeutils.c.
void tsPrint | ( | char * | str, |
const TimestampI * | ts | ||
) |
Print datetime to string.
str | destination area, must provide at least 20 consecutive bytes! |
ts | pointer to timestamp object holding the time value |
Definition at line 73 of file timeutils.c.
int64_t tsToTick | ( | const TimestampI * | ts, |
uint32_t | tps | ||
) |
Convert duration (~time value) to hardware ticks.
ts | time |
tps | ticks per second |
Definition at line 55 of file timeutils.c.
TimestampI * tsUToI | ( | TimestampI * | ti, |
const TimestampU * | tu | ||
) |
Convert unsigned timestamp to signed.
ti | destination (signed) timestamp |
tu | source (unsigned) timestamp |
Definition at line 8 of file timeutils.c.