flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
ptp_types.h File Reference

This module defines the fundamental PTP message and state machine type, flags, bitfields and the PTP engine's internal state types. More...

#include <stdbool.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "event.h"
#include "ptp_defs.h"
#include "timers.h"
#include "timeutils.h"
#include "ptp_sync_cycle_data.h"
#include <flexptp_options.h>

Go to the source code of this file.

Data Structures

struct  PtpFlags
 PTP flags structure. More...
 
struct  PtpHeader
 PTP message header structure. More...
 
struct  PtpDelay_RespIdentification
 Identification carrying Delay_Resp message. More...
 
struct  RawPtpMessage
 Raw PTP message structure. More...
 
struct  PtpAnnounceBody
 Contents of a PTP Announce message without the common PTP header. More...
 
struct  PtpBmcaState
 BMCA state. More...
 
struct  PtpProfileTlvElement
 PTP profile additional data list element. More...
 
struct  PtpProfile
 PTP profile structure. More...
 
struct  PtpTlvHeader
 PTP TLV. More...
 
struct  PtpSlaveMessagingState
 PTP slave messaging state structure. More...
 
struct  PtpMasterMessagingState
 PTP master messaging state structure. More...
 
struct  PtpP2PSlaveInfo
 PTP P2P slave info structure;. More...
 
struct  PtpHWClockState
 Hardware clock state. More...
 
struct  PtpNetworkState
 Network state. More...
 
struct  PtpStats
 Structure for statistics. More...
 
struct  PtpCoreState
 Giant PTP core state object. More...
 

Macros

#define MAX_PTP_MSG_SIZE   (128)
 Maximum PTP message size.
 
#define PTP_VARIANCE_HAS_NOT_BEEN_COMPUTED   (0xFFFF)
 
#define PTP_TLV_HEADER
 

Typedefs

typedef PtpAnnounceBody PtpMasterProperties
 
typedef void(* PtpSyncCallback) (int64_t time_error, const PtpSyncCycleData *pSCD, uint32_t freqCodeWord)
 
typedef void(* PtpUserEventCallback) (PtpUserEventCode uev)
 

Enumerations

enum  PtpMessageType {
  PTP_MT_Sync = 0 , PTP_MT_Delay_Req = 1 , PTP_MT_PDelay_Req = 2 , PTP_MT_PDelay_Resp = 3 ,
  PTP_MT_Follow_Up = 8 , PTP_MT_Delay_Resp = 9 , PTP_MT_PDelay_Resp_Follow_Up = 10 , PTP_MT_Announce = 11
}
 PTP packet type enumeration. More...
 
enum  PtpControl {
  PTP_CON_Sync = 0 , PTP_CON_Delay_Req = 1 , PTP_CON_Follow_Up = 2 , PTP_CON_Delay_Resp = 3 ,
  PTP_CON_Other = 5
}
 PTP header control field values. More...
 
enum  PtpTransportType { PTP_TP_IPv4 = 0 , PTP_TP_802_3 = 1 }
 PTP transport type enumeration. More...
 
enum  PtpDelayMechanism { PTP_DM_E2E = 0 , PTP_DM_P2P = 1 }
 PTP Delay mechanism enumeration. More...
 
enum  PtpTransportSpecific { PTP_TSPEC_UNKNOWN_DEF = 0 , PTP_TSPEC_GPTP_8021AS = 1 }
 PTP transport specific enumeration. More...
 
enum  PtpMessageClass { PTP_MC_EVENT = 0 , PTP_MC_GENERAL = 1 }
 Enumeration for different PTP message classes. More...
 
enum  PtpClockClass {
  PTP_CC_PRIMARY_REFERENCE = 6 , PTP_CC_PRIMARY_REFERENCE_HOLDOVER = 7 , PTP_CC_APPLICATION_SPECIFIC = 13 , PTP_CC_APPLICAION_SPECIFIC_HOLDOVER = 14 ,
  PTP_CC_PRIMARY_REFERENCE_DEGRAD_A = 52 , PTP_CC_APPLICATION_SPECIFIC_DEGRAD_A = 58 , PTP_CC_PRIMARY_REFERENCE_DEGRAD_B = 187 , PTP_CC_APPLICATION_SPECIFIC_DEGRAD_B = 193 ,
  PTP_CC_DEFAULT = 248 , PTP_CC_SLAVE_ONLY = 255
}
 Standard PTP clock classes. More...
 
enum  PtpClockAccuracy {
  PTP_CA_25NS = 0x20 , PTP_CA_100NS , PTP_CA_250NS , PTP_CA_1US ,
  PTP_CA_2_5US , PTP_CA_10US , PTP_CA_25US , PTP_CA_100US ,
  PTP_CA_250US , PTP_CA_1MS , PTP_CA_2_5MS , PTP_CA_10MS ,
  PTP_CA_25MS , PTP_CA_100MS , PTP_CA_250MS , PTP_CA_1S ,
  PTP_CA_10S , PTP_CA_GT10S , PTP_CA_UNKNOWN = 0xFE
}
 Standard clock accuray definitions. More...
 
