-
Notifications
You must be signed in to change notification settings - Fork 0
/
Driver.sv
107 lines (97 loc) · 3.08 KB
/
Driver.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
`ifndef PROTECT_GENERATOR
`define PROTECT_GENERATOR
`include "Instruction.sv"
`include "Coverage.sv"
class driver;
Coverage Cov;
Instruction instr;
mailbox #(Instruction) gen2drv;
virtual LC3_io.TB top_io;
virtual dut_Probe_WB.WB dut_wb;
virtual dut_Probe_if.FETCH dut_if;
virtual dut_Probe_DE.DECODE dut_de;
virtual dut_Probe_Exec dut_exec;
virtual memAccess_if mem_io;
virtual dut_Probe_CON dut_Con;
local logic instrmem_rd_prev = 1;
local int temp;
function new(mailbox #(Instruction) mbx, virtual LC3_io.TB top_io,virtual dut_Probe_WB.WB dut_wb,virtual dut_Probe_if.FETCH dut_if, virtual dut_Probe_DE.DECODE dut_de, virtual dut_Probe_Exec dut_exec,virtual memAccess_if mem_io,virtual dut_Probe_CON dut_Con);
this.gen2drv = mbx;
this.top_io = top_io;
this.dut_wb = dut_wb;
this.dut_if = dut_if;
this.dut_de = dut_de;
this.dut_exec = dut_exec;
this.mem_io = mem_io;
this.dut_Con = dut_Con;
Cov = new(dut_wb,dut_if,dut_de,dut_exec,mem_io,dut_Con,top_io);
endfunction : new
task Reset_dut();
@top_io.cb;
top_io.cb.reset <= 1;
top_io.complete_data <= 0;
top_io.complete_instr <= 0;
repeat(3)@top_io.cb;
top_io.cb.reset <= 0;
endtask : Reset_dut
task Init_dut();
top_io.complete_instr <= 1;
top_io.complete_data <= 1;
top_io.cb.Data_dout <= $urandom_range(0,65535);
repeat(1)@top_io.cb;
$display("%d : ns Writing 0 to reg R0",$time);
top_io.cb.Instr_dout <= 16'h5020;
repeat(1)@top_io.cb;
$display("%d : ns Writing 0 to reg R1",$time);
top_io.cb.Instr_dout <= 16'h5260;
repeat(1)@top_io.cb;
$display("%d : ns Writing 0 to reg R2",$time);
top_io.cb.Instr_dout <= 16'h54A0;
repeat(1)@top_io.cb;
$display("%d : ns Writing 0 to reg R3",$time);
top_io.cb.Instr_dout <= 16'h56E0;
repeat(1)@top_io.cb;
$display("%d : ns Writing 0 to reg R4",$time);
top_io.cb.Instr_dout <= 16'h5920;
repeat(1)@top_io.cb;
$display("%d : ns Writing 0 to reg R5",$time);
top_io.cb.Instr_dout <= 16'h5B60;
repeat(1)@top_io.cb;
$display("%d : ns Writing 0 to reg R6",$time);
top_io.cb.Instr_dout <= 16'h5DA0;
repeat(1)@top_io.cb;
$display("%d : ns Writing 0 to reg R7",$time);
top_io.cb.Instr_dout <= 16'h5FE0;
endtask : Init_dut
task Randomtest_dut();
forever begin
@top_io.cb;
if(top_io.cb.instrmem_rd)
begin
gen2drv.get(instr);
top_io.complete_instr <= 1;
top_io.complete_data <= 1;
top_io.cb.Instr_dout <= instr.Instr_base;
temp = $urandom_range(0,20);
if(temp==0) top_io.cb.Data_dout <= 16'h0000;
else if (temp==1) top_io.cb.Data_dout <= 16'hFFFF;
else if (temp==2) top_io.cb.Data_dout <= 16'hAAAA;
else if (temp==3) top_io.cb.Data_dout <= 16'h5555;
else top_io.cb.Data_dout <= $urandom_range(0,65535);
Cov.sample(instr.Instr_base);
end
else
begin
//$display("driver stalled");
end
instrmem_rd_prev = top_io.cb.instrmem_rd;
end
endtask : Randomtest_dut
task run();
Reset_dut();
Init_dut();
Randomtest_dut();
//$display("out of driver");
endtask
endclass
`endif