4#include "flexptp_options.h"
22#define MIN(a, b) (((a) < (b)) ? (a) : (b))
28#define MAX(a, b) (((a) > (b)) ? (a) : (b))
31#define S (gPtpCoreState)
205 delRespMsg.
pTs = NULL;
207 delRespMsg.
pTxCb = NULL;
222#define PTP_MASTER_P2P_SLAVE_STATE_LOG() \
223 CLILOG(S.logging.def && (si->state != prevState), "%s -> %s\n", P2P_SLAVE_STATE_HINTS[prevState], P2P_SLAVE_STATE_HINTS[si->state])
287 CLILOG(S.logging.timestamps,
289 "T1: %d.%09d <- PDelay_Req TX (master)\n"
290 "T2: %d.%09d <- PDelay_Req RX (slave) \n"
291 "T3: %d.%09d <- PDelay_Resp TX (slave) \n"
292 "T4: %d.%09d <- PDelay_Resp RX (master)\n"
293 " %09lu -- %09lu <- CF in PDelay_Resp and ..._Follow_Up\n\n",
294 (uint32_t)S.master.pdelay_reqSequenceID,
301 CLILOG(S.logging.def,
"%ld\n",
nsI(mpd));
330 scd->
t[
T4] = pRawMsg->
ts;
338 scd->
t[
T2] = scd->
t[
T3] = zeroTs;
387 S.master.enabled =
false;
395 S.master.enabled =
true;
403 S.master.syncTmr = 0;
404 S.master.announceTmr = 0;
405 S.master.pdelayReqTmr = 0;
408 S.master.pdelay_reqSequenceID = 0;
418 S.master.enabled =
false;
422 if (!S.master.enabled) {
430 if (++S.master.pdelayReqTmr >= S.master.pdelayReqTickPeriod) {
431 S.master.pdelayReqTmr = 0;
454 if (++S.master.syncTmr >= S.master.syncTickPeriod) {
455 S.master.syncTmr = 0;
463 if (++S.master.announceTmr >= S.master.announceTickPeriod) {
464 S.master.announceTmr = 0;
void ptp_compute_mean_path_delay_p2p(const TimestampI *pTs, const uint64_t *pCf, TimestampI *pMPD)
void ptp_send_delay_req_message()
This module defines messaging functions for both the slave and master modules.
@ PTP_UEV_PDELAY_RESP_FOLLOW_UP_RECVED
A PDelay_Resp_Follow_Up had been received (master/slave)
@ PTP_UEV_PDELAY_REQ_SENT
A PDelay_Req had been sent (master/slave)
@ PTP_UEV_SYNC_SENT
A Sync message has eebn sent (master)
@ PTP_UEV_PDELAY_RESP_RECVED
A PDelay_Resp had been received (master/slave)
@ PTP_UEV_DELAY_RESP_SENT
A Delay_Resp had been sent (master)
@ PTP_UEV_ANNOUNCE_SENT
An Announce message has been sent (master)
@ PTP_UEV_DELAY_REQ_RECVED
A Delay_Req had been received (master)
static void ptp_init_sync_header()
void ptp_master_disable()
static PtpHeader syncHeader
#define PTP_MASTER_P2P_SLAVE_STATE_LOG()
static void ptp_master_p2p_slave_reported(uint64_t slClockId)
static void ptp_send_delay_resp_message(const RawPtpMessage *pRawMsg, const PtpHeader *pHeader)
static void ptp_init_follow_up_message()
static RawPtpMessage followUp
static PtpHeader announceHeader
static void ptp_send_follow_up(const RawPtpMessage *pMsg)
static void ptp_send_announce_message()
void ptp_master_destroy()
static const PtpProfileTlvElement * tlvChain
void ptp_master_process_message(RawPtpMessage *pRawMsg, PtpHeader *pHeader)
static void ptp_init_announce_header()
static RawPtpMessage sync
static RawPtpMessage announce
static char * P2P_SLAVE_STATE_HINTS[]
static void ptp_send_sync_message()
static void ptp_master_commence_mpd_computation()
This module implements the master clock functionality.
void ptp_write_delay_resp_id_data(void *pPayload, const PtpDelay_RespIdentification *pDRData)
void ptp_construct_binary_announce_message(void *pData, const PtpAnnounceBody *pAnnounce)
void ptp_extract_header(PtpHeader *pHeader, const void *pPayload)
void ptp_extract_timestamps(TimestampI *ts, void *pPayload, uint8_t n)
void ptp_read_delay_resp_id_data(PtpDelay_RespIdentification *pDRData, void *pPayload)
void ptp_construct_binary_header(void *pData, const PtpHeader *pHeader)
void ptp_write_binary_timestamps(void *pPayload, const TimestampI *ts, uint8_t n)
void ptp_clear_flags(PtpFlags *pFlags)
This module defines functions that deal with actual PTP messages; they can extract or insert headers,...
Core of the PTP implementation. Defines functions for message processing, clock tuning,...
In here reside a multitude of fundamental PTP-related constants and definitions.
#define PTP_HEARTBEAT_TICKRATE_MS
Heartbeat ticking period.
#define PTP_PCKT_SIZE_FOLLOW_UP
Size of a Follow_Up message.
#define PTP_PCKT_SIZE_ANNOUNCE
Size of an Announce message.
#define PTP_PDELAY_DROPOUT
Maximum number of failed PDelReq-PDelResp cycles before the MASTER drops the SLAVE.
#define PTP_PCKT_SIZE_DELAY_RESP
Size of a Delay_Resp message.
#define PTP_PCKT_SIZE_SYNC
Size of a Sync message.
#define PTP_PORT_ID
PTP port ID on the device.
#define PTP_PDELAY_SLAVE_QUALIFICATION
Number of consecutive PDelReq-PDelResp iterations after the SLAVE is considered stable.
const PtpProfileTlvElement * ptp_tlv_chain_preset_get(const char *pName)
This module manages predefined profile presets. It allows their fetching by name or ID.
This module defines the context object of a full synchronization cycle. In SLAVE mode four timestamps...
This module defines the fundamental PTP message and state machine type, flags, bitfields and the PTP ...
@ PTP_CON_Follow_Up
Follow Up.
@ PTP_CON_Delay_Resp
Delay Response.
@ PTP_LOGPER_SYNCMATCHED
Messaging occurs whenever a Sync arrives.
@ PTP_MC_EVENT
Event Message Class.
@ PTP_MC_GENERAL
General Message Class.
PtpMessageType
PTP packet type enumeration.
@ PTP_MT_Delay_Resp
Delay Response.
@ PTP_MT_PDelay_Resp
Peer Delay Response.
@ PTP_MT_Announce
Announce.
@ PTP_MT_Delay_Req
Delay Request.
@ PTP_MT_PDelay_Resp_Follow_Up
Peer Delay Response Follow Up.
@ PTP_MT_Follow_Up
Follow Up.
PtpDelayMechanism
PTP Delay mechanism enumeration.
@ PTP_DM_E2E
End-to-End Delay Mechanism.
@ PTP_DM_P2P
Peer-to-Peer Delay Mechanism.
#define MAX_PTP_MSG_SIZE
Maximum PTP message size.
PtpP2PSlaveState
PTP P2P slave state viewed from the MASTER.
@ PTP_P2PSS_ESTABLISHED
The slave is considered stable and ready.
@ PTP_P2PSS_NONE
No slave is detected.
@ PTP_P2PSS_CANDIDATE
A slave has reported in at least once, now being checked on.
@ PTP_PF_ISSUE_SYNC_FOR_COMPLIANT_SLAVE_ONLY_IN_P2P
Send Sync messages only for a compliant peer in P2P mode.
Identification carrying Delay_Resp message.
uint64_t requestingSourceClockIdentity
Requesting Source Clock Identity.
uint16_t requestingSourcePortIdentity
Requesting Source Port Identity.
bool PTP_TIMESCALE
Timescale.
bool PTP_TWO_STEP
Two Step.
PTP master messaging state structure.
PTP P2P slave info structure;.
uint16_t reportCount
Number of times the slave had reported in.
uint16_t dropoutCntr
Dropout watchdog counter for resetting the state machine if the slave went silent.
uint64_t identity
The clock identity of the connected, operating P2P slave.
PtpP2PSlaveState state
Indicates that a slave is responding to our PDELAY_REQ messages.
PTP profile additional data list element.
PTP synchronization cycle data.
TimestampI t[6]
T1-T6 timestamps.
uint64_t cf[6]
T1-T6 correction fields.
Raw PTP message structure.
PtpDelayMechanism tx_dm
transmit transport type
PtpMessageClass tx_mc
transmit message class
void(* pTxCb)(const struct RawPtpMessage_ *pMsg)
transmit callback function
uint32_t size
Packet size.
TimestampI * pTs
pointer to timestamp
uint8_t data[(128)]
raw packet data
int32_t nanosec
nanoseconds
bool ptp_transmit_enqueue(const RawPtpMessage *pMsg)
The entry point of the whole PTP-implementation. Calling reg_task_ptp() initializes the PTP-engine,...
int64_t nsI(const TimestampI *t)
This module defines storage classes for timestamps and operations on time values.
uint16_t ptp_tlv_insert(void *dst, const PtpProfileTlvElement *pad, PtpMessageType mt, uint16_t maxLen)
This module implements the TLV-related functionality.