enum  PtpTimeSource {
  PTP_TSRC_ATOMIC_CLOCK = 0x10 , PTP_TSRC_GPS = 0x20 , PTP_TSRC_TERRESTRIAL_RADIO = 0x30 , PTP_TSRC_PTP = 0x40 ,
  PTP_TSRC_NTP = 0x50 , PTP_TSRC_HAND_SET = 0x60 , PTP_TSRC_OTHER = 0x90 , PTP_TSRC_INTERNAL_OSCILLATOR = 0xA0
}
 Standard PTP time source definitions. More...
 
enum  PtpM2SState { SIdle , SWaitFollowUp }
 Core state machine states. More...
 
enum  BmcaMasterState { BMCA_NO_MASTER = 0 , BMCA_MASTER_REMOTE , BMCA_MASTER_ME }
 BMCA master states. More...
 
enum  BmcaCandidateState { BMCA_NO_CANDIDATE = 0 , BMCA_CANDIDATE_COLLECTION }
 BMCA candidate states. More...
 
enum  PtpLogMsgPeriods { PTP_LOGPER_MIN = -3 , PTP_LOGPER_MAX = 4 , PTP_LOGPER_SYNCMATCHED = 127 }
 Enumeration for logarithmic message period boundaries. More...
 
enum  PtpBmcaFsmState {
  PTP_BMCA_INITIALIZING = 0x00 , PTP_BMCA_LISTENING , PTP_BMCA_PRE_MASTER , PTP_BMCA_MASTER ,
  PTP_BMCA_SLAVE , PTP_BMCA_PASSIVE , PTP_BMCA_UNCALIBRATED , PTP_BMCA_FAULTY ,
  PTP_BMCA_DISABLED
}
 
enum  PtpProfileFlags { PTP_PF_NONE = 0x00 , PTP_PF_ISSUE_SYNC_FOR_COMPLIANT_SLAVE_ONLY_IN_P2P = 0x01 , PTP_PF_SLAVE_ONLY = 0x02 , PTP_PF_N }
 PTP profile flags. More...
 
enum  PtpTlvType {
  PTP_TLV_MANAGEMENT = 0x01 , PTP_TLV_MANAGEMENT_ERROR_STATUS , PTP_TLV_ORGANIZATION_EXTENSION , PTP_TLV_REQUEST_UNICAST_TRANSMISSION = 0x04 ,
  PTP_TLV_GRANT_UNICAST_TRANSMISSION , PTP_TLV_CANCEL_UNICAST_TRANSMISSION , PTP_TLV_ACKNOWLEDGE_CANCEL_UNICAST_TRANSMISSION , PTP_TLV_PATH_TRACE = 0x08 ,
  PTP_TLV_ALTERNATE_TIME_OFFSET_INDICATOR = 0x09 , PTP_TLV_AUTHENTICATION = 0x2000 , PTP_TLV_AUTHENTICATION_CHALLENGE = 0x2001 , PTP_TLV_SECURITY_ASSOCIATION_UPDATE = 0x2002 ,
  PTP_TLV_CUM_FREQ_SCALE_FACTOR_OFFSET = 0x2003
}
 PTP TLV types. More...
 
enum  PtpP2PSlaveState { PTP_P2PSS_NONE = 0 , PTP_P2PSS_CANDIDATE , PTP_P2PSS_ESTABLISHED }
 PTP P2P slave state viewed from the MASTER. More...
 

Detailed Description

This module defines the fundamental PTP message and state machine type, flags, bitfields and the PTP engine's internal state types.

Definition in file ptp_types.h.

Macro Definition Documentation

◆ MAX_PTP_MSG_SIZE

#define MAX_PTP_MSG_SIZE   (128)

Maximum PTP message size.

Definition at line 157 of file ptp_types.h.

◆ PTP_TLV_HEADER

#define PTP_TLV_HEADER
Value:
uint16_t type; \
uint16_t length;

Length of this TLV

Definition at line 375 of file ptp_types.h.

◆ PTP_VARIANCE_HAS_NOT_BEEN_COMPUTED

#define PTP_VARIANCE_HAS_NOT_BEEN_COMPUTED   (0xFFFF)

Definition at line 231 of file ptp_types.h.

Typedef Documentation

◆ PtpMasterProperties

Definition at line 248 of file ptp_types.h.

◆ PtpSyncCallback

typedef void(* PtpSyncCallback) (int64_t time_error, const PtpSyncCycleData *pSCD, uint32_t freqCodeWord)

