flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
timeutils.h
Go to the documentation of this file.
1
10#ifndef TIMEUTILS_H_
11#define TIMEUTILS_H_
12
13#include <stdbool.h>
14#include <stdint.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
23typedef struct
24{
25 uint64_t sec;
26 uint32_t nanosec;
28
32typedef struct
33{
34 int64_t sec;
35 int32_t nanosec;
37
38#define NANO_PREFIX (1000000000)
39#define NANO_PREFIX_F (1000000000.0f)
40
41#define T_SEC_PER_MINUTE (60)
42#define T_SEC_PER_HOUR (60 * T_SEC_PER_MINUTE)
43#define T_SEC_PER_DAY (24 * T_SEC_PER_HOUR)
44#define T_SEC_PER_YEAR (365 * T_SEC_PER_DAY)
45#define T_SEC_PER_LEAPYEAR (366 * T_SEC_PER_DAY)
46#define T_SEC_PER_FOURYEAR (3 * T_SEC_PER_YEAR + T_SEC_PER_LEAPYEAR)
47
48// TIME OPERATIONS
55TimestampI *tsUToI(TimestampI *ti, const TimestampU *tu);
56
63TimestampU *tsIToU(TimestampU *tu, const TimestampI *ti);
64
75TimestampI *addTime(TimestampI *r, const TimestampI *a, const TimestampI *b);
76
87TimestampI *subTime(TimestampI *r, const TimestampI *a, const TimestampI *b);
88
98TimestampI *divTime(TimestampI *r, const TimestampI *a, int divisor);
99
107uint64_t nsU(const TimestampU *t); //
108
116int64_t nsI(const TimestampI *t);
117
123void normTime(TimestampI *t); // normalize time
124
133int64_t tsToTick(const TimestampI *ts, uint32_t tps);
134
143TimestampI *nsToTsI(TimestampI *r, int64_t ns);
144
152bool nonZeroI(const TimestampI *a);
153
160void tsPrint(char *str, const TimestampI *ts);
161
162#ifdef __cplusplus
163}
164#endif
165
166#endif /* TIMEUTILS_H_ */
Timestamp (signed)
Definition: timeutils.h:33
int32_t nanosec
nanoseconds
Definition: timeutils.h:35
int64_t sec
seconds
Definition: timeutils.h:34
Timestamp (unsigned)
Definition: timeutils.h:24
uint32_t nanosec
nanoseconds
Definition: timeutils.h:26
uint64_t sec
seconds
Definition: timeutils.h:25
uint64_t nsU(const TimestampU *t)
Definition: timeutils.c:47
TimestampU * tsIToU(TimestampU *tu, const TimestampI *ti)
Definition: timeutils.c:15
TimestampI * addTime(TimestampI *r, const TimestampI *a, const TimestampI *b)
Definition: timeutils.c:24
TimestampI * divTime(TimestampI *r, const TimestampI *a, int divisor)
Definition: timeutils.c:39
void normTime(TimestampI *t)
Definition: timeutils.c:57
int64_t tsToTick(const TimestampI *ts, uint32_t tps)
Definition: timeutils.c:63
TimestampI * nsToTsI(TimestampI *r, int64_t ns)
Definition: timeutils.c:69
TimestampI * tsUToI(TimestampI *ti, const TimestampU *tu)
Definition: timeutils.c:8
TimestampI * subTime(TimestampI *r, const TimestampI *a, const TimestampI *b)
Definition: timeutils.c:32
void tsPrint(char *str, const TimestampI *ts)
Definition: timeutils.c:81
bool nonZeroI(const TimestampI *a)
Definition: timeutils.c:75
int64_t nsI(const TimestampI *t)
Definition: timeutils.c:52