Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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
23#include <net/net_core.h>
24#include <net/ptp_time.h>
25#include <stdbool.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
33#define GPTP_OFFSET_SCALED_LOG_VAR_UNKNOWN 0x436A
34
35#define GPTP_PRIORITY1_NON_GM_CAPABLE 255
36#define GPTP_PRIORITY1_GM_CAPABLE 248
37
38#if defined(CONFIG_NET_GPTP_BMCA_PRIORITY2)
39#define GPTP_PRIORITY2_DEFAULT CONFIG_NET_GPTP_BMCA_PRIORITY2
40#else
41#define GPTP_PRIORITY2_DEFAULT 248
42#endif
43
52
55} __packed;
56
63
66} __packed;
67
70#if defined(CONFIG_NEWLIB_LIBC)
71#include <math.h>
72
73#define GPTP_POW2(exp) pow(2, exp)
74#else
75
76static inline double gptp_pow2(int exp)
77{
78 double res;
79
80 if (exp >= 0) {
81 res = 1 << exp;
82 } else {
83 res = 1.0;
84
85 while (exp++) {
86 res /= 2;
87 }
88 }
89
90 return res;
91}
92
93#define GPTP_POW2(exp) gptp_pow2(exp)
94#endif
95
96/* Pre-calculated constants */
97/* 2^16 */
98#define GPTP_POW2_16 65536.0
99/* 2^41 */
100#define GPTP_POW2_41 2199023255552.0
101
102/* Message types. Event messages have BIT(3) set to 0, and general messages
103 * have that bit set to 1. IEEE 802.1AS chapter 10.5.2.2.2
104 */
105#define GPTP_SYNC_MESSAGE 0x00
106#define GPTP_DELAY_REQ_MESSAGE 0x01
107#define GPTP_PATH_DELAY_REQ_MESSAGE 0x02
108#define GPTP_PATH_DELAY_RESP_MESSAGE 0x03
109#define GPTP_FOLLOWUP_MESSAGE 0x08
110#define GPTP_DELAY_RESP_MESSAGE 0x09
111#define GPTP_PATH_DELAY_FOLLOWUP_MESSAGE 0x0a
112#define GPTP_ANNOUNCE_MESSAGE 0x0b
113#define GPTP_SIGNALING_MESSAGE 0x0c
114#define GPTP_MANAGEMENT_MESSAGE 0x0d
115
116#define GPTP_IS_EVENT_MSG(msg_type) (!((msg_type) & BIT(3)))
117
118#define GPTP_CLOCK_ID_LEN 8
119
127 uint8_t clk_id[GPTP_CLOCK_ID_LEN];
128
131} __packed;
132
134 union {
137
140 };
141} __packed;
142
143struct gptp_hdr {
146
149
152
155
158
161
164
167
170
173
176
179
182
185} __packed;
186
189#define GPTP_GET_CURRENT_TIME_USCALED_NS(port, uscaled_ns_ptr) \
190 do { \
191 (uscaled_ns_ptr)->low = \
192 gptp_get_current_time_nanosecond(port) << 16; \
193 (uscaled_ns_ptr)->high = 0; \
194 } while (false)
195
212 uint8_t *gm_identity,
213 uint16_t *time_base,
214 struct gptp_scaled_ns *last_gm_ph_change,
215 double *last_gm_freq_change);
216
228
231};
232
241
244
247
250};
251
260
267
272
282int gptp_event_capture(struct net_ptp_time *slave_time, bool *gm_present);
283
293char *gptp_sprint_clock_id(const uint8_t *clk_id, char *output,
294 size_t output_len);
295
304typedef void (*gptp_port_cb_t)(int port, struct net_if *iface,
305 void *user_data);
306
314
321struct gptp_domain *gptp_get_domain(void);
322
330
338struct gptp_hdr *gptp_get_hdr(struct net_pkt *pkt);
339
340#ifdef __cplusplus
341}
342#endif
343
348#endif /* ZEPHYR_INCLUDE_NET_GPTP_H_ */
void
Definition: eswifi_shell.c:15
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_port_cb_t)(int port, struct net_if *iface, void *user_data)
Callback used while iterating over gPTP ports.
Definition: gptp.h:304
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:211
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_register_phase_dis_cb(struct gptp_phase_dis_cb *phase_dis, gptp_phase_dis_callback_t cb)
Register a phase discontinuity callback.
struct gptp_domain * gptp_get_domain(void)
Get gPTP domain.
flags
Definition: http_parser.h:131
Network core definitions.
Public functions for the Precision Time Protocol time specification.
struct _snode sys_snode_t
Definition: slist.h:33
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__INT32_TYPE__ int32_t
Definition: stdint.h:44
__UINT64_TYPE__ uint64_t
Definition: stdint.h:61
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
__INT64_TYPE__ int64_t
Definition: stdint.h:45
__INT8_TYPE__ int8_t
Definition: stdint.h:42
ClockSourceTime.invoke function parameters.
Definition: gptp.h:238
struct net_ptp_extended_time src_time
Definition: gptp.h:243
double last_gm_freq_change
Definition: gptp.h:240
struct gptp_scaled_ns last_gm_phase_change
Definition: gptp.h:246
uint16_t time_base_indicator
Definition: gptp.h:249
Definition: gptp.h:133
uint16_t all
Definition: gptp.h:139
uint8_t octets[2]
Definition: gptp.h:136
Definition: gptp.h:143
int64_t correction_field
Definition: gptp.h:169
uint8_t domain_number
Definition: gptp.h:160
uint16_t sequence_id
Definition: gptp.h:178
int8_t log_msg_interval
Definition: gptp.h:184
uint8_t control
Definition: gptp.h:181
struct gptp_port_identity port_id
Definition: gptp.h:175
uint8_t ptp_version
Definition: gptp.h:151
uint16_t message_length
Definition: gptp.h:157
uint32_t reserved2
Definition: gptp.h:172
uint8_t transport_specific
Definition: gptp.h:148
uint8_t message_type
Definition: gptp.h:145
uint8_t reserved1
Definition: gptp.h:163
uint8_t reserved0
Definition: gptp.h:154
Phase discontinuity callback structure.
Definition: gptp.h:225
gptp_phase_dis_callback_t cb
Definition: gptp.h:230
sys_snode_t node
Definition: gptp.h:227
Port Identity.
Definition: gptp.h:125
uint16_t port_number
Definition: gptp.h:130
uint8_t clk_id[GPTP_CLOCK_ID_LEN]
Definition: gptp.h:127
Scaled Nanoseconds.
Definition: gptp.h:49
int64_t low
Definition: gptp.h:54
int32_t high
Definition: gptp.h:51
UScaled Nanoseconds.
Definition: gptp.h:60
uint32_t high
Definition: gptp.h:62
uint64_t low
Definition: gptp.h:65
Network Interface structure.
Definition: net_if.h:468
Network packet.
Definition: net_pkt.h:62
Precision Time Protocol Extended Timestamp format.
Definition: ptp_time.h:76
Precision Time Protocol Timestamp format.
Definition: ptp_time.h:39
static const intptr_t user_data[5]
Definition: main.c:590