Sync callback type prototype.

Definition at line 447 of file ptp_types.h.

◆ PtpUserEventCallback

typedef void(* PtpUserEventCallback) (PtpUserEventCode uev)

User event callback prototype.

Definition at line 452 of file ptp_types.h.

Enumeration Type Documentation

◆ BmcaCandidateState

BMCA candidate states.

Enumerator
BMCA_NO_CANDIDATE 

No candidate on the network.

BMCA_CANDIDATE_COLLECTION 

Collecting candidates, we are in the candidate collection time window.

Definition at line 270 of file ptp_types.h.

◆ BmcaMasterState

BMCA master states.

Enumerator
BMCA_NO_MASTER 

No master.

BMCA_MASTER_REMOTE 

A remote master is found to be the best.

BMCA_MASTER_ME 

I am the best master, yeey!

Definition at line 261 of file ptp_types.h.

◆ PtpBmcaFsmState

Enumerator
PTP_BMCA_INITIALIZING 
PTP_BMCA_LISTENING 
PTP_BMCA_PRE_MASTER 
PTP_BMCA_MASTER 
PTP_BMCA_SLAVE 
PTP_BMCA_PASSIVE 
PTP_BMCA_UNCALIBRATED 
PTP_BMCA_FAULTY 
PTP_BMCA_DISABLED 

Definition at line 284 of file ptp_types.h.

◆ PtpClockAccuracy

Standard clock accuray definitions.

Enumerator
PTP_CA_25NS 

Accurate to within 25ns.

PTP_CA_100NS 

Accurate to within 100ns.

PTP_CA_250NS 

Accurate to within 250ns.

PTP_CA_1US 

Accurate to within 1us.

PTP_CA_2_5US 

Accurate to within 2.5us.

PTP_CA_10US 

Accurate to within 10us.

PTP_CA_25US 

Accurate to within 25us.

PTP_CA_100US 

Accurate to within 100us.

PTP_CA_250US 

Accurate to within 250us.

PTP_CA_1MS 

Accurate to within 1ms.

PTP_CA_2_5MS 

Accurate to within 2.5ms.

PTP_CA_10MS 

Accurate to within 10ms.

PTP_CA_25MS 

Accurate to within 25ms.

PTP_CA_100MS 

Accurate to within 100ms.

PTP_CA_250MS 

Accurate to within 250ms.

PTP_CA_1S 

Accurate to within 1s.

PTP_CA_10S 

Accurate to within 10s.

PTP_CA_GT10S 

Accurate to > 10s.

PTP_CA_UNKNOWN 

Accuracy is unknown.

Definition at line 195 of file ptp_types.h.

◆ PtpClockClass

Standard PTP clock classes.

Enumerator
PTP_CC_PRIMARY_REFERENCE 

Primary reference clock, cannot be a slave.

PTP_CC_PRIMARY_REFERENCE_HOLDOVER 

Normally a Primary reference clock, but now working in holdover mode.

PTP_CC_APPLICATION_SPECIFIC 

Application specific reference clock, ARB timescale, cannot be a slave.

PTP_CC_APPLICAION_SPECIFIC_HOLDOVER 

An Application specific class clock that operates in holdover.

PTP_CC_PRIMARY_REFERENCE_DEGRAD_A 

A Primary reference operating off the holdover specification.

PTP_CC_APPLICATION_SPECIFIC_DEGRAD_A 

An Application specific class clock operating off the holdover specification.

PTP_CC_PRIMARY_REFERENCE_DEGRAD_B 

A Primary reference operating off the holdover specification, can be a slave.

PTP_CC_APPLICATION_SPECIFIC_DEGRAD_B 

An Application specific class clock operating off the holdover specification, can be a slave.

PTP_CC_DEFAULT 

Default clock class.

PTP_CC_SLAVE_ONLY 

The clock is slave ony.

Definition at line 179 of file ptp_types.h.

◆ PtpControl

enum PtpControl

PTP header control field values.

Enumerator
PTP_CON_Sync 

Sync.

PTP_CON_Delay_Req 

Delay Request.

PTP_CON_Follow_Up 

Follow Up.

PTP_CON_Delay_Resp 

Delay Response.

PTP_CON_Other 

Other.

Definition at line 43 of file ptp_types.h.

◆ PtpDelayMechanism

PTP Delay mechanism enumeration.

Enumerator
PTP_DM_E2E 

End-to-End Delay Mechanism.

PTP_DM_P2P 

Peer-to-Peer Delay Mechanism.

Definition at line 136 of file ptp_types.h.

◆ PtpLogMsgPeriods

Enumeration for logarithmic message period boundaries.

Enumerator
PTP_LOGPER_MIN 

Minimal logarithmic messaging period.

