23#ifndef PROTOCORE_PTP_H
24#define PROTOCORE_PTP_H
37 PC_PTP_PDELAY_REQ = 0x2,
38 PC_PTP_PDELAY_RESP = 0x3,
39 PC_PTP_DELAY_REQ = 0x1,
40 PC_PTP_FOLLOW_UP = 0x8,
41 PC_PTP_DELAY_RESP = 0x9,
42 PC_PTP_PDELAY_RESP_FOLLOW_UP = 0xA,
46#define PC_PTP_HEADER_LEN 34
47#define PC_PTP_TS_LEN 10
48#define PC_PTP_EVENT_PORT 319
49#define PC_PTP_GENERAL_PORT 320
52struct pc_ptp_timestamp
62 uint8_t transport_specific;
64 uint16_t message_length;
68 uint8_t clock_identity[8];
76struct pc_ptp_delay_resp
78 pc_ptp_timestamp receive;
79 uint8_t req_clock_id[8];
84struct pc_ptp_pdelay_resp
86 pc_ptp_timestamp timestamp;
87 uint8_t req_clock_id[8];
94 pc_ptp_timestamp origin;
97 uint8_t gm_clock_class;
98 uint8_t gm_clock_accuracy;
100 uint8_t gm_priority2;
101 uint8_t gm_identity[8];
102 uint16_t steps_removed;
116void pc_ptp_ts_write(uint8_t *p,
const pc_ptp_timestamp *ts);
118void pc_ptp_ts_read(
const uint8_t *p, pc_ptp_timestamp *ts);
120int64_t pc_ptp_ts_to_ns(
const pc_ptp_timestamp *ts);
122void pc_ptp_ts_from_ns(int64_t ns, pc_ptp_timestamp *ts);
130size_t pc_ptp_build_header(uint8_t *buf,
size_t cap,
const pc_ptp_header *h, uint16_t body_len);
132bool pc_ptp_parse_header(
const uint8_t *s,
size_t len, pc_ptp_header *h);
137size_t pc_ptp_build_sync(uint8_t *buf,
size_t cap,
const pc_ptp_header *h,
const pc_ptp_timestamp *origin);
139size_t pc_ptp_build_delay_req(uint8_t *buf,
size_t cap,
const pc_ptp_header *h,
const pc_ptp_timestamp *origin);
141size_t pc_ptp_build_follow_up(uint8_t *buf,
size_t cap,
const pc_ptp_header *h,
const pc_ptp_timestamp *precise);
143size_t pc_ptp_build_delay_resp(uint8_t *buf,
size_t cap,
const pc_ptp_header *h,
const pc_ptp_timestamp *recv,
144 const uint8_t *req_clock_id, uint16_t req_port);
146size_t pc_ptp_build_announce(uint8_t *buf,
size_t cap,
const pc_ptp_header *h,
const pc_ptp_announce *a);
152size_t pc_ptp_build_pdelay_req(uint8_t *buf,
size_t cap,
const pc_ptp_header *h,
const pc_ptp_timestamp *origin);
154size_t pc_ptp_build_pdelay_resp(uint8_t *buf,
size_t cap,
const pc_ptp_header *h,
const pc_ptp_timestamp *recv,
155 const uint8_t *req_clock_id, uint16_t req_port);
158size_t pc_ptp_build_pdelay_resp_follow_up(uint8_t *buf,
size_t cap,
const pc_ptp_header *h,
159 const pc_ptp_timestamp *origin,
const uint8_t *req_clock_id,
166bool pc_ptp_parse_timestamp_msg(
const uint8_t *s,
size_t len, pc_ptp_header *h, pc_ptp_timestamp *ts);
168bool pc_ptp_parse_delay_resp(
const uint8_t *s,
size_t len, pc_ptp_header *h, pc_ptp_delay_resp *out);
170bool pc_ptp_parse_announce(
const uint8_t *s,
size_t len, pc_ptp_header *h, pc_ptp_announce *out);
172bool pc_ptp_parse_pdelay_req(
const uint8_t *s,
size_t len, pc_ptp_header *h, pc_ptp_timestamp *ts);
174bool pc_ptp_parse_pdelay_resp(
const uint8_t *s,
size_t len, pc_ptp_header *h, pc_ptp_pdelay_resp *out);
176bool pc_ptp_parse_pdelay_resp_follow_up(
const uint8_t *s,
size_t len, pc_ptp_header *h, pc_ptp_pdelay_resp *out);
186void pc_ptp_compute(int64_t t1, int64_t t2, int64_t t3, int64_t t4, pc_ptp_sync *out);
194int64_t pc_ptp_compute_link_delay(int64_t t1, int64_t t2, int64_t t3, int64_t t4);
User-facing configuration for ProtoCore.