|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
正常的按《UVM实战》写的那样只能对单个寄存器进行一次的读写操作,比如想要让spi进行一长段的发送怎么写adapter以下是写的adater和transaction以及driver
- class spi_adapter extends uvm_reg_adapter;
- function new(string name = "spi_adapter");
- super.new(name);
- endfunction
- virtual function uvm_sequence_item reg2bus(const ref uvm_reg_bus_op rw);
- spi_tr tr;
- tr = new("tr");
- tr.data[0][7] = (rw.kind == UVM_READ) ? 1'b0 : 1'b1;
- tr.data[0][6:0] = rw.addr;
- tr.data[1] = rw.data;
- return tr;
- endfunction
- 其中tr定义成动态数组,但是在adapter的时候根据连续多谢的字节进行调整??
- virtual function void bus2reg(uvm_sequence_item bus_item, ref uvm_reg_bus_op rw);
- spi_tr tr;
- if(!$cast(tr,bus_item)) begin
- `uvm_fatal(get_type_name(),"Provided bus_item is not of the correct type. expecting bus_transaction")
- return; //?????????
- end
- rw.kind = (tr.data[0][7] == 1'b0) ? UVM_READ : UVM_WRITE;
- rw.addr = tr.data[0][6:0];
- rw.data = tr.data[1];
- rw.status = UVM_IS_OK;
- endfunction
- `uvm_object_utils(spi_adapter)
- endclass : spi_adapter
复制代码
class spi_tr extends uvm_sequence_item;
rand logic [7:0] data[];
// rad logic [2:0] cs_delay;
`uvm_object_utils_begin(spi_tr) //use factory register
`uvm_field_array_int(data,UVM_ALL_ON) //use field_automation mechanism
// `uvm_field_int(cs_delay,UVM_ALL_ON)
`uvm_object_utils_end
function new(string name = "spi_tr");
super.new(name);
endfunction
endclass
- task spi_driver::configure_phase(uvm_phase phase);
- vtspi_if.cs <= 1'b1;//add to reset phase
- vtspi_if.mosi <= 1'b0;
- vtspi_if.miso <= 1'b0;
- vtspi_if.sclk <= 1'b1;
- `uvm_info("spi_driver","111",UVM_LOW)
- while(!vtspi_if.rstn)
- #1;
- `uvm_info("spi_driver","222",UVM_LOW)
- while(1)begin
- seq_item_port.get_next_item(req);
- req.print();
- sent_spi(req);
- seq_item_port.item_done();
- end
- endtask
- task spi_driver::sent_spi(spi_tr tr);
- vtspi_if.cs=0;
- sdo_q.delete();
- repeat(cs_delay) @(vtspi_if.mck);
- foreach(tr.data[j]) begin
- for(int i=7;i>=0;i--)begin
- vtspi_if.sclk=1'b0;
- vtspi_if.mosi=tr.data[j][i];
- sdo_q.push_back(vtspi_if.miso);
- repeat(spi_prescale) @(vtspi_if.mck);
- end
- if(tr.data[0][7]==1)begin
- foreach(tr.data[n])begin
- for(int m=0;m<=7;m++)begin
- tr.data[n][m]=sdo_q.pop_back();
- end
- end
- end
- end
- repeat(cs_delay) @(vtspi_if.mck);
- sdo_q.delete();
- endtask
复制代码
spi要求的时序:
|
|