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
19typedef struct
20{
21 uint64_t sec;
22 uint32_t nanosec;
24
28typedef struct
29{
30 int64_t sec;
31 int32_t nanosec;
33
34#define NANO_PREFIX (1000000000)
35#define NANO_PREFIX_F (1000000000.0f)
36
37#define T_SEC_PER_MINUTE (60)
38#define T_SEC_PER_HOUR (60 * T_SEC_PER_MINUTE)
39#define T_SEC_PER_DAY (24 * T_SEC_PER_HOUR)
40#define T_SEC_PER_YEAR (365 * T_SEC_PER_DAY)
41#define T_SEC_PER_LEAPYEAR (366 * T_SEC_PER_DAY)
42#define T_SEC_PER_FOURYEAR (3 * T_SEC_PER_YEAR + T_SEC_PER_LEAPYEAR)
43
44// TIME OPERATIONS
51TimestampI *tsUToI(TimestampI *ti, const TimestampU *tu);
52
63TimestampI *addTime(TimestampI *r, const TimestampI *a, const TimestampI *b);
64
75TimestampI *subTime(TimestampI *r, const TimestampI *a, const TimestampI *b);
76
86TimestampI *divTime(TimestampI *r, const TimestampI *a, int divisor);
87
95uint64_t nsU(const TimestampU *t); //
96
104int64_t nsI(const TimestampI *t);
105
111void normTime(TimestampI *t); // normalize time
112
121int64_t tsToTick(const TimestampI *ts, uint32_t tps);
122
131TimestampI *nsToTsI(TimestampI *r, int64_t ns);
132
140bool nonZeroI(const TimestampI *a);
141
148void tsPrint(char *str, const TimestampI *ts);
149
150#endif /* TIMEUTILS_H_ */
Timestamp (signed)
Definition: timeutils.h:29
int32_t nanosec
nanoseconds
Definition: timeutils.h:31
int64_t sec
seconds
Definition: timeutils.h:30
Timestamp (unsigned)
Definition: timeutils.h:20
uint32_t nanosec
nanoseconds
Definition: timeutils.h:22
uint64_t sec
seconds
Definition: timeutils.h:21
uint64_t nsU(const TimestampU *t)
Definition: timeutils.c:39
TimestampI * addTime(TimestampI *r, const TimestampI *a, const TimestampI *b)
Definition: timeutils.c:16
TimestampI * divTime(TimestampI *r, const TimestampI *a, int divisor)
Definition: timeutils.c:31
void normTime(TimestampI *t)
Definition: timeutils.c:49
int64_t tsToTick(const TimestampI *ts, uint32_t tps)
Definition: timeutils.c:55
TimestampI * nsToTsI(TimestampI *r, int64_t ns)
Definition: timeutils.c:61
TimestampI * tsUToI(TimestampI *ti, const TimestampU *tu)
Definition: timeutils.c:8
TimestampI * subTime(TimestampI *r, const TimestampI *a, const TimestampI *b)
Definition: timeutils.c:24
void tsPrint(char *str, const TimestampI *ts)
Definition: timeutils.c:73
bool nonZeroI(const TimestampI *a)
Definition: timeutils.c:67
int64_t nsI(const TimestampI *t)
Definition: timeutils.c:44