support_tasks.v
8.71 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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
task config_rdram;
begin
// set reset mode
@(posedge clock);
write_word(BUS_ADDRESS_RI_MODE, 3, {LOW, LOW, RDRAM_RESET_MODE});
// write the RI current control register
write_word(BUS_ADDRESS_RI_CONFIG, 3, 'b0_001000);
// wait for the current register to propogate
p_valid <= LOW;
repeat (32) @(posedge clock);
// load current control register
write_word(BUS_ADDRESS_RI_CURRENT_LOAD, 3, 0);
// set RAC transmit and receive selects
// write_word(BUS_ADDRESS_RI_SELECT, 3, {4'b0100, 4'b0100});
write_word(BUS_ADDRESS_RI_SELECT, 3, {4'b0001, 4'b0100});
// write_word(BUS_ADDRESS_RI_SELECT, 3, {4'b0001, 4'b0001});
// set the memory access count registers
write_word(BUS_ADDRESS_RI_REFRESH, 3, 'b100111);
// wait for reset_l to take hold
p_valid <= LOW;
repeat (80) @(posedge clock);
// set active mode
// write_word(BUS_ADDRESS_RI_MODE, 3, {LOW, LOW, RDRAM_ACTIVE_MODE});
// set standby mode
write_word(BUS_ADDRESS_RI_MODE, 3, {HIGH, HIGH, RDRAM_STANDBY_MODE});
// use the MI init mode to init the RDRAM delay register
write_word(BUS_ADDRESS_MI_INIT_MODE, 3, {2'b10, 7'd15});
write_word(BUS_ADDRESS_RDRAM_DELAY | RDRAM_GLOBAL_CONFIG, 3,
'h18_08_28_38);
`ifdef RDRAM_1_PRESENT
// initialize RDRAM 1
write_rdram_reg(BUS_ADDRESS_RDRAM_DEVICE_ID,
{RDRAM_1_DEVICE_ID, 3'b0,
8'b0000_0000,
8'b0000_0000,
8'b0000_0000} );
write_rdram_reg(BUS_ADDRESS_RDRAM_RAS_INTERVAL + RDRAM_1_CONFIG,
{8'd1,
8'd7,
8'd10,
8'd4} );
write_rdram_reg(BUS_ADDRESS_RDRAM_MODE + RDRAM_1_CONFIG,
{8'b0000_0010,
8'b0000_0000,
8'b0000_0000,
8'b0000_0000} );
`endif
`ifdef RDRAM_0_PRESENT
// initialize RDRAM 0
write_rdram_reg(BUS_ADDRESS_RDRAM_DEVICE_ID,
{RDRAM_0_DEVICE_ID, 3'b0,
8'b0000_0000,
8'b0000_0000,
8'b0000_0000} );
write_rdram_reg(BUS_ADDRESS_RDRAM_RAS_INTERVAL + RDRAM_0_CONFIG,
{8'd1,
8'd7,
8'd10,
8'd4} );
write_rdram_reg(BUS_ADDRESS_RDRAM_MODE + RDRAM_0_CONFIG,
{8'b0000_0010,
8'b0000_0000,
8'b0000_0000,
8'b0000_0000} );
`endif
`ifdef RDRAM_0_PRESENT
// validate the banks before refreshing beins
read_word(BUS_ADDRESS_DRAM + 'h00_0000, 3);
read_word(BUS_ADDRESS_DRAM + 'h10_0000, 3);
`endif
`ifdef RDRAM_1_PRESENT
// validate the banks before refreshing beins
read_word(BUS_ADDRESS_DRAM + 'h20_0000, 3);
read_word(BUS_ADDRESS_DRAM + 'h30_0000, 3);
`endif
// enable refresh
write_word(BUS_ADDRESS_RI_REFRESH, 3, 'b1_1_0_00110100_00110010);
p_valid <= LOW;
// wait for the post-write-reg delay
repeat (10) @(posedge clock);
end
endtask
/*** support tasks ***/
task write_rdram_reg;
input [31:0] address;
input [31:0] data;
begin
write_word(address, 3, data);
p_valid <= LOW;
@(posedge clock);
end
endtask
task write_word;
input [31:0] address;
input [1:0] size;
input [31:0] data;
begin
p_valid <= HIGH;
sys_cmd_out <= SYS_CMD_WRITE_WORD | size;
sys_ad_out <= address;
@(posedge clock);
while (!e_ok) @(posedge clock);
sys_cmd_out <= SYS_CMD_DATA_LAST;
sys_ad_out <= data;
if (monitor) begin
$display(`CLOCK_COUNT, " : R4200 write - %h @ %h",
data, address);
end
@(posedge clock);
while (!e_ok) begin
// canceled cycle
sys_cmd_out <= SYS_CMD_WRITE_WORD | size;
sys_ad_out <= address;
if (monitor) begin
$display(`CLOCK_COUNT, " : R4200 write - canceled");
end
@(posedge clock);
while (!e_ok) @(posedge clock);
sys_cmd_out <= SYS_CMD_DATA_LAST;
sys_ad_out <= data;
if (monitor) begin
$display(`CLOCK_COUNT, " : R4200 write - %h @ %h",
data, address);
end
@(posedge clock);
end
end
endtask
task write_block;
input [31:0] address;
input [1:0] size;
integer i;
begin
p_valid <= HIGH;
sys_cmd_out <= SYS_CMD_WRITE_BLOCK | size;
sys_ad_out <= address;
@(posedge clock);
while (!e_ok) @(posedge clock);
sys_cmd_out <= SYS_CMD_DATA_NEXT;
sys_ad_out <= data[0];
if (monitor) begin
$display(`CLOCK_COUNT, " : R4200 write[%h] - %h @ %h",
4'd0, data[0], address);
end
@(posedge clock);
while (!e_ok) begin
// canceled cycle
sys_cmd_out <= SYS_CMD_WRITE_BLOCK | size;
sys_ad_out <= address;
if (monitor) begin
$display(`CLOCK_COUNT, " : R4200 write - canceled");
end
@(posedge clock);
while (!e_ok) @(posedge clock);
sys_cmd_out <= SYS_CMD_DATA_NEXT;
sys_ad_out <= data[0];
if (monitor) begin
$display(`CLOCK_COUNT, " : R4200 write[%h] - %h @ %h",
4'h0, data[0], address);
end
@(posedge clock);
end
// finish sending data
for (i = 1; i < (2 << size) - 1; i = i + 1) begin
sys_ad_out <= data[i];
if (monitor) begin
$display(`CLOCK_COUNT, " : R4200 write[%h] - %h @ %h",
i[3:0], data[i], address + (i * 4));
end
@(posedge clock);
end
sys_cmd_out <= SYS_CMD_DATA_LAST;
sys_ad_out <= data[i];
if (monitor) begin
$display(`CLOCK_COUNT, " : R4200 write[%h] - %h @ %h",
i[3:0], data[i], address + (i * 4));
end
@(posedge clock);
end
endtask
task read_word;
input [31:0] address;
input [1:0] size;
begin
p_valid <= HIGH;
sys_cmd_out <= SYS_CMD_READ_WORD | size;
sys_ad_out <= address;
@(posedge clock);
while (!e_ok) @(posedge clock);
sys_ad_enable <= LOW;
p_valid <= LOW;
@(posedge clock);
while (!e_ok) begin
// canceled cycle
sys_ad_enable <= HIGH;
p_valid <= HIGH;
sys_cmd_out <= SYS_CMD_READ_WORD | size;
sys_ad_out <= address;
if (monitor) begin
$display(`CLOCK_COUNT, " : R4200 read - canceled");
end
@(posedge clock);
while (!e_ok) @(posedge clock);
sys_ad_enable <= LOW;
p_valid <= LOW;
end
while (!e_valid) @(posedge clock);
data[0] = sys_ad_in;
if (monitor) begin
$display(`CLOCK_COUNT, " : R4200 read - %h @ %h",
sys_ad_in, address);
end
sys_ad_enable <= HIGH;
end
endtask
task read_block;
input [31:0] address;
input [1:0] size;
integer i;
begin
p_valid <= HIGH;
sys_cmd_out <= SYS_CMD_READ_BLOCK | size;
sys_ad_out <= address;
@(posedge clock);
while (!e_ok) @(posedge clock);
sys_ad_enable <= LOW;
p_valid <= LOW;
@(posedge clock);
while (!e_ok) begin
// canceled cycle
sys_ad_enable <= HIGH;
p_valid <= HIGH;
sys_cmd_out <= SYS_CMD_READ_BLOCK | size;
sys_ad_out <= address;
if (monitor) begin
$display(`CLOCK_COUNT, " : R4200 read - canceled");
end
@(posedge clock);
while (!e_ok) @(posedge clock);
sys_ad_enable <= LOW;
p_valid <= LOW;
@(posedge clock);
end
// read data
for (i = 0; i < (2 << size) - 1; i = i + 1) begin
while (!e_valid) @(posedge clock);
data[i] = sys_ad_in;
if (monitor) begin
$display(`CLOCK_COUNT, " : R4200 read[%h] - %h @ %h",
i[3:0], sys_ad_in, address + (i * 4));
end
@(posedge clock);
end
while (!e_valid) @(posedge clock);
data[i] = sys_ad_in;
if (monitor) begin
$display(`CLOCK_COUNT, " : R4200 read[%h] - %h @ %h",
i[3:0], sys_ad_in, address + (i * 4));
end
sys_ad_enable <= HIGH;
end
endtask
task sp_dma_write;
input [31:0] master_address;
input [31:0] slave_address;
input [11:0] skip;
input [7:0] count;
input [11:0] length;
integer status;
begin
// while busy
read_word(BUS_ADDRESS_SP_STATUS, 3);
status = data[0];
while (status[3]) begin
read_word(BUS_ADDRESS_SP_STATUS, 3);
status = data[0];
end
write_word(BUS_ADDRESS_SP_MASTER, 3, master_address);
write_word(BUS_ADDRESS_SP_SLAVE, 3, slave_address);
write_word(BUS_ADDRESS_SP_WRITE, 3, {skip, count, length});
p_valid <= LOW;
@(posedge clock);
end
endtask
task sp_dma_read;
input [31:0] master_address;
input [31:0] slave_address;
input [11:0] skip;
input [7:0] count;
input [11:0] length;
integer status;
begin
// while busy
read_word(BUS_ADDRESS_SP_STATUS, 3);
status = data[0];
while (status[3]) begin
read_word(BUS_ADDRESS_SP_STATUS, 3);
status = data[0];
end
write_word(BUS_ADDRESS_SP_MASTER, 3, master_address);
write_word(BUS_ADDRESS_SP_SLAVE, 3, slave_address);
write_word(BUS_ADDRESS_SP_READ, 3, {skip, count, length});
p_valid <= LOW;
@(posedge clock);
end
endtask
task sp_mem_write;
input [31:0] address;
input [31:0] write_data;
integer status;
begin
// while busy
read_word(BUS_ADDRESS_SP_STATUS, 3);
status = data[0];
while (status[4]) begin
read_word(BUS_ADDRESS_SP_STATUS, 3);
status = data[0];
end
write_word(BUS_ADDRESS_SP_DMEM+address, 3, write_data);
p_valid <= LOW;
@(posedge clock);
end
endtask
task sp_mem_read;
input [31:0] address;
integer status;
begin
// while busy
read_word(BUS_ADDRESS_SP_STATUS, 3);
status = data[0];
while (status[4]) begin
read_word(BUS_ADDRESS_SP_STATUS, 3);
status = data[0];
end
read_word(BUS_ADDRESS_SP_DMEM+address, 3);
end
endtask