📄 ieee1588.h
字号:
#ifndef _IEEE1588_H
#define _IEEE1588_H
#include "IEEE1588.h"
#ifdef IEEE1588_GLOBALS
#define IEEE1588_EXT
#else
#define IEEE1588_EXT extern
#endif
#define PTP_EVENT_PORT (319)
#define PTP_GERNERAL_PORT (320)
#define COST_TIME_FUNCTION 120//ns
#define TRUE 1
#define FALSE 0
#define IEEE1588_CLOCK_MASTER
#define PTP_MASTER_STATION 0
#define PTP_RESP_NEED 1
#define PTP_DEBUG FALSE
#define PTP_SUPPORT_MULTI TRUE
#define PTP_AVG_ACC FALSE
#define DISCARD_EXCEPTION FALSE
#define PTPDesUdpPortH 0x01
#define EVENTPTPDesUdpPortL 0x3F
#define GERNERPTPDesUdpPortL 0x40
#define OffsetPTP_Control 74
#define DesUDPOFFSETH 36
#define DesUDPOFFSETL 37
#define ToffetSync_Delay 82
#define ToffetFollow_Up 86
#define ToffetDelay_Resp 82
#define PTP_TESTFRAME_TYPE 0x8888
#define PTP_TESTRECVFRAME_TYPE 0x8889
#define MAXOFPTP_EVENT_MESSAGE 124
#if PTP_SUPPORT_MULTI == TRUE
#define PTPIPADDR 0xE0000181UL
#else
#define PTPIPADDR 0xFFFFFFFFUL //not support to Multicast
#endif
//Time type derived from the primitive types.
typedef struct TIMEREPRESENTATION{
uint32 seconds;
int32 nanoseconds;
}TimeRepresentation;
typedef struct {
int32 seconds;
int32 nanoseconds;
}TimeDiff;
#if PTP_TEST_EN > 0
#define PTPTESTPROTOCOLHIG 12
#define PTPTESTPROTOCOLLOW 13
typedef struct{
unsigned char DsthAdr[6];//组播地址
unsigned char ScrhAdr[6];
unsigned short int wfProtocol;//0x8888
unsigned short int TestSequenceId;
}PTPTestFrame;
typedef struct{
unsigned char DsthAdr[6];
unsigned char ScrhAdr[6];
unsigned short int wfProtocol; //0x8889
unsigned short int TestSequenceId; //用收到的测试请求报文中的
TimeRepresentation RevTimeStamp; //地层接收到的时刻的事件戳,越底层加入约好
TimeRepresentation SdTimeStamp; //测试响应报文发送出来的时间戳,越底层加入约好
unsigned char DeviceNum; //添IP地址的最后一位。
unsigned char Version; //暂时没有意义。
}PTPRevStampFrame;
#endif // PTP_TEST_EN
//globle variables defined in following.
typedef enum PTP_STATE{
PTP_INITIALIZING,PTP_FAULTY,PTP_DISABLED,PTP_LISTENING,
PTP_PRE_MASTER,PTP_MASTER,PTP_PASSIVE,PTP_UNCALIBRATED,
PTP_SLAVE
}PTP_State;
typedef struct {
TimeRepresentation Tsync_origin;
TimeRepresentation Tsync_recv;
uint16 parent_port_id;
uint16 parent_last_sync_sequence_number;
uint8 parent_followup_capable;
Octet parent_subdomain[16];
Octet parent_uuid[6];
}PARENT_SET;
typedef struct {
TimeDiff TOne_way_Delay;
TimeDiff Toffset;
TimeRepresentation Tsync_origin;
TimeRepresentation Tsync_recv;
TimeRepresentation Tdelay_req;
TimeRepresentation Tdelay_resp;
TimeRepresentation CurTime;
TimeRepresentation BackTorigin;
PARENT_SET Parent_set;
uint16 sequenceIdCreator;//序号产生器
uint16 ResquestingsequenceId;
uint16 BackupsequenceId;
Octet LocalUuid[6];//本地Uuid
Octet Subdomain[16];
PTP_State State;
uint8 syncvaildFlag;
Octet PTPIP[4];
}Globle_Time_Parameter;
typedef enum COMMUNICATIONID
{
PTP_CLOSED = 0,//Closed system outside the scope of this standard
PTP_ETHER,//IEEE 802.3. (Ethernet)a
PTP_FFBUS = 4 , //FOUNDATION fieldbus
PTP_PROFIBUS, //PROFIBUS
PTP_LON,
PTP_DNET,//DeviceNet
PTP_SDS,//SmartDistributedSystem.c
PTP_CONTROLNET,
PTP_CANOPEN,
PTP_IEEE1394 = 243,
PTP_IEEE802_11A,
PTP_IEEE_WIRELESS,
PTP_INFINIBAND,
PTP_BLUETOOTH,
PTP_IEEE802_15_1,
PTP_IEEE1451_3,
PTP_IEEE1451_5,
PTP_USB,
PTP_ISA,
PTP_PCI,
PTP_VXI,
PTP_DEFAULT
}CommunicationId;
typedef enum CONCTROLFIELD{
PTP_SYNC_MESSAGE = 0,
PTP_DELAY_REQ_MESSAGE,
PTP_FOLLOWUP_MESSAGE,
PTP_DELAY_RESP_MESSAGE = 3,
PTP_MANAGEMENT_MESSAGE
//else reserved.
}ControlField;
typedef enum MANAGEMENTMESSAGE{
PTP_MM_NULL = 0,
PTP_MM_OBTAIN_IDENTITY,
PTP_MM_CLOCK_IDENTITY,
PTP_MM_INITIALIZE_CLOCK,
PTP_MM_SET_SUBDOMAIN,
PTP_MM_CLEAR_DESIGNATED_PREFERRED_MASTER,
PTP_MM_SET_DESIGNATED_PREFERRED_MASTER,
PTP_MM_GET_DEFAULT_DATA_SET,
PTP_MM_DEFAULT_DATA_SET,
PTP_MM_UPDATE_DEFAULT_DATA_SET,
PTP_MM_GET_CURRENT_DATA_SET,
PTP_MM_CURRENT_DATA_SET,
PTP_MM_GET_PARENT_DATA_SET,
PTP_MM_PARENT_DATA_SET,
PTP_MM_GET_PORT_DATA_SET,
PTP_MM_PORT_DATA_SET,
PTP_MM_GET_GLOBAL_TIME_DATA_SET,
PTP_MM_GLOBAL_TIME_DATA_SET,
PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES,
PTP_MM_GOTO_FAULTY_STATE,
PTP_MM_GET_FOREIGN_DATA_SET,
PTP_MM_FOREIGN_DATA_SET,
PTP_MM_SET_SYNC_INTERVAL,
PTP_MM_DISABLE_PORT,
PTP_MM_ENABLE_PORT,
PTP_MM_DISABLE_BURST,
PTP_MM_ENABLE_BURST,
PTP_MM_SET_TIME
//Reserved :28-127
//Implementation-specific:128–255
}ManagementMessage;
//PTP Sync,Delay_Req ,Follow_UP and Delay_Resp message Header
typedef struct PTP_HEADER{
uint16 versionPTP;
uint16 versionNetwork;
Octet subdomain[16];
uint8 messageType;
uint8 sourceCommunicationTechnology;
Octet sourceUuid[6];
uint16 sourcePortId;
uint16 sequenceId;
uint8 control;
Octet reserved1;
Octet flags[2];
Octet reserved2[4];
}PTP_Header,*PPTP_Header;
//PTP Sync and Delay_Req message body defined in following.
//PTP Sync and Delay_Req message include the body and
//PTP_HEADER.
//The Sync and Delay_Req messages format:
//struct Sync(or Delay_Req){
// PTP_HEADER;
// PTP_SYNC_OR_DELAY_REQ_BODY;
//}
typedef struct PTP_SYNC_OR_DELAY_REQ_BODY
{
TimeRepresentation originTimestamp;
uint16 epochNumber;
int16 currentUTCOffset;
Octet reserved1;
uint8 grandmasterCommunicationTechnology;
Octet grandmasterClockUuid[6];
uint16 grandmasterPortId;
uint16 grandmasterSequenceId;
Octet reserved2[3];
uint8 grandmasterClockStratum;
Octet grandmasterClockIdentifier[4];
Octet reserved3[2];
int16 grandmasterClockVariance;
Octet reserved4;
uint8 grandmasterPreferred;
Octet reserved5;
uint8 grandmasterIsBoundaryClock;
Octet reserved6[3];
int8 syncInterval;
Octet reserved7[2];
int16 localClockVariance;
Octet reserved8[2];
uint16 localStepsRemoved;
Octet reserved9[3];
uint8 localClockStratum;
Octet localClockIdentifier[4];
Octet reserved10;
uint8 parentCommunicationTechnology;
Octet parentUuid[6];
Octet reserved11[2];
uint16 parentPortField;
Octet reserved12[2];
int16 estimatedMasterVariance;
int32 estimatedMasterDrift;
Octet reserved13[3];
Octet utcReasonable;
}PTP_Sync_OR_Delay_Req_Body,*PPTP_Sync_OR_Delay_Req_Body;
//PTP Follow_Up message body defined in following.
//PTP Follow_Up message include the body and PTP_HEADER.
//
//The Follow_Up messages format:
//struct Follow_Up
//{
// PTP_HEADER;
// PTP_FOLLOW_UP_BODY;
//}
typedef struct PTP_FOLLOW_UP_BODY{
Octet reserved1[2];
uint16 associatedSequenceId;
TimeRepresentation preciseOriginTimestamp;
}PTP_Follow_Up_Body,*PPTP_Follow_Up_Body;
//PTP Delay_Resp messages body specification
//The Delay_Resp messages format:
//struct Delay_Resp{
// PTP_HEADER;
// PTP_DELAY_RESP_BODY;
//}
typedef struct PTP_DELAY_RESP_BODY{
TimeRepresentation delayReceiptTimestamp;
Octet reserved1;
uint8 requestingSourceCommunicationTechnology;
Octet requestingSourceUuid[6];
uint16 requestingSourcePortId;
uint16 requestingSourceSequenceId;
}PTP_Delay_Resp_Body,*PPTP_Delay_Resp_Body;
//message defined in the following.
typedef struct PTP_SYNC_OR_DELAY_REQ{
PTP_Header Header;
PTP_Sync_OR_Delay_Req_Body Body;
}PTP_Sync_Or_Delay_Req,*PPTP_Sync_Or_Delay_Req;
typedef struct PTP_FOLLOW_UP{
PTP_Header Header;
PTP_Follow_Up_Body Body;
}PTP_Follow_Up,*PPTP_Follow_Up;
typedef struct PTP_DELAY_RESP{
PTP_Header Header;
PTP_Delay_Resp_Body Body;
}PTP_Delay_Resp,*PPTP_Delay_Resp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -