Zephyr API 3.6.99
Loading...
Searching...
No Matches
ptp_time.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
15#ifndef ZEPHYR_INCLUDE_NET_PTP_TIME_H_
16#define ZEPHYR_INCLUDE_NET_PTP_TIME_H_
17
27#include <zephyr/net/net_core.h>
28#include <zephyr/net/net_time.h>
29#include <zephyr/toolchain.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
113 union {
114
116 struct {
117#ifdef CONFIG_LITTLE_ENDIAN
118 uint32_t low;
119 uint16_t high;
120 uint16_t unused;
121#else
122 uint16_t unused;
123 uint16_t high;
124 uint32_t low;
125#endif
126 } _sec;
131 };
132
135};
136
137#ifdef __cplusplus
138}
139#endif
140
156 union {
157
159 struct {
160#ifdef CONFIG_LITTLE_ENDIAN
161 uint32_t low;
162 uint16_t high;
163 uint16_t unused;
164#else
165 uint16_t unused;
166 uint16_t high;
167 uint32_t low;
168#endif
169 } _sec;
174 };
175
177 union {
178
180 struct {
181#ifdef CONFIG_LITTLE_ENDIAN
182 uint32_t low;
183 uint16_t high;
184 uint16_t unused;
185#else
186 uint16_t unused;
187 uint16_t high;
188 uint32_t low;
189#endif
190 } _fns;
195 };
196} __packed;
197
211{
212 if (!ts) {
213 return 0;
214 }
215
216 if (ts->second >= NET_TIME_SEC_MAX) {
217 return NET_TIME_MAX;
218 }
219
220 return ((int64_t)ts->second * NSEC_PER_SEC) + ts->nanosecond;
221}
222
232{
233 struct net_ptp_time ts;
234
235 __ASSERT_NO_MSG(nsec >= 0);
236
237 ts.second = nsec / NSEC_PER_SEC;
238 ts.nanosecond = nsec % NSEC_PER_SEC;
239 return ts;
240}
241
246#endif /* ZEPHYR_INCLUDE_NET_PTP_TIME_H_ */
#define NSEC_PER_SEC
number of nanoseconds per second
Definition sys_clock.h:107
#define NET_TIME_MAX
The largest positive time value that can be represented by net_time_t.
Definition net_time.h:106
#define NET_TIME_SEC_MAX
The largest positive number of seconds that can be safely represented by net_time_t.
Definition net_time.h:112
int64_t net_time_t
Any occurrence of net_time_t specifies a concept of nanosecond resolution scalar time span,...
Definition net_time.h:103
static net_time_t net_ptp_time_to_ns(struct net_ptp_time *ts)
Convert a PTP timestamp to a nanosecond precision timestamp, both related to the local network refere...
Definition ptp_time.h:210
static struct net_ptp_time ns_to_net_ptp_time(net_time_t nsec)
Convert a nanosecond precision timestamp to a PTP timestamp, both related to the local network refere...
Definition ptp_time.h:231
Network core definitions.
Representation of nanosecond resolution elapsed time and timestamps in the network stack.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT64_TYPE__ int64_t
Definition stdint.h:75
Generalized Precision Time Protocol Extended Timestamp format.
Definition ptp_time.h:154
uint64_t fract_nsecond
Fractional nanoseconds value.
Definition ptp_time.h:194
uint64_t second
Second value.
Definition ptp_time.h:173
(Generalized) Precision Time Protocol Timestamp format.
Definition ptp_time.h:111
uint32_t nanosecond
Nanoseconds.
Definition ptp_time.h:134
uint64_t second
Second value.
Definition ptp_time.h:130
Macros to abstract toolchain specific capabilities.