-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdram.v
executable file
·690 lines (653 loc) · 26 KB
/
dram.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/**************************************************************************************************/
/**** RVSoc (Mini Kuroda/RISC-V) since 2018-08-07 ArchLab. TokyoTech ****/
/**** ALU Module v0.01 ****/
/**************************************************************************************************/
`default_nettype none
/**************************************************************************************************/
`include "define.vh"
/**************************************************************************************************/
/*** For Nexys A7 board ***************************************************************************/
module DRAM_con_witout_cache #(
`ifndef ARTYA7
parameter DDR2_DQ_WIDTH = 16,
parameter DDR2_DQS_WIDTH = 2,
parameter DDR2_ADDR_WIDTH = 13,
parameter DDR2_BA_WIDTH = 3,
parameter DDR2_DM_WIDTH = 2,
parameter APP_ADDR_WIDTH = 27,
`else
parameter DDR3_DQ_WIDTH = 16,
parameter DDR3_DQS_WIDTH = 2,
parameter DDR3_ADDR_WIDTH = 14,
parameter DDR3_BA_WIDTH = 3,
parameter DDR3_DM_WIDTH = 2,
parameter APP_ADDR_WIDTH = 28,
`endif
parameter APP_CMD_WIDTH = 3,
parameter APP_DATA_WIDTH = 128, // Note
parameter APP_MASK_WIDTH = 16)
(
// input clk, rst (active-low)
input wire mig_clk,
input wire mig_rst_x,
`ifdef ARTYA7
input wire ref_clk,
`endif
// memory interface ports
`ifndef ARTYA7
inout wire [DDR2_DQ_WIDTH-1 : 0] ddr2_dq,
inout wire [DDR2_DQS_WIDTH-1 : 0] ddr2_dqs_n,
inout wire [DDR2_DQS_WIDTH-1 : 0] ddr2_dqs_p,
output wire [DDR2_ADDR_WIDTH-1 : 0] ddr2_addr,
output wire [DDR2_BA_WIDTH-1 : 0] ddr2_ba,
output wire ddr2_ras_n,
output wire ddr2_cas_n,
output wire ddr2_we_n,
output wire [0:0] ddr2_ck_p,
output wire [0:0] ddr2_ck_n,
output wire [0:0] ddr2_cke,
output wire [0:0] ddr2_cs_n,
output wire [DDR2_DM_WIDTH-1 : 0] ddr2_dm,
output wire [0:0] ddr2_odt,
`else
inout wire [DDR3_DQ_WIDTH-1 : 0] ddr3_dq,
inout wire [DDR3_DQS_WIDTH-1 : 0] ddr3_dqs_n,
inout wire [DDR3_DQS_WIDTH-1 : 0] ddr3_dqs_p,
output wire [DDR3_ADDR_WIDTH-1 : 0] ddr3_addr,
output wire [DDR3_BA_WIDTH-1 : 0] ddr3_ba,
output wire ddr3_ras_n,
output wire ddr3_cas_n,
output wire ddr3_we_n,
output wire [0:0] ddr3_ck_p,
output wire [0:0] ddr3_ck_n,
output wire ddr3_reset_n,
output wire [0:0] ddr3_cke,
output wire [0:0] ddr3_cs_n,
output wire [DDR3_DM_WIDTH-1 : 0] ddr3_dm,
output wire [0:0] ddr3_odt,
`endif
// output clk, rst (active-low)
output wire o_clk,
output wire o_rst_x,
// user interface ports
input wire i_rd_en,
input wire i_wr_en,
input wire [31:0] i_addr,
input wire [31:0] i_data,
output wire o_init_calib_complete,
output wire [127:0] o_data,
output wire o_busy,
input wire [3:0] i_mask);
wire mig_ui_clk;
wire mig_ui_rst_x;
wire clk;
wire rst_x;
wire dram_init_calib_complete;
wire dram_ren;
wire dram_wen;
`ifndef ARTYA7
wire [APP_ADDR_WIDTH-2 : 0] dram_addr;
`else
wire [APP_ADDR_WIDTH-1 : 0] dram_addr;
`endif
wire [APP_DATA_WIDTH-1 : 0] dram_din;
wire [APP_DATA_WIDTH-1 : 0] dram_dout;
wire dram_dout_valid;
wire dram_ready;
wire dram_wdf_ready;
reg wen_afifo1;
reg [68:0] din_afifo1;
wire ren_afifo1;
wire [68:0] dout_afifo1;
wire empty_afifo1;
wire full_afifo1;
wire dout_afifo1_wr_en;
wire [31:0] dout_afifo1_addr;
wire [31:0] dout_afifo1_data;
wire wen_afifo2;
wire [127:0] din_afifo2;
wire ren_afifo2;
wire [127:0] dout_afifo2;
wire empty_afifo2;
reg dram_init_calib_complete_sync1;
reg dram_init_calib_complete_sync2;
reg [1:0] state;
wire [3:0] data_mask;
localparam STATE_CALIB = 2'b00;
localparam STATE_IDLE = 2'b01;
localparam STATE_WRITE = 2'b10;
localparam STATE_READ = 2'b11;
wire locked;
wire rst_x_async;
reg rst_x_sync1;
reg rst_x_sync2;
clk_wiz_1 clkgen1 (
.clk_in1(mig_ui_clk),
.resetn(mig_ui_rst_x),
.clk_out1(clk),
.locked(locked));
assign rst_x_async = mig_ui_rst_x & locked;
assign rst_x = rst_x_sync2;
always @(posedge clk or negedge rst_x_async) begin
if (!rst_x_async) begin
rst_x_sync1 <= 1'b0;
rst_x_sync2 <= 1'b0;
end else begin
rst_x_sync1 <= 1'b1;
rst_x_sync2 <= rst_x_sync1;
end
end
assign o_clk = clk;
assign o_rst_x = rst_x;
// synchronize the calibration status signal: MIG -> MIPS core
always @(posedge clk) begin
if (!rst_x) begin
dram_init_calib_complete_sync1 <= 1'b0;
dram_init_calib_complete_sync2 <= 1'b0;
end else begin
dram_init_calib_complete_sync1 <= dram_init_calib_complete;
dram_init_calib_complete_sync2 <= dram_init_calib_complete_sync1;
end
end
assign o_init_calib_complete = dram_init_calib_complete_sync2;
// MIPS core -> MIG
assign ren_afifo1 = (dram_ren || dram_wen);
AsyncFIFO #(
.DATA_WIDTH(69),
.ADDR_WIDTH(2))
afifo1 (
.wclk(clk),
.rclk(mig_ui_clk),
.i_wrst_x(rst_x),
.i_rrst_x(mig_ui_rst_x),
.i_wen(wen_afifo1),
.i_data(din_afifo1),
.i_ren(ren_afifo1),
.o_data(dout_afifo1),
.o_empty(empty_afifo1),
.o_full(full_afifo1));
// MIG -> MIPS core
assign wen_afifo2 = dram_dout_valid;
assign din_afifo2 = dram_dout;
assign ren_afifo2 = !empty_afifo2;
AsyncFIFO #(
.DATA_WIDTH(128),
.ADDR_WIDTH(2))
afifo2 (
.wclk(mig_ui_clk),
.rclk(clk),
.i_wrst_x(mig_ui_rst_x),
.i_rrst_x(rst_x),
.i_wen(wen_afifo2),
.i_data(din_afifo2),
.i_ren(ren_afifo2),
.o_data(dout_afifo2),
.o_empty(empty_afifo2),
.o_full());
assign {dout_afifo1_wr_en, dout_afifo1_addr, dout_afifo1_data, data_mask} = dout_afifo1;
assign dram_ren = (!empty_afifo1 && !dout_afifo1_wr_en && dram_ready);
assign dram_wen = (!empty_afifo1 && dout_afifo1_wr_en && dram_ready && dram_wdf_ready);
`ifndef ARTYA7
assign dram_addr = dout_afifo1_addr[26:1];
assign dram_din = {{(APP_DATA_WIDTH-32){1'b0}}, dout_afifo1_data};
`else
assign dram_addr = {2'b0, dout_afifo1_addr[26:4], 3'b0};
assign dram_din = {4{dout_afifo1_data}};
wire [3:0] mask_t = ~data_mask;
wire [15:0] mask_t2 = mask_t << {dout_afifo1_addr[3:2], 2'b0};
`endif
DRAMController #(
`ifndef ARTYA7
.DDR2_DQ_WIDTH(DDR2_DQ_WIDTH),
.DDR2_DQS_WIDTH(DDR2_DQS_WIDTH),
.DDR2_ADDR_WIDTH(DDR2_ADDR_WIDTH),
.DDR2_BA_WIDTH(DDR2_BA_WIDTH),
.DDR2_DM_WIDTH(DDR2_DM_WIDTH),
`else
.DDR3_DQ_WIDTH(DDR3_DQ_WIDTH),
.DDR3_DQS_WIDTH(DDR3_DQS_WIDTH),
.DDR3_ADDR_WIDTH(DDR3_ADDR_WIDTH),
.DDR3_BA_WIDTH(DDR3_BA_WIDTH),
.DDR3_DM_WIDTH(DDR3_DM_WIDTH),
`endif
.APP_ADDR_WIDTH(APP_ADDR_WIDTH),
.APP_CMD_WIDTH(APP_CMD_WIDTH),
.APP_DATA_WIDTH(APP_DATA_WIDTH),
.APP_MASK_WIDTH(APP_MASK_WIDTH))
dc (
// input clk, rst (active-low)
.sys_clk(mig_clk),
.sys_rst_x(mig_rst_x),
`ifdef ARTYA7
.ref_clk(ref_clk),
`endif
// memory interface ports
`ifndef ARTYA7
.ddr2_dq(ddr2_dq),
.ddr2_dqs_n(ddr2_dqs_n),
.ddr2_dqs_p(ddr2_dqs_p),
.ddr2_addr(ddr2_addr),
.ddr2_ba(ddr2_ba),
.ddr2_ras_n(ddr2_ras_n),
.ddr2_cas_n(ddr2_cas_n),
.ddr2_we_n(ddr2_we_n),
.ddr2_ck_p(ddr2_ck_p),
.ddr2_ck_n(ddr2_ck_n),
.ddr2_cke(ddr2_cke),
.ddr2_cs_n(ddr2_cs_n),
.ddr2_dm(ddr2_dm),
.ddr2_odt(ddr2_odt),
`else
.ddr3_dq(ddr3_dq),
.ddr3_dqs_n(ddr3_dqs_n),
.ddr3_dqs_p(ddr3_dqs_p),
.ddr3_addr(ddr3_addr),
.ddr3_ba(ddr3_ba),
.ddr3_ras_n(ddr3_ras_n),
.ddr3_cas_n(ddr3_cas_n),
.ddr3_we_n(ddr3_we_n),
.ddr3_ck_p(ddr3_ck_p),
.ddr3_ck_n(ddr3_ck_n),
.ddr3_reset_n(ddr3_reset_n),
.ddr3_cke(ddr3_cke),
.ddr3_cs_n(ddr3_cs_n),
.ddr3_dm(ddr3_dm),
.ddr3_odt(ddr3_odt),
`endif
// output clk, rst (active-low)
.o_clk(mig_ui_clk),
.o_rst_x(mig_ui_rst_x),
// user interface ports
.i_rd_en(dram_ren),
.i_wr_en(dram_wen),
`ifndef ARTYA7
.i_addr({1'b0, dram_addr}),
`else
.i_addr(dram_addr),
`endif
.i_data(dram_din),
.o_init_calib_complete(dram_init_calib_complete),
.o_data(dram_dout),
.o_data_valid(dram_dout_valid),
.o_ready(dram_ready),
.o_wdf_ready(dram_wdf_ready),
`ifndef ARTYA7
.i_mask(data_mask));
`else
.i_mask(~mask_t2));
`endif
// state machine
always @(negedge clk) begin
if (!rst_x) begin
state <= STATE_CALIB;
wen_afifo1 <= 0;
din_afifo1 <= 0;
end else begin
wen_afifo1 <= 0;
din_afifo1 <= 0;
case (state)
STATE_CALIB: begin
if (o_init_calib_complete) begin
state <= STATE_IDLE;
end
end
STATE_IDLE: begin
if (i_wr_en) begin
state <= STATE_WRITE;
wen_afifo1 <= 1;
din_afifo1 <= {1'b1, i_addr, i_data, i_mask};
end else if (i_rd_en) begin
state <= STATE_READ;
wen_afifo1 <= 1;
din_afifo1 <= {1'b0, i_addr, i_data, 4'h0};
end
end
STATE_WRITE: begin
if (!full_afifo1) begin
state <= STATE_IDLE;
end
end
STATE_READ: begin
if (!empty_afifo2) begin
state <= STATE_IDLE;
end
end
endcase
end
end
assign o_data = dout_afifo2;
assign o_busy = (state != STATE_IDLE);
endmodule
/**************************************************************************************************/
module DRAMController #(
`ifndef ARTYA7
parameter DDR2_DQ_WIDTH = 16,
parameter DDR2_DQS_WIDTH = 2,
parameter DDR2_ADDR_WIDTH = 13,
parameter DDR2_BA_WIDTH = 3,
parameter DDR2_DM_WIDTH = 2,
parameter APP_ADDR_WIDTH = 27,
`else
parameter DDR3_DQ_WIDTH = 16,
parameter DDR3_DQS_WIDTH = 2,
parameter DDR3_ADDR_WIDTH = 14,
parameter DDR3_BA_WIDTH = 3,
parameter DDR3_DM_WIDTH = 2,
parameter APP_ADDR_WIDTH = 28,
`endif
parameter APP_CMD_WIDTH = 3,
parameter APP_DATA_WIDTH = 128,
parameter APP_MASK_WIDTH = 16)
(
// input clk, rst (active-low)
input wire sys_clk,
input wire sys_rst_x,
`ifdef ARTYA7
input wire ref_clk,
`endif
// memory interface ports
`ifndef ARTYA7
inout wire [DDR2_DQ_WIDTH-1 : 0] ddr2_dq,
inout wire [DDR2_DQS_WIDTH-1 : 0] ddr2_dqs_n,
inout wire [DDR2_DQS_WIDTH-1 : 0] ddr2_dqs_p,
output wire [DDR2_ADDR_WIDTH-1 : 0] ddr2_addr,
output wire [DDR2_BA_WIDTH-1 : 0] ddr2_ba,
output wire ddr2_ras_n,
output wire ddr2_cas_n,
output wire ddr2_we_n,
output wire [0:0] ddr2_ck_p,
output wire [0:0] ddr2_ck_n,
output wire [0:0] ddr2_cke,
output wire [0:0] ddr2_cs_n,
output wire [DDR2_DM_WIDTH-1 : 0] ddr2_dm,
output wire [0:0] ddr2_odt,
`else
inout wire [DDR3_DQ_WIDTH-1 : 0] ddr3_dq,
inout wire [DDR3_DQS_WIDTH-1 : 0] ddr3_dqs_n,
inout wire [DDR3_DQS_WIDTH-1 : 0] ddr3_dqs_p,
output wire [DDR3_ADDR_WIDTH-1 : 0] ddr3_addr,
output wire [DDR3_BA_WIDTH-1 : 0] ddr3_ba,
output wire ddr3_ras_n,
output wire ddr3_cas_n,
output wire ddr3_we_n,
output wire [0:0] ddr3_ck_p,
output wire [0:0] ddr3_ck_n,
output wire ddr3_reset_n,
output wire [0:0] ddr3_cke,
output wire [0:0] ddr3_cs_n,
output wire [DDR3_DM_WIDTH-1 : 0] ddr3_dm,
output wire [0:0] ddr3_odt,
`endif
// output clk, rst (active-low)
output wire o_clk,
output wire o_rst_x,
// user interface ports
input wire i_rd_en,
input wire i_wr_en,
input wire [APP_ADDR_WIDTH-1 : 0] i_addr,
input wire [APP_DATA_WIDTH-1 : 0] i_data,
output wire o_init_calib_complete,
output wire [APP_DATA_WIDTH-1 : 0] o_data,
output wire o_data_valid,
output wire o_ready,
output wire o_wdf_ready,
`ifndef ARTYA7
input wire [3:0] i_mask);
`else
input wire [APP_MASK_WIDTH-1 : 0] i_mask);
`endif
localparam STATE_CALIB = 3'b000;
localparam STATE_IDLE = 3'b001;
localparam STATE_ISSUE_CMD_WDATA = 3'b010;
localparam STATE_ISSUE_CMD = 3'b011;
localparam STATE_ISSUE_WDATA = 3'b100;
localparam CMD_READ = 3'b001;
localparam CMD_WRITE = 3'b000;
wire init_calib_complete;
wire [APP_DATA_WIDTH-1 : 0] app_rd_data;
wire app_rd_data_valid;
wire app_rdy;
wire app_wdf_rdy;
wire clk;
wire rst;
reg [APP_ADDR_WIDTH-1 : 0] app_addr;
reg [APP_CMD_WIDTH-1 : 0] app_cmd;
reg app_en;
reg [APP_DATA_WIDTH-1 : 0] app_wdf_data;
reg app_wdf_wren;
reg [2:0] state;
`ifndef ARTYA7
reg [3:0] data_mask = 0;
`else
reg [APP_MASK_WIDTH-1 : 0] data_mask = 0;
`endif
assign o_clk = clk;
assign o_rst_x = ~rst;
assign o_init_calib_complete = init_calib_complete;
assign o_data = app_rd_data;
assign o_data_valid = app_rd_data_valid;
assign o_ready = app_rdy;
assign o_wdf_ready = app_wdf_rdy;
mig_7series_0 mig
(
// memory interface ports
`ifndef ARTYA7
.ddr2_addr (ddr2_addr),
.ddr2_ba (ddr2_ba),
.ddr2_cas_n (ddr2_cas_n),
.ddr2_ck_n (ddr2_ck_n),
.ddr2_ck_p (ddr2_ck_p),
.ddr2_cke (ddr2_cke),
.ddr2_ras_n (ddr2_ras_n),
.ddr2_we_n (ddr2_we_n),
.ddr2_dq (ddr2_dq),
.ddr2_dqs_n (ddr2_dqs_n),
.ddr2_dqs_p (ddr2_dqs_p),
.ddr2_cs_n (ddr2_cs_n),
.ddr2_dm (ddr2_dm),
.ddr2_odt (ddr2_odt),
`else
.ddr3_addr (ddr3_addr),
.ddr3_ba (ddr3_ba),
.ddr3_cas_n (ddr3_cas_n),
.ddr3_ck_n (ddr3_ck_n),
.ddr3_ck_p (ddr3_ck_p),
.ddr3_reset_n (ddr3_reset_n),
.ddr3_cke (ddr3_cke),
.ddr3_ras_n (ddr3_ras_n),
.ddr3_we_n (ddr3_we_n),
.ddr3_dq (ddr3_dq),
.ddr3_dqs_n (ddr3_dqs_n),
.ddr3_dqs_p (ddr3_dqs_p),
.ddr3_cs_n (ddr3_cs_n),
.ddr3_dm (ddr3_dm),
.ddr3_odt (ddr3_odt),
`endif
// calibration
.init_calib_complete (init_calib_complete),
// application interface ports
.app_addr (app_addr),
.app_cmd (app_cmd),
.app_en (app_en),
.app_wdf_data (app_wdf_data),
.app_wdf_end (app_wdf_wren), // to simplify the user logic, app_wdf_end and app_wdf_wren are tied together
.app_wdf_wren (app_wdf_wren), // to ensure that they are always driven together
.app_rd_data (app_rd_data),
.app_rd_data_end (),
.app_rd_data_valid (app_rd_data_valid),
.app_rdy (app_rdy),
.app_wdf_rdy (app_wdf_rdy),
.app_sr_req (1'b0),
.app_ref_req (1'b0),
.app_zq_req (1'b0),
.app_sr_active (),
.app_ref_ack (),
.app_zq_ack (),
.ui_clk (clk),
.ui_clk_sync_rst (rst),
.app_wdf_mask ({{(APP_MASK_WIDTH-4){1'b1}}, data_mask}),
// system clock, reset ports
.sys_clk_i (sys_clk),
`ifndef ARTYA7
.sys_rst (sys_rst_x));
`else
.sys_rst (sys_rst_x),
.clk_ref_i (ref_clk));
`endif
always @(posedge clk) begin
if (rst) begin
state <= STATE_CALIB;
app_cmd <= 0;
app_addr <= 0;
app_en <= 0;
app_wdf_data <= 0;
app_wdf_wren <= 0;
data_mask <= 0;
end else begin
case (state)
STATE_CALIB: begin
if (init_calib_complete) begin
state <= STATE_IDLE;
end
end
STATE_IDLE: begin
if (i_wr_en) begin
app_cmd <= CMD_WRITE;
app_addr <= i_addr;
app_en <= 1;
app_wdf_data <= i_data;
app_wdf_wren <= 1;
state <= STATE_ISSUE_CMD_WDATA;
data_mask <= i_mask;
`ifdef SIM_MAIN
$display("STATE_IDLE app_cmd = CMD_WRITE, i_addr=%h i_data=%h i_mask=%h", i_addr, i_data, i_mask);
`endif
end else if (i_rd_en) begin
app_wdf_wren <= 0;
app_cmd <= CMD_READ;
app_addr <= i_addr;
app_en <= 1;
state <= STATE_ISSUE_CMD;
data_mask <= 0;
`ifdef SIM_MAIN
$display("STATE_IDLE app_cmd = CMD_READ, i_addr=%h", i_addr);
`endif
end
end
STATE_ISSUE_CMD_WDATA: begin
if (app_rdy && app_wdf_rdy) begin
if (i_wr_en) begin
app_cmd <= CMD_WRITE;
app_addr <= i_addr;
app_en <= 1;
app_wdf_data <= i_data;
app_wdf_wren <= 1;
state <= STATE_ISSUE_CMD_WDATA;
data_mask <= i_mask;
`ifdef SIM_MAIN
$display("STATE_ISSUE_CMD_WDATA app_cmd = CMD_WRITE, i_addr=%h i_data=%h i_mask=%h", i_addr, i_data, i_mask);
`endif
end else if (i_rd_en) begin
app_wdf_wren <= 0;
app_cmd <= CMD_READ;
app_addr <= i_addr;
app_en <= 1;
state <= STATE_ISSUE_CMD;
data_mask <= 0;
`ifdef SIM_MAIN
$display("STATE_ISSUE_CMD_WDATA app_cmd = CMD_READ, i_addr=%h", i_addr);
`endif
end else begin
app_en <= 0;
app_wdf_wren <= 0;
state <= STATE_IDLE;
`ifdef SIM_MAIN
if(app_rd_data_valid)
$display("STATE_ISSUE_CMD_WDATA app_rd_data=%h", app_rd_data);
`endif
end
end else if (app_rdy) begin
app_en <= 0;
state <= STATE_ISSUE_WDATA;
end else if (app_wdf_rdy) begin
app_wdf_wren <= 0;
state <= STATE_ISSUE_CMD;
end
end
STATE_ISSUE_CMD: begin
if (app_rdy) begin
if (i_wr_en) begin
app_cmd <= CMD_WRITE;
app_addr <= i_addr;
app_en <= 1;
app_wdf_data <= i_data;
app_wdf_wren <= 1;
state <= STATE_ISSUE_CMD_WDATA;
data_mask <= i_mask;
`ifdef SIM_MAIN
$display("STATE_ISSUE_CMD app_cmd = CMD_WRITE, i_addr=%h i_data=%h i_mask=%h", i_addr, i_data, i_mask);
`endif
end else if (i_rd_en) begin
app_wdf_wren <= 0;
app_cmd <= CMD_READ;
app_addr <= i_addr;
app_en <= 1;
state <= STATE_ISSUE_CMD;
data_mask <= 0;
`ifdef SIM_MAIN
$display("STATE_ISSUE_CMD app_cmd = CMD_READ, i_addr=%h", i_addr);
`endif
end else begin
app_en <= 0;
app_wdf_wren <= 0;
state <= STATE_IDLE;
`ifdef SIM_MAIN
if(app_rd_data_valid)
$display("STATE_ISSUE_CMD app_rd_data=%h", app_rd_data);
`endif
end
end
end
STATE_ISSUE_WDATA: begin
if (app_wdf_rdy) begin
if (i_wr_en) begin
app_cmd <= CMD_WRITE;
app_addr <= i_addr;
app_en <= 1;
app_wdf_data <= i_data;
app_wdf_wren <= 1;
state <= STATE_ISSUE_CMD_WDATA;
data_mask <= i_mask;
`ifdef SIM_MAIN
$display("STATE_ISSUE_CMD_WDATA app_cmd = CMD_WRITE, i_addr=%h i_data=%h i_mask=%h", i_addr, i_data, i_mask);
`endif
end else if (i_rd_en) begin
app_wdf_wren <= 0;
app_cmd <= CMD_READ;
app_addr <= i_addr;
app_en <= 1;
state <= STATE_ISSUE_CMD;
data_mask <= 0;
`ifdef SIM_MAIN
$display("STATE_ISSUE_CMD_WDATA app_cmd = CMD_READ, i_addr=%h", i_addr);
`endif
end else begin
app_wdf_wren <= 0;
state <= STATE_IDLE;
`ifdef SIM_MAIN
if(app_rd_data_valid)
$display("STATE_ISSUE_WDATA app_rd_data=%h", app_rd_data);
`endif
end
end
end
default: begin
app_en <= 0;
app_wdf_wren <= 0;
state <= STATE_IDLE;
end
endcase
end
end
endmodule
/**************************************************************************************************/