ri_tests.v
4.43 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
// ri_test.v v1 Doug Solomon
// RI ddr initialization
// :set tabstop=4
// ddr memory configuration;
// below list contains specific configs for testing;
// id[3:2] is cas latency, 4, 3, 3, 2;
// id[1:0] configure memory parameters, 9/4/5, 9/4/4, 9/4/3, 9/4/2;
reg [31:0] ri_ddr_mode [0:15];
reg [31:0] ri_ddr_rfsh [0:15];
reg [31:0] ri_ddr_parm [0:15];
initial
begin : ddr_init
integer n;
// setup modes for configs;
for(n = 0; n < 4; n = n + 1)
ri_ddr_mode[n] = 32'h0000_014a;
for(n = 4; n < 12; n = n + 1)
ri_ddr_mode[n] = 32'h0000_013a;
for(n = 12; n < 16; n = n + 1)
ri_ddr_mode[n] = 32'h0000_012a;
// setup refresh;
for(n = 0; n < 16; n = n + 1)
ri_ddr_rfsh[n] = 32'h0000_1080;
// setup memory parameters;
for(n = 0; n < 4; n = n + 1) begin
ri_ddr_parm[n + 0] = 32'h0511_1180 - (n * 32'h0100_0000);
ri_ddr_parm[n + 4] = 32'h0511_1180 - (n * 32'h0100_0000);
ri_ddr_parm[n + 8] = 32'h0510_0080 - (n * 32'h0100_0000);
ri_ddr_parm[n + 12] = 32'h0510_0080 - (n * 32'h0100_0000);
end
end
// configure ddr memory based on configuration id;
task ri_config_ddr;
input [3:0] id;
input fast_rfsh;
reg [31:0] mode;
reg [31:0] parm;
reg [31:0] ext;
reg [31:0] rdata;
begin
$display("test: %M: id %0d", id);
// 1st pre-charge all;
swrite(`RI_MODE, `CPU_SIZE_4, 32'h8000_0000);
sread(`RI_MODE, `CPU_SIZE_4, rdata);
// extended mode register write, enable pll;
swrite(`RI_MODE, `CPU_SIZE_4, 32'h0000_2002);
sread(`RI_MODE, `CPU_SIZE_4, rdata);
// write mode register;
`ifdef TOSHIBA_64MB
mode = 32'h0000_013a;
`else
mode = ri_ddr_mode[id];
mode = 32'h0000_013a;
`endif
swrite(`RI_MODE, `CPU_SIZE_4, mode);
sread(`RI_MODE, `CPU_SIZE_4, rdata);
// 2nd pre-charge all;
swrite(`RI_MODE, `CPU_SIZE_4, 32'h8000_0000);
sread(`RI_MODE, `CPU_SIZE_4, rdata);
// Auto Refesh
swrite(`RI_MODE, `CPU_SIZE_4, 32'h4000_0000);
sread(`RI_MODE, `CPU_SIZE_4, rdata);
// write Tref;
// if fast_rfsh is on, then force highest rate of refresh;
// this is supposed to increase bank act/close frequency;
// XXX implement fast_rfsh;
`ifdef TOSHIBA_64MB
swrite(`RI_RFSH, `CPU_SIZE_4, 32'h0000_11e0);
`else
//swrite(`RI_RFSH, `CPU_SIZE_4, ri_ddr_rfsh[id]);
swrite(`RI_RFSH, `CPU_SIZE_4, 32'h0000_11e0);
`endif
sread(`RI_RFSH, `CPU_SIZE_4, rdata);
// set memory parameters;
parm = ri_ddr_parm[id];
parm[3:0] = mode[7:4];
`ifdef TOSHIBA_64MB
swrite(`RI_PARAM, `CPU_SIZE_4, 32'h0311_11e4);
`else
// swrite(`RI_PARAM, `CPU_SIZE_4, parm);
swrite(`RI_PARAM, `CPU_SIZE_4, 32'h0310_00c4);
`endif
sread(`RI_PARAM, `CPU_SIZE_4, rdata);
// Issue Tref Read
sread(`RI_RFSH, `CPU_SIZE_4, rdata);
sread(`RI_RFSH, `CPU_SIZE_4, rdata);
// setup for x32 or x16 memories;
ext = vsim.ddr_x16? 1 : 0;
if (ext == 1) begin
swrite(`RI_XMEMSET, `CPU_SIZE_4, ext);
end else begin
swrite(`RI_STROBE, `CPU_SIZE_4, 1);
swrite(`RI_AUTO_PRC, `CPU_SIZE_4, 1);
end
// Wait at least 200xmemclk from DLL Reset
repeat(20) @(posedge sysclk);
$display("test: %M: mode 0x%h, rfsh 0x%h, parm 0x%h, ext 0x%h",
mode, ri_ddr_rfsh[id], parm, ext);
end
endtask
// initialize ddr;
task test_ri;
integer i;
begin
// 1st Precharge-All
swrite(32'h0470_0020, 2'b11, 32'h8000_0000);
sread(32'h0470_0020, 2'b11, data[0]);
// extended mode register write, enable pll;
swrite(32'h0470_0020, 2'b11, 32'h0000_2002);
sread(32'h0470_0020, 2'b11, data[0]);
// Mode Register Write
// Issue Mx Write Reset PLL
// CAS Latency = 2
// Interleaved
// Burst Length = 4
swrite(32'h0470_0020, 2'b11, 32'h0000_012a);
sread(32'h0470_0020, 2'b11, data[0]);
// 2st Precharge-All
swrite(32'h0470_0020, 2'b11, 32'h8000_0000);
sread(32'h0470_0020, 2'b11, data[0]);
// Auto Refesh
swrite(32'h0470_0020, 2'b11, 32'h4000_0000);
sread(32'h0470_0020, 2'b11, data[0]);
//Write Tref
swrite(32'h0470_0030, 2'b11, 32'h0000_1080);
sread(32'h0470_0030, 2'b11, data[0]);
// Issue Tref Read
sread(32'h0470_0030, 2'b11, data[0]);
sread(32'h0470_0030, 2'b11, data[0]);
// Wait at least 200xmemclk from DLL Reset
repeat(20) @(posedge sysclk);
for (i=0; i<64; i=i+1)
swrite(i<<2, 2'b11, 32'h87564300+(i<<2));
sread(32'h0000_0020, 2'b11, data[0]);
sread(32'h0000_0060, 2'b11, data[0]);
sread(32'h0000_0064, 2'b11, data[0]);
sread(32'h0000_0068, 2'b11, data[0]);
sread(32'h0000_0070, 2'b11, data[0]);
end
endtask