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

Subversion Repositories mem_ctrl

[/] [mem_ctrl/] [trunk/] [rtl/] [verilog/] [mc_timing.v] - Blame information for rev 4

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

Line No. Rev Author Line
1 4 rudi
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  WISHBONE Memory Controller Main Timing Block               ////
4
////                                                             ////
5
////                                                             ////
6
////  Author: Rudolf Usselmann                                   ////
7
////          rudi@asics.ws                                      ////
8
////                                                             ////
9
////                                                             ////
10
////  Downloaded from: http://www.opencores.org/cores/mem_ctrl/  ////
11
////                                                             ////
12
/////////////////////////////////////////////////////////////////////
13
////                                                             ////
14
//// Copyright (C) 2000 Rudolf Usselmann                         ////
15
////                    rudi@asics.ws                            ////
16
////                                                             ////
17
//// This source file may be used and distributed without        ////
18
//// restriction provided that this copyright statement is not   ////
19
//// removed from the file and that any derivative work contains ////
20
//// the original copyright notice and the associated disclaimer.////
21
////                                                             ////
22
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
23
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
24
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
25
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
26
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
27
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
28
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
29
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
30
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
31
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
32
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
33
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
34
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
35
////                                                             ////
36
/////////////////////////////////////////////////////////////////////
37
 
38
//  CVS Log
39
//
40
//  $Id: mc_timing.v,v 1.1 2001-07-29 07:34:41 rudi Exp $
41
//
42
//  $Date: 2001-07-29 07:34:41 $
43
//  $Revision: 1.1 $
44
//  $Author: rudi $
45
//  $Locker:  $
46
//  $State: Exp $
47
//
48
// Change History:
49
//               $Log: not supported by cvs2svn $
50
//               Revision 1.4  2001/06/14 01:57:37  rudi
51
//
52
//
53
//               Fixed a potential bug in a corner case situation where the TMS register
54
//               does not propegate properly during initialisation.
55
//
56
//               Revision 1.3  2001/06/12 15:19:49  rudi
57
//
58
//
59
//               Minor changes after running lint, and a small bug fix reading csr and ba_mask registers.
60
//
61
//               Revision 1.2  2001/06/03 11:37:17  rudi
62
//
63
//
64
//               1) Fixed Chip Select Mask Register
65
//                      - Power On Value is now all ones
66
//                      - Comparison Logic is now correct
67
//
68
//               2) All resets are now asynchronous
69
//
70
//               3) Converted Power On Delay to an configurable item
71
//
72
//               4) Added reset to Chip Select Output Registers
73
//
74
//               5) Forcing all outputs to Hi-Z state during reset
75
//
76
//               Revision 1.1.1.1  2001/05/13 09:39:44  rudi
77
//               Created Directory Structure
78
//
79
//
80
//
81
//
82
 
