-
Notifications
You must be signed in to change notification settings - Fork 0
/
Testbench_HCM.v
executable file
·195 lines (162 loc) · 6.12 KB
/
Testbench_HCM.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
`timescale 1ns / 1ps
//-------------------//
// Testbench for HCM //
//-------------------//
/*module Testbench_HCM(
input clk_p,
input clk_n
);
wire clk;
// derive signal from external differential clock: ext_clk_[p/n]
IBUFDS # (
.DIFF_TERM("FALSE"), // differential termination
.IBUF_LOW_PWR("TRUE"), // low power vs. performance setting for referenced I/O standards
.IOSTANDARD("DEFAULT") // specify the input I/O standard
) IBUFDS_ext_clk_inst (
.O(clk), // buffer output
.I(clk_p), // diff_p buffer input (connect directly to top-level port)
.IB(clk_n) // diff_n buffer input (connect directly to top-level port)
);*/
module Testbench_HCM;
wire clk;
Clock clock(
.clk(clk)
);
`include "MyParameters.vh"
//-----//
// DUT //
//-----//
reg writeRow = 0;
reg readRow = 0;
reg reset = 0;
reg SSIDIsNew = 0;
reg [ROWINDEXBITS_HCM-1:0] rowToRead, rowToWrite;
wire [ROWINDEXBITS_HCM-1:0] rowPassed;
wire [NCOLS_HCM-1:0] rowReadOutput;
wire [MAXHITNBITS-1:0] nHits;
wire readReady, writeReady, busy;
HCMPP HCM (
.clk(clk),
.writeReady(readReady),
.writeRow(writeRow),
.inputRowToWrite(rowToWrite),
.SSIDIsNew(SSIDIsNew), // whether or not this SSID is new for the event
.readReady(writeReady),
.inputRowToRead(rowToRead),
.readRow(readRow),
.reset(reset),
.rowPassed(rowPassed),
.rowReadOutput(rowReadOutput),
.nHits(nHits),
.busy(busy)
);
//---------------//
// DEBUG SIGNALS //
//---------------//
(*mark_debug="TRUE"*)
reg [12:0] debugRowReadOutput;
(*mark_debug="TRUE"*)
reg [ROWINDEXBITS_HCM-1:0] debugRowPassed;
// debug signals
always @(posedge clk) begin
debugRowReadOutput <= rowReadOutput[12:0];
debugRowPassed <= rowPassed;
end
//------------------//
// VALIDATION TESTS //
//------------------//
reg [2:0] testNumber = 0;
// 000 = none; 001 = print BRAM; 010 = store incrementing; 011 = store SSIDs from list
reg [2:0] currentTest = 0; // currently performing test number
reg [ROWINDEXBITS_HCM-1:0] testingRow = 0; // row number for reading and writing
reg [SSIDBITS-1:0] testingSSID = 0; // SSID for reading and writing
reg [ROWINDEXBITS_HCM-1:0] testingStoreRow[22:0] = {0, 3, 1, 1, 1, 1, 1, 3, 4, 7, 2, 1, 5, 4, 4, 2, 8, 9, 65534, 65534, 65534, 65533, 65534};
reg [ROWINDEXBITS_HCM-1:0] testingSSIDIsNew[22:0] = {1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1};
integer currentTime = 0;
initial begin
$monitor ("%d\t%b\t%d", rowPassed, rowReadOutput[12:0], nHits);
//$monitor ("%d\t%b\t%d", debugRowPassed, debugRowReadOutput[12:0], nHits);
//$monitor ("%d\t%d\t%b", currentTime, rowPassed, rowReadOutput[12:0]);
//$monitor ("%g\t%b\t%b", $time, SSID_passed[6:0], HCM_readOutput);
end
always @(posedge clk) begin
currentTime <= currentTime + 1;
if (currentTest == 2'b00) begin // if not already testing
currentTest <= testNumber; // start testing
end
//--------------//
// SET UP TESTS //
//--------------//
if (currentTime == 0) begin
testNumber <= 3'b001; // print BRAM
$display ("Printing initial BRAM");
end
if (currentTime == 1) testNumber <= 3'b000;
/*if (currentTime == 200) begin
testNumber <= 3'b010; // store incrementing
$display ("Storing incrementing rows");
end
if (currentTime == 201) testNumber <= 3'b000;*/
if (currentTime == 200) begin
testNumber <= 3'b011; // store SSIDs from list
$display ("Storing SSIDs from list");
end
if (currentTime == 201) testNumber <= 3'b000;
if (currentTime == 400) begin
testNumber <= 3'b001; // print BRAM again
$display ("Printing final BRAM");
end
if (currentTime == 401) testNumber <= 3'b000;
if (currentTime == 600) begin
reset <= 1;
$display ("Reset");
end
if (currentTime > 600) begin
reset <= 0;
currentTime <= 0;
end
//------------------//
// CONTENT OF TESTS //
//------------------//
readRow <= 0;
writeRow <= 0;
if (currentTest == 3'b001) begin // print BRAM
readRow <= 1'b1; // read enabled
rowToRead <= testingRow; // row to read
testingRow <= testingRow + 1; // increment row
if (testingRow == 49) begin // read the first 50 rows
testingRow <= NROWS_HCM - 50;
end
else if (testingRow == NROWS_HCM - 1) begin // read the last 50 rows
testingRow <= 0;
testNumber <= 3'b000; // stop testing
currentTest <= 0;
end
end
else if (currentTest == 3'b010) begin // store incrementing
writeRow <= 1'b1; // write enabled
rowToWrite <= testingRow; // row number
SSIDIsNew <= 1; // every row is new for this event
testingRow <= testingRow + 1; // increment row
if (testingRow == 49) begin // first 50 rows
testingRow <= NROWS_HCM - 50;
end
else if (testingRow == NROWS_HCM - 1) begin // last 50 rows
testingRow <= 0;
testNumber <= 3'b000; // stop testing
currentTest <= 0;
end
end
else if (currentTest == 3'b011) begin // store SSIDs from list
writeRow <= 1'b1; // write enabled
rowToWrite <= testingStoreRow[testingSSID];
SSIDIsNew <= testingSSIDIsNew[testingSSID];
testingSSID <= testingSSID + 1; // increment SSID
if (testingSSID >= 22) begin // if the SSID we just read is the last one
testingSSID <= 0;
testNumber <= 3'b000; // stop testing
currentTest <= 0;
end
end
end
endmodule