-
Notifications
You must be signed in to change notification settings - Fork 18
/
loop_add_7_tb.v
169 lines (111 loc) · 3.27 KB
/
loop_add_7_tb.v
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
`define assert(signal, value) if ((signal) !== (value)) begin $display("ASSERTION FAILED in %m: signal != value"); $finish(1); end
module test();
reg clk;
reg rst;
wire valid;
// Depth 16, width 32 RAM
reg [4:0] dbg_addr;
wire [31:0] dbg_data;
reg [4:0] dbg_wr_addr;
reg [31:0] dbg_wr_data;
reg dbg_wr_en;
wire[4:0] waddr;
wire[31:0] wdata;
wire[0:0] wen;
wire[4:0] raddr0;
wire[4:0] raddr1;
wire [31:0] rdata0;
wire [31:0] rdata1;
initial begin
#1 rst = 1;
#1 dbg_wr_addr = 10; // b[0]
#1 dbg_wr_data = 10;
#1 dbg_wr_en = 1;
#1 clk = 0;
#1 clk = 1;
#1 dbg_wr_addr = 11; // b[1]
#1 dbg_wr_data = 5;
#1 dbg_wr_en = 1;
#1 clk = 0;
#1 clk = 1;
#1 dbg_wr_en = 0; // a[0]
#1 clk = 0;
#1 clk = 1;
#1 rst = 1;
#1 dbg_addr = 0;
// `assert(dbg_data, 32'hxxxxxxxx)
// `assert(valid, 1'd0)
#1 rst = 0;
#1 clk = 0;
#1 clk = 1;
#2 $display("------ cycle bound");
#1 clk = 0;
#1 clk = 1;
#2 $display("------ cycle bound");
// `assert(valid, 1'd0)
#1 clk = 0;
#1 clk = 1;
#2 $display("------ cycle bound");
// `assert(valid, 1'd0)
#1 clk = 0;
#1 clk = 1;
#2 $display("------ cycle bound");
#1 clk = 0;
#1 clk = 1;
#2 $display("------ cycle bound");
#1 clk = 0;
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
$display("dbg_data = %d", dbg_data);
`assert(valid, 1'd0)
`assert(dbg_data, 32'd17)
#1 clk = 0;
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
#1 dbg_addr = 1;
#1 clk = 0;
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
`assert(dbg_data, 32'd12)
#1 clk = 0;
#1 clk = 1;
$display("at end dbg_data = %d", dbg_data);
//`assert(valid, 1'd0)
`assert(dbg_data, 32'd12)
#1 $display("Passed");
end // initial begin
always @(posedge clk) begin
$display("-- In tb, waddr_0 = %d", waddr);
$display("-- In tb, wdata_0 = %d", wdata);
$display("-- In tb, raddr_0 = %d", raddr0);
$display("-- In tb, rdata_0 = %d", rdata0);
$display("-- dbg_data = %d", dbg_data);
$display("-- dbg_addr = %d", dbg_addr);
end
RAM2 mem(.clk(clk),
.rst(rst),
.raddr_0(raddr0),
.rdata_0(rdata0),
.raddr_1(raddr1),
.rdata_1(rdata1),
.debug_write_addr(dbg_wr_addr),
.debug_write_data(dbg_wr_data),
.debug_write_en(dbg_wr_en),
.debug_addr(dbg_addr),
.debug_data(dbg_data),
.wen(wen),
.wdata(wdata),
.waddr(waddr));
loop_add_7 ss(.clk(clk), .rst(rst), .valid(valid), .ram_waddr_0(waddr), .ram_wdata_0(wdata), .ram_wen_0(wen), .ram_raddr_0(raddr0), .ram_rdata_0(rdata0));
endmodule