前言
先介绍一下官方提供的几个demo吧,重点参考Xilinx官方文档65444.有的可以帮助我们开发应用,有的编成应用后可以当做小工具直接帮助我们直接配置寄存器或者读取内存地址的数值。
https://www.xilinx.com/support/answers/65444.html
下面重点介绍一下Xdma_rw例程:
这个例程用来打开任何设备节点并执行读/写操作。通常操作是读取控制器或用户PCIe bar的内存空间。然而,它也可以用于执行对齐的DMA传输通过h2c_*和c2h_节点,其中表示通道索引(0-3)。默认情况下,主机端数据缓冲区,该应用程序分配的内存与PAGE_SIZE边界对齐(通常为4kB)
Xdma_ rW This application can be usedto open any ofthe device nodes and perform read/write operations. Typically this is useful for reading memorv space ofthecontro/oruserPCleBARs.However it can also be used to perform alianed DMA transfers via theh2c*andc2h*nodes. where the asterisk denotes the channel index (0-3). Bv default the host-side data buffer that this application allocates is memory aligned to the PAGE SIZE boundary (typically 4kB). Usage xdma rw.exe <DEVNODE> <read write> <ADDR> [OPTIONS] 「DATA -DEVNODE :One of:control| user | event * | hc2 * | c2h *, where the * is a numeric wildcard(0-15 for events, 0-3 for hc2 and c2h). - ADDR : The target offset address of the read write operation. Can be in hex or decimal. - OPTIONS : -l (length of data to read/write) Copyright 2018 Xilinx -b open file as binary -f use data file as input/output (for write/read respectively). -v more verbose output -a set host-side buffer alignment in bytes (default: PAGE SIZE) - DATA : Space separated byte data in decimal or hex e.g.: 17 34 51 68 or : 0x11 0x22 0x33 0x44 Hx--1024
示例:
1.在偏移0x1000的控制寄存器地址下读一个4Byte的值(注意小写L不是数字1):
xdma_rw.exe control read 0x1000 -l 4
2.在偏移0x2004的控制寄存器地址下写一个2Byte 的值(0x1234)(注意当指定字节序列中的数据时-l选项不是必需的。
xdma_rw.exe control write 0x2004 0x34 0x12
3.C2H_0通道从偏移0地址读取4KB大小数据并存为一个bin文件,文件名为my_data.bin
xdma_rw.exe c2h_0 read 0 –l 0x1000 -b -f my_data.bin
4.C2H_0通道从偏移0x100地址读取4KB大小数据,不存文件直接打印
xdma_rw.exe c2h_0 read 0x100 -l 0x1000
5.H2C_3通道在偏移0x10的地址下写入4Byte数据,数据内容为0x12345678
xdma_rw.exe h2c_3 write 0x10 0x78 0x56 0x34 0x12
6.通过AXI-Lite口在偏移0的地址下读取4Byte的数据
xdma_rw.exe user read 0 –l 4
7.在确定的偏移地址0x0000下写确定的数据0x1234567给Bram
xdma_rw.exe user write 0x0 0x67 0x45 0x23 0x01
8.在用户内存空间偏移0地址下读取256byte数据
xdma_rw.exe user read 0 -l 0x100
9.从指定bin文件(my_data.bin)获得数据,并将其写入用户内存地址偏移0的位置
xdma_rw.exe user write 0 -b -f my_data.bin