OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [orpsocv2/] [boards/] [actel/] [ordb1a3pe1500/] [rtl/] [verilog/] [versatile_mem_ctrl/] [rtl/] [verilog/] [versatile_mem_ctrl_top.v] - Blame information for rev 411

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 408 julius
`timescale 1ns/1ns
2
`ifdef DDR_16
3
 `include "ddr_16_defines.v"
4
`endif
5
`ifdef SDR_16
6
 `include "sdr_16_defines.v"
7
`endif
8
module versatile_mem_ctrl_top
9
  (
10
   // wishbone side
11
   wb_adr_i_0, wb_dat_i_0, wb_dat_o_0,
12
   wb_stb_i_0, wb_cyc_i_0, wb_ack_o_0,
13
   wb_adr_i_1, wb_dat_i_1, wb_dat_o_1,
14
   wb_stb_i_1, wb_cyc_i_1, wb_ack_o_1,
15
   wb_adr_i_2, wb_dat_i_2, wb_dat_o_2,
16
   wb_stb_i_2, wb_cyc_i_2, wb_ack_o_2,
17
   wb_adr_i_3, wb_dat_i_3, wb_dat_o_3,
18
   wb_stb_i_3, wb_cyc_i_3, wb_ack_o_3,
19
   wb_clk, wb_rst,
20
 
21
`ifdef SDR_16
22
   ba_pad_o, a_pad_o, cs_n_pad_o, ras_pad_o, cas_pad_o, we_pad_o, dq_o, dqm_pad_o, dq_i, dq_oe, cke_pad_o,
23
`endif
24
 
25
`ifdef DDR_16
26
   ck_pad_o, ck_n_pad_o, cke_pad_o, ck_fb_pad_o, ck_fb_pad_i,
27
   cs_n_pad_o, ras_pad_o, cas_pad_o,  we_pad_o,
28
   dm_rdqs_pad_io,  ba_pad_o, addr_pad_o, dq_pad_io, dqs_pad_io, dqs_oe, dqs_n_pad_io, rdqs_n_pad_i, odt_pad_o,
29
`endif
30
   // SDRAM signals
31
   sdram_clk, sdram_rst
32
   );
33
 
34
   // number of wb clock domains
35
   parameter nr_of_wb_clk_domains = 1;
36
   // number of wb ports in each wb clock domain
37
   parameter nr_of_wb_ports_clk0  = 3;
38
   parameter nr_of_wb_ports_clk1  = 0;
39
   parameter nr_of_wb_ports_clk2  = 0;
40
   parameter nr_of_wb_ports_clk3  = 0;
41
 
42
   input  [36*nr_of_wb_ports_clk0-1:0] wb_adr_i_0;
43
   input [36*nr_of_wb_ports_clk0-1:0]  wb_dat_i_0;
44
   output [32*nr_of_wb_ports_clk0-1:0] wb_dat_o_0;
45
   input [0:nr_of_wb_ports_clk0-1]     wb_stb_i_0, wb_cyc_i_0;
46
   output [0:nr_of_wb_ports_clk0-1]    wb_ack_o_0;
47
 
48
 
49
   input [36*nr_of_wb_ports_clk1-1:0]  wb_adr_i_1;
50
   input [36*nr_of_wb_ports_clk1-1:0]  wb_dat_i_1;
51
   output [32*nr_of_wb_ports_clk1-1:0] wb_dat_o_1;
52
   input [0:nr_of_wb_ports_clk1-1]     wb_stb_i_1, wb_cyc_i_1;
53
   output [0:nr_of_wb_ports_clk1-1]    wb_ack_o_1;
54
 
55
   input [36*nr_of_wb_ports_clk2-1:0]  wb_adr_i_2;
56
   input [36*nr_of_wb_ports_clk2-1:0]  wb_dat_i_2;
57
   output [32*nr_of_wb_ports_clk2-1:0] wb_dat_o_2;
58
   input [0:nr_of_wb_ports_clk2-1]     wb_stb_i_2, wb_cyc_i_2;
59
   output [0:nr_of_wb_ports_clk2-1]    wb_ack_o_2;
60
 
61
   input [36*nr_of_wb_ports_clk3-1:0]  wb_adr_i_3;
62
   input [36*nr_of_wb_ports_clk3-1:0]  wb_dat_i_3;
63
   output [32*nr_of_wb_ports_clk3-1:0] wb_dat_o_3;
64
   input [0:nr_of_wb_ports_clk3-1]     wb_stb_i_3, wb_cyc_i_3;
65
   output [0:nr_of_wb_ports_clk3-1]    wb_ack_o_3;
66
 
67
   input [0:nr_of_wb_clk_domains-1]    wb_clk;
68
   input [0:nr_of_wb_clk_domains-1]    wb_rst;
69
 
70
`ifdef SDR_16
71
   output [1:0]                 ba_pad_o;
