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

📄 xdma_channel_sg.c

📁 linux嵌入式系统的dma方式的实现代码
💻 C
📖 第 1 页 / 共 4 页
字号:
*   <br><br>* - A value of XST_DMA_SG_LIST_EMPTY indicates no buffer descriptor was*   retrieved from the list because there are no buffer descriptors to be*   processed in the list.*   <br><br>* - BufDescriptorPtr is updated to point to the buffer descriptor which was*   retrieved from the list if the status indicates success.** @note** None.*******************************************************************************/XStatus XDmaChannel_GetDescriptor(XDmaChannel *InstancePtr,                                       XBufDescriptor** BufDescriptorPtr){    /* assert to verify input arguments */    XASSERT_NONVOID(InstancePtr != XNULL);    XASSERT_NONVOID(BufDescriptorPtr != XNULL);    XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    /* if a scatter gather list has not been created yet, return a status */    if (InstancePtr->TotalDescriptorCount == 0)    {        return XST_DMA_SG_NO_LIST;    }    /* if the buffer descriptor list is empty, then indicate an error */    if (XDmaChannel_IsSgListEmpty(InstancePtr))    {        return XST_DMA_SG_LIST_EMPTY;    }    /* set the input argument, which is also an output, to point to the     * buffer descriptor which is to be retrieved from the list     */    *BufDescriptorPtr = InstancePtr->GetPtr;    /* update the pointer of the DMA channel to reflect the buffer descriptor     * was retrieved from the list by setting it to the next buffer descriptor     * in the list and indicate one less descriptor in the list now     */    InstancePtr->GetPtr = XBufDescriptor_GetNextPtr(InstancePtr->GetPtr);    InstancePtr->ActiveDescriptorCount--;    return XST_SUCCESS;}/*********************** Interrupt Coalescing Functions **********************//*****************************************************************************//**** This function returns the value of the unserviced packet count register of* the DMA channel.  This count represents the number of packets that have been* sent or received by the hardware, but not processed by software.** @param** InstancePtr contains a pointer to the DMA channel to operate on.  The DMA* channel should be configured to use scatter gather in order for this function* to be called.** @return** The unserviced packet counter register contents for the DMA channel.** @note** None.*******************************************************************************/Xuint32 XDmaChannel_GetPktCount(XDmaChannel *InstancePtr){    /* assert to verify input arguments */    XASSERT_NONVOID(InstancePtr != XNULL);    XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    /* get the unserviced packet count from the register and return it */    return XIo_In32(InstancePtr->RegBaseAddress + XDC_UPC_REG_OFFSET);}/*****************************************************************************//**** This function decrements the value of the unserviced packet count register.* This informs the hardware that the software has processed a packet.  The* unserviced packet count register may only be decremented by one in the* hardware.** @param** InstancePtr contains a pointer to the DMA channel to operate on.  The DMA* channel should be configured to use scatter gather in order for this function* to be called.** @return** None.** @note** None.*******************************************************************************/void XDmaChannel_DecrementPktCount(XDmaChannel *InstancePtr){    Xuint32 Register;    /* assert to verify input arguments */    XASSERT_VOID(InstancePtr != XNULL);    XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    /* if the unserviced packet count register can be decremented (rather     * than rolling over) decrement it by writing a 1 to the register,     * this is the only valid write to the register as it serves as an     * acknowledge that a packet was handled by the software     */    Register = XIo_In32(InstancePtr->RegBaseAddress + XDC_UPC_REG_OFFSET);    if (Register > 0)    {        XIo_Out32(InstancePtr->RegBaseAddress + XDC_UPC_REG_OFFSET, 1UL);    }}/*****************************************************************************//**** This function sets the value of the packet count threshold register of the* DMA channel.  It reflects the number of packets that must be sent or* received before generating an interrupt.  This value helps implement* a concept called "interrupt coalescing", which is used to reduce the number* of interrupts from devices with high data rates.** @param** InstancePtr contains a pointer to the DMA channel to operate on.  The DMA* channel should be configured to use scatter gather in order for this function* to be called.** @param** Threshold is the value that is written to the threshold register of the* DMA channel.** @return** A status containing XST_SUCCESS if the packet count threshold was* successfully set.** @note** The packet threshold could be set to larger than the number of descriptors* allocated to the DMA channel. In this case, the wait bound will take over* and always indicate data arrival. There was a check in this function that* returned an error if the threshold was larger than the number of descriptors,* but that was removed because users would then have to set the threshold* only after they set descriptor space, which is an order dependency that* caused confusion.*******************************************************************************/XStatus XDmaChannel_SetPktThreshold(XDmaChannel *InstancePtr,                                         Xuint8 Threshold){    /* assert to verify input arguments, don't assert the threshold since     * it's range is unknown     */    XASSERT_NONVOID(InstancePtr != XNULL);    XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    /* set the packet count threshold in the register such that an interrupt     * may be generated, if enabled, when the packet count threshold is     * reached or exceeded     */    XIo_Out32(InstancePtr->RegBaseAddress + XDC_PCT_REG_OFFSET,              (Xuint32)Threshold);    /* indicate the packet count threshold was successfully set */    return XST_SUCCESS;}/*****************************************************************************//**** This function gets the value of the packet count threshold register of the* DMA channel.  This value reflects the number of packets that must be sent or* received before generating an interrupt.  This value helps implement a concept* called "interrupt coalescing", which is used to reduce the number of* interrupts from devices with high data rates.** @param** InstancePtr contains a pointer to the DMA channel to operate on.  The DMA* channel should be configured to use scatter gather in order for this function* to be called.** @return** The packet threshold register contents for the DMA channel and is a value in* the range 0 - 1023.  A value of 0 indicates the packet wait bound timer is* disabled.** @note** None.*******************************************************************************/Xuint8 XDmaChannel_GetPktThreshold(XDmaChannel *InstancePtr){    /* assert to verify input arguments */    XASSERT_NONVOID(InstancePtr != XNULL);    XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    /* get the packet count threshold from the register and return it,     * since only 8 bits are used, cast it to return only those bits */    return (Xuint8)XIo_In32(InstancePtr->RegBaseAddress + XDC_PCT_REG_OFFSET);}/*****************************************************************************//**** This function sets the value of the packet wait bound register of the* DMA channel.  This value reflects the timer value used to trigger an* interrupt when not enough packets have been received to reach the packet* count threshold.** The timer is in millisecond units with +/- 33% accuracy.** @param** InstancePtr contains a pointer to the DMA channel to operate on.  The DMA* channel should be configured to use scatter gather in order for this function* to be called.** @param** WaitBound is the value, in milliseconds, to be stored in the wait bound* register of the DMA channel and is a value in the range 0  - 1023.  A value* of 0 disables the packet wait bound timer.** @return** None.** @note** None.*******************************************************************************/void XDmaChannel_SetPktWaitBound(XDmaChannel *InstancePtr,                                      Xuint32 WaitBound){    /* assert to verify input arguments */    XASSERT_VOID(InstancePtr != XNULL);    XASSERT_VOID(WaitBound < 1024);    XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    /* set the packet wait bound in the register such that interrupt may be     * generated, if enabled, when packets have not been handled for a specific     * amount of time     */    XIo_Out32(InstancePtr->RegBaseAddress + XDC_PWB_REG_OFFSET, WaitBound);}/*****************************************************************************//**** This function gets the value of the packet wait bound register of the* DMA channel.  This value contains the timer value used to trigger an* interrupt when not enough packets have been received to reach the packet* count threshold.** The timer is in millisecond units with +/- 33% accuracy.** @param** InstancePtr contains a pointer to the DMA channel to operate on.  The DMA* channel should be configured to use scatter gather in order for this function* to be called.** @return** The packet wait bound register contents for the DMA channel.** @note** None.*******************************************************************************/Xuint32 XDmaChannel_GetPktWaitBound(XDmaChannel *InstancePtr){    /* assert to verify input arguments */    XASSERT_NONVOID(InstancePtr != XNULL);    XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    /* get the packet wait bound from the register and return it */    return XIo_In32(InstancePtr->RegBaseAddress + XDC_PWB_REG_OFFSET);}

⌨️ 快捷键说明

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