1、背景介绍
最近项目中需要做一个JTAG测试功能,该功能是需要在DDR的一段空间中准备一组数据,发送出去,再用DDR的另一段空间收数,判断收到的数是否和发送的数据相同,以此加以验证。为此,需要在ZYNQ PL中实现GPIO通过HP读写DDR实地址的操作,同时在PS中通过ARM实现对发送和接收两段内存区域的读写操作。
2、实现方法
linux中提供了dev/mem来对DDR进行读写,让应用程序可以直接读写DDR实地址,很显然,这里也将采用这一方法。需要注意的是,在映射的过程中一定要加上O_SYNC标志位,这样才能保证Dcache和DDR中数据的一致性,确保读写时不光写入Dcache,也写入DDR中。
代码如下:
/*
* Copyright (c) 2012 Xilinx, Inc. All rights reserved.
*
* Xilinx, Inc.
* XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
* COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
* ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
* STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
* IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
* FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
* XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
* THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
* ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
* FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#include
#include
#i