微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 微电子和IC设计 > IC验证交流 > 求助:怎么写uvm_reg的sequence与test?

求助:怎么写uvm_reg的sequence与test?

时间:10-02 整理:3721RD 点击:
各位:
我回来折腾UVM了。现在我的DUT是一个带apb接口的ram,该ram宽32bit,深1024。我想使用uvm_reg对DUT进行仿真。首先是写ralf文件,然后再用vcs提供的工具来生成uvm_reg_block的相关代码。
ralf文件内容如下:

  1. memory MY_RAM {
  2. size 1k;
  3. bits 32;
  4. access rw;
  5. }

  6. block apb_basic_block {
  7. bytes 4;
  8. memory MY_RAM @32'h0000_0000;
  9. }

  10. system apb_basic_slave {
  11. bytes 4;
  12. block apb_basic_block=slave_block;
  13. }

复制代码

而vcs生成的uvm_reg_block的相关代码如下:

  1. `ifndef RAL_APB_BASIC_SLAVE
  2. `define RAL_APB_BASIC_SLAVE

  3. import uvm_pkg::*;

  4. class ral_mem_MY_RAM extends uvm_mem;
  5. function new(string name ="MY_RAM");
  6. super.new(name,`UVM_REG_ADDR_WIDTH'h400,32,"RW",build_coverage(UVM_NO_COVERAGE));
  7. endfunction
  8. virtual function void build();
  9. end function :build

  10. `uvm_component_utils(ral_mem_MY_RAM)
  11. endclass

  12. class ral_block_apb_basic_block extends uvm_reg_block;
  13. rand ral_mem_MY_RAM MY_RAM;
  14. function new (string name ="apb_basic_block");
  15. super.new(name,build_coverage(UVM_NO_COVERAGE));
  16. endfunction
  17. virtual function void build();
  18. this.default_map=create_map("",0,4,UVM_LITTLE_ENDIAN);
  19. this.MY_RAM=ral_mem_MY_RAM::type_id::create("MY_RAM");
  20. this.MY_RAM.build();
  21. this.MY_RAM.configure(this,"");
  22. this.default_map.add_mem(this.MY_RAM,`UVM_REG_ADDR_WIDTH'h0,"RW",0);
  23. endfunction : build

  24. `uvm_object_utils(ral_block_apb_basic_block)
  25. endclass : ral_block_apb_basic_block

  26. class ral_sys_apb_basic_slave extends uvm_reg_block;
  27. rand ral_block_apb_basic_block slave_block;
  28. function new(string name="apb_basic_slave");
  29. super.new(name);
  30. endfunction
  31. function build();
  32. this.default_map=create_map("",0,4,UVM_LITTLE_ENDIAN);
  33. this.slave_block=ral_block_apb_basic_block::type_id::create("slave_block");
  34. this.slave_block.configure(this,"");
  35. this.slave_block.build();
  36. this.default_map.add_submap(this.slave_block.default_map,`uvm_REG_ADDR_WIDTH'h0);
  37. endfunction : build

  38. `uvm_component_utils(ral_sys_apb_basic_slave)
  39. endclass : ral_sys_apb_basic_slave
  40. `endif

复制代码

然后,建立一个environment来与apb_env放一块,这块是自己写的,代码如下:

  1. `ifndef REG_TB
  2. `define REG_TB

  3. `include "demo_cfg.sv"
  4. `include "reg_seq.sv"
  5. `include "ral_sys_apb_basic_slave.sv"

  6. class reg_tb extends uvm_env;
  7. `uvm_component_utils(reg_tb)
  8. apb_envapb0;
  9. demo_configdemo_cfg;
  10. ral_sys_apb_basic_slaveregmodel;
  11. reg_to_apb_adapterreg_sqr_adapter;
  12. reg_to_apb_adaptermon_reg_adapter;
  13. uvm_reg_prediector#(apb_transfer) reg_predictor;

  14. function new(string name,uvm_component parent);
  15. super.new(name,parent);
  16. endfunction
  17. virtual function build_phase(uvm_phase phase);
  18. super.build_phase(phase);
  19. demo_cfg=demo_config::type_id::create("demo_cfg");
  20. uvm_config_object::set(this,"apb0*","cfg",demo_cfg);
  21. uvm_config_object::set(this,"apb0.slave[0]*","cfg",demo_cfg.slave_configs[0]);
  22. apb0=apb_env::type_id::create("apb0");
  23. //for reg model
  24. regmodel=ral_sys_apb_basic_slave::type_id::create("regmodel");
  25. regmodel.configure(null,"top.u_dut");
  26. regmodel.build();
  27. regmodel.lock();
  28. regmodel.reset();
  29. reg_sqr_adapter=reg_to_apb_adapter::type_id::create("reg_sqr_adapter",,get_full_name());
  30. mon_reg_adapter=reg_to_apb_adapter::type_id::create("mon_reg_adapter",,get_full_name());
  31. reg_predictor=new("reg_predictor",this);

  32. endfunction : build_phase

  33. function void connect_phase(uvm_phase phase);
  34. regmodel.define_map.set_sequencer(apb0.master.sequencer,reg_sqr_adapter);
  35. regmodel.define_map.set_auto_predict(1);
  36. reg_predictor.map=regmodel.define_map;
  37. reg_predictor.adapter=mon_reg_adapter;
  38. apb0.slave.monitor.item_collected_port.connect(reg_predictor.bus_in);
  39. endfunction:connect_phase
  40. endclass :reg_tb
  41. `endif

复制代码

然后到写sequence和test的时候,我就不知道该怎么写了,有谁能指点一下,或者提供一个例子,或者指出上哪儿去找例子呀?

建议别折腾什么RGM的东西,直接用driver和monitor那一套搞就好了,不大一点的RAM,用RGM有点浪费。呵呵。就照着APB的时序写组件就好了。

我目前是用一个最简单的来练手,实际上我们要验的IP是对高清图像处理的,需要存储器的地方又多又大又杂,全从总线上的话太费时间了,想能不能通过RGM的后面直接往存储器里面灌图像数据。

另外,问一下,除了sequence和test,还需要改写一下apb_master_sequencer么?

I have never used UVM_REG. But I think you still need something like REG2APB/APB2REG to mapping your register sequence item to the APB sequence time and verse.

apb_adapter已经写好。准确的说是用了从cadence网站下的ref_flow中的apb环境,里面带有apb_adapter。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top