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

📄 zl5011xdma.c

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


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

 Function:
   zl5011xHostRxFreePacketStructInit

 Description:
   This function will set the default parameters for zl5011xHostRxFreePacket

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance.
                  (Unused in this function)
   par            Pointer to the structure for configuration items.

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xHostRxFreePacketStructInit(zl5011xParamsS *zl5011xParams, zl5011xHostRxFreePacketS *par)
{
   zlStatusE status = ZL5011X_OK;

   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_RUNNING(zl5011xParams);
   }

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_DMA_FN_ID,
            "zl5011xHostRxFreePacketStructInit:", 0, 0, 0, 0, 0, 0);
      par->buffer = NULL;
      par->queueNumber = ZL5011X_QUEUE_0;
   }

   return status;
}

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

 Function:
   zl5011xHostRxFreePacket

 Description:
   This function will free the memory associated with a packet so it can be
   reused

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance.
                  (Unused in this function)
   par            Pointer to the structure for configuration items. See below:

 Structure inputs:
   buffer        Pointer to packet to be freed
   queueNumber   Receive queue number.
                 Any of: ZL5011X_QUEUE_0,
                         ZL5011X_QUEUE_1,
                         ZL5011X_QUEUE_2,
                         ZL5011X_QUEUE_3

 Structure outputs:
   None

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xHostRxFreePacket(zl5011xParamsS *zl5011xParams, zl5011xHostRxFreePacketS *par)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T indexNumber;

   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_RUNNING(zl5011xParams);
   }

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_DMA_FN_ID,"zl5011xHostRxFreePacket:", 0, 0, 0, 0, 0, 0);
      ZL5011X_CHECK_FOR_INVALID_VALUE(rxQParams,NULL,ZL5011X_DMA_QUEUE_NOT_INIT)
   }

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_QUEUE_NUMBER(par->queueNumber);
   }

   ZL5011X_CHECK_FOR_INVALID_VALUE(par->buffer,NULL,ZL5011X_INVALID_POINTER)

   if (status == ZL5011X_OK)
   {
      indexNumber = ((Uint32T)par->buffer
            -(Uint32T)rxQParams->buffer[par->queueNumber])/
            (rxQParams->size[par->queueNumber]*sizeof(Uint32T));

      /* Check that pointer is valid                                           */
      if ((indexNumber * rxQParams->size[par->queueNumber]
            *sizeof(Uint32T)) != ((Uint32T)par->buffer
            -(Uint32T)rxQParams->buffer[par->queueNumber]))
      {
         status = ZL5011X_DMA_INVALID_POINTER;
      }

      if (status == ZL5011X_OK)
      {
         /* Check that the index number is inside the valid range               */
         ZL5011X_CHECK_PARAMETER_RANGE(indexNumber,0,
               rxQParams->size[par->queueNumber],ZL5011X_DMA_INVALID_POINTER)
         if (status == ZL5011X_OK)
         {
            if (rxQParams->pointerUsage[par->queueNumber][indexNumber]
                  == ZL5011X_TRUE)
            {
               /* Match found                                                     */
               ZL5011X_DYNAMIC_MUTEX_TAKE(rxQParams)
               rxQParams->pointerUsage[par->queueNumber][indexNumber]
                     = ZL5011X_FALSE;
               ZL5011X_MUTEX_GIVE(rxQParams)
            }
            else
            {
               /* Attempting to free a pointer not current in use                 */
               status = ZL5011X_DMA_INVALID_POINTER;
            }
         }
      }
   }

   return status;
}

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

 Function:
   zl5011xHostRxReceivePacketStructInit

 Description:
   Initialise the structure used in function HostRxReceivePacket

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance.
                  (Unused in this function)
   par            Pointer to the structure for configuration items.

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xHostRxReceivePacketStructInit(zl5011xParamsS *zl5011xParams,zl5011xHostRxReceivePacketS *par)
{
   zlStatusE status = ZL5011X_OK;

   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_RUNNING(zl5011xParams);
   }

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE( ZL5011X_DMA_FN_ID,
            "zl5011xHostRxReceivePacketStructInit:", 0, 0, 0, 0, 0, 0);

      par->timeout = 0;
      par->queueNumber = ZL5011X_QUEUE_0;
      par->buffer = NULL;
   }

   return status;
}

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

 Function:
   zl5011xHostRxReceivePacket

 Description:
   This function will receive the packet at the top of the message queue

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance.
                  (Unused in this function)
   par            Pointer to the structure for configuration items.

 Structure inputs:
   timeout        The time (in processor ticks) to wait for a packet to be
                  received.
   queueNumber    Receive queue number

 Structure outputs:
   buffer         Pointer to packet returned by function
   packetLength   Length of packet in bytes excluding any padding
   sequenceNumber Sequence number (if appropriate)
   packetClass    Class of packet
                  Any of: ZL5011X_UNICAST,
                          ZL5011X_MULTICAST,
                          ZL5011X_BROADCAST
   truncationFlag Any of: ZL5011X_TRUE (Packet length was truncated because it
                                      exceeded the buffer size in the msg queue)
                          ZL5011X_FALSE

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xHostRxReceivePacket(zl5011xParamsS *zl5011xParams, zl5011xHostRxReceivePacketS *par)
{
   zlStatusE status = ZL5011X_OK;
   zl5011xRxMessageQS RxMsgQ;

   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_RUNNING(zl5011xParams);
   }

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_DMA_FN_ID,"zl5011xHostRxReceivePacket:",0,0,0,0,0,0);
      ZL5011X_CHECK_FOR_INVALID_VALUE(rxQParams,NULL,ZL5011X_DMA_QUEUE_NOT_INIT)
   }

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_QUEUE_NUMBER(par->queueNumber);
   }

   if ((status == ZL5011X_OK) && (OS_MSG_Q_RECEIVE(rxQParams->msq[par->queueNumber],
         (char *)&RxMsgQ,sizeof(zl5011xRxMessageQS), par->timeout) != OS_ERROR))
   {
      /* Packet ready for receiving                                             */
      par->buffer = (Uint8T *)RxMsgQ.buffer;
      par->packetLength = RxMsgQ.packetLength;
      par->sequenceNumber = RxMsgQ.sequenceNumber;
      par->truncationFlag = (zl5011xBooleanE)RxMsgQ.truncationFlag;
      par->packetClass = RxMsgQ.packetClass;
   }
   else
   {
      status = ZL5011X_DMA_NO_PACKET;
      par->buffer = NULL;
      par->sequenceNumber = 0;
      par->packetLength = 0;
      par->truncationFlag = ZL5011X_FALSE;
   }

   return status;
}


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

 Function:
   zl5011xHostRxGetStatsStructInit

 Description:
   This function will set the default parameters for zl5011xHostRxGetStats

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance.
                  (Unused in this function)
   par            Pointer to the structure for configuration items.

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xHostRxGetStatsStructInit(zl5011xParamsS *zl5011xParams, zl5011xHostRxGetStatsS *par)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T n;

   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_RUNNING(zl5011xParams);
   }

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_DMA_FN_ID,"zl5011xHostRxGetStatsStructInit:",0,0,0,0,0,0);

      for (n=0;n<ZL5011X_CPQ_QUEUES;n++)
      {
         par->packetsReceived[n] = 0;
         par->bytesReceivedh[n] = 0;
         par->bytesReceivedl[n] = 0;
         par->packetsDropped[n] = 0;
         par->bytesDroppedh[n] = 0;
         par->bytesDroppedl[n] = 0;
         par->packetsTruncated[n] = 0;
         par->bytesTruncatedh[n] = 0;
         par->bytesTruncatedl[n] = 0;
         par->packetsInMemory[n] = 0;
         par->packetsInQueue[n] = 0;
         par->packetsInDevice[n] = 0;
      }

      par->buffersProcessed = 0;
   }

   return status;
}

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

 Function:
   zl5011xHostRxGetStats

 Description:
   This function will return the stats for the receive queues

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance.
                  (Unused in this function)
   par            Pointer to the structure for configuration items.

 Structure inputs:
   None

 Structure outputs:
   packetsReceived[]   Number of packets received per queue
   bytesReceivedh[]    The MSB bytes received per queue (excluding the PRHs)
   bytesReceivedl[]    The LSB bytes received per queue
   packetsDropped[]    Number of packets dropped per queue because there was
                       no memory available at the time when the packet was
                       received.
   bytesDroppedh[]     The MSB bytes dropped per queue (excluding the PRHs)
   bytesDroppedl[]     The LSB bytes dropped per queue
   packetsTruncated[]  Number of packets per queue whose length exceeded the
                       buffer size in the message queue
   bytesTruncatedh[]   The MSB bytes truncated per queue (excluding the PRHs)
   bytesTruncatedl[]   The LSB bytes truncated per queue
   packetsInMemory[]   Number of packets per queue currently held in memory
   packetsInQueue[]    Number of unread packets per queue currently held in
                       memory
   packetsInDevice[]   Number of packets per queue currently held in the
                       device
   buffersProcessed    Total number of descriptor buffers processed so far

 Outputs:
   None

 Ret

⌨️ 快捷键说明

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