hxing

拒绝思维懒惰,习惯深度思考,提升认知水平。

导航

ahb 总线仿真的master

仿真用ahb bus master

task ahb_write;
input [31:0] addr;
input [31:0] wdata;
input [2:0] size;
begin

`ifdef NET_EN
i2c_write(1,addr,wdata);
`else
//bus req
@(posedge `cpu_clk);
while(`hgrantcpu==0) begin
#1 force `hbusreqcpu = 1;
@(posedge `cpu_clk);
end
//address
while(`hreadycpu==0 || `hgrantcpu==0) @(posedge `cpu_clk);
#1;
force `htrans = 2;//AHB_TRANS_NON_SEQ
force `haddr = addr;
force `hsize = size;
force `hprot = 0;
force `hmaster = 0;
force `hwrite = 1;
force `hburst = 0;
@(posedge `cpu_clk);
while(`hreadycpu == 0) @(posedge `cpu_clk);
//data
#1;
force `htrans = 0;//AHB_TRANS_IDLE
force `haddr = 0;
force `hsize = size;
force `hwrite = 0;
force `hwdata = wdata;
@(posedge `cpu_clk);
while(`hreadycpu == 0) @(posedge `cpu_clk);
#1;
force `hwdata = 0;
// $display("CPU write A[%h], W[%h];",addr,wdata);
`endif
end
endtask

task ahb_read;
input [31:0] addr;
output [31:0] rdata;
input [2:0] size;
begin
`ifdef NET_EN
i2c_read(1,addr,rdata);
`else
//bus req
@(posedge `cpu_clk);
while(`hgrantcpu==0) begin
#1 force `hbusreqcpu = 1;
@(posedge `cpu_clk);
end
//address
while(`hreadycpu==0 || `hgrantcpu==0) @(posedge `cpu_clk);
#1;
force `htrans = 2;//AHB_TRANS_NON_SEQ
force `haddr = addr;
force `hsize = size;
force `hprot = 0;
force `hmaster = 0;
force `hwrite = 0;
force `hburst = 0;
force `hwdata = 0;
@(posedge `cpu_clk);
while(`hreadycpu == 0) @(posedge `cpu_clk);
//data
#1;
force `htrans = 0;//AHB_TRANS_IDLE
force `haddr = 0;
force `hsize = size;
force `hwrite = 0;

@(posedge `cpu_clk);
while(`hreadycpu == 0) @(posedge `cpu_clk);
rdata = `hrdatacpu;
// $display("cpu read A[%h], R[%h];",addr,rdata);
`endif
end
endtask

posted on 2026-04-24 17:31  hxing  阅读(13)  评论(0)    收藏  举报