赛灵思
直播中

谢赛

7年用户 276经验值
私信 关注
[问答]

如何编写C程序通过CDMA将DDR3数据写入BRAM?

嗨,
我已将Xilinx CDMA(中央DMA控制器)连接到EDK项目。
现在我需要使用SDK中的C程序来测试它。
我的项目中有DDR3和BRAM。
如何编写C程序通过CDMA将DDR3数据写入BRAM?
谢谢。

以上来自于谷歌翻译


以下为原文

Hi,

I have attached a Xilinx CDMA (central DMA controller) to EDK project.
Now I need to test this using a C program in SDK. I have DDR3 and BRAM in my project.
How to write a C program to write DDR3 data to BRAM via CDMA?

Thank you.

回帖(8)

邢待湘

2019-2-18 10:12:05
Sam,在ASK中,您可以创建一个新的C项目来测试系统中的外围设备。
您可以查看DMA的测试应用程序。
否则,您可以创建一个弓形支撑包并查看牲畜来源。
在那里,您将看到中央DMA的文件夹。
您可以查看xcdma.h,这是中央DMA引擎的API。
您将了解到Dan通过配置DMA执行所需的传输,然后调用传递函数并将源和目标指针与传输大小一起传递给它。
如果您有任何疑问,请回复。
祝你好运!

以上来自于谷歌翻译


以下为原文

Sam,

In ASK you can create a new C Project for testing the peripherals in you system. There is a test app for the DMA that you can look at. Otherwise you can create a bowed support package and look at the livestock sources. In there you will see a folder for the central DMA. You can look at xcdma.h, this is the API for the central DMA engine. You will learn that you Dan perform the transfer you want by configuring the DMA, then calling the transfer function and pass it the source and destination pointers along with the transfer size. Post back if you have any questions.

Good luck!
举报

邢待湘

2019-2-18 10:22:12
**哔**,我在手机里这样做,我没有拼写检查,自动纠正了我。
更正如下:SDK不是ASKboard没有鞠躬库不是牲畜不能Dan我再也不会在手机中这样做了。

以上来自于谷歌翻译


以下为原文

**bleep**, I am doing this in my phone and I didn't spell check, auto correct got me. Corrections as follows:
SDK not ASK
board not bowed
library not livestock
can not Dan

I'm never doing this in a phone again.
举报

刘耀清

2019-2-18 10:37:11
嗨,
感谢您的答复。
以下是我试过的基于中断的CDMA数据传输。
在这里,我使用以下API:
int XAxiCdma_SimpleTransfer(XAxiCdma * InstancePtr,u32 SrcAddr,u32 DstAddr,int Length,XAxiCdma_CallBackFn SimpleCallBack,void * CallbackRef);
但,
1)以下代码不起作用!
知道为什么会这样吗?
2)比较“轮询模式下的DMA”和“DMA中断模式”时最快的是什么?
3)我可以在XAxiCdma_SimpleTransfer(...)中传输的最大长度是多少?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++
#include“xparameters.h”#include“stdio.h”#include“xutil.h”#include“xaxicdma.h”#include“xil_exception.h”#include“xtmrctr.h”#include“xil_cache.h”volatile
static int Done = 0; volatile static int Error = 0;
static void Example_CallBack(void * CallBackRef,u32 IrqMask,int * IgnorePtr){if(IrqMask& XAXICDMA_XR_IRQ_ERROR_MASK){Error = 1;
} if(IrqMask& XAXICDMA_XR_IRQ_IOC_MASK){Done = 1;
int main(void){int i = 0;
int状态;
int * ddrData = XPAR_DDR3_SDRAM_S_AXI_BASEADDR;
int * ptrData = XPAR_DATA_BRAM_CNTLR_0_S_AXI_BASEADDR;
XAxiCdma xcdma;
//初始化源数据(i = 0; i {*(ddrData + i)= i;} / *内存传输* / 
XAxiCdma_IntrEnable(& xcdma,XAXICDMA_XR_IRQ_ALL_MASK);
Status = XAxiCdma_SimpleTransfer(& xcdma,* ddrData,* ptrData,16,Example_CallBack,(void *)& xcdma);
for(i = 0; i {xil_printf(“目标数据:%d  n”,*(ptrData + i));}返回0;}
++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++

以上来自于谷歌翻译


以下为原文

Hi,
 
Thank you for the reply. Following is a interrupt based CDMA data transfer I tried. Here, I use following API:
 
int XAxiCdma_SimpleTransfer(XAxiCdma *InstancePtr, u32 SrcAddr, u32 DstAddr,
            int Length, XAxiCdma_CallBackFn SimpleCallBack, void *CallbackRef);
 
But,
 
1) Following code is not working! Any idea why is that?
2) What is the fastest when compare "DMA in polling mode" and "DMA in interrupt mode"?
3) What is the maximum length that I can transfer in XAxiCdma_SimpleTransfer(...)?

 
++++++++++++++++++++++++++++++++++ CODE +++++++++++++++++++++++++++++++++++++++
 
