⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zl5011xrtp.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 4 页
字号:

 Remarks:
   None
*******************************************************************************/

extern zlStatusE zl5011xRtpSeedTimestamp(zl5011xParamsS *zl5011xParams,
      Uint32T context,
      Uint32T timestamp)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T headerAddress;
   Uint32T timestampWord = 0, position = 0, timestampBit0 = 0;
   zl5011xContextHeaderSwitchE modifyHeader;

   ZL5011X_TRACE_CONTEXT(ZL5011X_RTP_FN_ID, context,
         "zl5011xRtpSeedTimestamp: ctxt %3d, timestamp 0x%.8lx",
         context, timestamp, 0, 0, 0, 0);

   /* determine which is the shadow header. This is the one to add the
      timestamp into - and not the active header */
   modifyHeader = zl5011xParams->packetIf.packetTx.txHeader[context].shadowHeader;

   /* check that the timestamp is enabled before continuing */
   if (zl5011xParams->packetIf.packetTx.txHeader[context].highHeader[modifyHeader].layer5TimestampEnable != ZL5011X_TRUE)
   {
      status = ZL5011X_INVALID_MODE;
   }

   /* check that the timestamp position is valid */
   if (status == ZL5011X_OK)
   {
      if (((zl5011xParams->packetIf.packetTx.txHeader[context].highHeader[modifyHeader].layer5Timestamp32bit == ZL5011X_TRUE) &&
            (zl5011xParams->packetIf.packetTx.txHeader[context].highHeader[modifyHeader].layer5TimestampPos > (ZL5011X_RTP_HIGH_HEADER_MAX_LEN - 4))) ||
            ((zl5011xParams->packetIf.packetTx.txHeader[context].highHeader[modifyHeader].layer5Timestamp32bit == ZL5011X_FALSE) &&
            (zl5011xParams->packetIf.packetTx.txHeader[context].highHeader[modifyHeader].layer5TimestampPos > (ZL5011X_RTP_HIGH_HEADER_MAX_LEN - 2))))
      {
         status = ZL5011X_INVALID_MODE;
      }
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xRtpGetHeaderAddress(zl5011xParams, context, modifyHeader,
            &headerAddress);
   }

   if (status == ZL5011X_OK)
   {
      /* get location of timestamp in words and bits */
      position = zl5011xParams->packetIf.packetTx.txHeader[context].highHeader[modifyHeader].layer5TimestampPos;
      timestampWord = position & ~ ZL5011X_2BIT_MASK;

      /* check the bottom two bits to determine the shift required for
         this part of the field */
      if ((position & ZL5011X_2BIT_MASK) != 0)
      {
         timestampBit0 = 16;
      }
      else
      {
         timestampBit0 = 0;
      }

      if (zl5011xParams->packetIf.packetTx.txHeader[context].highHeader[modifyHeader].layer5Timestamp32bit == ZL5011X_FALSE)
      {
         /* a 16 bit timestamp, so write it into the correct 16 bit location */
         status = zl5011xReadModWrite(zl5011xParams,
               headerAddress + timestampWord,
               timestamp << timestampBit0,
               ZL5011X_16BIT_MASK << timestampBit0);
      }
      else
      {
         /* a 32 bit timestamp is aligned on a 32 bit boundary */
         status = zl5011xWrite(zl5011xParams,
               headerAddress + timestampWord,
               timestamp);
      }
   }

   return status;
}

/*******************************************************************************
 Function:
    zl5011xRtpGetTimestamp

 Description:
      Returns the timestamp from the RTP Tx header. This is the timestamp used for
      the last Tx packet.
      This uses the currently active header. Implying that the delay from the PLA
      to the RTP block is short.

 Inputs:
    zl5011xParams      Pointer to the structure for this device instance
   context            Selected context

 Outputs:
   timestamp   Timestamp from the RTP Tx header, used for the last Tx packet.

 Returns:
   zlStatusE

 Remarks:
   None

*******************************************************************************/

