![]() |
emacps
Xilinx SDK Drivers API Documentation
|
This is top level c file for the IEEE1588 (PTP) standalone example.
It has the following functionalities. It uses SCUTimer to transmit PTP packets at regular intervals.
MODIFICATION HISTORY:
Ver Who Date Changes
1.00a asa 09/16/11 First release based on the AVB driver. 1.01a asa 03/03/12 Support for Zynq is added. BD handling is changed. 3.3 asa 05/19/16 Fix for CR#951152. Made following changes.
Functions | |
int | XEmacPs_InitScuTimer (void) |
This function initializes the SCUTimer. More... | |
void | XEmacPs_PHYSetup (XEmacPs *EmacPsInstancePtr) |
This function configures the PHY with proper speed settings and set up the PHY to be used subsequently. More... | |
int | XEmacPs_SetupIntrSystem (XScuGic *IntcInstancePtr, XEmacPs *EmacPsInstancePtr, XScuTimer *TimerInstancePtr, u16 EmacPsIntrId, u16 TimerIntrId) |
This function sets up interrupts. More... | |
void | XEmacPs_RunIEEE1588Protocol (XEmacPs *EmacInstance) |
This function implements the main state machine. More... | |
void | XEmacPs_InitializeEmacPsDma (XEmacPs_Ieee1588 *InstancePntr) |
This function initializes the EmacPs DMA buffer descriptors. More... | |
void | XEmacPs_InitializeProtocolData (XEmacPs_Ieee1588 *InstancePntr) |
This function does various initializations. More... | |
void | XEmacPs_HandleRecdPTPPacket (XEmacPs_Ieee1588 *InstancePtr) |
This function is processes the received packets. More... | |
void | XEmacPs_PtpTxInterruptHandler (XEmacPs_Ieee1588 *InstancePtr) |
This function is the Tx Done interrupt callback invoked from the EmacPs driver. More... | |
void | XEmacPs_SetDfltTxFrms (XEmacPs_Ieee1588 *InstancePtr) |
This function is used to populate the PTP Tx buffers. More... | |
u8 | XEmacPs_GetMsgType (u8 *PacketBuf) |
This function extracts PTP messgae type information from the PTP packet. More... | |
void | XEmacPs_PtpTxDoFurtherProcessing (XEmacPs_Ieee1588 *InstancePtr, u8 *PacketBuf) |
This function is invoked from the TxDone callback. More... | |
void | XEmacPs_TimerInterruptHandler (XEmacPs_Ieee1588 *InstancePtr) |
This function is the timer ISR that is invoked every 500 mseconds. More... | |
void | XEmacPs_PtpErrorInterruptHandler (XEmacPs_Ieee1588 *InstancePtr, u8 Direction, u32 ErrorWord) |
This function is the Error interrupt callback invoked from the EmacPs driver. More... | |
int | main (void) |
This is the main function for the IEEE1588 (PTP) standalone example. More... | |
unsigned int | XEmacPs_TsuCalcClk (u32 Freq) |
Calculate clock configuration register values for indicated input clock. More... | |
unsigned long | XEmacPs_DetectPHY (XEmacPs *EmacPsInstancePtr) |
This function finds out if a PHY is connected or not and if connected what is the PHY address of the connected PHY. More... | |
void | XEmacPs_ResetIeee1588Protocol (XEmacPs_Ieee1588 *InstancePtr) |
This function is used when PTP node is initialized once again. More... | |
void | XEmacPs_PtpRxInterruptHandler (XEmacPs_Ieee1588 *InstancePtr) |
This function is the EmacPs Rx interrupt callback invoked from the EmacPs driver. More... | |
int | XEmacPs_PtpTxPacket (XEmacPs_Ieee1588 *InstancePtr, u8 *PacketBuf, int PacketLen) |
This function is initiates a PTP Tx. More... | |
u32 | XEmacPs_IsRxFramePTP (u8 *PacketBuf) |
This function extracts length/type information from the Ethernet packet. More... | |
u32 | XEmacPs_ComparePortIdentity (XEmacPs_PortIdentity Identity1, XEmacPs_PortIdentity Identity2) |
A function to compare two PortIdentity values. More... | |
u32 | XEmacPs_CompareClockIdentity (XEmacPs_ClockIdentity Identity1, XEmacPs_ClockIdentity Identity2) |
A function to compare two ClockIdentity values. More... | |
void | XEmacPs_GetPortIdentity (u8 *PacketBuf, XEmacPs_PortIdentity *portID) |
A function to extract portIdentity information from a received PTP frame. More... | |
u16 | XEmacPs_GetSequenceId (u8 *PacketBuf) |
A function to extract SequenceId information from a received PTP frame. More... | |
u16 | XEmacPs_IncSequenceId (u8 *PacketBuf) |
A function to increment sequence ID in a PTP frames. More... | |
u32 | XEmacPs_htonll (unsigned long long int n) |
A function to do endian conversion for long long int type. More... | |
u32 | XEmacPs_ntohll (long long int n) |
A function to do endian conversion for long long int type. More... | |
int main | ( | void | ) |
This is the main function for the IEEE1588 (PTP) standalone example.
It calls routines to initialize ScuTimer and EmacPs. It enables interrupts at the end of all initializations and calls XEmacPs_RunIEEE1588Protocol that runs the protocol state machine.
None. |
u32 XEmacPs_CompareClockIdentity | ( | XEmacPs_ClockIdentity | Identity1, |
XEmacPs_ClockIdentity | Identity2 | ||
) |
A function to compare two ClockIdentity values.
Identity1 | is the first ClockIdentity to be compared |
Identity2 | is the second ClockIdentity to be compared |
Referenced by XEmacPs_DecodeRxAnnounceFrame().
u32 XEmacPs_ComparePortIdentity | ( | XEmacPs_PortIdentity | Identity1, |
XEmacPs_PortIdentity | Identity2 | ||
) |
A function to compare two PortIdentity values.
Identity1 | is the first sourcePortIdentity to be compared |
Identity2 | is the second sourcePortIdentity to be compared |
Referenced by XEmacPs_DecodeRxAnnounceFrame(), XEmacPs_DecodeRxFollowUp(), XEmacPs_DecodeRxPDelayResp(), XEmacPs_DecodeRxPDelayRespFollowUp(), and XEmacPs_DecodeRxSync().
unsigned long XEmacPs_DetectPHY | ( | XEmacPs * | EmacPsInstancePtr | ) |
This function finds out if a PHY is connected or not and if connected what is the PHY address of the connected PHY.
EmacPsInstancePtr | is a pointer to the instance of the EmacPs. |
References XEmacPs_PhyRead().
u8 XEmacPs_GetMsgType | ( | u8 * | PacketBuf | ) |
This function extracts PTP messgae type information from the PTP packet.
PacketBuf | contains the Ethernet packet. |
Referenced by XEmacPs_PtpTxDoFurtherProcessing().
void XEmacPs_GetPortIdentity | ( | u8 * | PacketBuf, |
XEmacPs_PortIdentity * | portID | ||
) |
A function to extract portIdentity information from a received PTP frame.
This can be any portIdentity field (header portIdentity, requestingPortIdentity etc...)
PacketBuf | contains the PTP buffer from which the portIdentity is to be extracted. |
portID | is the address of type XEmacPs_PortIdentity is which the extracted port identity is put. |
Referenced by XEmacPs_DecodeRxFollowUp(), XEmacPs_DecodeRxPDelayResp(), XEmacPs_DecodeRxPDelayRespFollowUp(), XEmacPs_DecodeRxSync(), and XEmacPs_ReadAnnounceFrame().
u16 XEmacPs_GetSequenceId | ( | u8 * | PacketBuf | ) |
A function to extract SequenceId information from a received PTP frame.
PacketBuf | contains the PTP buffer from which the portIdentity is to be extracted. |
Referenced by XEmacPs_DecodeRxFollowUp(), XEmacPs_DecodeRxPDelayRespFollowUp(), and XEmacPs_DecodeRxSync().
void XEmacPs_HandleRecdPTPPacket | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |
This function is processes the received packets.
This is invoked from XEmacPs_RunIEEE1588Protocol. It copies the received packet from the RxBuf to the corresponding buffer in XEmacPs_Ieee1588 structure instance.It then identifies the type of PTP packet received and calls the corresponding handlers to do further processing. It then frees the corresponding BD, does a allocation of the freed BD and populates the BD with appropriate buffer address (RxBuf).
InstancePntr | is a pointer to the instance of the XEmacPs_Ieee1588. |
References XEmacPs_BdRingFromHwRx(), XEmacPs_GetRxRing, and XEmacPs_GetTxRing.
u32 XEmacPs_htonll | ( | unsigned long long int | n | ) |
A function to do endian conversion for long long int type.
This is for little to big endian conversion.
Parameter | whose endian conversion is needed |
Referenced by XEmacPs_ntohll().
u16 XEmacPs_IncSequenceId | ( | u8 * | PacketBuf | ) |
A function to increment sequence ID in a PTP frames.
It first extracts the sequence ID and then increments and puts it back in the PTP frame.
PacketBuf | contains the PTP buffer from which the portIdentity is to be extracted. |
Referenced by XEmacPs_MasterSendAnnounce(), and XEmacPs_SendPDelayReq().
void XEmacPs_InitializeEmacPsDma | ( | XEmacPs_Ieee1588 * | InstancePntr | ) |
This function initializes the EmacPs DMA buffer descriptors.
16 BDs are used on the Tx path and 16 on the Rx path. On the Rx path a 2-dimensional array RxBuf[16][1540] is used. The last byte in each of the buffers is used to mark whether the RxBuf is already submitted or not. For example, if the location RxBuf[1][1539] is 1, then it means the RxBuf[1] is already submitted. During initialization, for 16 BDs, 16 RxBufs are submitted (RxBuf[0, RxBuf[1], ... RxBuf[15]]) and the corresponding entries RxBuf[0][1539], RxBuf[1][1539], ... RxBuf[15][1539] are marked as 1. On the Rx path, all 16 BDs are submitted to the hardware. Once that is done, the timer is started and so is the EmacPs.
EmacPsInstancePtr | is a pointer to the instance of the EmacPs. |
References XEmacPs_BdClear, XEmacPs_BdRingCreate(), XEmacPs_GetRxRing, and XEmacPs_GetTxRing.
void XEmacPs_InitializeProtocolData | ( | XEmacPs_Ieee1588 * | InstancePntr | ) |
This function does various initializations.
InstancePntr | is a pointer to the instance of the XEmacPs_Ieee1588. |
References XEmacPs_BecomeRtcMaster(), XEmacPs_ChangePeerIeee1588v2Capability(), XEmacPs_DecodeTxAnnounceFrame(), and XEmacPs_SetDfltTxFrms().
Referenced by XEmacPs_ResetIeee1588Protocol().
int XEmacPs_InitScuTimer | ( | void | ) |
This function initializes the SCUTimer.
None. |
u32 XEmacPs_IsRxFramePTP | ( | u8 * | PacketBuf | ) |
This function extracts length/type information from the Ethernet packet.
PacketBuf | contains the Ethernet packet. |
u32 XEmacPs_ntohll | ( | long long int | n | ) |
A function to do endian conversion for long long int type.
This is for big to little endian conversion.
Parameter | whose endian conversion is needed |
References XEmacPs_htonll().
void XEmacPs_PHYSetup | ( | XEmacPs * | EmacPsInstancePtr | ) |
This function configures the PHY with proper speed settings and set up the PHY to be used subsequently.
EmacPsInstancePtr | is a pointer to the instance of the EmacPs. |
void XEmacPs_PtpErrorInterruptHandler | ( | XEmacPs_Ieee1588 * | InstancePtr, |
u8 | Direction, | ||
u32 | ErrorWord | ||
) |
This function is the Error interrupt callback invoked from the EmacPs driver.
InstancePntr | is a pointer to the instance of the XEmacPs_Ieee1588. |
Direction | can be Rx or Tx |
ErrorWord | gives further information about the exact error type. |
void XEmacPs_PtpRxInterruptHandler | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |
This function is the EmacPs Rx interrupt callback invoked from the EmacPs driver.
Here we set the flag PtpNewPktRecd to true. This flag is checked for in the function XEmacPs_RunIEEE1588Protocol for further processing of packets.
InstancePntr | is a pointer to the instance of the XEmacPs_Ieee1588. |
void XEmacPs_PtpTxDoFurtherProcessing | ( | XEmacPs_Ieee1588 * | InstancePtr, |
u8 * | PacketBuf | ||
) |
This function is invoked from the TxDone callback.
For sync frame it obtains the time stamp and populates the FollowUp frame Tx buffer. For PDelayReq and PDelayResp frames it obtains the time stamp and stores it is appropriate buffers.
InstancePntr | is a pointer to the instance of the XEmacPs_Ieee1588. |
PacketBuf | which contains the buffer just transmitted |
References XEmacPs_GetMsgType().
void XEmacPs_PtpTxInterruptHandler | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |
This function is the Tx Done interrupt callback invoked from the EmacPs driver.
For some PTP packets, upon getting a Tx done interrupt some actions need to be taked. For example, when SYNC frame is successfully sent and Tx Done interrupt is received, the time stamp for the SYNC frame needs to be stored. For all such processing the function XEmacPs_PtpTxDoFurtherProcessing is invoked from here.
InstancePntr | is a pointer to the instance of the XEmacPs_Ieee1588. |
References XEmacPs_BdRingFromHwTx(), and XEmacPs_GetTxRing.
int XEmacPs_PtpTxPacket | ( | XEmacPs_Ieee1588 * | InstancePtr, |
u8 * | PacketBuf, | ||
int | PacketLen | ||
) |
This function is initiates a PTP Tx.
This is called from various places.
InstancePntr | is a pointer to the instance of the XEmacPs_Ieee1588. |
PacketBuf | is the buffer that contains the packet to be Txed |
PacketLen | is the length of the packet to be Txed. |
References XEmacPs_BdClearTxUsed, XEmacPs_BdRingAlloc(), XEmacPs_BdRingToHw(), XEmacPs_BdSetAddressTx, XEmacPs_BdSetLast, XEmacPs_BdSetLength, XEmacPs_GetTxRing, XEmacPs_ReadReg, XEmacPs_Transmit, and XEMACPS_TXSR_OFFSET.
Referenced by XEmacPs_MasterSendAnnounce().
void XEmacPs_ResetIeee1588Protocol | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |
This function is used when PTP node is initialized once again.
InstancePntr | is a pointer to the instance of the XEmacPs_Ieee1588. |
References XEmacPs_InitializeProtocolData().
void XEmacPs_RunIEEE1588Protocol | ( | XEmacPs * | EmacInstance | ) |
This function implements the main state machine.
After initializing the EmacPs DMA and initializing some protocol data structures it enters into a while(1) loop. Here it repeatedly checks if a new packet has been received or not. If received (the ISR marks the variable PtpNewPktRecd as true), then it calls XEmacPs_HandleRecdPTPPacket for further processing. Similarly if a packet needs to be sent out (as marked by the bits in variable PTPSendPacket, it sends it out.
EmacPsInstancePtr | is a pointer to the instance of the EmacPs. |
References XEmacPs_Stop().
void XEmacPs_SetDfltTxFrms | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |
This function is used to populate the PTP Tx buffers.
Some of the entries in a PTP Tx packet do not change with time and are constants over time for this PTP standalone example. Those entries are populated here.
InstancePntr | is a pointer to the instance of the XEmacPs_Ieee1588. |
Referenced by XEmacPs_InitializeProtocolData().
int XEmacPs_SetupIntrSystem | ( | XScuGic * | IntcInstancePtr, |
XEmacPs * | EmacPsInstancePtr, | ||
XScuTimer * | TimerInstancePtr, | ||
u16 | EmacPsIntrId, | ||
u16 | TimerIntrId | ||
) |
This function sets up interrupts.
It registers interrupt handlers and then enables them..
IntcInstancePtr | is a pointer to the instance of the SCUGic.. |
EmacPsInstancePtr | is a pointer to the instance of the EmacPs. |
TimerInstancePtr | is a pointer to the instance of the SCUTimer. |
EmacPsIntrId | is the Interrupt ID for EmacPs and the value used is taken from xparameters_ps.h. |
TimerIntrId | is the Interrupt ID for SCUTimer and the value used is taken from xparameters_ps.h. |
void XEmacPs_TimerInterruptHandler | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |
This function is the timer ISR that is invoked every 500 mseconds.
The Tx of PTP packets are initiated from here at appropriate intervals. When the PTP node is Master, the Tx of SYNC frame is triggered from here. Similarly Announce frame and PDelayReq frame Tx are triggered from here. When the PTP node is Slave, the PDelayReq frame Tx is triggered from here.
InstancePntr | is a pointer to the instance of the XEmacPs_Ieee1588. |
unsigned int XEmacPs_TsuCalcClk | ( | u32 | Freq | ) |
Calculate clock configuration register values for indicated input clock.
- | Freq |
Referenced by XEmacPs_BecomeRtcMaster().