#include "xparameters.h"
#include "stdio.h"
#include "xutil.h"
#include "xaxicdma.h"
#include "xil_exception.h"
#include "xtmrctr.h"
#include "xil_cache.h"

volatile static int Done = 0;
volatile static int Error = 0;

static void Example_CallBack(void *CallBackRef, u32 IrqMask, int *IgnorePtr)
{

    if (IrqMask & XAXICDMA_XR_IRQ_ERROR_MASK) {
        Error = 1;
    }

    if (IrqMask & XAXICDMA_XR_IRQ_IOC_MASK) {
        Done = 1;
    }

}

int main(void)
{
    int i = 0;
    int Status;

    int *ddrData = XPAR_DDR3_SDRAM_S_AXI_BASEADDR;
    int *ptrData = XPAR_DATA_BRAM_CNTLR_0_S_AXI_BASEADDR;

    XAxiCdma xcdma;

    //Initialize source data
    for (i=0;i<1024;i++)
    {
        *(ddrData+i) = i;
    }

    /*Memory transfer*/

    XAxiCdma_IntrEnable(&xcdma, XAXICDMA_XR_IRQ_ALL_MASK);
    Status = XAxiCdma_SimpleTransfer(&xcdma, *ddrData, *ptrData, 16, Example_CallBack, (void *) &xcdma);

    for (i=0;i<16;i++)
    {
        xil_printf("Destination Data : %dn",*(ptrData+i));
    }

    return 0;
}


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 
举报

邢待湘

2019-2-18 10:49:32
好的,您必须在第一次使用DMA之前配置DMA。
您还必须在中断控制器中启用DMA中断。
您将在xparameters.h中看到中断ID,您需要初始化中断控制器并启用DMA中断ID。
你在用什么处理器?
微纤维需要一些额外的步骤。
就轮询与中断驱动而言,中断驱动将允许您在DMA引擎进行传输时执行处理器中的指令。
但是,当DMA是总线主控时,你不能执行任何总线事务。我真的建议查看外设测试代码。
一切都在那里使DMA工作。祝你好运!P.S。
我又在手机上做了这件事......恨自己

以上来自于谷歌翻译


以下为原文

Ok,

You have to configure the DMA before you use it the first time. You also have to enable the DMA interrupt in the interrupt controller. You will see the interrupt ID in xparameters.h , you need to initialize the interrupt controller and enable the DMA interrupt ID. What processor are you using? There are some extra steps needed for microblaze.

As far as polled vs interrupt driven, interrupt driven will allow you to execute instructions in the processor while the DMA engine is doing the transfer. You cannot however perform any bus transaction while the DMA is the bus master.

I would really suggest looking at the peripheral test code. Everything is in there to make the DMA work.

Good luck!

P.S. I did this on a phone again... Hate myself
举报

更多回帖

发帖
×
20
完善资料,
赚取积分