[UVM笔记]UVM 保存mem
在UVM 环境中,测试完成后从Mem中保存数据到文件:
tasksave_mem_data()string file_name="data.mem";bit[31:0]addr=32'h001;// addr width 32bit[31:0]addr_l;integer num_blocks=6;bit[511:0]data[];//salve data width is 512int file;bit[7:0]byte_d;string line_s="";string line_s_1="";int k=0;// use for data order formatdata=new[num_blocks];file=$fopen(filename,"w");if(file==0)begin `uvm_error("FILE_OPEN_ERR",$sformatf("body , Could not open file %s",filename))endfor(int i=0;i<num_blocks;i++)begin addr_l=addr+i*32'h40;data[i]=salve_agent.axi_slave_mem.read(addr_l);line_s="";// chage the addr order, from left to rightfor(int j=0;j<64;j++)begin byte_d=data[i][j*8+:8];line_s=$sformatf("%s%h",line_s,byte_d);end// two line to oneif(k==1)begin line_s_1=$sformatf("%s%s",line_s_1,line_s);$fdisplay(file,"%s",line_s_1);line_s_1="";k=0;endelsebegin k+=1;line_s_1=$sformatf("%s%s",line_s_1,line_s);end end $fclose(file);endtask在上述接口中,使用到了salve_agent.axi_slave_mem的read接口,这里如果要获取salve_agent这个对象,可以按照下面方式进行:
uvm_pkg::uvm_root root=uvm_pkg::uvm_root::get();uvm_pkg::uvm_component comp=root.find("*env.axi_system_env.slave[0]");//根据dut接口中进行配置,这里0是获取slave0assert($cast(salve_agent,comp));这里有几点需要注意:
1.地址位宽2.数据位宽3.输出数据的格式要求,可以根据需求进行调整4.salve_agent.axi_slave_mem的read,这里是关键,如何获取接口,在那个comp中获取。5.示例中有一个 two line to one的操作,这里可以根据需要调整,这里的调整需要根据data width来进行