PTP_LOGPER_MAX 

Maximal logarithmic messaging period.

PTP_LOGPER_SYNCMATCHED 

Messaging occurs whenever a Sync arrives.

Definition at line 278 of file ptp_types.h.

◆ PtpM2SState

Core state machine states.

Enumerator
SIdle 

Idle.

SWaitFollowUp 

Waiting for a Follow Up message.

Definition at line 253 of file ptp_types.h.

◆ PtpMessageClass

Enumeration for different PTP message classes.

Enumerator
PTP_MC_EVENT 

Event Message Class.

PTP_MC_GENERAL 

General Message Class.

Definition at line 152 of file ptp_types.h.

◆ PtpMessageType

PTP packet type enumeration.

Enumerator
PTP_MT_Sync 

Sync.

PTP_MT_Delay_Req 

Delay Request.

PTP_MT_PDelay_Req 

Peer Delay Request.

PTP_MT_PDelay_Resp 

Peer Delay Response.

PTP_MT_Follow_Up 

Follow Up.

PTP_MT_Delay_Resp 

Delay Response.

PTP_MT_PDelay_Resp_Follow_Up 

Peer Delay Response Follow Up.

PTP_MT_Announce 

Announce.

Definition at line 29 of file ptp_types.h.

◆ PtpP2PSlaveState

PTP P2P slave state viewed from the MASTER.

Enumerator
PTP_P2PSS_NONE 

No slave is detected.

PTP_P2PSS_CANDIDATE 

A slave has reported in at least once, now being checked on.

PTP_P2PSS_ESTABLISHED 

The slave is considered stable and ready.

Definition at line 406 of file ptp_types.h.

◆ PtpProfileFlags

PTP profile flags.

Enumerator
PTP_PF_NONE 

Empty profile flags.

PTP_PF_ISSUE_SYNC_FOR_COMPLIANT_SLAVE_ONLY_IN_P2P 

Send Sync messages only for a compliant peer in P2P mode.

PTP_PF_SLAVE_ONLY 

Operating only in SLAVE mode.

PTP_PF_N 

Number of available PTP profile flags.

Definition at line 321 of file ptp_types.h.

◆ PtpTimeSource

Standard PTP time source definitions.

Enumerator
PTP_TSRC_ATOMIC_CLOCK 

The clock is directly connected to such a device and using the PTP timescale.

PTP_TSRC_GPS 

The clock is synchronized to a satellite system that distribtues time and frequency tied to international standards.

PTP_TSRC_TERRESTRIAL_RADIO 

The clock is synchronized via any type of radio distribution system that is tied to international standards.

PTP_TSRC_PTP 

The clock is synchronized to a different PTP domain.

PTP_TSRC_NTP 

The clock is synchronized via NTP or SNTP.

PTP_TSRC_HAND_SET 

The clock has been set by means of a human interface based on observation of an international standard source of time within the claimed clock accuracy.

PTP_TSRC_OTHER 

Any of source not covered by other values.

PTP_TSRC_INTERNAL_OSCILLATOR 

Undisciplined, free running oscillator.

Definition at line 220 of file ptp_types.h.

◆ PtpTlvType

enum PtpTlvType

PTP TLV types.

Enumerator
PTP_TLV_MANAGEMENT 

Management extension.

PTP_TLV_MANAGEMENT_ERROR_STATUS 

Management error status.

PTP_TLV_ORGANIZATION_EXTENSION 

Organization extension.

PTP_TLV_REQUEST_UNICAST_TRANSMISSION 
PTP_TLV_GRANT_UNICAST_TRANSMISSION 
PTP_TLV_CANCEL_UNICAST_TRANSMISSION 
PTP_TLV_ACKNOWLEDGE_CANCEL_UNICAST_TRANSMISSION 
PTP_TLV_PATH_TRACE 
PTP_TLV_ALTERNATE_TIME_OFFSET_INDICATOR 
PTP_TLV_AUTHENTICATION 
PTP_TLV_AUTHENTICATION_CHALLENGE 
PTP_TLV_SECURITY_ASSOCIATION_UPDATE 
PTP_TLV_CUM_FREQ_SCALE_FACTOR_OFFSET 

Definition at line 346 of file ptp_types.h.

◆ PtpTransportSpecific

PTP transport specific enumeration.

Enumerator
PTP_TSPEC_UNKNOWN_DEF 

Unkown Transport Specific Flag (default)

PTP_TSPEC_GPTP_8021AS 

802.1AS Transport Specific Flag

Definition at line 144 of file ptp_types.h.

◆ PtpTransportType

PTP transport type enumeration.

Enumerator
PTP_TP_IPv4 

IPv4 Transport Type.

PTP_TP_802_3 

Ethernet Transport Type.

Definition at line 128 of file ptp_types.h.