72
   output [12:0]                        a_pad_o;
73
   output                              cs_n_pad_o;
74
   output                              ras_pad_o;
75
   output                              cas_pad_o;
76
   output                              we_pad_o;
77
   output reg [(`SDRAM_DATA_WIDTH)-1:0] dq_o /*synthesis syn_useioff=1 syn_allow_retiming=0 */;
78
   output [1:0]                 dqm_pad_o;
79
   input [(`SDRAM_DATA_WIDTH)-1:0]     dq_i ;
80
   output                              dq_oe;
81
   output                              cke_pad_o;
82
`endif
83
`ifdef DDR_16
84
   output                              ck_pad_o;
85
   output                              ck_n_pad_o;
86
   output                              cke_pad_o;
87
   output                              ck_fb_pad_o;
88
   input                               ck_fb_pad_i;
89
   output                              cs_n_pad_o;
90
   output                              ras_pad_o;
91
   output                              cas_pad_o;
92
   output                              we_pad_o;
93
   inout [1:0]                          dm_rdqs_pad_io;
94
   output [1:0]                 ba_pad_o;
95
   output [12:0]                        addr_pad_o;
96
   inout [15:0]                 dq_pad_io;
97
   inout [1:0]                          dqs_pad_io;
98
   output                              dqs_oe;
99
   inout [1:0]                          dqs_n_pad_io;
100
   input [1:0]                          rdqs_n_pad_i;
101
   output                              odt_pad_o;
