[STM32F2] STM32F2 1588问题 发送可以打时标,接收不能打

[复制链接]
3167|5
 楼主| 455685673 发表于 2014-10-13 20:03 | 显示全部楼层 |阅读模式
下面是我根据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, &timestamp);
  if(p != NULL)
  {
p->time_sec = timestamp.tv_sec;
p->time_nsec = timestamp.tv_nsec;
  }
#endif

  ETH_RxPkt_ChainMode_CleanUp(&frame);

  return p;
}
mmuuss586 发表于 2014-10-13 20:56 | 显示全部楼层

这个不会,回答不了你;
支持下;
 楼主| 455685673 发表于 2014-10-13 21:28 | 显示全部楼层
谢谢支持
steelen 发表于 2016-9-1 14:05 | 显示全部楼层
都可以的
aabbme 发表于 2018-3-25 16:50 | 显示全部楼层
请问问题解决了吗
aabbme 发表于 2018-3-25 16:52 | 显示全部楼层

请教一下,能否指点一下,我现在也是出现问题,收到的数据包总是不捕获时间戳,时间戳显示为0,这个问题大致出在哪个寄存器上面?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

6

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部