-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathhbram_ctrl.v
285 lines (248 loc) · 5.14 KB
/
hbram_ctrl.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
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
`timescale 1ps/1ps
module hbram_ctrl(
);
`define hram 1
//`define opi 1
localparam CA_Bits = 0;
localparam LA_Bits = 1;
localparam DQ_Bits = 2;
reg [1:0] state = 2'h0;
integer count = 0;
reg start = 1'b0;
reg start_clk = 1'b0;
reg CSNeg_tmp = 1'b1;
reg sys_clk = 1'b0;
reg hb_clk_tmp = 1'b0;
reg [7:0] buffer [0:1023];
reg [7:0] read_buffer [0:1023];
localparam td = 10;
integer end_count = 7'd36;
reg data_strb_p_tmp;
reg data_strb_n_tmp;
reg [7:0] Dout_zd_p;
reg [7:0] Dout_tmp;
reg [7:0] Dout_zd_n;
reg data_strb_n;
reg data_strb_p;
reg pause = 1'b0;
reg [5:0] pause_count = 0;
reg rwds_sel = 1'b0;
reg rwds_tmp = 1'bz;
reg [5:0] latency = 6'd14;
reg reset_neg = 1'b1;
reg rwds_in = 1'bz;
`ifdef opi
reg reg_write = 1'b0;
reg mem_write = 1'b0;
`endif
integer read_count = 0;
integer sys_clk_period = 500;
integer sys_count;
integer period_cnt;
integer freq = 2500;
integer tdsv = 12000;
integer tdsz = 7000;
integer tIS = 600;
integer tCSH = 10000;
integer tCSS = 3000;
wire [7:0] Dout;
wire rwds,CSNeg,hb_clk;
assign Dout = Dout_tmp;
assign rwds = rwds_tmp;
assign hb_clk = hb_clk_tmp;
assign CSNeg = CSNeg_tmp;
`ifdef hram
s27kl0642 dut(
.DQ7(Dout[7]) ,
.DQ6(Dout[6]) ,
.DQ5(Dout[5]) ,
.DQ4(Dout[4]) ,
.DQ3(Dout[3]) ,
.DQ2(Dout[2]) ,
.DQ1(Dout[1]) ,
.DQ0(Dout[0]) ,
.RWDS(rwds) ,
.CSNeg(CSNeg) ,
.CK(hb_clk) ,
.CKn(1'b0) ,
.RESETNeg(reset_neg)
);
`elsif opi
s27kl0643 dut(
.DQ7(Dout[7]) ,
.DQ6(Dout[6]) ,
.DQ5(Dout[5]) ,
.DQ4(Dout[4]) ,
.DQ3(Dout[3]) ,
.DQ2(Dout[2]) ,
.DQ1(Dout[1]) ,
.DQ0(Dout[0]) ,
.RWDS(rwds) ,
.CSNeg(CSNeg) ,
.CK(hb_clk) ,
.RESET(1'b1)
);
`endif
always @(posedge start)
begin
period_cnt = freq/sys_clk_period;
end
always
begin
#sys_clk_period sys_clk <= ~sys_clk;
end
always @(CSNeg_tmp || hb_clk_tmp)
begin
if(!start_clk) begin
count <= 0;
end else if(pause) begin
count <= count;
end else begin
count <= count + 1;
end
end
always @(start_clk)//sys_clk)
begin
if(count == end_count)begin
start <= 1'b0;
end
end
always @(start or count)//sys_clk)
begin
if(!start) begin
start_clk <= 1'b0;
end else if(count == end_count) begin
start_clk <= 1'b0;
end else if(count == 0)begin
start_clk <= #(tCSS) 1'b1;
end
end
always @(sys_clk)
begin
if(start_clk)begin
sys_count = sys_count+1;
end else begin
sys_count = 0;
end
end
always @(sys_clk)
begin
if(start_clk) begin
if(sys_count%period_cnt == 0)begin
hb_clk_tmp <= ~hb_clk_tmp;
end
end else begin
hb_clk_tmp <= 1'b0;
end
end
always @(start)//sys_clk)
begin
if(!start) begin
CSNeg_tmp <= #tCSH 1'b1;
end else begin
CSNeg_tmp <= 1'b0;
end
end
always @(negedge CSNeg_tmp or negedge hb_clk_tmp)
begin
data_strb_p_tmp <= 1'b1;
#5 data_strb_p_tmp <= 1'b0;
//data_strb_p <= #(freq - tIS) data_strb_p_tmp;
end
always @(posedge hb_clk_tmp)
begin
data_strb_n_tmp <= 1'b1;
#5 data_strb_n_tmp <= 1'b0;
//data_strb_n <= #(freq - tIS) data_strb_n_tmp;
end
always @(data_strb_p_tmp)
begin
data_strb_p <= #(freq - tIS) data_strb_p_tmp;
end
always @(data_strb_n_tmp)
begin
data_strb_n <= #(freq - tIS) data_strb_n_tmp;
end
always @(posedge data_strb_p or posedge data_strb_n or rwds_sel)
begin
if(rwds_sel)begin
Dout_tmp <= 8'hz;
end else if(data_strb_p)begin
Dout_tmp <= Dout_zd_p;
end else if(data_strb_n) begin
Dout_tmp <= Dout_zd_n;
end
end
always @(data_strb_p_tmp)
begin
Dout_zd_p <= buffer[count];
end
always @(data_strb_n_tmp)
begin
Dout_zd_n <= buffer[count];
end
always @(sys_clk)
begin
if(CSNeg_tmp)begin
rwds_sel <= 1'b0;
`ifdef hram
end else if(buffer[0][7])begin
rwds_sel <= dut.rwds_enable;
end
`elsif opi
end else if(count == 6'h20 && !mem_write)begin
rwds_sel <= 1'b1;
end
`endif
if(CSNeg_tmp)begin
rwds_tmp <= 1'bz;
`ifdef hram
end else if(count == 6'h6 && !buffer[0][7] && buffer[0][6])begin
rwds_tmp <= 1'b0;
end else if(count == (latency+4) && !buffer[0][7] && !buffer[0][6])begin
rwds_tmp <= 1'b0;
end
`elsif opi
end else if(count == 6'h6 && reg_write) begin
rwds_tmp <= 1'b0;
end else if(count == (latency+4) && mem_write)begin
rwds_tmp <= 1'b0;
end
`endif
end
always @(rwds)
begin
rwds_in <= #2 rwds;
if(CSNeg_tmp)begin
read_count <= 0;
end else if(rwds_sel) begin
read_count <= #3 read_count + 1;
end
end
always @(rwds_in)
begin
if(rwds_sel)begin
read_buffer[read_count] <= Dout;
end
end
always @(sys_clk)
begin
if(CSNeg_tmp)begin
pause = 0;
end else if(pause && (pause_count == latency))begin
pause = 0;
end else if(count == 6 && rwds_in && buffer[0][7])begin
pause = 1;
end else if(count == 6 && rwds_in && !buffer[0][6] && !buffer[0][7])begin
pause = 1;
end
end
always @(hb_clk_tmp)
begin
if(count == 1)begin
pause_count = 0;
end else if(pause) begin
pause_count = pause_count+1;
end
end
endmodule