102
`endif
103
   input                               sdram_clk, sdram_rst;
104
 
105
   wire [0:15]                          fifo_empty[0:3];
106
   wire                                current_fifo_empty;
107
   wire [0:15]                          fifo_re[0:3];
108
   wire [35:0]                          fifo_dat_o[0:3];
109
   wire [31:0]                          fifo_dat_i;
110
   wire [0:15]                          fifo_we[0:3];
111
   wire                                fifo_rd_adr, fifo_rd_data, fifo_wr, idle, count0;
112
 
113
   wire [0:15]                          fifo_sel_i, fifo_sel_dly;
114
   reg [0:15]                           fifo_sel_reg;
115
   wire [1:0]                           fifo_sel_domain_i, fifo_sel_domain_dly;
116
   reg [1:0]                            fifo_sel_domain_reg;
117
 
118
   reg                                 refresh_req;
119
 
120
   wire [35:0]                          tx_fifo_dat_o;
121
 
122
   wire                                burst_reading;
123
   reg                                 sdram_fifo_wr_r;
124
 
125
 
126
   generate
127
      if (nr_of_wb_clk_domains > 0) begin
128
         versatile_mem_ctrl_wb
129
           # (.nr_of_wb_ports(nr_of_wb_ports_clk0))
130
         wb0
131
           (
132
            // wishbone side
133
            .wb_adr_i_v(wb_adr_i_0),
134
            .wb_dat_i_v(wb_dat_i_0),
135
            .wb_dat_o_v(wb_dat_o_0),
136
            .wb_stb_i(wb_stb_i_0),
137
            .wb_cyc_i(wb_cyc_i_0),
138
            .wb_ack_o(wb_ack_o_0),
139
            .wb_clk(wb_clk[0]),
140
            .wb_rst(wb_rst[0]),
141
            // SDRAM controller interface
142
            .sdram_dat_o(fifo_dat_o[0]),
143
            .sdram_fifo_empty(fifo_empty[0][0:nr_of_wb_ports_clk0-1]),
144
            .sdram_fifo_rd_adr(fifo_rd_adr),
145
            .sdram_fifo_rd_data(fifo_rd_data),
146
            .sdram_fifo_re(fifo_re[0][0:nr_of_wb_ports_clk0-1]),
147
            .sdram_dat_i(fifo_dat_i),
148
            .sdram_fifo_wr(fifo_wr),
149
            .sdram_fifo_we(fifo_we[0][0:nr_of_wb_ports_clk0-1]),
150
            .sdram_burst_reading(burst_reading),
151
            .debug_wb_fsm_state(),
152
            .debug_ingress_fifo_empty(),
153
            .debug_egress_fifo_empty(),
154
            .sdram_clk(sdram_clk),
155
            .sdram_rst(sdram_rst) );
156
      end
157
      if (nr_of_wb_ports_clk0 < 16) begin
158
         assign fifo_empty[0][nr_of_wb_ports_clk0:15] = {(16-nr_of_wb_ports_clk0){1'b1}};
159
      end
160
   endgenerate
161
 
162
   generate
163
      if (nr_of_wb_clk_domains > 1) begin
164
         versatile_mem_ctrl_wb
165
           # (.nr_of_wb_ports(nr_of_wb_ports_clk1))
166
         wb1
167
           (
168
            // wishbone side
169
            .wb_adr_i_v(wb_adr_i_1),
170
            .wb_dat_i_v(wb_dat_i_1),
171
            .wb_dat_o_v(wb_dat_o_1),
172
            .wb_stb_i(wb_stb_i_1),
173
            .wb_cyc_i(wb_cyc_i_1),
174
            .wb_ack_o(wb_ack_o_1),
175
            .wb_clk(wb_clk[1]),
176
            .wb_rst(wb_rst[1]),
177
            // SDRAM controller interface
178
            .sdram_dat_o(fifo_dat_o[1]),
179
            .sdram_fifo_empty(fifo_empty[1][0:nr_of_wb_ports_clk1-1]),
180
            .sdram_fifo_rd_adr(fifo_rd_adr),
181
            .sdram_fifo_rd_data(fifo_rd_data),
182
            .sdram_fifo_re(fifo_re[1][0:nr_of_wb_ports_clk1-1]),
183
            .sdram_dat_i(fifo_dat_i),
184
            .sdram_fifo_wr(fifo_wr),
185
            .sdram_fifo_we(fifo_we[1][0:nr_of_wb_ports_clk1-1]),
186
            .sdram_burst_reading(burst_reading),
187
            .sdram_clk(sdram_clk),
188
            .sdram_rst(sdram_rst) );
189
         if (nr_of_wb_ports_clk1 < 16) begin
190
            assign fifo_empty[1][nr_of_wb_ports_clk1:15] = {(16-nr_of_wb_ports_clk1){1'b1}};
191
         end
192
      end else begin
193
         assign fifo_empty[1] = {16{1'b1}};
194
         assign fifo_dat_o[1] = {36{1'b0}};
195
      end
196
   endgenerate
197
 
198
   generate
199
      if (nr_of_wb_clk_domains > 2) begin
200
         versatile_mem_ctrl_wb
201
           # (.nr_of_wb_ports(nr_of_wb_ports_clk1))
202
         wb2
203
           (
204
            // wishbone side
205
            .wb_adr_i_v(wb_adr_i_2),
206
            .wb_dat_i_v(wb_dat_i_2),
207
            .wb_dat_o_v(wb_dat_o_2),
208
            .wb_stb_i(wb_stb_i_2),
209
            .wb_cyc_i(wb_cyc_i_2),
210
            .wb_ack_o(wb_ack_o_2),
211
            .wb_clk(wb_clk[2]),
212
            .wb_rst(wb_rst[2]),
213
            // SDRAM controller interface
214
            .sdram_dat_o(fifo_dat_o[2]),
215
            .sdram_fifo_empty(fifo_empty[2][0:nr_of_wb_ports_clk2-1]),
216
            .sdram_fifo_rd_adr(fifo_rd_adr),
217
            .sdram_fifo_rd_data(fifo_rd_data),
218
            .sdram_fifo_re(fifo_re[2][0:nr_of_wb_ports_clk2-1]),
219
            .sdram_dat_i(fifo_dat_i),
220
            .sdram_fifo_wr(fifo_wr),
221
            .sdram_fifo_we(fifo_we[2][0:nr_of_wb_ports_clk2-1]),
222
            .sdram_burst_reading(burst_reading),
223
            .sdram_clk(sdram_clk),
224
            .sdram_rst(sdram_rst) );
225
         if (nr_of_wb_ports_clk2 < 16) begin
226
            assign fifo_empty[2][nr_of_wb_ports_clk2:15] = {(16-nr_of_wb_ports_clk2){1'b1}};
227
         end
228
      end else begin
229
         assign fifo_empty[2] = {16{1'b1}};
230
         assign fifo_dat_o[2] = {36{1'b0}};
231
      end
232
   endgenerate
233
 
234
   generate
235
      if (nr_of_wb_clk_domains > 3) begin
236
         versatile_mem_ctrl_wb
237
           # (.nr_of_wb_ports(nr_of_wb_ports_clk3))
238
         wb3
239
           (
240
            // wishbone side
241
            .wb_adr_i_v(wb_adr_i_3),
242
            .wb_dat_i_v(wb_dat_i_3),
243
            .wb_dat_o_v(wb_dat_o_3),
244
            .wb_stb_i(wb_stb_i_3),
245
            .wb_cyc_i(wb_cyc_i_3),
246
            .wb_ack_o(wb_ack_o_3),
247
            .wb_clk(wb_clk[3]),
248
            .wb_rst(wb_rst[3]),
249
            // SDRAM controller interface
250
            .sdram_dat_o(fifo_dat_o[3]),
251
            .sdram_fifo_empty(fifo_empty[3][0:nr_of_wb_ports_clk3-1]),
252
            .sdram_fifo_rd_adr(fifo_rd_adr),
253
            .sdram_fifo_rd_data(fifo_rd_data),
254
            .sdram_fifo_re(fifo_re[3][0:nr_of_wb_ports_clk3-1]),
255
            .sdram_dat_i(fifo_dat_i),
256
            .sdram_fifo_wr(fifo_wr),
257
            .sdram_fifo_we(fifo_we[3][0:nr_of_wb_ports_clk3-1]),
258
            .sdram_burst_reading(burst_reading),
259
            .sdram_clk(sdram_clk),
260
            .sdram_rst(sdram_rst) );
261
         if (nr_of_wb_ports_clk3 < 16) begin
262
            assign fifo_empty[3][nr_of_wb_ports_clk3:15] = {(16-nr_of_wb_ports_clk3){1'b1}};
263
         end
264
      end else begin
265
         assign fifo_empty[3] = {16{1'b1}};
266
         assign fifo_dat_o[3] = {36{1'b0}};
267
      end
268
   endgenerate
269
 
270
   encode encode0
271
     (
272
      .fifo_empty_0(fifo_empty[0]), .fifo_empty_1(fifo_empty[1]),
273
      .fifo_empty_2(fifo_empty[2]), .fifo_empty_3(fifo_empty[3]),
274
      .fifo_sel(fifo_sel_i), .fifo_sel_domain(fifo_sel_domain_i)
275
      );
276
 
277
   always @ (posedge sdram_clk or posedge sdram_rst)
278
     begin
279
        if (sdram_rst)
280
          {fifo_sel_reg,fifo_sel_domain_reg} <= {16'h0,2'b00};
281
        else
282
          if (idle)
283
            {fifo_sel_reg,fifo_sel_domain_reg}<={fifo_sel_i,fifo_sel_domain_i};
284
     end
285
 
286
   decode decode0
287
     (
288
      .fifo_sel(fifo_sel_reg), .fifo_sel_domain(fifo_sel_domain_reg),
289
      .fifo_we_0(fifo_re[0]), .fifo_we_1(fifo_re[1]), .fifo_we_2(fifo_re[2]),
290
      .fifo_we_3(fifo_re[3])
291
      );
292
 
293
   // fifo_re[0-3] is a one-hot read enable structure
294
   // fifo_empty should go active when chosen fifo queue is empty
295
   assign current_fifo_empty = (idle) ?
296
                               (!(|fifo_sel_i)) :
297
                               (|(fifo_empty[0] & fifo_re[0])) |
298
                               (|(fifo_empty[1] & fifo_re[1])) |
299
                               (|(fifo_empty[2] & fifo_re[2])) |
300
                               (|(fifo_empty[3] & fifo_re[3]));
301
 
302
   decode decode1
303
     (
304
      .fifo_sel(fifo_sel_dly), .fifo_sel_domain(fifo_sel_domain_dly),
305
      .fifo_we_0(fifo_we[0]), .fifo_we_1(fifo_we[1]), .fifo_we_2(fifo_we[2]),
306
      .fifo_we_3(fifo_we[3])
307
      );
308
 
309
`ifdef SDR_16
310
 
