This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS570LS3137: DP83640 create ptp messages and send

Part Number: TMS570LS3137
Other Parts Discussed in Thread: DP83640

Hello,

I'm trying to use ptpv2 protocol with TMS570LS31HDK. HDK has DP83640 as ethernet phy on it. First of all I'm trying to see very first sync message in wireshark. Note that I can succesfully send and receive udp messages with lwIP library.

I initialize ptp protocol with PTPInit() and call this function in hdkif_hw_init(), after EMACEnable and before TX/RX Int Enable functions. 

I comfirmed that I can correctly change register values via mdio.

void PTPInit()
{
RX_CFG_ITEMS rxCfgItems;
uint32_t rxCfgOpts;
TimeInternal ts;

// Disable 1588 clock, set start time, set rate to 0
PTPEnable( &pObj, FALSE);

// Disconnect event from GPIO 12
PTPSetEventConfig( &pObj, 7, FALSE, FALSE, FALSE, 0);

flags = 0;

PTPSetClockConfig( &pObj, flags, 0, 0, 8); 

PTPEnable( &pObj, TRUE);

PTPClockSet( &pObj, 0, 0);

// Setup the PPS configuration
// PTPSetTriggerConfig( &pObj, 0, TRGOPT_PULSE|TRGOPT_PERIODIC|TRGOPT_NOTIFY_EN, ptpStackCfg->ppsGpio);
// PTPArmTrigger( &pObj, 0, ptpStackCfg->ppsStartTime, 0,
// ptpStackCfg->ppsRiseOrFallFlag, FALSE, 500000000, 500000000);


// Disable Transmit and Receive Timestamp
PTPSetTransmitConfig( &pObj, 0, 0, 0, 0);
memset( &rxCfgItems, 0, sizeof( RX_CFG_ITEMS));
PTPSetReceiveConfig( &pObj, 0, &rxCfgItems);

// Flush Transmit, Receive and Event Timestamps
while ( (events = PTPCheckForEvents( &pObj))) {
if ( events & PTPEVT_TRANSMIT_TIMESTAMP_BIT)
PTPGetTransmitTimestamp( &pObj, &ts.seconds, &ts.nanoseconds, &overflowCount);
if ( events & PTPEVT_RECEIVE_TIMESTAMP_BIT)
PTPGetReceiveTimestamp( &pObj, &ts.seconds, &ts.nanoseconds, &overflowCount, &seqId, &msgType, &hashValue);
if ( events & PTPEVT_EVENT_TIMESTAMP_BIT)
PTPGetEvent( &pObj, &eventNum, &riseFlag, &ts.seconds, &ts.nanoseconds, &eventsMissed);
}

// Enable Transmit Timestamp operation
flags = TXOPT_IPV4_EN | TXOPT_TS_EN ;//| TXOPT_CRC_1STEP | TXOPT_CHK_1STEP | TXOPT_SYNC_1STEP | TXOPT_IGNORE_2STEP ;

PTPSetTransmitConfig( &pObj, flags, 2, 0xF8, 0x00);

MDIOPhyRegWrite(pObj.portMdioAddress, pObj.portPhyAddress,(uint32_t)PHY_PAGESEL ,(uint16_t) 4);
MDIOPhyRegWrite(pObj.portMdioAddress, pObj.portPhyAddress,(uint32_t)PTP_TXCFG1 , (uint16_t)TXTS_IE);

// Enable Receive Timestamp operation
rxCfgItems.ptpVersion = 0x02;
rxCfgItems.ptpFirstByteMask = 0xF8;
rxCfgItems.ptpFirstByteData = 0x00;
rxCfgItems.ipAddrData = 0;
rxCfgItems.tsMinIFG = 0x0C;
rxCfgItems.srcIdHash = 0;
rxCfgItems.ptpDomain = 0;
rxCfgItems.tsSecLen = 3; //0; // DRs option
rxCfgItems.rxTsNanoSecOffset = 0; //0x24; // DRs option
rxCfgItems.rxTsSecondsOffset = 0; //0x21; // DRs option

rxCfgOpts = RXOPT_RX_IPV4_EN|RXOPT_RX_TS_EN|RXOPT_ACC_UDP|RXOPT_ACC_CRC;


PTPSetReceiveConfig( &pObj, rxCfgOpts, &rxCfgItems);

}

When i want to read current clock, i get reasonable values. But I couldn't understand how do I start the sync process. I know I have to get event bits like below Phy_Sync() but events always returns 0. 

void Phy_Sync() {

TimeInternal ts;
while ( (events = PTPCheckForEvents( &pObj))) {
if ( events & PTPEVT_TRANSMIT_TIMESTAMP_BIT)
PTPGetTransmitTimestamp( &pObj, &ts.seconds, &ts.nanoseconds, &overflowCount);
if ( events & PTPEVT_RECEIVE_TIMESTAMP_BIT)
PTPGetReceiveTimestamp( &pObj, &ts.seconds, &ts.nanoseconds, &overflowCount, &seqId, &msgType, &hashValue);
if ( events & PTPEVT_EVENT_TIMESTAMP_BIT)
PTPGetEvent( &pObj, &eventNum, &riseFlag, &ts.seconds, &ts.nanoseconds, &eventsMissed);
}
}

I'm new to ethernet so sorry if this is an obvious question. Do I have to create a buffer according to ptpmessage and fill it with register values and send it via udp? Or the hardware does it automatically and i miss something.