extern zlStatusE zl5011xRtpGetTimestamp(zl5011xParamsS *zl5011xParams,
      Uint32T context,
      Uint32T *pTimestamp)
{
   zlStatusE status = ZL5011X_OK;
   zl5011xContextHeaderSwitchE activeHeader;
   Uint32T headerAddress;
   Uint32T timestampWord= 0, position= 0, timestampBit0= 0;
   Uint32T rtpData;

   ZL5011X_TRACE_CONTEXT(ZL5011X_RTP_FN_ID, context, "zl5011xRtpGetTimestamp: ctxt %3d, ",
              context, 0, 0, 0, 0, 0);

   /* Determine which is the active header */
   if (zl5011xParams->packetIf.packetTx.txHeader[context].shadowHeader == ZL5011X_PRIMARY_HEADER)
   {
      activeHeader = ZL5011X_SECONDARY_HEADER;
   }
   else
   {
      activeHeader = ZL5011X_PRIMARY_HEADER;
   }

   /* get location of timestamp if enabled */
   if ( zl5011xParams->packetIf.packetTx.txHeader[context].highHeader[activeHeader].layer5TimestampEnable == ZL5011X_TRUE)
   {
      status = zl5011xRtpGetHeaderAddress(zl5011xParams, context, activeHeader,
                                          &headerAddress);

      if (status == ZL5011X_OK)
      {
         /* get the position of the timestamp in the header */
         position = zl5011xParams->packetIf.packetTx.txHeader[context].highHeader[activeHeader].layer5TimestampPos;
         /* mask off the bottom bits of the position, to get a 32 bit address */
         timestampWord = position & ~ ZL5011X_2BIT_MASK;

         /* check the bottom two bits to determine the shift required for
            this part of the field */
         if ((position & ZL5011X_2BIT_MASK) != 0)
         {
            timestampBit0 = 16;
         }
         else
         {
            timestampBit0 = 0;
         }

         /* read word containing timestamp */
         status = zl5011xRead(zl5011xParams,
               headerAddress + timestampWord,
               &rtpData);
      }

      if (status == ZL5011X_OK)
      {
         /* either 32 or 16 bit timestamp */
         if (zl5011xParams->packetIf.packetTx.txHeader[context].highHeader[activeHeader].layer5Timestamp32bit == ZL5011X_TRUE)
         {
            *pTimestamp = rtpData;
         }
         else
         {
            if (timestampBit0 == 0)
            {
               *pTimestamp = rtpData & ZL5011X_16BIT_MASK;
            }
            else
            {
               *pTimestamp = (rtpData >> timestampBit0) & ZL5011X_16BIT_MASK;
            }
         }
      }

      ZL5011X_TRACE(ZL5011X_RTP_FN_ID, "zl5011xRtpGetTimestamp: ctxt %3d, timestamp 0x%.8lx ",
              context, *pTimestamp, 0, 0, 0, 0);
   }
   else
   {
      *pTimestamp = 0;

      ZL5011X_TRACE(ZL5011X_RTP_FN_ID, "zl5011xRtpGetTimestamp: ctxt %3d, timestamp not enabled",
              context, 0, 0, 0, 0, 0);
   }

   return status;
}

/*******************************************************************************
 Function:
    zl5011xRtpInitStatisticsEntry

 Description:
   Writes to the memory that holds the Tx and Rx statistics for a particular
   context, setting the interrupt bits to allow an interrupt on counter
   overflow, and clearing the counters.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context        Selected context

 Outputs:
   None

 Returns:
  zlStatusE

 Remarks:
   None

*******************************************************************************/

extern zlStatusE  zl5011xRtpInitStatisticsEntry(zl5011xParamsS *zl5011xParams,
            Uint32T context)
{

   zlStatusE status = ZL5011X_OK;
   Uint32T statsAddress, bits;

   ZL5011X_TRACE_CONTEXT(ZL5011X_RTP_FN_ID, context,
         "zl5011xRtpInitStatisticsEntry: ctxt %d",
         context, 0, 0, 0, 0, 0);

   /* Set all fields in statistics data base structure to zero */
   status = zl5011xRtpGetStatisticsAddress(zl5011xParams, context,
         &statsAddress);

   /* write the Tx byte count word in the sender stats table */
   if (status == ZL5011X_OK)
   {
      bits = 0;
      status = zl5011xWrite(zl5011xParams,
            statsAddress + (ZL5011X_RTP_TX_BYTE_COUNT_INDEX * sizeof(Uint32T)),
            bits);
   }

   /* write the Tx packet count word in the sender stats table */
   if (status == ZL5011X_OK)
   {
      bits = ZL5011X_RTP_TCE_OFFSET_MASK;
      status = zl5011xWrite(zl5011xParams,
            statsAddress + (ZL5011X_RTP_TX_PACKET_COUNT_INDEX * sizeof(Uint32T)),
            bits);
   }

   /* write the Rx packet count word in the sender stats table */
   if (status == ZL5011X_OK)
   {
      bits = ZL5011X_RTP_RCE_OFFSET_MASK;

      status = zl5011xWrite(zl5011xParams,
            statsAddress + (ZL5011X_RTP_RX_PACKET_COUNT_INDEX * sizeof(Uint32T)),
            bits);
   }

   /* write the seq number word in the sender stats table */
   if (status == ZL5011X_OK)
   {
      bits = ZL5011X_RTP_INTERRUPT_MODE;
      status = zl5011xWrite(zl5011xParams,
            statsAddress + (ZL5011X_RTP_RX_SEQ_NUM_INDEX * sizeof(Uint32T)),
            bits);
   }

   if (status == ZL5011X_OK)
   {
      /* reset the software counts for the RTP statistics */
      (void)memset(&(zl5011xParams->rtp.rtpSwCounts[context]), 0, sizeof(zl5011xRtpStatsS));
      zl5011xParams->rtp.rtpSwCounts[context].rxFirstSequenceNumber = (Uint32T)ZL5011X_INVALID;
   }

   return status;
}

