forked from gtjennings1/HyperBUS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hbc_tb.v
248 lines (229 loc) · 5.95 KB
/
hbc_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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// Copyright 2017 Gnarly Grey LLC
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
`timescale 1ns/1ps
module hbc_tb;
// Inputs
reg i_clk;
reg i_rstn;
reg i_cfg_access;
reg i_mem_valid;
reg [3:0] i_mem_wstrb;
reg [31:0] i_mem_addr;
reg [31:0] i_mem_wdata;
// Outputs
wire o_mem_ready;
wire [31:0] o_mem_rdata;
wire o_csn0;
wire o_csn1;
wire o_clk;
wire o_clkn;
wire o_resetn;
// Bidirs
wire [7:0] io_dq;
wire io_rwds;
reg [31:0] test_data [0:31];
integer i, k;
integer uint8_addr = 0;
integer uint16_addr = 128;
integer uint32_addr = 256;
hbc_wrapper hbc (
.i_clk(i_clk),
.i_rstn(i_rstn),
.i_cfg_access(i_cfg_access),
.i_mem_valid(i_mem_valid),
.o_mem_ready(o_mem_ready),
.i_mem_wstrb(i_mem_wstrb),
.i_mem_addr(i_mem_addr),
.i_mem_wdata(i_mem_wdata),
.o_mem_rdata(o_mem_rdata),
.o_csn0(o_csn0),
.o_csn1(o_csn1),
.o_clk(o_clk),
.o_clkn(o_clkn),
.io_dq(io_dq),
.io_rwds(io_rwds),
.o_resetn(o_resetn)
);
s27kl0641
#(
.TimingModel("S27KL0641DABHI000"))
hyperram (
.DQ7(io_dq[7]),
.DQ6(io_dq[6]),
.DQ5(io_dq[5]),
.DQ4(io_dq[4]),
.DQ3(io_dq[3]),
.DQ2(io_dq[2]),
.DQ1(io_dq[1]),
.DQ0(io_dq[0]),
.RWDS(io_rwds),
.CSNeg(o_csn0),
.CK(o_clk),
.RESETNeg(o_resetn)
);
initial begin
// Initialize Inputs
i_clk = 0;
i_rstn = 0;
i_cfg_access = 0;
i_mem_valid = 0;
i_mem_wstrb = 0;
i_mem_addr = 0;
i_mem_wdata = 0;
#100;
i_rstn = 1;
$display("Waiting for device power-up...");
#160e6;
$display("Reading the ID/CFG registers");
i_cfg_access = 1;
i_mem_valid = 1;
i_mem_wstrb = 0;
i_mem_addr = 0;
#10;
i_mem_valid = 0;
wait(o_mem_ready == 1);
$display("ID0: 0x%H", o_mem_rdata[15:0]);
#20;
i_mem_valid = 1;
i_mem_wstrb = 0;
i_mem_addr = 2;
#10;
i_mem_valid = 0;
wait(o_mem_ready == 1);
$display("ID1: 0x%H", o_mem_rdata[15:0]);
#20;
i_mem_valid = 1;
i_mem_wstrb = 0;
i_mem_addr = 2048;
#10;
i_mem_valid = 0;
wait(o_mem_ready == 1);
$display("CFG0: 0x%H", o_mem_rdata[15:0]);
#20;
i_mem_valid = 1;
i_mem_wstrb = 0;
i_mem_addr = 2049;
#10;
i_mem_valid = 0;
wait(o_mem_ready == 1);
$display("CFG1: 0x%H", o_mem_rdata[15:0]);
#20;
i_cfg_access = 0;
test_data[0] = 32'hDEADBEEF;
for(i = 1; i < 32; i = i + 1) begin
test_data[i] = {test_data[i - 1][27:0], test_data[i - 1][31:28]};
end
#20;
$display("UINT8_t test");
for(i = 0; i < 32; i = i + 1) begin
i_mem_wdata = test_data[i];
i_mem_addr = uint8_addr + (i << 2);
for(k = 0; k < 4; k = k + 1) begin
i_mem_valid = 1;
i_mem_wstrb = (1 << k);
#10;
i_mem_valid = 0;
wait(o_mem_ready == 1);
#20;
end
end
#20;
$display("expected\tread\t\tstatus");
i_mem_wstrb = 0;
for(i = 0; i < 32; i = i + 1) begin
i_mem_addr = uint8_addr + (i << 2);
for(k = 0; k < 4; k = k + 1) begin
i_mem_valid = 1;
#10;
i_mem_valid = 0;
wait(o_mem_ready == 1);
if((o_mem_rdata & (255 << k*8)) == (test_data[i] & (255 << k*8))) begin
$display("0x%H\t0x%H\tOK", (test_data[i] & (255 << k*8)), (o_mem_rdata & (255 << k*8)));
end else begin
$display("0x%H\t0x%H\tFAIL", (test_data[i] & (255 << k*8)), (o_mem_rdata & (255 << k*8)));
end
#20;
end
end
#20;
$display("UINT16_t test");
for(i = 0; i < 32; i = i + 1) begin
i_mem_wdata = test_data[i];
i_mem_addr = uint16_addr + (i << 2);
for(k = 0; k < 2; k = k + 1) begin
i_mem_valid = 1;
i_mem_wstrb = (3 << (k*2));
#10;
i_mem_valid = 0;
wait(o_mem_ready == 1);
#20;
end
end
#20;
$display("expected\tread\t\tstatus");
i_mem_wstrb = 0;
for(i = 0; i < 32; i = i + 1) begin
i_mem_addr = uint8_addr + (i << 2);
for(k = 0; k < 2; k = k + 1) begin
i_mem_valid = 1;
#10;
i_mem_valid = 0;
wait(o_mem_ready == 1);
if((o_mem_rdata & (16'hFFFF << k*16)) == (test_data[i] & (16'hFFFF << k*16))) begin
$display("0x%H\t0x%H\tOK", (test_data[i] & (16'hFFFF << k*16)), (o_mem_rdata & (16'hFFFF << k*16)));
end else begin
$display("0x%H\t0x%H\tFAIL", (test_data[i] & (16'hFFFF << k*16)), (o_mem_rdata & (16'hFFFF << k*16)));
end
#20;
end
end
#20;
$display("UINT32_t test");
for(i = 0; i < 32; i = i + 1) begin
i_mem_wdata = test_data[i];
i_mem_addr = uint32_addr + (i << 2);
i_mem_valid = 1;
i_mem_wstrb = 15;
#10;
i_mem_valid = 0;
wait(o_mem_ready == 1);
#20;
end
#20;
$display("expected\tread\t\tstatus");
i_mem_wstrb = 0;
for(i = 0; i < 32; i = i + 1) begin
i_mem_addr = uint8_addr + (i << 2);
i_mem_valid = 1;
#10;
i_mem_valid = 0;
wait(o_mem_ready == 1);
if(o_mem_rdata == test_data[i]) begin
$display("0x%H\t0x%H\tOK", (test_data[i]), (o_mem_rdata));
end else begin
$display("0x%H\t0x%H\tFAIL", (test_data[i]), (o_mem_rdata));
end
#20;
end
#20;
$stop;
end
always @(*) begin
i_clk <= #5 ~i_clk;
end
endmodule