-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryAccessTestbench.sv
More file actions
359 lines (334 loc) · 7.49 KB
/
MemoryAccessTestbench.sv
File metadata and controls
359 lines (334 loc) · 7.49 KB
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
module MemoryAccessTestbench (input logic clk,
output logic CKE, WE, CAS, RAS, CS, memclk,
output logic [12:0] addr,
output logic [1:0] bank,
output logic [1:0] dqm,
inout wire [15:0] dq,
output logic light);
//These signals are required for the vJTAG module
logic tck, tdi, tdo, cdr, eldr, e2dr, pdr;
logic sdr, udr, uir, cir, e1dr, bypass_reg;
logic [2:0] ir_in;
logic ir_out;
logic [3:0] registeraddress;
logic [2:0] opco;
logic [31:0] shift_buffer = 32'h0;
logic [31:0] active_register = 0;
logic [31:0] test_buffer = 0;
logic [31:0] registers [3:0];
//JTAG OPCODES
localparam BYPASS = 4'b1111;
localparam IDCODE = 4'b0001;
localparam READREG = 4'b0010;
localparam SETREGISTER = 4'b0011;
localparam RUNTEST = 4'b0100;
localparam PRESENCE = 4'b0101;
localparam SETTEST = 4'b0110;
localparam WRITEREG = 4'b0111;
localparam NIL = 4'b1111;
//Memory controller signals
logic readRequest, readRequestGrant;
logic [31:0] readAddress;
logic [15:0] readData;
logic readValid;
logic membusy;
logic writeRequest, writeRequestGrant;
logic [31:0] writeAddress;
logic [15:0] writeData;
logic writeCommit;
//PLL
logic locked;
MemPLL pll (clk, memclk, locked);
//Test signals
logic [3:0] SelectedTest = 0;
logic [4:0] StageCounter = 0;
logic run = 0;
logic trigger = 0;
MemoryController mem (memclk, readRequest, readRequestGrant, readAddress, readData, readValid,
writeRequest, writeRequestGrant, writeAddress, writeData, writeCommit, CKE, CS, RAS, CAS, WE,
addr,
bank,
dqm,
dq);
//Instantiation of the JTAG module.
JTAG v(
.tdo (tdo),
.tck (tck),
.tdi (tdi),
.ir_in(ir_in),
.ir_out(ir_out),
.virtual_state_cdr (cdr),
.virtual_state_e1dr(e1dr),
.virtual_state_e2dr(e2dr),
.virtual_state_pdr (pdr),
.virtual_state_sdr (sdr),
.virtual_state_udr (udr),
.virtual_state_uir (uir),
.virtual_state_cir (cir)
);
assign ir_out = ir_in[0]; //Assignment for passthrough.
always_ff @ (posedge tck) begin
if (sdr) begin
shift_buffer <= {tdi, shift_buffer[31:1]}; //VJ State is Shift DR, so we shift using tdi and the existing bits.
end
if (cdr) begin //Capture DR is asserted. This means we lookup the current instruction and plop stuff here.
case (opco)
IDCODE: shift_buffer <= 32'h100011d3;
READREG: shift_buffer <= registers[active_register];
endcase
end
if (udr) begin
case (opco)
SETREGISTER: active_register <= shift_buffer;
SETTEST: test_buffer <= shift_buffer;
endcase
end
end
always_ff @ (posedge uir) begin
trigger <= 0;
if (opco != ir_in) trigger <= 1;
opco <= ir_in;
case (ir_in)
PRESENCE: begin
light = ~light;
end
NIL: begin
light = 0;
end
endcase
end
always_comb begin
if (ir_in == BYPASS) tdo <= tdi;
else tdo <= shift_buffer[0];
end
always_ff @ (posedge memclk) begin
case (opco)
WRITEREG: registers[active_register] <= shift_buffer;
RUNTEST: begin
if (trigger) begin
//Set the test as selected.
run <= 1;
SelectedTest <= test_buffer[3:0];
StageCounter <= 0;
end
end
endcase
if (run) begin
case (SelectedTest)
3'b001: begin
BasicRW();
end
3'b010: begin
BasicW();
end
3'b011: begin
BasicR();
end
3'b100: begin
WValue();
end
3'b101: begin
SequenceTest();
end
endcase
end
end
task SequenceTest;
case (StageCounter)
0: begin
StageCounter <= 1;
writeAddress <= 32'd0;
end
1: begin
writeRequest <= 1;
writeData <= 65535 - writeAddress[15:0];
StageCounter <= StageCounter + 5'b1;
end
2: begin
//await the grant from the controller.
if (writeRequestGrant) begin
StageCounter <= StageCounter +5'b1;
writeRequest <= 0;
end
end
3: begin
//Await the commit signal
if (writeCommit) begin
writeAddress <= writeAddress + 1'b1;
StageCounter <= 5'b1;
writeData <= 0;
end
if (writeAddress == 32'd4194313) begin
StageCounter <= 4;
readAddress <= 32'd0;
end
end
4: begin
//Setup the read request
readRequest <= 1;
//If granted then advance
if (readRequestGrant) begin
StageCounter <= StageCounter + 5'b1;
readRequest <= 0;
end
end
5: begin
//read is marked valid, check value
if (readValid) begin
StageCounter <= 4;
readAddress <= readAddress + 1;
if (readData != readAddress) begin
SelectedTest <= 0;
registers[1] <= readAddress;
registers[0] <= 0;
end
if (readAddress > 32'd4194314) StageCounter <= 6;
end
end
6: begin
registers[0] <= 1;
registers[1] <= 0;
SelectedTest <= 0;
run <= 0;
end
endcase
endtask
task BasicR();
case (StageCounter)
0: begin
//Setup the read request
readAddress <= registers[0];
readRequest <= 1;
//If granted then advance
if (readRequestGrant) begin
StageCounter <= StageCounter + 5'b1;
readRequest <= 0;
end
end
1: begin
//read is marked valid, capture to lowest register.
if (readValid) begin
registers[0] <= readData;
SelectedTest <= 0;
run <= 0;
end
end
endcase
endtask
task WValue();
case (StageCounter)
0: begin
//Setup a write request with parameter buffer input.
writeAddress <= registers[0];
writeRequest <= 1;
writeData <= registers[1];
StageCounter <= StageCounter + 5'b1;
end
1: begin
//await the grant from the controller.
if (writeRequestGrant) begin
StageCounter <= StageCounter + 5'b1;
writeRequest <= 0;
end
end
2: begin
//Await the commit signal
if (writeCommit) begin
writeData <= 0;
SelectedTest <= 0;
run <= 0;
end
end
endcase
endtask
task BasicW();
case (StageCounter)
0: begin
//Setup a write request with broken barber pole input.
writeAddress <= 0;
writeRequest <= 1;
writeData <= 16'b1110101110101110;
StageCounter <= StageCounter + 5'b1;
end
1: begin
//await the grant from the controller.
if (writeRequestGrant) begin
StageCounter <= StageCounter + 5'b1;
writeRequest <= 0;
end
end
2: begin
//Await the commit signal
if (writeCommit) begin
writeData <= 0;
SelectedTest <= 0;
run <= 0;
end
end
endcase
endtask
task BasicRW();
case (StageCounter)
0: begin
//Setup a write request with barber pole input.
writeAddress <= 0;
writeRequest <= 1;
writeData <= 16'b1010101010101010;
StageCounter <= StageCounter + 5'b1;
end
1: begin
//await the grant from the controller.
if (writeRequestGrant) begin
StageCounter <= StageCounter +5'b1;
writeRequest <= 0;
end
end
2: begin
//Await the commit signal
if (writeCommit) begin
StageCounter <= StageCounter + 5'b1;
writeData <= 0;
end
end
3: begin
//Setup a write request with broken pole input.
writeAddress <= 1;
writeRequest <= 1;
writeData <= 16'b1110111010111010;
StageCounter <= StageCounter + 5'b1;
end
4: begin
//await the grant from the controller.
if (writeRequestGrant) begin
StageCounter <= StageCounter + 5'b1;
writeRequest <= 0;
end
end
5: begin
//Await the commit signal
if (writeCommit) begin
StageCounter <= StageCounter + 5'b1;
writeData <= 0;
end
end
6: begin
//Setup the read request
readAddress <= 0;
readRequest <= 1;
//If granted then advance
if (readRequestGrant) begin
StageCounter <= StageCounter + 5'b1;
readRequest <= 0;
end
end
7: begin
//read is marked valid, capture to lowest register.
if (readValid) begin
registers[0] <= readData;
SelectedTest <= 0;
run <= 0;
end
end
endcase
endtask
endmodule