下面是我根据107和207的以太网程序改的接收和发送函数,其中发送函数是调用的207的ETH_HandlePTPTxPkt 函数完成,能够正常获取时戳 ,接收是用的107的改的,同时也用过207的ETH_HandlePTPTxPkt函数进行修改,均部能正常获取15588时戳
///发送函数 OK
static err_t low_level_output(struct netif *netif, struct pbuf *p)
{
struct pbuf *q;
int framelength = 0;
#if LWIP_PTP
u32 stimestamp[2];
u8 Frambuffer[200];
u8 *buffer = (u8 *)Frambuffer;
if (p->tot_len>=200 ) return ERR_VAL;
#else
u8 *buffer = (u8 *)(DMATxDescToSet->Buffer1Addr);
#endif
/* copy frame from pbufs to driver buffers */
for(q = p; q != NULL; q = q->next)
{
memcpy((u8_t*)&buffer[framelength], q->payload, q->len);
framelength = framelength + q->len;
}
#if LWIP_PTP
ETH_HandlePTPTxPkt(buffer,framelength,&stimestamp[0]);
stimestamp[0] =ETH_PTPSubSecond2NanoSecond(stimestamp[0]);
p->time_sec = stimestamp[1];
p->time_nsec =stimestamp[0];
#else
/* Note: padding and CRC for transmitted frame
are automatically inserted by DMA */
/* Prepare transmit descriptors to give to DMA*/
ETH_Prepare_Transmit_Descriptors(framelength);
#endif
return ERR_OK;
}
///////接收函数 正常接收数据但时标不正确
static struct pbuf *
low_level_input(struct netif *netif)
{
struct pbuf *p, *q;
u16_t len;
int l =0;
FrameTypeDef frame;
u8 *buffer;
#if LWIP_PTP
__IO struct ptptime_t timestamp;
#endif
p = NULL;
frame.descriptor = NULL;
#if LWIP_PTP
frame.PTPdescriptor = NULL;
ETH_PTPRxPkt_ChainMode(&frame);
#else
ETH_RxPkt_ChainMode(&frame);
#endif
// Obtain the size of the packet and put it into the "len"
// variable.
len = frame.length;
buffer = (u8 *)frame.buffer;
// We allocate a pbuf chain of pbufs from the pool.
p = pbuf_alloc(PBUF_LINK, len, PBUF_RAM);
//p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != NULL)
{
for (q = p; q != NULL; q = q->next)
{
memcpy((u8_t*)q->payload, (u8_t*)&buffer[l], q->len);
l = l + q->len;
}
} else
{
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
}
#if LWIP_PTP
timestamp.tv_nsec = ETH_PTPSubSecond2NanoSecond(frame.descriptor->TimeStampLow);
timestamp.tv_sec = frame.descriptor->TimeStampHigh;
// timestamp.tv_nsec = ETH_PTPSubSecond2NanoSecond(frame.descriptor->Buffer1Addr);
// timestamp.tv_sec = frame.descriptor->Buffer2NextDescAddr;
frame.descriptor->Buffer1Addr = frame.PTPdescriptor->Buffer1Addr;
frame.descriptor->Buffer2NextDescAddr = frame.PTPdescriptor->Buffer2NextDescAddr;
// ETH_PTPRxPkt_ChainMode_CleanUp(&frame, ×tamp);
if(p != NULL)
{
p->time_sec = timestamp.tv_sec;
p->time_nsec = timestamp.tv_nsec;
}
#endif
ETH_RxPkt_ChainMode_CleanUp(&frame);
return p;
}
|