311
   wire ref_cnt_zero;
312
   reg [(`SDRAM_DATA_WIDTH)-1:0] dq_i_reg /*synthesis syn_useioff=1 syn_allow_retiming=0 */;
313
   reg [(`SDRAM_DATA_WIDTH)-1:0] dq_i_tmp_reg;
314
   reg [17:0] dq_o_tmp_reg;
315
   wire       cmd_aref, cmd_read;
316
 
317
   // refresch counter
318
   //ref_counter ref_counter0( .zq(ref_cnt_zero), .rst(sdram_rst), .clk(sdram_clk));
319
   ref_counter
320
`ifdef MT48LC32M16
321
     #(.length(9), .wrap_value(67))
322
`endif
323
   ref_counter0( .zq(ref_cnt_zero), .rst(sdram_rst), .clk(sdram_clk));
324
 
325
   always @ (posedge sdram_clk or posedge sdram_rst)
326
     if (sdram_rst)
327
       refresh_req <= 1'b0;
328
     else
329
       if (ref_cnt_zero)
330
         refresh_req <= 1'b1;
331
       else if (cmd_aref)
332
         refresh_req <= 1'b0;
333
 
334
   reg        current_fifo_empty_r;
335
   always @(posedge sdram_clk)
336
     current_fifo_empty_r <= current_fifo_empty;