83
`include "mc_defines.v"
84
 
85
module mc_timing(clk, rst,
86
 
87
                // Wishbone Interface
88
                wb_cyc_i, wb_we_i,
89
                wb_read_go, wb_write_go, wb_first, wb_wait, mem_ack,
90
                err,
91
 
92
                // Suspend/Resume Interface
93
                susp_req, resume_req, suspended, susp_sel,
94
 
95
                // Memory Interface
96
                mc_clk, data_oe, oe_, we_, cas_, ras_, cke_,
97
                cs_en, wb_cycle, wr_cycle,
98
                mc_br, mc_bg, mc_adsc, mc_adv,
99
                mc_c_oe, mc_ack,
100
 
101
                // Register File Interface
102
                csc, tms, cs, lmr_req, lmr_ack, cs_le,
103
 
104
                // Address Select Signals
105
                cmd_a10, row_sel, next_adr, page_size,
106
 
107
                // OBCT Signals
108
                bank_set, bank_clr, bank_clr_all, bank_open, any_bank_open, row_same,
109
 
110
                // Data path Controller Signals
111
                dv, pack_le0, pack_le1, pack_le2, par_err,
112
 
113
                // Refresh Counter Signals
114
                rfr_req, rfr_ack,
115
 
116
                // Initialize Request & Ack
117
                init_req, init_ack
118
                );
119
 
120
input           clk;
121
input           rst;
122
 
123
// Wishbone Interface
124
input           wb_cyc_i, wb_we_i;
125
input           wb_read_go;
126
input           wb_write_go;
127
input           wb_first;
128
input           wb_wait;
129
output          mem_ack;
130
output          err;
131
 
132
// Suspend/Resume Interface
133
input           susp_req;
134
input           resume_req;
135
output          suspended;
136
output          susp_sel;
137
 
138
// Memory Interface
139
input           mc_clk;
140
output          data_oe;
141
output          oe_;
142
output          we_;
143
output          cas_;
144
output          ras_;
145
output          cke_;
146
output          cs_en;
147
output          wb_cycle;
148
output          wr_cycle;
149
input           mc_br;
150
output          mc_bg;
151
output          mc_adsc;
152
output          mc_adv;
153
output          mc_c_oe;
154
input           mc_ack;
155
 
156
// Register File Interface
157
input   [31:0]   csc;
158
input   [31:0]   tms;
159
input   [7:0]    cs;
160
input           lmr_req;
161
output          lmr_ack;
162
output          cs_le;
163
 
164
// Address Select Signals
165
input   [10:0]   page_size;
166
output          cmd_a10;
167
output          row_sel;
168
output          next_adr;
169
 
170
// OBCT Signals
171
output          bank_set;
172
output          bank_clr;
173
output          bank_clr_all;
174
input           bank_open;
175
input           any_bank_open;
176
input           row_same;
177
 
178
// Data path Controller Signals
179
output          dv;
180
output          pack_le0, pack_le1, pack_le2;   // Pack Latch Enable
181
input           par_err;
182
 
183
// Refresh Counter Signals
184
input           rfr_req;
185
output          rfr_ack;
186
 
187
// Initialize Request & Ack
188
input           init_req;
189
output          init_ack;
190
 
191
////////////////////////////////////////////////////////////////////
192
//
193
// Defines & Parameters
194
//
195
 
196
// Command Valid, Ras_, Cas_, We_
197
`define CMD_NOP         4'b0111
198
`define CMD_PC          4'b1010
199
`define CMD_ACT         4'b1011
200
`define CMD_WR          4'b1100
201
`define CMD_RD          4'b1101
202
`define CMD_BT          4'b1110
203
`define CMD_ARFR        4'b1001
204
`define CMD_LMR         4'b1000
205
`define CMD_XRD         4'b1111
206
`define CMD_XWR         4'b1110
207
 
208
`define SINGLE_BANK     1'b0
209
`define ALL_BANKS       1'b1
210
 
211
// Number of states: 66
212
parameter       [65:0]   // synopsys enum state
213
POR             = 66'b000000000000000000000000000000000000000000000000000000000000000001,
214
IDLE            = 66'b000000000000000000000000000000000000000000000000000000000000000010,
215
IDLE_T          = 66'b000000000000000000000000000000000000000000000000000000000000000100,
216
IDLE_T2         = 66'b000000000000000000000000000000000000000000000000000000000000001000,
217
PRECHARGE       = 66'b000000000000000000000000000000000000000000000000000000000000010000,
218
PRECHARGE_W     = 66'b000000000000000000000000000000000000000000000000000000000000100000,
219
ACTIVATE        = 66'b000000000000000000000000000000000000000000000000000000000001000000,
220
ACTIVATE_W      = 66'b000000000000000000000000000000000000000000000000000000000010000000,
221
SD_RD_WR        = 66'b000000000000000000000000000000000000000000000000000000000100000000,
222
SD_RD           = 66'b000000000000000000000000000000000000000000000000000000001000000000,
223
SD_RD_W         = 66'b000000000000000000000000000000000000000000000000000000010000000000,
224
SD_RD_LOOP      = 66'b000000000000000000000000000000000000000000000000000000100000000000,
225
SD_RD_W2        = 66'b000000000000000000000000000000000000000000000000000001000000000000,
226
SD_WR           = 66'b000000000000000000000000000000000000000000000000000010000000000000,
227
SD_WR_W         = 66'b000000000000000000000000000000000000000000000000000100000000000000,
228
BT              = 66'b000000000000000000000000000000000000000000000000001000000000000000,
229
BT_W            = 66'b000000000000000000000000000000000000000000000000010000000000000000,
230
REFR            = 66'b000000000000000000000000000000000000000000000000100000000000000000,
231
LMR0            = 66'b000000000000000000000000000000000000000000000001000000000000000000,
232
LMR1            = 66'b000000000000000000000000000000000000000000000010000000000000000000,
233
LMR2            = 66'b000000000000000000000000000000000000000000000100000000000000000000,
234
INIT0           = 66'b000000000000000000000000000000000000000000001000000000000000000000,
235
INIT            = 66'b000000000000000000000000000000000000000000010000000000000000000000,
236
INIT_W          = 66'b000000000000000000000000000000000000000000100000000000000000000000,
237
INIT_REFR1      = 66'b000000000000000000000000000000000000000001000000000000000000000000,
238
INIT_REFR1_W    = 66'b000000000000000000000000000000000000000010000000000000000000000000,
239
INIT_LMR        = 66'b000000000000000000000000000000000000000100000000000000000000000000,
240
SUSP1           = 66'b000000000000000000000000000000000000001000000000000000000000000000,
241
SUSP2           = 66'b000000000000000000000000000000000000010000000000000000000000000000,
242
SUSP3           = 66'b000000000000000000000000000000000000100000000000000000000000000000,
243
SUSP4           = 66'b000000000000000000000000000000000001000000000000000000000000000000,
244
RESUME1         = 66'b000000000000000000000000000000000010000000000000000000000000000000,
245
RESUME2         = 66'b000000000000000000000000000000000100000000000000000000000000000000,
246
BG0             = 66'b000000000000000000000000000000001000000000000000000000000000000000,
247
BG1             = 66'b000000000000000000000000000000010000000000000000000000000000000000,
248
BG2             = 66'b000000000000000000000000000000100000000000000000000000000000000000,
249
ACS_RD          = 66'b000000000000000000000000000001000000000000000000000000000000000000,
250
ACS_RD1         = 66'b000000000000000000000000000010000000000000000000000000000000000000,
251
ACS_RD2A        = 66'b000000000000000000000000000100000000000000000000000000000000000000,
252
ACS_RD2         = 66'b000000000000000000000000001000000000000000000000000000000000000000,
253
ACS_RD3         = 66'b000000000000000000000000010000000000000000000000000000000000000000,
254
ACS_RD_8_1      = 66'b000000000000000000000000100000000000000000000000000000000000000000,
255
ACS_RD_8_2      = 66'b000000000000000000000001000000000000000000000000000000000000000000,
256
ACS_RD_8_3      = 66'b000000000000000000000010000000000000000000000000000000000000000000,
257
ACS_RD_8_4      = 66'b000000000000000000000100000000000000000000000000000000000000000000,
258
ACS_RD_8_5      = 66'b000000000000000000001000000000000000000000000000000000000000000000,
259
ACS_RD_8_6      = 66'b000000000000000000010000000000000000000000000000000000000000000000,
260
ACS_WR          = 66'b000000000000000000100000000000000000000000000000000000000000000000,
261
ACS_WR1         = 66'b000000000000000001000000000000000000000000000000000000000000000000,
262
ACS_WR2         = 66'b000000000000000010000000000000000000000000000000000000000000000000,
263
ACS_WR3         = 66'b000000000000000100000000000000000000000000000000000000000000000000,
264
ACS_WR4         = 66'b000000000000001000000000000000000000000000000000000000000000000000,
265
SRAM_RD         = 66'b000000000000010000000000000000000000000000000000000000000000000000,
266
SRAM_RD0        = 66'b000000000000100000000000000000000000000000000000000000000000000000,
267
SRAM_RD1        = 66'b000000000001000000000000000000000000000000000000000000000000000000,
268
SRAM_RD2        = 66'b000000000010000000000000000000000000000000000000000000000000000000,
269
SRAM_RD3        = 66'b000000000100000000000000000000000000000000000000000000000000000000,
270
SRAM_RD4        = 66'b000000001000000000000000000000000000000000000000000000000000000000,
271
SRAM_WR         = 66'b000000010000000000000000000000000000000000000000000000000000000000,
272
SRAM_WR0        = 66'b000000100000000000000000000000000000000000000000000000000000000000,
273
SCS_RD          = 66'b000001000000000000000000000000000000000000000000000000000000000000,
274
SCS_RD1         = 66'b000010000000000000000000000000000000000000000000000000000000000000,
275
SCS_RD2         = 66'b000100000000000000000000000000000000000000000000000000000000000000,
276
SCS_WR          = 66'b001000000000000000000000000000000000000000000000000000000000000000,
277
SCS_WR1         = 66'b010000000000000000000000000000000000000000000000000000000000000000,
278
SCS_ERR         = 66'b100000000000000000000000000000000000000000000000000000000000000000;
279
 
280
////////////////////////////////////////////////////////////////////
281
//
282
// Local Registers & Wires
283
//
284
 
285
reg     [65:0]   /* synopsys enum state */ state, next_state;
286
// synopsys state_vector state
287
 
288
reg             mc_bg;
289
 
290
wire    [2:0]    mem_type;
291
wire    [1:0]    bus_width;
292
wire            kro;
293
 
294
wire            cs_a;
295
reg     [3:0]    cmd;
296
 
297
reg             mem_ack;
298
wire            mem_ack_s;
299
reg             mem_ack_d;
300
reg             err_d;
301
reg             err;
302
reg             cmd_a10;
303
reg             lmr_ack;
304
reg             row_sel;
305
reg             oe_;
306
reg             oe_d;
307
reg             data_oe;
308
reg             data_oe_d;
309
reg             cke_d;
310
reg             cke_;
311
reg             init_ack;
312
reg             dv;
313
reg             rfr_ack;
314
reg             mc_adsc;
315
reg             mc_adv;
316
 
317
reg             bank_set;
318
reg             bank_clr;
319
reg             bank_clr_all;
320
 
321
reg             wr_set, wr_clr;
322
reg             wr_cycle;
323
 
324
reg             cmd_asserted;
325
reg             cmd_asserted2;
326
 
327
reg     [10:0]   burst_val;
328
reg     [10:0]   burst_cnt;
329
wire            burst_act;
330
reg             burst_act_rd;
331
wire            single_write;
332
 
333
reg             cs_le;
334
 
335
reg             susp_req_r;
336
reg             resume_req_r;
337
reg             suspended;
338
reg             suspended_d;
339
reg             susp_sel;
340
 
341
reg     [3:0]    cmd_del;
342
reg     [3:0]    cmd_r;
343
reg             data_oe_r;
344
reg             data_oe_r2;
345
reg             cke_r;
346
reg             cke_rd;
347
reg             cke_o_del;
348
reg             cke_o_r1;
349
reg             cke_o_r2;
350
reg             wb_cycle_set, wb_cycle;
351
reg     [3:0]    ack_cnt;
352
wire            ack_cnt_is_0;
353
reg             cnt, cnt_next;
354
reg     [7:0]    timer;
355
reg             tmr_ld_trp, tmr_ld_trcd, tmr_ld_tcl, tmr_ld_trfc;
356
reg             tmr_ld_twr, tmr_ld_txsr;
357
reg             tmr2_ld_tscsto;
358
reg             tmr_ld_trdv;
359
reg             tmr_ld_trdz;
360
reg             tmr_ld_twr2;
361
wire            timer_is_zero;
362
reg             tmr_done;
363
reg             tmr2_ld_trdv, tmr2_ld_trdz;
364
reg             tmr2_ld_twpw, tmr2_ld_twd, tmr2_ld_twwd;
365
reg             tmr2_ld_tsrdv;
366
reg     [8:0]    timer2;
367
reg             tmr2_done;
368
wire            timer2_is_zero;
369
reg     [3:0]    ir_cnt;
370
reg             ir_cnt_ld;
371
reg             ir_cnt_dec;
372
reg             ir_cnt_done;
373
reg             rfr_ack_r;
374
reg             burst_cnt_ld;
375
reg             burst_fp;
376
reg             wb_wait_r, wb_wait_r2;
377
reg             lookup_ready1, lookup_ready2;
378
reg             burst_cnt_ld_4;
379
reg             dv_r;
380
reg             mc_adv_r1, mc_adv_r;
381
 
382
reg             next_adr;
383
reg             pack_le0, pack_le1, pack_le2;
384
reg             pack_le0_d, pack_le1_d, pack_le2_d;
385
wire            bw8, bw16;
386
 
387
reg             mc_c_oe_d;
388
reg             mc_c_oe;
389
 
390
////////////////////////////////////////////////////////////////////
391
//
392
// Aliases
393
//
394
assign mem_type  = csc[3:1];
395
assign bus_width = csc[5:4];
396
assign kro       = csc[10];
397
assign single_write = tms[9];
398
 
399
////////////////////////////////////////////////////////////////////
400
//
401
// Misc Logic
402
//
403
 
404
// Control Signals Output Enable
405
always @(posedge clk or negedge rst)
406
        if(!rst)        mc_c_oe <= #1 1'b0;
407
        else            mc_c_oe <= mc_c_oe_d;
408
 
409
always @(posedge clk)
410
        pack_le0 <= #1 pack_le0_d;
411
 
412
always @(posedge clk)
413
        pack_le1 <= #1 pack_le1_d;
414
 
415
always @(posedge clk)
416
        pack_le2 <= #1 pack_le2_d;
417
 
418
always @(posedge mc_clk)
419
        mc_adv_r1 <= #1 mc_adv;
420
 
421
always @(posedge mc_clk)
422
        mc_adv_r <= #1 mc_adv_r1;
423
 
424
// Bus Width decoder
425
assign bw8  = (bus_width == `BW_8);
426
assign bw16 = (bus_width == `BW_16);
427
 
428
assign  cs_a = |cs;     // Any Chip Select
429
 
430
// Memory to Wishbone Ack
431
always @(posedge clk)
432
        mem_ack <= #1 (mem_ack_d | mem_ack_s) & (wb_read_go | wb_write_go);
433
 
434
always @(posedge clk)
435
        err <= #1 err_d;
436
 
437
// SDRAM Command, either delayed (for writes) or straight through
438
always @(posedge clk)
439
        cmd_r <= #1 cmd;
440
 
441
always @(posedge clk)
442
        cmd_del <= #1 cmd_r;
443
 
444
assign {cs_en, ras_, cas_, we_} = wr_cycle ? cmd_del : cmd;
445
 
446
// Track Timing of Asserting a command
447
always @(posedge mc_clk)
448
        cmd_asserted <= #1 cmd[3];
449
 
450
always @(posedge mc_clk)
451
        cmd_asserted2 <= #1 cmd_asserted;
452
 
453
// Output Enable
454
always @(posedge clk)
455
        oe_ <= #1 ~oe_d;
456
 
457
// Memory Bus Data lines Output Enable
458
always @(posedge clk)
459
        data_oe_r <= #1 data_oe_d;
460
 
461
always @(posedge clk)
462
        data_oe_r2 <= #1 data_oe_r;
463
 
464
always @(posedge clk)
465
        data_oe <= #1 wr_cycle ? data_oe_r2 : data_oe_d;
466
 
467
// Clock Enable
468
always @(posedge clk)
469
        cke_r <= #1 cke_d;
470
 
471
always @(posedge clk)
472
        cke_ <= #1 cke_r & cke_rd;
473
 
474
// CKE output delay line to time DV for reads
475
always @(posedge clk)
476
        cke_o_r1 <= #1 cke_;
477
 
478
always @(posedge clk)
479
        cke_o_r2 <= #1 cke_o_r1;
480
 
481
always @(posedge clk)
482
        cke_o_del <= #1 cke_o_r2;
483
 
484
// Delayed version of the wb_wait input
485
always @(posedge clk)
486
        wb_wait_r2 <= #1 wb_wait;
487
 
488
always @(posedge clk)
489
        wb_wait_r <= #1 wb_wait_r2;
490
 
491
// Indicates when the row_same and bank_open lookups are done
492
always @(posedge clk)
493
        lookup_ready1 <= #1 cs_le;
494
 
495
always @(posedge clk)
496
        lookup_ready2 <= #1 lookup_ready1;
497
 
498
// Keep Track if it is a SDRAM write cycle
499
always @(posedge clk or negedge rst)
500
        if(!rst)        wr_cycle <= #1 1'b0;
501
        else
502
        if(wr_set)      wr_cycle <= #1 1'b1;
503
        else
504
        if(wr_clr)      wr_cycle <= #1 1'b0;
505
 
506
// Track when a cycle is *still* active
507
always @(posedge clk or negedge rst)
508
        if(!rst)                        wb_cycle <= #1 1'b0;
509
        else
510
        if(wb_cycle_set)                wb_cycle <= #1 1'b1;
511
        else
512
        if(!wb_cyc_i)                   wb_cycle <= #1 1'b0;
513
 
514
// Track ack's for read cycles 
515
always @(posedge clk or negedge rst)
516
        if(!rst)                                ack_cnt <= #1 4'h0;
517
        else
518
        if(!wb_read_go & !wb_write_go)          ack_cnt <= #1 4'h0;
519
        else
520
        if(dv & !mem_ack_s)                     ack_cnt <= #1 ack_cnt + 4'h1;
521
        else
522
        if(!dv & mem_ack_s)                     ack_cnt <= #1 ack_cnt - 4'h1;
523
 
524
assign ack_cnt_is_0 = (ack_cnt==4'h0);
525
 
526
assign mem_ack_s = (ack_cnt != 4'h0) & !wb_wait & !mem_ack & wb_read_go & !wb_we_i;
527
 
528
// Internal Cycle Tracker
529
always @(posedge clk)
530
        cnt <= #1 cnt_next;
531
 
532
// Suspend/resume Logic
533
always @(posedge clk)
534
        susp_req_r <= #1 susp_req;
535
 
536
always @(posedge clk)
537
        resume_req_r <= #1 resume_req;
538
 
539
always @(posedge clk)
540
        suspended <= #1 suspended_d;
541
 
542
always @(posedge clk)
543
        rfr_ack_r <= #1 rfr_ack;
544
 
545
////////////////////////////////////////////////////////////////////
546
//
547
// Timing Logic
548
//
549
 
550
always @(posedge clk)
551
        if(tmr2_ld_tscsto)      timer2 <= #1 tms[24:16];
552
        else
553
        if(tmr2_ld_tsrdv)       timer2 <= #1 9'd2;      // SSRAM RD->1st DATA VALID
554
        else
555
        if(tmr2_ld_twpw)        timer2 <= #1 { 5'h0, tms[15:12]};
556
        else
557
        if(tmr2_ld_twd)         timer2 <= #1 { 4'h0, tms[19:16],1'b0};
558
        else
559
        if(tmr2_ld_twwd)        timer2 <= #1 { 3'h0, tms[25:20]};
560
        else
561
        if(tmr2_ld_trdz)        timer2 <= #1 { 4'h0, tms[11:8], 1'b1};
562
        else
563
        if(tmr2_ld_trdv)        timer2 <= #1 { tms[7:0], 1'b1};
564
        else
565
        if(!timer2_is_zero)     timer2 <= #1 timer2 - 9'b1;
566
 
567
wire    twd_is_zero;
568
assign twd_is_zero =  tms[19:16] == 0;
569
 
570
assign timer2_is_zero = (timer2 == 9'h0);
571
 
572
always @(posedge clk)
573
        tmr2_done <= #1 timer2_is_zero & !tmr2_ld_trdv & !tmr2_ld_trdz &
574
                        !tmr2_ld_twpw & !tmr2_ld_twd & !tmr2_ld_twwd & !tmr2_ld_tscsto;
575
 
576
// SDRAM Memories timing tracker
577
always @(posedge mc_clk or negedge rst)
578
`ifdef POR_DELAY
579
        if(!rst)                timer <= #1 `POR_DELAY_VAL ;
580
        else
581
`endif
582
        if(tmr_ld_twr2)         timer <= #1 { 4'h0, tms[15:12] };
583
        else
584
        if(tmr_ld_trdz)         timer <= #1 { 4'h0, tms[11:8] };
585
        else
586
        if(tmr_ld_trdv)         timer <= #1 tms[7:0];
587
        else
588
        if(tmr_ld_twr)          timer <= #1 { 6'h0, tms[16:15]};
589
        else
590
        if(tmr_ld_trp)          timer <= #1 { 4'h0, tms[23:20]};
591
        else
592
        if(tmr_ld_trcd)         timer <= #1 { 5'h0, tms[19:17]};
593
        else
594
        if(tmr_ld_tcl)          timer <= #1 { 6'h0, tms[05:04]};
595
        else
596
        if(tmr_ld_trfc)         timer <= #1 { 4'h0, tms[27:24]};
597
        else
598
        if(tmr_ld_txsr)         timer <= #1 8'd7;
599
        else
600
        if(!timer_is_zero)      timer <= #1 timer - 8'b1;
601
 
602
assign timer_is_zero = (timer == 8'h0);
603
 
604
always @(posedge clk)
605
        tmr_done <= #1 timer_is_zero;
606
 
607
// Init Refresh Cycles Counter
608
always @(posedge clk)
609
        if(ir_cnt_ld)   ir_cnt <= #1 `INIT_RFRC_CNT;
610
        else
611
        if(ir_cnt_dec)  ir_cnt <= #1 ir_cnt - 4'b1;
612
 
613
always @(posedge clk)
614
        ir_cnt_done <= #1 (ir_cnt == 4'h0);
615
 
616
// Burst Counter
617
always @(tms or page_size)
618
        case(tms[2:0])           // synopsys full_case parallel_case
619
           3'h0: burst_val = 11'd1;
620
           3'h1: burst_val = 11'd2;
621
           3'h2: burst_val = 11'd4;
622
           3'h3: burst_val = 11'd8;
623
           3'h7: burst_val = page_size;
624
        endcase
625
 
626
always @(posedge clk)
627
        if(burst_cnt_ld_4)                      burst_cnt <= #1 11'h4;
628
        else
629
        if(burst_cnt_ld)                        burst_cnt <= #1 burst_val;
630
        else
631
        if(wr_cycle ? mem_ack_d : dv)           burst_cnt <= #1 burst_cnt - 11'h1;
632
 
633
always @(posedge clk)
634
        if(burst_cnt_ld)        burst_fp <= #1 (tms[2:0] == 3'h7);
635
 
636
assign burst_act = |burst_cnt & ( |tms[2:0] );
637
 
638
always @(posedge clk)
639
        burst_act_rd <= #1 |burst_cnt;
640
 
641
always @(posedge clk)
642
        dv_r <= #1 dv;
643
 
644
////////////////////////////////////////////////////////////////////
645
//
646
// Main State Machine
647
//
648
 
649
always @(posedge clk or negedge rst)
650
`ifdef POR_DELAY
651
        if(!rst)        state <= #1 POR;
652
`else
653
        if(!rst)        state <= #1 IDLE;
654
`endif
655
        else            state <= #1 next_state;
656
 
657
always @(state or cs_a or
658
        twd_is_zero or
659
        wb_first or wb_read_go or wb_write_go or wb_wait or mem_ack or wb_we_i or
660
        ack_cnt_is_0 or wb_wait_r or cnt or wb_cycle or
661
        mem_type or kro or lookup_ready1 or lookup_ready2 or row_same or
662
        bank_open or single_write or
663
        cmd_asserted or tmr_done or tmr2_done or ir_cnt_done or cmd_asserted2 or
664
        burst_act or burst_act_rd or burst_fp or cke_ or cke_r or cke_o_del or
665
        rfr_req or lmr_req or init_req or rfr_ack_r or susp_req_r or resume_req_r or
666
        mc_br or bw8 or bw16 or dv_r or mc_adv_r or mc_ack
667
        )
668
   begin
669
        next_state = state;     // Default keep current state
670
        cnt_next = 1'b0;
671
 
672
        cmd = `CMD_NOP;
673
        cmd_a10 = ~kro;
674
        oe_d = 1'b0;
675
        data_oe_d = 1'b0;
676
        cke_d = 1'b1;
677
        cke_rd = 1'b1;
678
        mc_adsc = 1'b0;
679
        mc_adv = 1'b0;
680
 
681
        bank_set = 1'b0;
682
        bank_clr = 1'b0;
683
        bank_clr_all = 1'b0;
684
 
685
        burst_cnt_ld = 1'b0;
686
        burst_cnt_ld_4 = 1'b0;
687
        tmr_ld_trp = 1'b0;
688
        tmr_ld_trcd = 1'b0;
689
        tmr_ld_tcl = 1'b0;
690
        tmr_ld_trfc = 1'b0;
691
        tmr_ld_twr = 1'b0;
692
        tmr_ld_txsr = 1'b0;
693
        tmr_ld_trdv = 1'b0;
694
        tmr_ld_trdz = 1'b0;
695
        tmr_ld_twr2 = 1'b0;
696
 
697
        tmr2_ld_trdv = 1'b0;
698
        tmr2_ld_trdz = 1'b0;
699
 
700
        tmr2_ld_twpw = 1'b0;
701
        tmr2_ld_twd = 1'b0;
702
        tmr2_ld_twwd = 1'b0;
703
        tmr2_ld_tsrdv = 1'b0;
704
        tmr2_ld_tscsto = 1'b0;
705
 
706
        mem_ack_d = 1'b0;
707
        err_d = 1'b0;
708
        rfr_ack = 1'b0;
709
        lmr_ack = 1'b0;
710
        init_ack = 1'b0;
711
 
712
        ir_cnt_dec = 1'b0;
713
        ir_cnt_ld = 1'b0;
714
 
715
        row_sel = 1'b0;
716
        cs_le = 1'b0;
717
        wr_clr = 1'b0;
718
        wr_set = 1'b0;
719
        wb_cycle_set = 1'b0;
720
        dv = 1'b0;
721
 
722
        suspended_d = 1'b0;
723
        susp_sel = 1'b0;
724
        mc_bg = 1'b0;
725
 
726
        next_adr = 1'b0;
727
        pack_le0_d = 1'b0;
728
        pack_le1_d = 1'b0;
729
        pack_le2_d = 1'b0;
730
 
731
        mc_c_oe_d = 1'b1;
732
 
733
        case(state)             // synopsys full_case parallel_case
734
`ifdef POR_DELAY
735
           POR:
736
              begin
737
                if(tmr_done)    next_state = IDLE;
738
              end
739
`endif
740
           IDLE:
741
              begin
742
                cs_le = wb_first | lmr_req;
743
                burst_cnt_ld = 1'b1;
744
                wr_clr = 1'b1;
745
 
746
                if(rfr_req)
747
                   begin
748
                        rfr_ack = 1'b1;
749
                        next_state = PRECHARGE;
750
                   end
751
                else
752
                if(init_req)
753
                   begin
754
                        cs_le = 1'b1;
755
                        next_state = INIT0;
756
                   end
757
                else
758
                if(lmr_req & lookup_ready2)
759
                   begin
760
                        lmr_ack = 1'b1;
761
                        cs_le = 1'b1;
762
                        next_state = LMR0;
763
                   end
764
                else
765
                if(susp_req_r)
766
                   begin
767
                        cs_le = 1'b1;
768
                        susp_sel = 1'b1;
769
                        next_state = SUSP1;
770
                   end
771
                else
772
                if(cs_a & (wb_read_go | wb_write_go) & (lookup_ready1 | wb_cycle) )
773
                  begin
774
                   wb_cycle_set = 1'b1;
775
                   case(mem_type)               // synopsys full_case parallel_case
776
                     `MEM_TYPE_SDRAM:                   // SDRAM
777
                        if((lookup_ready2 | wb_cycle) & !wb_wait)
778
                           begin
779
                                if(wb_write_go  | wb_we_i)      wr_set = 1'b1;
780
                                if(kro & bank_open & row_same)  next_state = SD_RD_WR;
781
                                else
782
                                if(kro & bank_open)             next_state = PRECHARGE;
783
                                else                            next_state = ACTIVATE;
784
                           end
785
                     `MEM_TYPE_ACS:
786
                        begin                           // Async Chip Select
787
                                if(!wb_wait)
788
                                   begin
789
                                        cs_le = 1'b1;
790
                                        if(wb_write_go)
791
                                           begin
792
                                                                data_oe_d = 1'b1;
793
                                                                next_state = ACS_WR;
794
                                           end
795
                                        else                    next_state = ACS_RD;
796
                                   end
797
                        end
798
                     `MEM_TYPE_SCS:
799
                        begin                           // Sync Chip Select
800
                                if(!wb_wait)
801
                                   begin
802
                                        tmr2_ld_tscsto = 1'b1;
803
                                        cs_le = 1'b1;
804
                                        if(wb_write_go)
805
                                           begin
806
                                                cmd = `CMD_XWR;
807
                                                data_oe_d = 1'b1;
808
                                                tmr_ld_twr2 = 1'b1;
809
                                                next_state = SCS_WR;
810
                                           end
811
                                        else
812
                                           begin
813
                                                cmd = `CMD_XRD;
814
                                                oe_d = 1'b1;
815
                                                tmr_ld_trdv = 1'b1;
816
                                                next_state = SCS_RD;
817
                                           end
818
                                   end
819
                        end
820
                     `MEM_TYPE_SRAM:
821
                        begin           // SRAM
822
                                if(!wb_wait)
823
                                   begin
824
                                        cs_le = 1'b1;
825
                                        if(wb_write_go)
826
                                           begin
827
                                                data_oe_d = 1'b1;
828
                                                mem_ack_d = 1'b1;
829
                                                next_state = SRAM_WR;
830
                                           end
831
                                        else
832
                                           begin
833
                                                cmd = `CMD_XRD;
834
                                                oe_d = 1'b1;
835
                                                mc_adsc = 1'b1;
836
                                                tmr2_ld_tsrdv = 1'b1;
837
                                                next_state = SRAM_RD;
838
                                           end
839
                                   end
840
                        end
841
                   endcase
842
                  end
843
                else
844
                if(mc_br)
845
                   begin
846
                        if(!cmd_asserted2)      next_state = BG0;
847
                   end
848
              end
849
 
850
           IDLE_T:
851
              begin
852
                if(tmr_done)    next_state = IDLE;
853
              end
854
 
855
           IDLE_T2:
856
              begin
857
                if(tmr2_done)   next_state = IDLE;
858
              end
859
 
860
                /////////////////////////////////////////
861
                // SCS STATES ....
862
                /////////////////////////////////////////
863
           SCS_RD:
864
              begin
865
                cmd = `CMD_XRD;
866
                oe_d = 1'b1;
867
                tmr_ld_trdv = 1'b1;
868
                if(mc_ack)      next_state = SCS_RD1;
869
                else
870
                if(tmr2_done)   next_state = SCS_ERR;
871
              end
872
 
873
           SCS_RD1:
874
              begin
875
                cmd = `CMD_XRD;
876
                oe_d = 1'b1;
877
                if(tmr_done)
878
                   begin
879
                        mem_ack_d = 1'b1;
880
                        tmr_ld_trdz = 1'b1;
881
                        next_state = SCS_RD2;
882
                   end
883
              end
884
 
885
           SCS_RD2:
886
              begin
887
                tmr_ld_trdz = 1'b1;
888
                next_state = IDLE_T;
889
              end
890
 
891
           SCS_WR:
892
              begin
893
                tmr_ld_twr2 = 1'b1;
894
                cmd = `CMD_XWR;
895
                data_oe_d = 1'b1;
896
                if(mc_ack)      next_state = SCS_WR1;
897
                else
898
                if(tmr2_done)   next_state = SCS_ERR;
899
              end
900
 
901
           SCS_WR1:
902
              begin
903
                data_oe_d = 1'b1;
904
                if(tmr_done)
905
                   begin
906
                        mem_ack_d = 1'b1;
907
                        next_state = IDLE_T;
908
                   end
909
                else    cmd = `CMD_XWR;
910
              end
911
 
912
           SCS_ERR:
913
              begin
914
                mem_ack_d = 1'b1;
915
                err_d = 1'b1;
916
                next_state = IDLE_T2;
917
              end
918
 
919
                /////////////////////////////////////////
920
                // SSRAM STATES ....
921
                /////////////////////////////////////////
922
 
923
           SRAM_RD:
924
              begin
925
                cmd = `CMD_XRD;
926
                oe_d = 1'b1;
927
                mc_adsc = 1'b1;
928
                tmr2_ld_tsrdv = 1'b1;
929
                burst_cnt_ld_4 = 1'b1;
930
                if(cmd_asserted)        next_state = SRAM_RD0;
931
              end
932
 
933
           SRAM_RD0:
934
              begin
935
                mc_adv = 1'b1;
936
                oe_d = 1'b1;
937
                if(tmr2_done)
938
                   begin
939
                        mc_adv = !wb_wait;
940
                        next_state = SRAM_RD1;
941
                   end
942
              end
943
 
944
           SRAM_RD1:
945
              begin
946
                if(mc_adv_r)    dv = ~dv_r;
947
                mc_adv = !wb_wait;
948
 
949
                if(!burst_act | !wb_read_go)    next_state = SRAM_RD2;
950
                else            oe_d = 1'b1;
951
              end
952
 
953
           SRAM_RD2:
954
              begin
955
                if(ack_cnt_is_0 & wb_read_go)   next_state = SRAM_RD3;
956
                else
957
                if(!wb_read_go)
958
                   begin
959
                        mc_adsc = 1'b1;
960
                        next_state = SRAM_RD4;
961
                   end
962
              end
963
 
964
           SRAM_RD3:
965
              begin
966
                if(!wb_read_go)
967
                   begin
968
                        mc_adsc = 1'b1;
969
                        next_state = SRAM_RD4;
970
                   end
971
                else
972
                if(!wb_wait)
973
                   begin
974
                        cs_le = 1'b1;
975
                        next_state = SRAM_RD;
976
                   end
977
              end
978
 
979
           SRAM_RD4:    // DESELECT
980
              begin
981
                mc_adsc = 1'b1;
982
                next_state = IDLE;
983
              end
984
 
985
           SRAM_WR: // 80
986
              begin
987
                cmd = `CMD_XWR;
988
                mc_adsc = 1'b1;
989
                data_oe_d = 1'b1;
990
                if(cmd_asserted)
991
                   begin
992
                        if(wb_wait)             next_state = SRAM_WR0;
993
                        else
994
                        if(!wb_write_go)
995
                           begin
996
                                mc_adsc = 1'b1;
997
                                next_state = SRAM_RD4;
998
                           end
999
                        else
1000
                           begin
1001
                                data_oe_d = 1'b1;
1002
                                mem_ack_d = ~mem_ack;
1003
                           end
1004
                   end
1005
              end
1006
 
1007
           SRAM_WR0: // 81
1008
              begin
1009
                if(wb_wait)             next_state = SRAM_WR0;
1010
                else
1011
                if(!wb_write_go)
1012
                   begin
1013
                        mc_adsc = 1'b1;
1014
                        next_state = SRAM_RD4;
1015
                   end
1016
                else
1017
                   begin
1018
                        data_oe_d = 1'b1;
1019
                        //mem_ack_d = ~mem_ack;
1020
                        next_state = SRAM_WR;
1021
                   end
1022
 
1023
                //data_oe_d = 1'b1;
1024
                //if(!wb_wait)  next_state = SRAM_WR;
1025
              end
1026
 
1027
                /////////////////////////////////////////
1028
                // Async Devices STATES ....
1029
                /////////////////////////////////////////
1030
           ACS_RD:
1031
              begin
1032
                cmd = `CMD_XRD;
1033
                oe_d = 1'b1;
1034
                tmr2_ld_trdv = 1'b1;
1035
                next_state = ACS_RD1;
1036
              end
1037
 
1038
           ACS_RD1:
1039
              begin     // 32 bit, 8 bit - first; 16 bit - first
1040
                cmd = `CMD_XRD;
1041
                oe_d = 1'b1;
1042
                if(tmr2_done)
1043
                   begin
1044
                        if(bw8 | bw16)          next_adr = 1'b1;
1045
                        if(bw8)                 next_state = ACS_RD_8_1;
1046
                        else
1047
                        if(bw16)                next_state = ACS_RD_8_5;
1048
                        else                    next_state = ACS_RD2A;
1049
                        //else                  next_state = ACS_RD3;
1050
                   end
1051
              end
1052
 
1053
           ACS_RD_8_1:
1054
              begin     // 8 bit 2nd byte
1055
                pack_le0_d = 1'b1;
1056
                cmd = `CMD_XRD;
1057
                oe_d = 1'b1;
1058
                tmr2_ld_trdv = 1'b1;
1059
                next_state = ACS_RD_8_2;
1060
              end
1061
 
1062
           ACS_RD_8_2:
1063
              begin
1064
                cmd = `CMD_XRD;
1065
                oe_d = 1'b1;
1066
                if(tmr2_done)
1067
                   begin
1068
                        next_adr = 1'b1;
1069
                        next_state = ACS_RD_8_3;
1070
                   end
1071
              end
1072
 
1073
           ACS_RD_8_3:
1074
              begin     // 8 bit 3rd byte
1075
                pack_le1_d = 1'b1;
1076
                cmd = `CMD_XRD;
1077
                oe_d = 1'b1;
1078
                tmr2_ld_trdv = 1'b1;
1079
                next_state = ACS_RD_8_4;
1080
              end
1081
 
1082
           ACS_RD_8_4:
1083
              begin
1084
                cmd = `CMD_XRD;
1085
                oe_d = 1'b1;
1086
                if(tmr2_done)
1087
                   begin
1088
                        next_adr = 1'b1;
1089
                        next_state = ACS_RD_8_5;
1090
                   end
1091
              end
1092
 
1093
           ACS_RD_8_5:
1094
              begin     // 8 bit 4th byte; 16 bit 2nd word
1095
                if(bw8)                 pack_le2_d = 1'b1;
1096
                if(bw16)                pack_le0_d = 1'b1;
1097
                cmd = `CMD_XRD;
1098
                oe_d = 1'b1;
1099
                tmr2_ld_trdv = 1'b1;
1100
                next_state = ACS_RD_8_6;
1101
              end
1102
 
1103
           ACS_RD_8_6:
1104
              begin
1105
                cmd = `CMD_XRD;
1106
                oe_d = 1'b1;
1107
                if(tmr2_done)
1108
                   begin
1109
                        next_state = ACS_RD2;
1110
                   end
1111
              end
1112
 
1113
           ACS_RD2A:
1114
              begin
1115
                oe_d = 1'b1;
1116
                cmd = `CMD_XRD;
1117
                next_state = ACS_RD2;
1118
              end
1119
 
1120
           ACS_RD2:
1121
              begin
1122
                cmd = `CMD_XRD;
1123
                next_state = ACS_RD3;
1124
              end
1125
 
1126
           ACS_RD3:
1127
              begin
1128
                mem_ack_d = 1'b1;
1129
                tmr2_ld_trdz = 1'b1;
1130
                next_state = IDLE_T2;
1131
              end
1132
 
1133
           ACS_WR:
1134
              begin
1135
                tmr2_ld_twpw = 1'b1;
1136
                cmd = `CMD_XWR;
1137
                data_oe_d = 1'b1;
1138
                next_state = ACS_WR1;
1139
              end
1140
 
1141
           ACS_WR1:
1142
              begin
1143
                if(!cmd_asserted)       tmr2_ld_twpw = 1'b1;
1144
                cmd = `CMD_XWR;
1145
                data_oe_d = 1'b1;
1146
                if(tmr2_done)
1147
                   begin
1148
                        tmr2_ld_twd = 1'b1;
1149
                        next_state = ACS_WR2;
1150
                   end
1151
              end
1152
 
1153
           ACS_WR2:
1154
              begin
1155
                if(twd_is_zero) next_state = ACS_WR3;
1156
                else
1157
                   begin
1158
                        cmd = `CMD_XRD;
1159
                        data_oe_d = 1'b1;
1160
                        next_state = ACS_WR3;
1161
                   end
1162
              end
1163
 
1164
           ACS_WR3:
1165
              begin
1166
                if(tmr2_done)   next_state = ACS_WR4;
1167
                else            cmd = `CMD_XRD;
1168
              end
1169
 
1170
           ACS_WR4:
1171
              begin
1172
                tmr2_ld_twwd = 1'b1;
1173
                mem_ack_d = 1'b1;
1174
                next_state = IDLE_T2;
1175
              end
1176
 
1177
                /////////////////////////////////////////
1178
                // SDRAM STATES ....
1179
                /////////////////////////////////////////
1180
 
1181
           PRECHARGE:
1182
              begin
1183
                cmd = `CMD_PC;
1184
                if(rfr_ack_r)
1185
                   begin
1186
                        rfr_ack = 1'b1;
1187
                        cmd_a10 = `ALL_BANKS;
1188
                        bank_clr_all = 1'b1;
1189
                   end
1190
                else
1191
                   begin
1192
                        bank_clr = 1'b1;
1193
                        cmd_a10 = `SINGLE_BANK;
1194
                   end
1195
                tmr_ld_trp = 1'b1;
1196
                if(cmd_asserted)        next_state = PRECHARGE_W;
1197
              end
1198
 
1199
           PRECHARGE_W:
1200
              begin
1201
                rfr_ack = rfr_ack_r;
1202
                if(tmr_done)
1203
                   begin
1204
                        if(rfr_ack_r)   next_state = REFR;
1205
                        else            next_state = ACTIVATE;
1206
                   end
1207
              end
1208
 
1209
           ACTIVATE:    // 4
1210
              begin
1211
                if(!wb_wait_r)
1212
                   begin
1213
                        row_sel = 1'b1;
1214
                        tmr_ld_trcd = 1'b1;
1215
                        cmd = `CMD_ACT;
1216
                   end
1217
                if(cmd_asserted)        next_state = ACTIVATE_W;
1218
              end
1219
 
1220
           ACTIVATE_W:
1221
              begin
1222
                row_sel = 1'b1;
1223
                if(wb_write_go | wb_we_i)       wr_set = 1'b1;
1224
 
1225
                if(kro)         bank_set = 1'b1;
1226
 
1227
                if(tmr_done)
1228
                   begin
1229
                        if(wb_write_go)
1230
                           begin
1231
                                mem_ack_d = !mem_ack;
1232
                                next_state = SD_WR;
1233
                           end
1234
                        else
1235
                        if(!wb_wait_r)  next_state = SD_RD;
1236
                   end
1237
              end
1238
 
1239
           SD_RD_WR:    // 6
1240
              begin
1241
                if(wb_write_go | wb_we_i)       wr_set = 1'b1;
1242
 
1243
                if(wb_write_go & !wb_wait)
1244
                   begin        // Write
1245
                        data_oe_d = 1'b1;
1246
                        mem_ack_d = !mem_ack;
1247
                        next_state = SD_WR;
1248
                   end
1249
                else
1250
                if(!wb_wait)
1251
                   begin        // Read
1252
                        if(kro)
1253
                           begin
1254
                                if(!wb_wait_r)  next_state = SD_RD;
1255
                           end
1256
                        else    next_state = SD_RD;
1257
                   end
1258
              end
1259
 
1260
           SD_WR:       // Write Command A
1261
              begin     // Does the first single write
1262
                data_oe_d = 1'b1;
1263
                tmr_ld_twr = 1'b1;
1264
                cnt_next = ~cnt;
1265
                cmd = `CMD_WR;
1266
                cmd_a10 = ~kro;
1267
 
1268
                if(!cnt & wb_cycle & burst_act) cke_d = !wb_wait;
1269
                else                            cke_d = cke_r;
1270
 
1271
                if(cmd_asserted)
1272
                   begin
1273
                        mem_ack_d = !mem_ack & wb_write_go & !wb_wait & wb_cycle & burst_act;
1274
 
1275
                        if(wb_cycle & !burst_act)       next_state = IDLE_T;
1276
                        else
1277
                        if(wb_cycle)                    next_state = SD_WR_W;
1278
                        else
1279
                        if(burst_act & !single_write)   next_state = BT;
1280
                        else                            next_state = IDLE_T;
1281
                   end
1282
 
1283
              end
1284
 
1285
           SD_WR_W:     // B
1286
              begin     // Does additional Writes or Times them
1287
                tmr_ld_twr = 1'b1;
1288
                cnt_next = ~cnt;
1289
 
1290
                if(single_write & wb_cycle)
1291
                   begin
1292
                        cmd = `CMD_WR;
1293
                        if(burst_act)   cmd_a10 = 1'b0;
1294
                        else            cmd_a10 = ~kro;
1295
                   end
1296
 
1297
                data_oe_d = 1'b1;
1298
                mem_ack_d = !mem_ack & wb_write_go & !wb_wait & wb_cycle & burst_act;
1299
 
1300
                if(!cnt)        cke_d = ~wb_wait;
1301
                else            cke_d = cke_r;
1302
 
1303
                if(cke_r)
1304
                   begin
1305
                        if(single_write & !wb_cycle)            next_state = IDLE_T;
1306
                        else
1307
                        if(burst_act & !single_write & !wb_write_go )
1308
                                                                next_state = BT;
1309
                        else
1310
                        if(!burst_act)                          next_state = IDLE_T;
1311
                        else
1312
                        if(!wb_write_go & wb_read_go)           next_state = IDLE_T;    // Added for WMR
1313
                   end
1314
              end
1315
 
1316
           SD_RD:       // Read Command 7
1317
              begin
1318
                cmd = `CMD_RD;
1319
                if(burst_fp)    cmd_a10 = 1'b0;
1320
                else            cmd_a10 = ~kro;
1321
                tmr_ld_tcl = 1'b1;
1322
                if(cmd_asserted)                        next_state = SD_RD_W;
1323
              end
1324
 
1325
           SD_RD_W: // 8
1326
              begin
1327
                if(tmr_done)                            next_state = SD_RD_LOOP;
1328
              end
1329
 
1330
           SD_RD_LOOP: // 9
1331
              begin
1332
 
1333
                cnt_next = ~cnt;
1334
 
1335
                if(cnt & !(burst_act & !wb_cycle) & burst_act )         cke_rd = !wb_wait;
1336
                else                                                    cke_rd = cke_;
1337
 
1338
                if(wb_cycle & !cnt & burst_act_rd & cke_o_del)  dv = 1'b1;
1339
 
1340
                if(wb_cycle & wb_we_i)                  next_state = BT;
1341
                else
1342
                if(burst_act & !wb_cycle)               next_state = BT;
1343
                else
1344
                if(!burst_act)                          next_state = SD_RD_W2;
1345
              end
1346
 
1347
           SD_RD_W2: //32
1348
              begin
1349
                if(wb_cycle & wb_we_i)                  next_state = IDLE;
1350
                else
1351
                if(!wb_cycle | ack_cnt_is_0)            next_state = IDLE;
1352
              end
1353
 
1354
           BT:          // Burst Terminate  C
1355
              begin
1356
                cmd = `CMD_BT;
1357
                tmr_ld_trp = 1'b1;
1358
                if(cmd_asserted)                        next_state = BT_W;
1359
              end
1360
 
1361
           BT_W:        // D
1362
              begin
1363
                if(kro)                                 next_state = IDLE;
1364
                else
1365
                if(tmr_done & (!burst_fp | kro))        next_state = IDLE;
1366
                else
1367
                if(tmr_done & burst_fp & ~kro)  // Must PRECHARGE Full Page Bursts
1368
                   begin
1369
                        bank_clr = 1'b1;
1370
                        cmd = `CMD_PC;
1371
                        cmd_a10 = `SINGLE_BANK;
1372
                        tmr_ld_trp = 1'b1;
1373
                        if(cmd_asserted)                next_state = IDLE_T;
1374
                   end
1375
              end
1376
 
1377
           REFR:        // Refresh Cycle
1378
              begin
1379
                cmd = `CMD_ARFR;
1380
                tmr_ld_trfc = 1'b1;
1381
                rfr_ack = 1'b1;
1382
                if(cmd_asserted)                next_state = IDLE_T;
1383
              end
1384
 
1385
           LMR0:
1386
              begin
1387
                lmr_ack = 1'b1;
1388
                cmd = `CMD_PC;
1389
                cmd_a10 = `ALL_BANKS;
1390
                bank_clr_all = 1'b1;
1391
                tmr_ld_trp = 1'b1;
1392
                if(cmd_asserted)                next_state = LMR1;
1393
              end
1394
 
1395
           LMR1:
1396
              begin
1397
                lmr_ack = 1'b1;
1398
                if(tmr_done)                    next_state = LMR2;
1399
              end
1400
 
1401
           LMR2:
1402
              begin
1403
                bank_clr_all = 1'b1;
1404
                cmd = `CMD_LMR;
1405
                tmr_ld_trfc = 1'b1;
1406
                lmr_ack = 1'b1;
1407
                if(cmd_asserted)                next_state = IDLE_T;
1408
              end
1409
 
1410
           INIT0:
1411
              begin
1412
                cs_le = 1'b1;
1413
                next_state = INIT;
1414
              end
1415
 
1416
           INIT:        // Initialize SDRAMS
1417
              begin     // PRECHARGE
1418
                init_ack = 1'b1;
1419
                cmd = `CMD_PC;
1420
                cmd_a10 = `ALL_BANKS;
1421
                bank_clr_all = 1'b1;
1422
                tmr_ld_trp = 1'b1;
1423
                ir_cnt_ld = 1'b1;
1424
                if(cmd_asserted)                next_state = INIT_W;
1425
              end
1426
 
1427
           INIT_W:
1428
              begin
1429
                init_ack = 1'b1;
1430
                if(tmr_done)                    next_state = INIT_REFR1;
1431
              end
1432
 
1433
           INIT_REFR1:  // Init Refresh Cycle 1
1434
              begin
1435
                init_ack = 1'b1;
1436
                cmd = `CMD_ARFR;
1437
                tmr_ld_trfc = 1'b1;
1438
                if(cmd_asserted)
1439
                   begin
1440
                        ir_cnt_dec = 1'b1;
1441
                        next_state = INIT_REFR1_W;
1442
                   end
1443
              end
1444
 
1445
           INIT_REFR1_W:        // 21
1446
              begin
1447
                init_ack = 1'b1;
1448
                if(tmr_done)
1449
                   begin
1450
                        if(ir_cnt_done)         next_state = INIT_LMR;
1451
                        else                    next_state = INIT_REFR1;
1452
                   end
1453
              end
1454
 
1455
           INIT_LMR:
1456
              begin
1457
                init_ack = 1'b1;
1458
                cmd = `CMD_LMR;
1459
                bank_clr_all = 1'b1;
1460
                tmr_ld_trfc = 1'b1;
1461
                if(cmd_asserted)                next_state = IDLE_T;
1462
              end
1463
 
1464
                /////////////////////////////////////////
1465
                // Bus Arbitration STATES ....
1466
                /////////////////////////////////////////
1467
           BG0:
1468
              begin     // Bus Grant
1469
                mc_bg = 1'b1;
1470
                mc_c_oe_d = 1'b0;
1471
                next_state = BG1;
1472
              end
1473
           BG1:
1474
              begin     // Bus Grant
1475
                mc_bg = 1'b1;
1476
                cs_le = 1'b1;
1477
                mc_c_oe_d = 1'b0;
1478
                next_state = BG2;
1479
              end
1480
           BG2:
1481
              begin     // Bus Grant
1482
                mc_bg = !wb_read_go & !wb_write_go &
1483
                        !rfr_req & !init_req & !lmr_req &
1484
                        !susp_req_r;
1485
                if(!mc_br)      next_state = IDLE;
1486
                else            mc_c_oe_d = 1'b0;
1487
              end
1488
 
1489
                /////////////////////////////////////////
1490
                // SUSPEND/RESUME STATES ....
1491
                /////////////////////////////////////////
1492
           SUSP1:
1493
              begin             // Precharge All
1494
                susp_sel = 1'b1;
1495
                cmd = `CMD_PC;
1496
                cmd_a10 = `ALL_BANKS;
1497
                bank_clr_all = 1'b1;
1498
                tmr_ld_trp = 1'b1;
1499
                if(cmd_asserted)        next_state = SUSP2;
1500
              end
1501
 
1502
           SUSP2:
1503
              begin
1504
                susp_sel = 1'b1;
1505
                if(tmr_done)    next_state = SUSP3;
1506
              end
1507
 
1508
           SUSP3:
1509
              begin             // Enter Self refresh Mode
1510
                cke_d = 1'b0;
1511
                susp_sel = 1'b1;
1512
                cmd = `CMD_ARFR;
1513
                rfr_ack = 1'b1;
1514
                if(cmd_asserted)
1515
                   begin
1516
                        next_state = SUSP4;
1517
                   end
1518
              end
1519
 
1520
           SUSP4:
1521
              begin             // Now we are suspended
1522
                susp_sel = 1'b1;
1523
                cke_rd = 1'b0;
1524
                suspended_d = 1'b1;
1525
                tmr_ld_txsr = 1'b1;
1526
                if(resume_req_r)        next_state = RESUME1;
1527
              end
1528
 
1529
           RESUME1:
1530
              begin
1531
                suspended_d = 1'b1;
1532
                susp_sel = 1'b1;
1533
                tmr_ld_txsr = 1'b1;
1534
                next_state = RESUME2;
1535
              end
1536
 
1537
           RESUME2:
1538
              begin
1539
                suspended_d = 1'b1;
1540
                susp_sel = 1'b1;
1541
                if(tmr_done)    next_state = REFR;
1542
              end
1543
 
1544
// synopsys translate_off
1545
           default:
1546
                $display("MC_TIMING SM: Entered non existing state ... (%t)",$time);
1547
// synopsys translate_on
1548
 
1549
        endcase
1550
   end
1551
 
1552
 
1553
endmodule

powered by: WebSVN 2.1.0

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