Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
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
25#include <zephyr/net/net_core.h>
26#include <zephyr/net/net_time.h>
27#include <zephyr/toolchain.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
111 union {
112
114 struct {
115#ifdef CONFIG_LITTLE_ENDIAN
116 uint32_t low;
117 uint16_t high;
118 uint16_t unused;
119#else
120 uint16_t unused;
121 uint16_t high;
122 uint32_t low;
123#endif
124 } _sec;
129 };
130
133};
134
135#ifdef __cplusplus
136}
137#endif
138
154 union {
155
157 struct {
158#ifdef CONFIG_LITTLE_ENDIAN
159 uint32_t low;
160 uint16_t high;
161 uint16_t unused;
162#else
163 uint16_t unused;
164 uint16_t high;
165 uint32_t low;
166#endif
167 } _sec;
172 };
173
175 union {
176
178 struct {
179#ifdef CONFIG_LITTLE_ENDIAN
180 uint32_t low;
181 uint16_t high;
182 uint16_t unused;
183#else
184 uint16_t unused;
185 uint16_t high;
186 uint32_t low;
187#endif
188 } _fns;
193 };
194} __packed;
195
209{
210 if (!ts) {
211 return 0;
212 }
213
214 if (ts->second >= NET_TIME_SEC_MAX) {
215 return NET_TIME_MAX;
216 }
217
218 return ((int64_t)ts->second * NSEC_PER_SEC) + ts->nanosecond;
219}
220
230{
231 struct net_ptp_time ts;
232
233 __ASSERT_NO_MSG(nsec >= 0);
234
235 ts.second = nsec / NSEC_PER_SEC;
236 ts.nanosecond = nsec % NSEC_PER_SEC;
237 return ts;
238}
239
244#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:104
#define NET_TIME_SEC_MAX
The largest positive number of seconds that can be safely represented by net_time_t.
Definition: net_time.h:110
int64_t net_time_t
Any occurrence of net_time_t specifies a concept of nanosecond resolution scalar time span,...
Definition: net_time.h:101
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:208
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:229
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:152
uint64_t fract_nsecond
Fractional nanoseconds value.
Definition: ptp_time.h:192
uint64_t second
Second value.
Definition: ptp_time.h:171
(Generalized) Precision Time Protocol Timestamp format.
Definition: ptp_time.h:109
uint32_t nanosecond
Nanoseconds.
Definition: ptp_time.h:132
uint64_t second
Second value.
Definition: ptp_time.h:128
Macros to abstract toolchain specific capabilities.