337
 
338
   always @(posedge sdram_clk)
339
     sdram_fifo_wr_r <= fifo_wr;
340
 
341
 
342
 
343
   // SDR SDRAM 16 FSM
344
   fsm_sdr_16 fsm_sdr_16_0
345
     (
346
      .adr_i({fifo_dat_o[0][`BA_SIZE+`ROW_SIZE+`COL_SIZE+6-2:6],1'b0}),
347
      .we_i(fifo_dat_o[0][5]),
348
      .bte_i(fifo_dat_o[0][4:3]),
349
      .cti_i(fifo_dat_o[0][2:0]),
350
      .sel_i({fifo_dat_o[0][3:2],dq_o_tmp_reg[1:0]}),
351
      .fifo_empty(current_fifo_empty_r),
352
      .fifo_rd_adr(fifo_rd_adr),
353
      .fifo_rd_data(fifo_rd_data),
354
      .state_idle(idle),
355
      .count0(count0),
356
      .refresh_req(refresh_req),
357
      .cmd_aref(cmd_aref),
358
      .cmd_read(cmd_read),
359
      .ba(ba_pad_o), .a(a_pad_o),
360
      .cmd({ras_pad_o, cas_pad_o, we_pad_o}),
361
      .dq_oe(dq_oe),
362
      .dqm(dqm_pad_o),
363
      .sdram_fifo_wr(sdram_fifo_wr_r),
364
      .sdram_burst_reading(burst_reading),
365
      .debug_state(),
366
      .debug_fifo_we_record(),
367
      .sdram_clk(sdram_clk),
368
      .sdram_rst(sdram_rst)
369
      );
370
 
371
   assign cs_pad_o = 1'b0;
372
   assign cke_pad_o = 1'b1;
373
 
374
   genvar     i;
375
   generate
376
      for (i=0; i < 16; i=i+1) begin : dly
377
 
378
         defparam delay0.depth=`INIT_CL+2;
379
         defparam delay0.width=1;
380
         delay delay0 (
381
                       .d(fifo_sel_reg[i]),
382
                       .q(fifo_sel_dly[i]),
383
                       .clk(sdram_clk),
384
                       .rst(sdram_rst)
385
                       );
386
      end
387
 
388
      defparam delay1.depth=`INIT_CL+2;
389
      defparam delay1.width=2;
390
      delay delay1 (
391
                    .d(fifo_sel_domain_reg),
392
                    .q(fifo_sel_domain_dly),
393
                    .clk(sdram_clk),
394
                    .rst(sdram_rst)
395
                    );
396
 
397
      defparam delay2.depth=`INIT_CL+2;
398
      defparam delay2.width=1;
399
      delay delay2 (
400
                    .d(cmd_read),
401
                    .q(fifo_wr),
402
                    .clk(sdram_clk),
403
                    .rst(sdram_rst)
404
                    );
405
 
406
   endgenerate
407
 
408
   // output registers
409
   assign cs_n_pad_o = 1'b0;
410
   assign cke_pad_o  = 1'b1;
411
 
412
   always @ (posedge sdram_clk)
413
     dq_i_reg <= dq_i;
414
 
415
   always @(posedge sdram_clk)
416
     dq_i_tmp_reg <= dq_i_reg;
417
 
418
   assign fifo_dat_i = {dq_i_tmp_reg, dq_i_reg};
419
 
420
   always @ (posedge sdram_clk or posedge sdram_rst)
421
     if (sdram_rst)
422
       dq_o_tmp_reg <= 18'h0;
423
     else
424
       dq_o_tmp_reg <= {fifo_dat_o[0][19:4],fifo_dat_o[0][1:0]};
425
 
426
   // output dq_o mux and dffs
427
   always @ (posedge sdram_clk or posedge sdram_rst)
428
     if (sdram_rst)
429
       dq_o <= 16'h0000;
430
     else
431
       if (~count0)
432
         dq_o <= fifo_dat_o[0][35:20];
433
       else
434
         dq_o <= dq_o_tmp_reg[17:2];
435
 
436
   /*
437
    // data mask signals should be not(sel_i) for write and 2'b00 for read
438
    always @ (posedge sdram_clk or posedge sdram_rst)
439
    if (sdram_rst)
440
    dqm_pad_o <= 2'b00;
441
    else
442
    if (~count0)
443
    dqm_pad_o <= ~fifo_dat_o[fifo_sel_domain_reg][3:2];
444
    else
445
    dqm_pad_o <= ~dq_o_tmp_reg[1:0];
446
    */
447
   /*
448
    always @ (posedge sdram_clk or posedge sdram_rst)
449
    if (sdram_rst) begin
450
    {dq_o, dqm_pad_o} <= {16'h0000,2'b00};
451
 
452
    end else
453
    if (~count0) begin
454
    dq_o <= fifo_dat_o[fifo_sel_domain_reg][35:20];
455
    dq_o_tmp_reg[17:2] <= fifo_dat_o[fifo_sel_domain_reg][19:4];
456
    if (cmd_read)
457
    dqm_pad_o <= 2'b00;
458
    else
459
    dqm_pad_o <= ~fifo_dat_o[fifo_sel_domain_reg][3:2];
460
    if (cmd_read)
461
    dq_o_tmp_reg[1:0] <= 2'b00;
462
    else
463
    dq_o_tmp_reg[1:0] <= ~fifo_dat_o[fifo_sel_domain_reg][1:0];
464
       end else
465
    {dq_o,dqm_pad_o} <= dq_o_tmp_reg;
466
    */
467
 
468
 
469
`endif //  `ifdef SDR_16
470
 
471
 
472
`ifdef DDR_16
473
   wire        read, write;
474
   wire        sdram_clk_90, sdram_clk_180, sdram_clk_270;
475
   wire        ck_fb;
476
   reg         cke, ras, cas, we, cs_n;
477
   wire        cke_d, ras_d, cas_d, we_d, cs_n_d;
478
   wire        ras_o, cas_o, we_o, cs_n_o;
479
   wire [1:0]  ba_o;
480
   wire [12:0] addr_o;
481
   reg  [1:0]  ba;
482
   wire [1:0]  ba_d;
483
   reg [12:0]  addr;
484
   wire [12:0] addr_d;
485
   wire        dq_en, dqm_en;
486
   reg [15:0]  dq_tx_reg;
487
   wire [15:0] dq_tx;
488
   reg [31:0]  dq_rx_reg;
489
   wire [31:0] dq_rx;
490
   wire [15:0] dq_o;
491
   reg [3:0]   dqm_tx_reg;
492
   wire [3:0]  dqm_tx;
493
   wire [1:0]  dqm_o, dqs_o, dqs_n_o;
494
   wire        ref_delay, ref_delay_ack;
495
   wire        bl_en, bl_ack;
496
   wire        tx_fifo_re, tx_fifo_re_i;
497
   //wire        adr_init_delay;
498
   //reg         adr_init_delay_i;
499
   reg [3:0]   burst_cnt;
500
   wire [3:0]  burst_next_cnt, burst_length;
501
   //wire        burst_mask;
502
   reg         burst_mask;
503
   wire [12:0] cur_row;
504
   wire  [3:0] burst_adr;
505
   //wire  [2:0] tx_fifo_b_sel_i_cur;
506
   wire  [2:0] rx_fifo_a_sel_i;
507
   //wire  [7:0] tx_fifo_empty;
508
   wire        rx_fifo_we;
509
 
510
   wire ref_cnt_zero;
511
   wire cmd_aref;
512
 
513
   // refresh counter
514
   ref_counter ref_counter0(
515
     .zq(ref_cnt_zero),
516
     .rst(sdram_rst),
517
     .clk(sdram_clk));
518
   always @ (posedge sdram_clk or posedge sdram_rst)
519
   if (sdram_rst)
520
     refresh_req <= 1'b0;
521
   else
522
     if (ref_cnt_zero)
523
       refresh_req <= 1'b1;
524
     else if (cmd_aref)
525
       refresh_req <= 1'b0;
526
 
527
   // DDR SDRAM 16 FSM
528
   ddr_16 ddr_16_0
529
     (
530
      .adr_init(adr_init),
531
      .fifo_re(tx_fifo_re_i),
532
      .fifo_re_d(tx_fifo_re),
533
      .tx_fifo_dat_o(fifo_dat_o[fifo_sel_domain_reg]),
534
      .burst_adr(burst_adr),
535
      .fifo_empty(current_fifo_empty),
536
      .fifo_sel(),
537
      .read(read),
538
      .write(write),
539
      .ref_req(refresh_req),
540
      .ref_ack(cmd_aref),
541
      .ref_delay(ref_delay),
542
      .state_idle(idle),
543
      .ref_delay_ack(ref_delay_ack),
544
      .bl_en(bl_en),
545
      .bl_ack(bl_ack),
546
      .a({ba_o,addr_o}),
547
      .cmd({ras_o,cas_o,we_o}),
548
      .cs_n(cs_n_o),
549
      .cur_row(cur_row),
550
      .clk(sdram_clk_0),
551
      .rst(sdram_rst)
552
      );
553
 
554
   inc_adr inc_adr0
555
     (
556
      .adr_i(fifo_dat_o[fifo_sel_domain_reg][9:6]),
557
      .bte_i(fifo_dat_o[fifo_sel_domain_reg][4:3]),
558
      .cti_i(fifo_dat_o[fifo_sel_domain_reg][2:0]),
559
      .init(adr_init),
560
      .inc(),
561
      .adr_o(burst_adr),
562
      .done(done),
563
      .clk(sdram_clk_0),
564
      .rst(sdram_rst)
565
      );
566
 
567
   // Delay, refresh to activate/refresh
568
   ref_delay_counter ref_delay_counter0
569
     (
570
      .cke(ref_delay),
571
      .zq(ref_delay_ack),
572
      .clk(sdram_clk_0),
573
      .rst(sdram_rst)
574
      );
575
 
576
   // Burst length, DDR2 SDRAM
577
   burst_length_counter burst_length_counter0
578
     (
579
      .cke(bl_en),
580
      .zq(bl_ack),
581
      .clk(sdram_clk_0),
582
      .rst(sdram_rst)
583
      );
584
 
585
   // Wishbone burst length
586
   assign burst_length = (adr_init && fifo_dat_o[fifo_sel_domain_reg][2:0] == 3'b000) ? 4'd1 :   // classic cycle
587
                         (adr_init && fifo_dat_o[fifo_sel_domain_reg][2:0] == 3'b010) ? 4'd4 :   // incremental burst cycle
588
                         burst_length;
589
 
590
   // Burst mask
591
   // Burst length counter
592
   assign burst_next_cnt = (burst_cnt == 3) ? 4'd0 : burst_cnt + 4'd1;
593
   always @ (posedge sdram_clk_0 or posedge sdram_rst)
594
     if (sdram_rst)
595
       burst_cnt <= 4'h0;
596
     else
597
       if (bl_en)
598
         burst_cnt <= burst_next_cnt;
599
   // Burst Mask
600
   //assign burst_mask = (burst_cnt >= burst_length) ? 1'b1 : 1'b0;
601
 
602
   // Burst Mask
603
   always @ (posedge sdram_clk_0 or posedge sdram_rst)
604
     if (sdram_rst)
605
       burst_mask <= 1'b0;
606
     else
607
       burst_mask <= (burst_cnt >= burst_length) ? 1'b1 : 1'b0;
608
 
609
   // Delay address and control to compensate for delay in Tx FIOFs
610
   defparam delay0.depth=3;
611
   defparam delay0.width=20;
612
   delay delay0 (
613
      .d({cs_n_o,1'b1,ras_o,cas_o,we_o,ba_o,addr_o}),
614
      .q({cs_n_d,cke_d,ras_d,cas_d,we_d,ba_d,addr_d}),
615
      .clk(sdram_clk_180),
616
      .rst(sdram_rst));
617
 
618
   // Assing outputs
619
   // Non-DDR outputs
620
   assign cs_n_pad_o  = cs_n_d;
621
   assign cke_pad_o   = cke_d;
622
   assign ras_pad_o   = ras_d;
623
   assign cas_pad_o   = cas_d;
624
   assign we_pad_o    = we_d;
625
   assign ba_pad_o    = ba_d;
626
   assign addr_pad_o  = addr_d;
627
   assign ck_fb_pad_o = ck_fb;
628
   assign dqs_oe      = dq_en;
629
 
630
   // Read latency, delay the control signals to fit latency of the DDR2 SDRAM
631
   defparam delay1.depth=`CL+`AL+4;
632
   defparam delay1.width=1;
633
   delay delay1
634
     (
635
      .d(read && !burst_mask),
636
      .q(fifo_wr),
637
      .clk(sdram_clk_0),
638
      .rst(sdram_rst)
639
      );
640
 
641
   // write latency, delay the control signals to fit latency of the DDR2 SDRAM
642
   defparam delay2.depth=`CL+`AL+1;
643
   defparam delay2.width=1;
644
   delay delay2
645
     (
646
      .d(write),
647
      .q(dq_en),
648
      .clk(sdram_clk_270),
649
      .rst(sdram_rst)
650
      );
651
 
652
   // write latency, delay the control signals to fit latency of the DDR2 SDRAM
653
   defparam delay21.depth=`CL+`AL;
654
   defparam delay21.width=1;
655
   delay delay21
656
     (
657
      .d(burst_mask),
658
      .q(dqm_en),
659
      .clk(sdram_clk_270),
660
      .rst(sdram_rst)
661
      );
662
 
663
/*   // if CL>3 delay read from Tx FIFO
664
   defparam delay3.depth=`CL+`AL-3;
665
   defparam delay3.width=1;
666
   delay delay3
667
     (
668
                 .d(tx_fifo_re_i && !burst_mask),
669
                 .q(tx_fifo_re),
670
                 .clk(sdram_clk_0),
671
                 .rst(sdram_rst)
672
                 );
673
*/
674
 
675
   // if CL=3, no delay
676
   assign tx_fifo_re = tx_fifo_re_i && !burst_mask;
677
   assign fifo_rd_adr = tx_fifo_re;
678
 
679
   //
680
   genvar i;
681
   generate
682
     for (i=0; i < 16; i=i+1) begin : dly
683
 
684
       defparam delay4.depth=`CL+2;
685
       defparam delay4.width=1;
686
       delay delay4 (
687
         .d(fifo_sel_reg[i]),
688
         .q(fifo_sel_dly[i]),
689
         .clk(sdram_clk),
690
         .rst(sdram_rst)
691
       );
692
     end
693
 
694
     defparam delay5.depth=`CL+2;
695
     defparam delay5.width=2;
696
     delay delay5 (
697
       .d(fifo_sel_domain_reg),
698
       .q(fifo_sel_domain_dly),
699
       .clk(sdram_clk),
700
       .rst(sdram_rst)
701
     );
702
endgenerate
703
 
704
 
705
   // Increment address
706
   defparam delay6.depth=`CL+`AL-1;
707
   defparam delay6.width=1;
708
   delay delay6
709
     (
710
      .d({write|read}),
711
      .q({adr_inc}),
712
      .clk(sdram_clk_0),
713
      .rst(sdram_rst)
714
      );
715
 
716
   // DCM/PLL with internal and external feedback
717
   // Remove skew from internal and external clock
718
   // Parameters are set in dcm_pll.v
719
   dcm_pll dcm_pll_0
720
     (
721
      .rst(sdram_rst),
722
      .clk_in(sdram_clk),
723
      .clkfb_in(ck_fb_pad_i),
724
      .clk0_out(sdram_clk_0),
725
      .clk90_out(sdram_clk_90),
726
      .clk180_out(sdram_clk_180),
727
      .clk270_out(sdram_clk_270),
728
      .clkfb_out(ck_fb)
729
      );
730
 
731
   // DDR2 IF
732
   versatile_mem_ctrl_ddr versatile_mem_ctrl_ddr_0
733
     (
734
      // DDR2 SDRAM ports
735
      .ck_o(ck_pad_o),
736
      .ck_n_o(ck_n_pad_o),
737
      .dq_io(dq_pad_io),
738
      .dqs_io(dqs_pad_io),
739
      .dqs_n_io(dqs_n_pad_io),
740
      .dm_rdqs_io(dm_rdqs_pad_io),
741
      // Memory controller side
742
      .tx_dat_i(fifo_dat_o[fifo_sel_domain_reg]),
743
      .rx_dat_o(fifo_dat_i),
744
      .dq_en(dq_en),
745
      .dqm_en(dqm_en),
746
      .rst(sdram_rst),
747
      .clk_0(sdram_clk_0),
748
      .clk_90(sdram_clk_90),
749
      .clk_180(sdram_clk_180),
750
      .clk_270(sdram_clk_270));
751
 
752
`endif //  `ifdef DDR_16
753
 
754
endmodule // wb_sdram_ctrl_top

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.