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 struct {
113#ifdef CONFIG_LITTLE_ENDIAN
117#else
121#endif
122 } _sec;
124 };
125
128};
129
130#ifdef __cplusplus
131}
132#endif
133
149 union {
150 struct {
151#ifdef CONFIG_LITTLE_ENDIAN
155#else
159#endif
160 } _sec;
162 };
163
165 union {
166 struct {
167#ifdef CONFIG_LITTLE_ENDIAN
171#else
175#endif
176 } _fns;
178 };
179} __packed;
180
194{
195 if (!ts) {
196 return 0;
197 }
198
199 if (ts->second >= NET_TIME_SEC_MAX) {
200 return NET_TIME_MAX;
201 }
202
203 return ((int64_t)ts->second * NSEC_PER_SEC) + ts->nanosecond;
204}
205
215{
216 struct net_ptp_time ts;
217
218 __ASSERT_NO_MSG(nsec >= 0);
219
220 ts.second = nsec / NSEC_PER_SEC;
221 ts.nanosecond = nsec % NSEC_PER_SEC;
222 return ts;
223}
224
229#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:193
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:214
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:147
uint16_t unused
Definition: ptp_time.h:156
uint16_t high
Definition: ptp_time.h:157
uint64_t fract_nsecond
Definition: ptp_time.h:177
uint64_t second
Definition: ptp_time.h:161
uint32_t low
Definition: ptp_time.h:158
(Generalized) Precision Time Protocol Timestamp format.
Definition: ptp_time.h:109
uint16_t high
Definition: ptp_time.h:119
uint32_t nanosecond
Nanoseconds.
Definition: ptp_time.h:127
uint64_t second
Definition: ptp_time.h:123
uint16_t unused
Definition: ptp_time.h:118
uint32_t low
Definition: ptp_time.h:120
Macros to abstract toolchain specific capabilities.