-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdram_controller_testbench.v
184 lines (162 loc) · 3.45 KB
/
sdram_controller_testbench.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
`timescale 1ns/1ns
module sdram_controller_testbench();
reg clk;
reg clk_90_degree;
reg arst_n = 0;
initial begin
clk = 0;
clk_90_degree = 0;
#1 arst_n = 1;
end
//
wire sdram_CLK, sdram_CKE, sdram_nCS, sdram_nRAS, sdram_nCAS, sdram_nWE;
wire [1:0] sdram_BA, sdram_DM;
wire [12:0] sdram_ADDR;
wire [15:0] sdram_DQ;
wire init_done;
reg [24:0] dbus_address = 25'd0;
reg [15:0] dbus_writedata = 16'd100;
wire [15:0] dbus_readdata;
reg [1:0] dbus_byteenable = 2'b11;
reg [6:0] dbus_burstcount = 16;
reg dbus_read = 0,
dbus_write = 0;
wire dbus_waitrequest,
dbus_readdatavalid;
initial begin
$dumpfile(`SIMRESULT);
$dumpvars;
#`PERIODS
$finish;
end
always begin
#5 clk <= !clk;
end
always @* begin
clk_90_degree <= #2 clk;
end
reg [3:0] state = 0;
reg [4:0] burst_left = 1;
always @* begin
case(state)
0: begin
dbus_address = {13'b0000000000000,2'b00,9'b000000000, 1'b0};
dbus_writedata = 16'hFFFF;
dbus_byteenable = 2'b11;
dbus_burstcount = 1;
dbus_write = 1;
dbus_read = 0;
end
1: begin
dbus_address <= {13'b0000000000000,2'b01,9'b000000000, 1'b0};
dbus_writedata = 16'h4444;
dbus_byteenable = 2'b11;
dbus_burstcount = 1;
dbus_write = 1;
dbus_read = 0;
end
2: begin
dbus_address = {13'b0000000000000,2'b01,9'b000001100, 1'b0};
dbus_writedata = 16'h4444;
dbus_byteenable = 2'b11;
dbus_burstcount = 8;
dbus_write = 1;
dbus_read = 0;
end
3: begin
dbus_address = {13'b0000000000000,2'b01,9'b000001100, 1'b0};
dbus_writedata = 16'h4444;
dbus_byteenable = 2'b11;
dbus_burstcount = 16;
dbus_write = 0;
dbus_read = 1;
end
4: begin
dbus_address = {13'b0000000000000,2'b01,9'b000001100, 1'b0};
dbus_writedata = 16'h4444;
dbus_byteenable = 2'b11;
dbus_burstcount = 1;
dbus_write = 0;
dbus_read = 1;
end
5: begin
dbus_address = {13'b0000000000000,2'b01,9'b000001100, 1'b0};
dbus_writedata = 16'h8677;
dbus_byteenable = 2'b11;
dbus_burstcount = 1;
dbus_write = 1;
dbus_read = 0;
end
default: begin
dbus_address = {13'b0000000000000,2'b00,9'b000000000, 1'b0};
dbus_read = 0;
dbus_write = 0;
dbus_burstcount = 1;
dbus_byteenable = 2'b00;
dbus_writedata = 16'h0000;
end
endcase
end
always @(posedge clk) begin
case(state)
0: begin
if(!dbus_waitrequest) begin
state <= 1;
end
end
1: begin
if(!dbus_waitrequest) begin
state <= 2;
burst_left <= 8 - 1;
end
end
2: begin
if(dbus_write && !dbus_waitrequest) begin
if(burst_left)
burst_left <= burst_left - 1;
else begin
state <= 3;
burst_left <= 16 - 1;
end
end
end
3: begin
if(dbus_read && dbus_readdatavalid && !dbus_waitrequest) begin
if(burst_left)
burst_left <= burst_left - 1;
else begin
state <= 4;
burst_left <= 1;
end
end
end
4: begin
if(dbus_read && dbus_readdatavalid && !dbus_waitrequest) begin
state <= 5;
end
end
5: begin
if(dbus_write && !dbus_waitrequest) begin
state <= 6;
end
end
endcase
end
sdram_controller u0(
.clk(clk),
.arst_n(arst_n),
.*
);
sdr u1(
.Clk(sdram_CLK),
.Cke(sdram_CKE),
.Cs_n(sdram_nCS),
.Ras_n(sdram_nRAS),
.Cas_n(sdram_nCAS),
.We_n(sdram_nWE),
.Dqm(sdram_DM),
.Dq(sdram_DQ),
.Addr(sdram_ADDR),
.Ba(sdram_BA)
);
endmodule