69 lines
1.1 KiB
Systemverilog
69 lines
1.1 KiB
Systemverilog
class spi_monitor;
|
|
|
|
|
|
virtual spi_if wif;
|
|
virtual sram_if#(25,32) xif;
|
|
integer fid;
|
|
|
|
//collect MOSI(exp) & MISO(act)
|
|
spi_trans exp_trans;
|
|
spi_trans act_trans;
|
|
|
|
|
|
function new();
|
|
endfunction
|
|
extern task collect();
|
|
extern task do_mon();
|
|
|
|
endclass : spi_monitor
|
|
|
|
|
|
task spi_monitor::do_mon();
|
|
|
|
while(1) begin
|
|
collect();
|
|
end
|
|
|
|
endtask: do_mon
|
|
|
|
|
|
|
|
|
|
task spi_monitor::collect();
|
|
bit temp[$];
|
|
int i=0;
|
|
|
|
@(negedge wif.csn);
|
|
|
|
//capture cmd-words
|
|
temp.delete();
|
|
repeat(32) begin
|
|
@(posedge wif.sclk or posedge wif.csn);
|
|
if(wif.csn) break;
|
|
temp.push_back(wif.mosi);
|
|
end
|
|
|
|
//capture write-data or read-data
|
|
while(1) begin
|
|
@(posedge wif.sclk or posedge wif.csn);
|
|
if(wif.csn) break;
|
|
temp.push_back(temp[0] ? wif.miso : wif.mosi);
|
|
end
|
|
temp.pop_back();
|
|
|
|
if(!temp[0]) begin
|
|
exp_trans = new();
|
|
exp_trans.pack(temp);
|
|
exp_trans.print(fid);
|
|
end
|
|
else begin
|
|
act_trans = new();
|
|
act_trans.pack(temp);
|
|
act_trans.print(fid);
|
|
end
|
|
|
|
|
|
if(!wif.csn) @(posedge wif.csn);
|
|
|
|
endtask
|