generator.sv

本文档展示了一个用Verilog HDL编写的类`generator`的详细实现,该类用于生成内存操作任务,如写入32位数据到特定地址、随机数据写入和读取操作。类包含初始化、构建、不同类型的写入和读取任务,以及运行任务的循环。这些任务在高级综合和验证环境中非常常见。
摘要由CSDN通过智能技术生成
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jealky

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值