/*******************************************************************************
 Function:
   zl5011xRtpInitStatisticsRxEntry

 Description:
   Writes to the memory that holds the Rx statistics for a particular
   context, setting the interrupt bits to allow an interrupt on counter
   overflow, and clearing the counters.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context        Selected context

 Outputs:
   None

 Returns:
  zlStatusE

 Remarks:
   None

*******************************************************************************/

extern zlStatusE  zl5011xRtpInitStatisticsRxEntry(zl5011xParamsS *zl5011xParams,
      Uint32T context)
{

   zlStatusE status = ZL5011X_OK;
   Uint32T statsAddress, bits;

   ZL5011X_TRACE_CONTEXT(ZL5011X_RTP_FN_ID, context,
         "zl5011xRtpInitStatisticsRxEntry: ctxt %d",
         context, 0, 0, 0, 0, 0);

   /* Set all fields in statistics data base structure to zero */
   status = zl5011xRtpGetStatisticsAddress(zl5011xParams, context,
         &statsAddress);

   /* write the Rx packet count word in the sender stats table */
   if (status == ZL5011X_OK)
   {
      bits = ZL5011X_RTP_RCE_OFFSET_MASK;

      status = zl5011xWrite(zl5011xParams,
            statsAddress + (ZL5011X_RTP_RX_PACKET_COUNT_INDEX * sizeof(Uint32T)),
            bits);
   }

   /* write the seq number word in the sender stats table */
   if (status == ZL5011X_OK)
   {
      bits = ZL5011X_RTP_INTERRUPT_MODE;
      status = zl5011xWrite(zl5011xParams,
            statsAddress + (ZL5011X_RTP_RX_SEQ_NUM_INDEX * sizeof(Uint32T)),
            bits);
   }

   if (status == ZL5011X_OK)
   {
      /* reset the software counts for the RTP statistics */
      zl5011xParams->rtp.rtpSwCounts[context].interArrivalJitter = 0;
      zl5011xParams->rtp.rtpSwCounts[context].rxPacketCount = 0;
      zl5011xParams->rtp.rtpSwCounts[context].rxSequenceNumber = 0;

      zl5011xParams->rtp.rtpSwCounts[context].rxFirstSequenceNumber = (Uint32T)ZL5011X_INVALID;
   }

   return status;
}

/*******************************************************************************
 Function:
    zl5011xRtpInitStatisticsTxEntry

 Description:
   Writes to the memory that holds the Tx statistics for a particular
   context, clearing the counters.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context        Selected context

 Outputs:
   None

 Returns:
  zlStatusE

 Remarks:
   None

*******************************************************************************/

extern zlStatusE  zl5011xRtpInitStatisticsTxEntry(zl5011xParamsS *zl5011xParams,
      Uint32T context)
{

   zlStatusE status = ZL5011X_OK;
   Uint32T statsAddress, bits;

   ZL5011X_TRACE_CONTEXT(ZL5011X_RTP_FN_ID, context,
         "zl5011xRtpInitStatisticsTxEntry: ctxt %d",
         context, 0, 0, 0, 0, 0);

   /* Set all fields in statistics data base structure to zero */
   status = zl5011xRtpGetStatisticsAddress(zl5011xParams, context,
         &statsAddress);

   /* write the Tx byte count word in the sender stats table */
   if (status == ZL5011X_OK)
   {
      bits = 0;
      status = zl5011xWrite(zl5011xParams,
            statsAddress + (ZL5011X_RTP_TX_BYTE_COUNT_INDEX * sizeof(Uint32T)),
            bits);
   }

   /* write the Tx packet count word in the sender stats table */
   if (status == ZL5011X_OK)
   {
      bits = ZL5011X_RTP_TCE_OFFSET_MASK;
      status = zl5011xWrite(zl5011xParams,
            statsAddress + (ZL5011X_RTP_TX_PACKET_COUNT_INDEX * sizeof(Uint32T)),
            bits);
   }

   if (status == ZL5011X_OK)
   {
      /* reset the software counts for the RTP statistics */
      zl5011xParams->rtp.rtpSwCounts[context].txByteCount = 0;
      zl5011xParams->rtp.rtpSwCounts[context].txPacketCount = 0;
   }

   return status;
}

/*******************************************************************************
 Function:
    zl5011xRtpUpdateStatistics

 Description:
   Updates the s/w counters when a rollover is detected. Generally called from
   the ISR. Interrupts must be disabled if this is not called from an interrupt.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context        Context for which statistics are to be updated.
   rollOverFlags  Flags to indicate counter roll over

 Outputs:
   None

 Returns:
  zlStatusE

 Remarks:
   None

*******************************************************************************/

extern zlStatusE  zl5011xRtpUpdateStatistics(zl5011xParamsS *zl5011xParams,
      Uint32T context, Uint32T rollOverFlags)
{
   zlStatusE status = ZL5011X_OK;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -