Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
gptp.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
13#ifndef ZEPHYR_INCLUDE_NET_GPTP_H_
14#define ZEPHYR_INCLUDE_NET_GPTP_H_
15
25#include <zephyr/net/net_core.h>
26#include <zephyr/net/ptp_time.h>
27#include <stdbool.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
35#define GPTP_OFFSET_SCALED_LOG_VAR_UNKNOWN 0x436A
36
37#define GPTP_PRIORITY1_NON_GM_CAPABLE 255
38#define GPTP_PRIORITY1_GM_CAPABLE 248
39
40#if defined(CONFIG_NET_GPTP_BMCA_PRIORITY2)
41#define GPTP_PRIORITY2_DEFAULT CONFIG_NET_GPTP_BMCA_PRIORITY2
42#else
43#define GPTP_PRIORITY2_DEFAULT 248
44#endif
45
54
57} __packed;
58
65
68} __packed;
69
72#if defined(CONFIG_NEWLIB_LIBC)
73#include <math.h>
74
75#define GPTP_POW2(exp) pow(2, exp)
76#else
77
78static inline double gptp_pow2(int exp)
79{
80 double res;
81
82 if (exp >= 0) {
83 res = 1 << exp;
84 } else {
85 res = 1.0;
86
87 while (exp++) {
88 res /= 2;
89 }
90 }
91
92 return res;
93}
94
95#define GPTP_POW2(exp) gptp_pow2(exp)
96#endif
97
98/* Pre-calculated constants */
99/* 2^16 */
100#define GPTP_POW2_16 65536.0
101/* 2^41 */
102#define GPTP_POW2_41 2199023255552.0
103
104/* Message types. Event messages have BIT(3) set to 0, and general messages
105 * have that bit set to 1. IEEE 802.1AS chapter 10.5.2.2.2
106 */
107#define GPTP_SYNC_MESSAGE 0x00
108#define GPTP_DELAY_REQ_MESSAGE 0x01
109#define GPTP_PATH_DELAY_REQ_MESSAGE 0x02
110#define GPTP_PATH_DELAY_RESP_MESSAGE 0x03
111#define GPTP_FOLLOWUP_MESSAGE 0x08
112#define GPTP_DELAY_RESP_MESSAGE 0x09
113#define GPTP_PATH_DELAY_FOLLOWUP_MESSAGE 0x0a
114#define GPTP_ANNOUNCE_MESSAGE 0x0b
115#define GPTP_SIGNALING_MESSAGE 0x0c
116#define GPTP_MANAGEMENT_MESSAGE 0x0d
117
118#define GPTP_IS_EVENT_MSG(msg_type) (!((msg_type) & BIT(3)))
119
120#define GPTP_CLOCK_ID_LEN 8
121
129 uint8_t clk_id[GPTP_CLOCK_ID_LEN];
130
133} __packed;
134
137 union {
140
143 };
144} __packed;
145
190
193#define GPTP_GET_CURRENT_TIME_USCALED_NS(port, uscaled_ns_ptr) \
194 do { \
195 (uscaled_ns_ptr)->low = \
196 gptp_get_current_time_nanosecond(port) << 16; \
197 (uscaled_ns_ptr)->high = 0; \
198 } while (false)
199
216 uint8_t *gm_identity,
217 uint16_t *time_base,
218 struct gptp_scaled_ns *last_gm_ph_change,
219 double *last_gm_freq_change);
220
236
255
264
271
276
286int gptp_event_capture(struct net_ptp_time *slave_time, bool *gm_present);
287
297char *gptp_sprint_clock_id(const uint8_t *clk_id, char *output,
298 size_t output_len);
299
308typedef void (*gptp_port_cb_t)(int port, struct net_if *iface,
309 void *user_data);
310
317void gptp_foreach_port(gptp_port_cb_t cb, void *user_data);
318
325struct gptp_domain *gptp_get_domain(void);
326
334
342struct gptp_hdr *gptp_get_hdr(struct net_pkt *pkt);
343
344#ifdef __cplusplus
345}
346#endif
347
352#endif /* ZEPHYR_INCLUDE_NET_GPTP_H_ */
void gptp_foreach_port(gptp_port_cb_t cb, void *user_data)
Go through all the gPTP ports and call callback for each of them.
void gptp_call_phase_dis_cb(void)
Call a phase discontinuity callback function.
char * gptp_sprint_clock_id(const uint8_t *clk_id, char *output, size_t output_len)
Utility function to print clock id to a user supplied buffer.
void gptp_unregister_phase_dis_cb(struct gptp_phase_dis_cb *phase_dis)
Unregister a phase discontinuity callback.
struct gptp_hdr * gptp_get_hdr(struct net_pkt *pkt)
Return pointer to gPTP packet header in network packet.
int gptp_event_capture(struct net_ptp_time *slave_time, bool *gm_present)
Get gPTP time.
void gptp_clk_src_time_invoke(struct gptp_clk_src_time_invoke_params *arg)
This interface is used by the ClockSource entity to provide time to the ClockMaster entity of a time-...
void(* gptp_port_cb_t)(int port, struct net_if *iface, void *user_data)
Callback used while iterating over gPTP ports.
Definition gptp.h:308
void gptp_register_phase_dis_cb(struct gptp_phase_dis_cb *phase_dis, gptp_phase_dis_callback_t cb)
Register a phase discontinuity callback.
void(* gptp_phase_dis_callback_t)(uint8_t *gm_identity, uint16_t *time_base, struct gptp_scaled_ns *last_gm_ph_change, double *last_gm_freq_change)
Define callback that is called after a phase discontinuity has been sent by the grandmaster.
Definition gptp.h:215
struct gptp_domain * gptp_get_domain(void)
Get gPTP domain.
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
Network core definitions.
flags
Definition parser.h:96
Public functions for the Precision Time Protocol time specification.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT64_TYPE__ int64_t
Definition stdint.h:75
__INT8_TYPE__ int8_t
Definition stdint.h:72
ClockSourceTime.invoke function parameters.
Definition gptp.h:242
struct net_ptp_extended_time src_time
The time this function is invoked.
Definition gptp.h:247
double last_gm_freq_change
Frequency change on the last Time Base Indicator Change.
Definition gptp.h:244
struct gptp_scaled_ns last_gm_phase_change
Phase change on the last Time Base Indicator Change.
Definition gptp.h:250
uint16_t time_base_indicator
Time Base - changed only if Phase or Frequency changes.
Definition gptp.h:253
gPTP message flags
Definition gptp.h:136
uint16_t all
Whole field access.
Definition gptp.h:142
uint8_t octets[2]
Byte access.
Definition gptp.h:139
gPTP message header
Definition gptp.h:147
int64_t correction_field
Correction Field.
Definition gptp.h:173
uint8_t domain_number
Domain number, always 0.
Definition gptp.h:164
uint16_t sequence_id
Sequence Id.
Definition gptp.h:182
int8_t log_msg_interval
Message Interval in Log2 for Sync and Announce messages.
Definition gptp.h:188
uint8_t control
Control value.
Definition gptp.h:185
struct gptp_port_identity port_id
Port Identity of the sender.
Definition gptp.h:179
uint8_t ptp_version
Version of the PTP, always 2.
Definition gptp.h:155
uint16_t message_length
Total length of the message from the header to the last TLV.
Definition gptp.h:161
uint32_t reserved2
Reserved field.
Definition gptp.h:176
uint8_t transport_specific
Transport specific, always 1.
Definition gptp.h:152
uint8_t message_type
Type of the message.
Definition gptp.h:149
uint8_t reserved1
Reserved field.
Definition gptp.h:167
uint8_t reserved0
Reserved field.
Definition gptp.h:158
Phase discontinuity callback structure.
Definition gptp.h:229
gptp_phase_dis_callback_t cb
Phase discontinuity callback.
Definition gptp.h:234
sys_snode_t node
Node information for the slist.
Definition gptp.h:231
Port Identity.
Definition gptp.h:127
uint16_t port_number
Number of the port.
Definition gptp.h:132
uint8_t clk_id[GPTP_CLOCK_ID_LEN]
Clock identity of the port.
Definition gptp.h:129
Scaled Nanoseconds.
Definition gptp.h:51
int64_t low
Low half.
Definition gptp.h:56
int32_t high
High half.
Definition gptp.h:53
UScaled Nanoseconds.
Definition gptp.h:62
uint32_t high
High half.
Definition gptp.h:64
uint64_t low
Low half.
Definition gptp.h:67
Network Interface structure.
Definition net_if.h:680
Network packet.
Definition net_pkt.h:69
Generalized Precision Time Protocol Extended Timestamp format.
Definition ptp_time.h:154
(Generalized) Precision Time Protocol Timestamp format.
Definition ptp_time.h:111