class generator;
int tr_num;
transaction tr;
mailbox gen2drv_mbx;
event data_gen;
extern function new(int tr_num, mailbox gen2drv_mbx);
extern function build();
extern task write32();
extern task write32_data_random(logi[31:0] addr);
extern task write32_addr_random(logic[31:0] data);
extern task read32(logic[31:0] addr);
extern task read32_addr_random();
extern task run();
endclass
function generator::new(int tr_num, mailbox gen2drv_mbx);
this.tr_num = tr_num;
this.gen2drv_mbx = gen2drv_mbx;
endfunction
function generator::build();
tr = new;
if(!tr.randomize())
$display("@%0t,Generator ERROR::randomize failed",$time);
endfunction
task generator::task write32(logic[31:0] addr, logic[31:0] data);
tr = new;
hsel = 1'b1;
hwrite = 1'b1;
hready = 1'b1;
htrans = 2'b00;
hburst = 3'b000;
hsize = 3'b010;
haddr = addr;
hwdata = data;
-> data_gen;
endtask
task generator::task write32_data_random(logic[31:0] addr);
build();
hsel = 1'b1;
hwrite = 1'b1;
hready = 1'b1;
htrans = 2'b00;
hburst = 3'b000;
hsize = 3'b010;
haddr = addr;
-> data_gen;
endtask
task generator::task write32_addr_random(logic[31:0] data);
build();
hsel = 1'b1;
hwrite = 1'b1;
hready = 1'b1;
htrans = 2'b00;
hburst = 3'b000;
hsize = 3'b010;
hwdata = data;
-> data_gen;
endtask
task generator::task read32(logic[31:0] addr);
tr = new;
hsel = 1'b1;
hwrite = 1'b1;
hready = 1'b1;
htrans = 2'b00;
hburst = 3'b000;
hsize = 3'b010;
haddr = addr;
hwdata = data;
-> data_gen;
endtask
task generator::task read32_addr_random();
build();
hsel = 1'b1;
hwrite = 1'b1;
hready = 1'b1;
htrans = 2'b00;
hburst = 3'b000;
hsize = 3'b010;
-> data_gen;
endtask
task gennerator::run();
repeat(tr_num)begin
@(data_gen);
gen2drv_mbx.put(tr);
end
endtask
generator.sv
最新推荐文章于 2022-08-27 20:32:26 发布
本文档展示了一个用Verilog HDL编写的类`generator`的详细实现,该类用于生成内存操作任务,如写入32位数据到特定地址、随机数据写入和读取操作。类包含初始化、构建、不同类型的写入和读取任务,以及运行任务的循环。这些任务在高级综合和验证环境中非常常见。
摘要由CSDN通过智能技术生成