目录
前言
在进行FPGA开发时,经常会用到AXI总线,但由于仿真和实际调试中,对AXI总线的操作较为繁琐,本问提出如何在仿真中产生AXI master激励并且在调试过程中,在没有PS的情况下如何调试AXI master接口。
1、 AXI master仿真接口
1.1 仿真代码准备
以XIlinx AXI JTAG 代码例程为例子
其中需要修改的配置如下:
(1) ·define dut_path xx修改,将xx改为需要替换AXI_lite master信号所在模块,如例程代码中直接替换顶层仿真文件tb_uart中axi信号,直接指向顶层即可。
(2) 修改代码中`dut_path.xx的信号名称,修改xx使之与需要仿真的信号名称一致,这样,就可以采用该代码实现AXI_lite master仿真
- 所有代码如下:
`define dut_path tb_uart
//-----------------------------------------------------------------------------
module tb_jtag_axi4lite_rw (
input wire enable_read_messaging ,
input wire enable_write_messaging
);
localparam A_IDLE = 'd0;
localparam WR0 = 'd1;
localparam WR1 = 'd2;
localparam RD0 = 'd3;
localparam RD1 = 'd4;
//---------------------------------------------------------------------------
// AXI-Lite Interface
//----------------------------------------------------------------------------
reg wr_req = 0 ; //
reg rd_req = 0 ; //
reg [31:0] address = 0 ; //
reg [31:0] wr_data = 0 ; //
reg [31:0] rd_data = 0 ; //
reg [3:0] accessor = 0 ; //
//----------------------------------------------------------------------------
// AXI-Lite Interface
//----------------------------------------------------------------------------
reg clk = 0 ; //
reg aresetn = 0 ; //
reg [31:0] axi_awaddr ; //
reg axi_awvalid ; //
reg axi_awready ; //
reg [3:0] axi_wstrb ; //
reg [31:0] axi_wdata ; //
reg axi_wvalid ; //
reg axi_wready ; //
reg [1:0] axi_bresp ; //
reg axi_bvalid ; //
reg axi_bready ; //
reg [31:0] axi_araddr ; //
reg axi_arvalid ; //
reg axi_arready ; //
reg [31:0] axi_rdata ; //
reg [1:0] axi_rresp ; //
reg axi_rvalid ; //
reg axi_rready ; //
// Status
reg access_busy = 0 ; //
//---------------------------------------------------------------------------
// AXI write task.
//---------------------------------------------------------------------------
task axi_write;
input [31:0] addr;
input [31:0] data;
begin
while (access_busy) // Wait on other tasks completing
@(posedge clk);
@(posedge clk); // Drive Address, data and the request flag
wr_req <= 1'b1;
wr_data <= data;
address <= addr;
while (access_busy == 0) // Wait until the AXI convertor is busy
@(posedge clk);
wr_req <= 1'b0; // Clear the request
while (access_busy) // Wait for the AXI4-Lite transaction to complete
@(posedge clk);
if (enable_write_messaging)
$display ("MWR: @ 0x%8x = 0x%x", address, data);
end
endtask // axi_write
//---------------------------------------------------------------------------
// AXI read task.
//---------------------------------------------------------------------------