-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy paths27kl0642.v
1815 lines (1622 loc) · 55.3 KB
/
s27kl0642.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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///////////////////////////////////////////////////////////////////////////////
// File name : s27kl0642.v
///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 Cypress Semiconductor.
//
// MODIFICATION HISTORY :
//
// version: | author: | date: | changes made:
// V1.0 VINI 27 Feb 19 Initial release
// V2.0 VINI 13 Jan 20 updated the AC specs
// Fixed latency issues
// fixed data mismatch at higher 200MHz
// fixed Hybrid sleep and DPD entry &exit
// Added Partial Refresh
// Added Refresh Interval and variable latency feature
// Added MPN based AC characteristics selection
//
///////////////////////////////////////////////////////////////////////////////
/// PART DESCRIPTION:
//
// Library: Cypress
// Technology: RAM
// Part: S27KL0642
// spec #: 002-26518
//
// Description: Reduced Pin Count Pseudo Static RAM,
// 64Mb high-speed CMOS 3.0 and 1.8 Volt Core, x8 data bus
//
//
//////////////////////////////////////////////////////////////////////////////
// Comments :
// For correct simulation, simulator resolution should be set to 1 ps
// Model validated using ModelSim (vsim)SE 10.1
//
//////////////////////////////////////////////////////////////////////////////
// Known Bugs:
// 1. Decars functionality is not implemented
// 2. diferential clock is not used for functionality
// 3. a 1ps of delay on DQ, with respect to RWDS observed for lower frequency access.
// 4. an additinal 1ps may require for tRP in simulation.
// 5. Partial refresh uses a 64-bit variable to record the time. partial refresh simulation may not work properly if simulation time exceeds the 64bit value.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// MODULE DECLARATION //
//////////////////////////////////////////////////////////////////////////////
`timescale 1 ps/1 ps
//`define S27KS0642GABHI
//`define S27KS0642DPBHI
//`define S27KL0642GABHI
//`define S27KL0642DPBHI
`ifdef S27KS0642GABHI
`define FREQ_200MHz_1P8V
`define INDUSTRIAL
`elsif S27KS0642DPBHI
`define FREQ_166MHz_1P8V
`define INDUSTRIAL
`elsif S27KL0642GABHI
`define FREQ_200MHz_3P3V
`define INDUSTRIAL
`elsif S27KL0642DPBHI
`define FREQ_166MHz_3P3V
`define INDUSTRIAL
`else // IS66WVH8M8BLL-100B1LI
`define INDUSTRIAL
`endif
module s27kl0642
(
DQ7 ,
DQ6 ,
DQ5 ,
DQ4 ,
DQ3 ,
DQ2 ,
DQ1 ,
DQ0 ,
RWDS ,
CSNeg ,
CK ,
CKn ,
RESETNeg
);
`ifdef FREQ_200MHz_1P8V
`define CONFIG_REG0_DEFAULT 16'h8F2F
`define tDSV 5000 //tDSZ,tDSV
`define tCKDS 5000 //tCKDS
`define tCKD 5000 //tCKD,tCKDS
`define tCKDI 4200
`define tCKDSR 5500
//tsetup values
`define tCSS 4000 //tCSS edge /
`define tIS 500 //tIS
//thold values
`define tCSH 0 //tCSH edge
`define tIH 500 //tIH
`define tRH 200000 //tRH
`define tRWR 35000 //tRWR
//tpw values: pulse width
`define tCL 2500 //tCL 50% of the min clock period
`define tCH 2500 //tCH 50% of the min clock period
`define tCSHI 6e3 //tCSHI
`define tRP 200e3 //tRP
`define tACC 35e3
`define tOZ 5000
`define tDSZ 5000
`define tDQLZ 0
`define tRFH 35e3 //refresh time
//tperiod values
`define tCK 5000//tCK
//-------------------------------------------------------------
`elsif FREQ_166MHz_3P3V
`define CONFIG_REG0_DEFAULT 16'h8F2F
`define tDSV 12000 //tDSV
`define tCKDS 7000 //tCKDS
`define tCKD 7000 //tCKD,tCKDS
`define tCKDI 5600
`define tDSZ 7000
`define tCKDSR 7000
//tsetup values
`define tCSS 3000 //tCSS edge /
`define tIS 600 //tIS
//thold values
`define tCSH 0 //tCSH edge
`define tIH 600 //tIH
`define tRH 200000 //tRH
`define tRWR 36000 //tRWR
//tpw values: pulse width
`define tCL 3000 //tCL 50% of the min clock period
`define tCH 3000 //tCH 50% of the min clock period
`define tCSHI 6e3 //tCSHI
`define tRP 2e5 //tRP
`define tACC 36e3
`define tOZ 7000
`define tDQLZ 0
`define tRFH 36e3 //refresh time
//tperiod values
`define tCK 6000//tCK
`elsif FREQ_200MHz_3P3V
`define CONFIG_REG0_DEFAULT 16'h8F2F
`define tDSV 6500 //tDSZ,tDSV
`define tCKDS 6500 //tCKDS
`define tCKD 6500 //tCKD,tCKDS
`define tCKDI 5700
`define tCKDSR 7000
//tsetup values
`define tCSS 4000 //tCSS edge /
`define tIS 500 //tIS
//thold values
`define tCSH 0 //tCSH edge
`define tIH 500 //tIH
`define tRH 200000 //tRH
`define tRWR 35000 //tRWR
//tpw values: pulse width
`define tCL 2500 //tCL 50% of the min clock period
`define tCH 2500 //tCH 50% of the min clock period
`define tCSHI 6e3 //tCSHI
`define tRP 2e5 //tRP
`define tACC 35e3
`define tOZ 6500
`define tDSZ 6500
`define tDQLZ 0
`define tRFH 35e3 //refresh time
//tperiod values
`define tCK 5000//tCK
//-------------------------------------------------------------
`elsif FREQ_166MHz_1P8V
`define CONFIG_REG0_DEFAULT 16'h8F2F
`define tDSV 12000 //tDSV
`define tCKDS 5500 //tCKDS
`define tCKD 5500 //tCKD,tCKDS
`define tCKDI 4600
`define tDSZ 6000
`define tCKDSR 5500
//tsetup values
`define tCSS 3000 //tCSS edge /
`define tIS 600 //tIS
//thold values
`define tCSH 0 //tCSH edge
`define tIH 600 //tIH
`define tRH 200000 //tRH
`define tRWR 36000 //tRWR
//tpw values: pulse width
`define tCL 3000 //tCL 50% of the min clock period
`define tCH 3000 //tCH 50% of the min clock period
`define tCSHI 6e3 //tCSHI
`define tRP 2e5 //tRP
`define tACC 36e3
`define tOZ 6000
`define tDQLZ 0
`define tRFH 36e3 //refresh time
//tperiod values
`define tCK 6000//tCK
`else // IS66WVH8M8BLL-100B1LI
`define CONFIG_REG0_DEFAULT 16'h8F1F
`define tDSV 6000 //tDSZ,tDSV
`define tCKDS 4000 //tCKDS
`define tCKD 4000 //tCKD,tCKDS
`define tCKDI 2900
`define tCKDSR 5500
//tsetup values
`define tCSS 3000 //tCSS edge /
`define tIS 1000 //tIS
//thold values
`define tCSH 0 //tCSH edge
`define tIH 1000 //tIH
`define tRH 40000 //tRH
`define tRWR 40000 //tRWR
//tpw values: pulse width
`define tCL 5000 //tCL 50% of the min clock period
`define tCH 5000 //tCH 50% of the min clock period
`define tCSHI 10e3 //tCSHI
`define tRP 200e3 //tRP
`define tACC 40e3
`define tOZ 3500
`define tDSZ 3500
`define tDQLZ 0
`define tRFH 40e3 //refresh time
//tperiod values
`define tCK 10000//tCK
`endif
`ifdef INDUSTRIAL
`define DRI 2'h1
`define tCSM 4e6 //tCSM
`elsif INDUSTRIAL_PLUS
`define DRI 2'h2
`define tCSM 1e6 //tCSM
`endif
////////////////////////////////////////////////////////////////////////
// Port / Part Pin Declarations
////////////////////////////////////////////////////////////////////////
inout DQ7;
inout DQ6;
inout DQ5;
inout DQ4;
inout DQ3;
inout DQ2;
inout DQ1;
inout DQ0;
inout RWDS;
input CSNeg;
input CK;
input CKn;
input RESETNeg;
// interconnect path delay signals
wire CSNeg_ipd;
wire CK_ipd;
wire RESETNeg_ipd;
wire DQ7_ipd;
wire DQ6_ipd;
wire DQ5_ipd;
wire DQ4_ipd;
wire DQ3_ipd;
wire DQ2_ipd;
wire DQ1_ipd;
wire DQ0_ipd;
wire RWDS_ipd;
wire [7:0] Din;
assign Din = { DQ7_ipd,
DQ6_ipd,
DQ5_ipd,
DQ4_ipd,
DQ3_ipd,
DQ2_ipd,
DQ1_ipd,
DQ0_ipd};
wire [7:0] Dout;
assign Dout = { DQ7,
DQ6,
DQ5,
DQ4,
DQ3,
DQ2,
DQ1,
DQ0 };
wire RWDSin;
assign RWDSin = RWDS_ipd;
// internal delays
reg HS_in = 0;
reg HS_out = 0;
reg DPD_in = 0;
reg DPD_out = 0;
reg RPH_in = 0;
reg RPH_out = 0;
reg REF_in = 0;
reg REF_out = 0;
reg PO_in = 0;
reg PO_out = 0;
wire DPDExt_in; // DPD Exit event
reg DPDExt_out = 0; // DPD Exit event confirmed
reg DPDExt = 0; // DPD Exit event detected
// event control registers
reg rising_edge_PoweredUp = 0;
reg rising_edge_CKDiff = 0;
reg falling_edge_CKDiff = 0;
reg rising_edge_CSNeg = 0;
reg falling_edge_CSNeg = 0;
reg rising_edge_REF_out = 0;
reg rising_edge_PO_out = 0;
reg rising_edge_RPH_out = 0;
reg rising_edge_DPD_in = 0;
reg rising_edge_DPD_out = 0;
reg rising_edge_HS_in = 0;
reg rising_edge_HS_out = 0;
reg rising_edge_RESETNeg = 0;
reg falling_edge_RESETNeg = 0;
reg rising_edge_glitch_rwds= 0;
integer tACC_delay = 0;
integer DQt_01;
integer RWDSt_01;
integer RWDSRt_01;
time CK_cycle = 0;
time prev_CK;
reg tacc_start = 1'b0;
reg glitch_dq = 1'b0;
reg glitch_rwds = 1'b0;
reg glitch_rwdsR = 1'b0;
reg Viol = 1'b0;
reg [7:0] Dout_zd = 8'bzzzzzzzz;
reg [7:0] Dout_zdp = 8'bzzzzzzzz;
reg [7:0] Dout_zdn = 8'bzzzzzzzz;
reg RWDSout_zd = 1'bz;
reg RWDS_zdp = 1'bz;
reg RWDS_zdn = 1'bz;
reg DQp_latch = 1'b0;
reg DQn_latch = 1'b0;
wire DQ7_zd ;
wire DQ6_zd ;
wire DQ5_zd ;
wire DQ4_zd ;
wire DQ3_zd ;
wire DQ2_zd ;
wire DQ1_zd ;
wire DQ0_zd ;
assign {DQ7_zd,
DQ6_zd,
DQ5_zd,
DQ4_zd,
DQ3_zd,
DQ2_zd,
DQ1_zd,
DQ0_zd } = Dout_zd;
wire RWDS_zd;
assign RWDS_zd = RWDSout_zd;
reg [7:0] Dout_zd_tmp = 8'bzzzzzzzz;
reg RWDSout_zd_tmp = 1'bz;
reg [7:0] Dout_zd_latchH ;
reg [7:0] Dout_zd_latchL ;
reg RWDS_zd_latchH ;
reg RWDS_zd_latchL ;
wire RESETNeg_pullup;
assign RESETNeg_pullup = (RESETNeg === 1'bZ) ? 1 : RESETNeg;
wire CKDiff;
reg RW = 0;
reg REFCOLL = 0;
reg REFCOLL_ACTIV = 0; // = 1 : refresh collision occured
reg t_RWR_CHK = 1'b0;
parameter UserPreload = 1;
parameter mem_file_name = "none";
parameter TimingModel = "S27KS0642GAXXXXXX";//do not change. identical for all device options
parameter PartID = "S27KL0642";//do not change. identical for all device options
parameter MaxData = 16'hFFFF;
parameter MemSize = 25'h3FFFFF;
parameter no_of_rows = 8192;
parameter HiAddrBit = 34;
parameter AddrRANGE = 25'h3FFFFF;
integer PartialRefresh_Array[0:7][1:0];
wire temp;
///////////////////////////////////////////////////////////////////////////////
//Interconnect Path Delay Section
///////////////////////////////////////////////////////////////////////////////
buf (DQ7_ipd , DQ7 );
buf (DQ6_ipd , DQ6 );
buf (DQ5_ipd , DQ5 );
buf (DQ4_ipd , DQ4 );
buf (DQ3_ipd , DQ3 );
buf (DQ2_ipd , DQ2 );
buf (DQ1_ipd , DQ1 );
buf (DQ0_ipd , DQ0 );
buf (RWDS_ipd , RWDS );
buf (CK_ipd , CK );
buf (RESETNeg_ipd , RESETNeg);
buf (CSNeg_ipd , CSNeg );
///////////////////////////////////////////////////////////////////////////////
// Propagation delay Section
///////////////////////////////////////////////////////////////////////////////
nmos (DQ7 , DQ7_zd , 1);
nmos (DQ6 , DQ6_zd , 1);
nmos (DQ5 , DQ5_zd , 1);
nmos (DQ4 , DQ4_zd , 1);
nmos (DQ3 , DQ3_zd , 1);
nmos (DQ2 , DQ2_zd , 1);
nmos (DQ1 , DQ1_zd , 1);
nmos (DQ0 , DQ0_zd , 1);
nmos (RWDS , RWDS_zd , 1);
wire Dout_Z;
assign Dout_Z = Dout_zd==8'bzzzzzzzz;
wire RWDSout_Z;
assign RWDSout_Z = RWDSout_zd==1'bz & RW == 0;
//assign RWDS_zd = RWDSout_Z;
wire tRWR_CHK;
assign tRWR_CHK = t_RWR_CHK;
real REFinterval;
specify
// tpd delays
specparam tpd_CSNeg_RWDSn = `tDSV; //tDSZ,tDSV
specparam tpd_CSNeg_RWDSp = `tDSZ;
specparam tpd_CK_RWDS = `tCKDS; //tCKDS
specparam tpd_CSNeg_DQ0 = `tOZ;//(`tCSS - `tIS); //(tCSS - tIS)
specparam tpd_CK_DQ0 = `tCKD; //tCKD,tCKDS
//tsetup values
specparam tsetup_CSNeg_CK = `tCSS; //tCSS edge /
specparam tsetup_DQ0_CK = `tIS; //tIS
//thold values
specparam thold_CSNeg_CK = `tCSH; //tCSH edge
specparam thold_DQ0_CK = `tIH; //tIH
specparam thold_CSNeg_RESETNeg = `tRH; //tRH
specparam trecovery_CSNeg_CK = `tRWR; //tRWR
specparam tskew_CSNeg_CSNeg = `tCSM; //tCSM
//tpw values: pulse width
specparam tpw_CK_negedge = `tCL; //tCL
specparam tpw_CK_posedge = `tCH; //tCH
specparam tpw_CSNeg_posedge = `tCSHI; //tCSHI
specparam tpw_RESETNeg_negedge = `tRP; //tRP
specparam tACC_device = `tACC;
//tperiod values
specparam tperiod_CK = `tCK; //tCK
//tdevice values: values for internal delays
// power-on reset
specparam tdevice_VCS = 150e6;
// Deep Power Down to Idle wake up time
specparam tdevice_DPD = 150e6;
// Exit Event from Deep Power Down
specparam tdevice_DPDCSL = 150e6;
// Exit from Hybrid sleep
specparam tdevice_HSCSL = 100e6;
// Warm HW reset
specparam tdevice_RPH = 200e3;
// Refresh time
specparam tdevice_REF100 = `tRFH;
// Page Open Time
specparam tdevice_PO100 = 0;
//Hybrid Sleep Enter Time
specparam tHSIN = 3e6;
//DPD Enter Time
specparam tDPDIN = 3e6;
//CS pulse to exit HS
specparam tCSHS = 60e3;
//CS pulse to exit DPD
specparam tCSDPD = 200e3;
///////////////////////////////////////////////////////////////////////////////
// Input Port Delays don't require Verilog description
///////////////////////////////////////////////////////////////////////////////
// Path delays //
///////////////////////////////////////////////////////////////////////////////
// Data output paths
(CSNeg => DQ0) = tpd_CSNeg_DQ0;
(CSNeg => DQ1) = tpd_CSNeg_DQ0;
(CSNeg => DQ2) = tpd_CSNeg_DQ0;
(CSNeg => DQ3) = tpd_CSNeg_DQ0;
(CSNeg => DQ4) = tpd_CSNeg_DQ0;
(CSNeg => DQ5) = tpd_CSNeg_DQ0;
(CSNeg => DQ6) = tpd_CSNeg_DQ0;
(CSNeg => DQ7) = tpd_CSNeg_DQ0;
if (falling_edge_CSNeg) (CSNeg => RWDS) = tpd_CSNeg_RWDSn;
if (rising_edge_CSNeg) (CSNeg => RWDS) = tpd_CSNeg_RWDSp;
///////////////////////////////////////////////////////////////////////////
// Timing Violation //
///////////////////////////////////////////////////////////////////////////
$setup (CSNeg, posedge CK, tsetup_CSNeg_CK);
$setup (DQ0 &&& Dout_Z, CK, tsetup_DQ0_CK);
$setup (DQ1 &&& Dout_Z, CK, tsetup_DQ0_CK);
$setup (DQ2 &&& Dout_Z, CK, tsetup_DQ0_CK);
$setup (DQ3 &&& Dout_Z, CK, tsetup_DQ0_CK);
$setup (DQ4 &&& Dout_Z, CK, tsetup_DQ0_CK);
$setup (DQ5 &&& Dout_Z, CK, tsetup_DQ0_CK);
$setup (DQ6 &&& Dout_Z, CK, tsetup_DQ0_CK);
$setup (DQ7 &&& Dout_Z, CK, tsetup_DQ0_CK);
$setup (RWDS &&& RWDSout_Z, CK, tsetup_DQ0_CK);
$hold (negedge CK, CSNeg, thold_CSNeg_CK);
$hold (CK, DQ0 &&& Dout_Z, thold_DQ0_CK, Viol);
$hold (CK, DQ1 &&& Dout_Z, thold_DQ0_CK, Viol);
$hold (CK, DQ2 &&& Dout_Z, thold_DQ0_CK, Viol);
$hold (CK, DQ3 &&& Dout_Z, thold_DQ0_CK, Viol);
$hold (CK, DQ4 &&& Dout_Z, thold_DQ0_CK, Viol);
$hold (CK, DQ5 &&& Dout_Z, thold_DQ0_CK, Viol);
$hold (CK, DQ6 &&& Dout_Z, thold_DQ0_CK, Viol);
$hold (CK, DQ7 &&& Dout_Z, thold_DQ0_CK, Viol);
$hold (CK, RWDS &&& RWDSout_Z, thold_DQ0_CK, Viol);
$hold (posedge RESETNeg, CSNeg, thold_CSNeg_RESETNeg);
$recovery (posedge CSNeg, negedge CK &&& tRWR_CHK, trecovery_CSNeg_CK, Viol);
$skew (negedge CSNeg, posedge CSNeg, tskew_CSNeg_CSNeg, Viol);
$width (posedge CK , tpw_CK_posedge);
$width (negedge CK , tpw_CK_negedge);
$width (posedge CSNeg , tpw_CSNeg_posedge);
$width (negedge RESETNeg , tpw_RESETNeg_negedge);
$period(posedge CK ,tperiod_CK);
endspecify
///////////////////////////////////////////////////////////////////////////////
// Main Behavior Block //
///////////////////////////////////////////////////////////////////////////////
// FSM states
parameter POWER_ON = 3'd0;
parameter ACT = 3'd1;
parameter RESET_STATE = 3'd2;
parameter DPD_STATE = 3'd3;
parameter HSLEEP_STATE = 3'd4;
reg [2:0] current_state = POWER_ON;
reg [2:0] next_state = POWER_ON;
//Bus cycle state
parameter STAND_BY = 2'd0;
parameter CA_BITS = 2'd1;
parameter DATA_BITS = 2'd2;
reg [1:0] bus_cycle_state;
// Parameters that define read mode, burst or continuous
parameter LINEAR = 4'd0;
parameter CONTINUOUS = 4'd1;
reg [1:0] RD_MODE = CONTINUOUS;
integer Mem [0:MemSize];
real Mem_time[0:MemSize];
reg PoweredUp = 0;
reg DPD_ACT = 0;
reg HS_ACT = 0;
integer Address; // entire address
reg [15:0] Config_reg0 = `CONFIG_REG0_DEFAULT;
reg [15:0] Config_reg1 = {14'h3FF0,`DRI};
reg [15:0] Identification_reg0 = 16'h0C81;
reg [15:0] Identification_reg1 = 16'h0001;
reg UByteMask = 0;
reg LByteMask = 0;
reg Target = 0;
integer BurstDelay;
integer RefreshDelay = 4;
integer BurstLength;
//varaibles to resolve architecture used
reg [24*8-1:0] tmp_timing;//stores copy of TimingModel
reg [7:0] tmp_char1; //Identify Speed option
reg [7:0] tmp_char2;
integer found = 1'b0;
reg SPEED100 = 0;
reg refresh_pulse = 1'b0;
always
begin
#`tCSM refresh_pulse = 1'b1;
#`tRFH refresh_pulse = 1'b0;
end
//Power Up time;
initial
begin
# tdevice_VCS PoweredUp = 1'b1;
end
initial
begin: InitTimingModel
integer i;
integer j;
//assumptions:
//1. TimingModel has format as S27KL0642XXXXXXXX
//it is important that 10-th character from first one is "GA" or "DP"
//2. TimingModel does not have more than 24 characters
tmp_timing = TimingModel;//copy of TimingModel
i = 23;
while ((i >= 0) && (found != 1'b1))//search for first non null character
begin //i keeps position of first non null character
j = 7;
while ((j >= 0) && (found != 1'b1))
begin
if (tmp_timing[i*8+j] != 1'd0)
found = 1'b1;
else
j = j-1;
end
i = i - 1;
end
i = i +1;
if (found)//if non null character is found
begin
for (j=0;j<=7;j=j+1)
begin
//Speed is 11.
tmp_char1[j] = TimingModel[(i-10)*8+j];
tmp_char2[j] = TimingModel[(i-9)*8+j];
end
end
if (tmp_char1 == "A" && tmp_char2 == "G")begin
SPEED100 = 1;
end else if(tmp_char1 == "P" && tmp_char2 == "D")begin
SPEED100 = 1;
end else begin
$error ("No speed grade found\n");
end
PartialRefresh_Array[0][0] = 0;
PartialRefresh_Array[0][1] = MemSize;
PartialRefresh_Array[1][0] = 0;
PartialRefresh_Array[1][1] = MemSize/2;
PartialRefresh_Array[2][0] = 0;
PartialRefresh_Array[2][1] = MemSize/4;
PartialRefresh_Array[3][0] = 0;
PartialRefresh_Array[3][1] = MemSize/8;
PartialRefresh_Array[4][0] = 0;
PartialRefresh_Array[4][1] = 0;
PartialRefresh_Array[5][1] = MemSize;
PartialRefresh_Array[5][0] = MemSize/2;
PartialRefresh_Array[6][1] = MemSize;
PartialRefresh_Array[6][0] = 3*MemSize/4;
PartialRefresh_Array[7][1] = MemSize;
PartialRefresh_Array[7][0] = 7*MemSize/8;
end
// ------------------------------------------------------------------------
// Hybrid Sleep time
// ------------------------------------------------------------------------
// HSExit_in is any write or read access for which CSNeg_ipd is asserted
// more than tHSCSL time
reg HSExit_in = 1'b1;
reg HSExt_out = 1'b0;
reg HSExt;
assign HSExt_in = ((falling_edge_CSNeg == 1'b1) && (HS_in == 1'b1)) ?
1'b1 : 1'b0;
always @(posedge HSExt_in or posedge HS_in)
begin
if(HS_in && !HSExit_in)begin
HSExit_in = 1'b1;
end else begin
#tCSHS HSExit_in = CSNeg_ipd;
end
end
always @(negedge HSExit_in)
begin : HSExtEvent
#(tdevice_HSCSL - 1 - tCSHS) HSExt_out = 1'b1;
#1 HSExt_out = 1'b0;
end
// Generate event to trigger exiting from HS mode
always @(posedge HSExt_out or CSNeg_ipd or RESETNeg or falling_edge_RESETNeg or
HS_in)
begin : HSExtDetected
if ((HSExt_out == 1'b1) ||
(!RESETNeg && falling_edge_RESETNeg && HS_in))
begin
HSExt = 1'b1;
#1 HSExt = 1'b0;
end
end
// HS exit event, generated after tHSOUT time (maximal: 150 us)
always @(posedge HSExt)
begin : HSTime
HS_out = 1'b0;
#1 HS_out = 1'b1;
end
reg DPDExit_in = 1'b1;
// ------------------------------------------------------------------------
// Deep Power Down time
// ------------------------------------------------------------------------
// DPDExit_in is any write or read access for which CSNeg_ipd is asserted
// more than tCSDPD time
assign DPDExt_in = ((falling_edge_CSNeg == 1'b1) && (DPD_in == 1'b1)) ?
1'b1 : 1'b0;
always @(posedge DPDExt_in or posedge DPD_in)
begin
if(DPD_in && !DPDExit_in)begin
DPDExit_in = 1'b1;
end else if(DPDExt_in)begin
#tCSDPD DPDExit_in = CSNeg_ipd;
end
end
always @(negedge DPDExit_in)
begin : DPDExtEvent
#(tdevice_DPDCSL - 1 - tCSDPD) DPDExt_out = 1'b1;
#1 DPDExt_out = 1'b0;
end
// Generate event to trigger exiting from DPD mode
always @(posedge DPDExt_out or CSNeg_ipd or RESETNeg or falling_edge_RESETNeg or
DPD_in)
begin : DPDExtDetected
if ((DPDExt_out == 1'b1) ||
(!RESETNeg && falling_edge_RESETNeg && DPD_in))
begin
DPDExt = 1'b1;
#1 DPDExt = 1'b0;
end
end
// DPD exit event, generated after tDPDEXIT time (maximal: 150 us)
always @(posedge DPDExt)
begin : DPDTime
DPD_out = 1'b0;
#1 DPD_out = 1'b1;
end
// Timing control
// Warm HW reset
always @(posedge RPH_in)
begin:RPHr
#tdevice_RPH RPH_out = RPH_in;
end
always @(negedge RPH_in)
begin:RPHf
#1 RPH_out = RPH_in;
end
// Refresh Collision Time
always @(posedge REF_in)
begin:REFr
if (SPEED100)
#(tdevice_REF100 * REFinterval) REF_out = REF_in;
end
always @(negedge REF_in)
begin:REFf
#1 REF_out = REF_in;
end
// Page Open Time
always @(posedge PO_in)
begin:POr
if (SPEED100)
#tdevice_PO100 PO_out = PO_in;
end
always @(negedge PO_in)
begin:POf
#1 PO_out = PO_in;
end
// initialize memory and load preoload files if any
initial
begin: InitMemory
integer i;
for (i=0;i<=MemSize;i=i+1)begin
Mem[i]=MaxData;
Mem_time[i] = $time;
end
if (UserPreload && !(mem_file_name == "none"))
$readmemh(mem_file_name,Mem);
end
///////////////////////////////////////////////////////////////////////////
// CKDiff is not actualy diferential clock.
///////////////////////////////////////////////////////////////////////////
assign CKDiff = CK;
///////////////////////////////////////////////////////////////////////////
// Process for clock frequency determination
///////////////////////////////////////////////////////////////////////////
always @(posedge CK)
begin : clk_period
CK_cycle = $time - prev_CK;
prev_CK = $time;
end
///////////////////////////////////////////////////////////////////////////
// Check if device is selected during power up
///////////////////////////////////////////////////////////////////////////
always @(negedge CSNeg_ipd)
begin:CheckCSOnPowerUP
if (~PoweredUp)
$display ("Device is selected during Power Up");
end
always @(rising_edge_CKDiff or falling_edge_CKDiff)
begin : clock_period
if (CSNeg_ipd == 1'b0)
begin
if (DQt_01 > CK_cycle/2)
glitch_dq = 1'b1;
end
end
integer tACC_start_time = 0;
always @(posedge tacc_start)begin
tACC_start_time = $time;
end
always @(rising_edge_CKDiff or falling_edge_CKDiff)
begin : tacc
if(!CSNeg_ipd && tacc_start)begin
tACC_delay = $time - tACC_start_time;
end
end
///////////////////////////////////////////////////////////////////////////
// Bus Cycle Decode
///////////////////////////////////////////////////////////////////////////
integer data_cycle = 0;
integer ca_cnt = 48;
reg [47:0] ca_in ;
reg [15:0] Data_in ;
reg RD_WRAP;
integer Start_BurstAddr;
reg RdWrStart = 1'b0;
reg ALTERNATE_64 = 1'b0;
reg HYBRID = 1'b0;
reg po_out_flag = 1'b0;
reg flag = 1'b0;
always @(rising_edge_CSNeg or falling_edge_CSNeg or
rising_edge_CKDiff or falling_edge_CKDiff or falling_edge_RESETNeg
or rising_edge_REF_out or rising_edge_PO_out)
begin: BusCycle
integer i;
if (current_state == ACT)
begin
case (bus_cycle_state)
STAND_BY:
begin
if (falling_edge_CSNeg)
begin
ca_cnt = 48;
data_cycle = 0;
RW = 1'b0;
RD_WRAP = 1'b0;
RdWrStart = 1'b0;
REFCOLL = 1'b0;
REFCOLL_ACTIV = 1'b0;
ALTERNATE_64 = 1'b0;
HYBRID = 1'b0;
RWDSout_zd_tmp = Config_reg0[3];
bus_cycle_state = CA_BITS;
po_out_flag = 1'b0;
tacc_start = 1'b0;
flag =1'b0;
end
end
CA_BITS:
begin
if (!CSNeg &&
(rising_edge_CKDiff || falling_edge_CKDiff) && !po_out_flag)
begin
for(i=1;i<=8;i=i+1)
ca_in[ca_cnt-i] = Din[8-i];
ca_cnt = ca_cnt - 8;
po_out_flag = 1'b1;
po_out_flag = #2 1'b0;
if (ca_cnt == 40)
begin
REFCOLL = 1'b1;
if (Config_reg0[3] == 1'b1)// fixed latency
begin
REFCOLL_ACTIV = 1'b1;
RWDSout_zd_tmp = 1'b1;
end
else if (Config_reg0[3] == 1'b0) begin// variable latency
if(refresh_pulse)begin
REFCOLL_ACTIV = 1'b1;
RWDSout_zd_tmp = 1'b1;
end else begin
REFCOLL_ACTIV = 1'b0;
RWDSout_zd_tmp = 1'b0;
end
end
end
else if (ca_cnt == 24)
t_RWR_CHK = 1'b1;
else if (ca_cnt == 16)
begin
RW = ca_in[47];
Target = ca_in[46];
if (Target==1'b0 || (Target==1'b1 && RW==1'b1))
begin
if (REFCOLL_ACTIV)
REF_in = 1'b1;
else begin
tacc_start = 1'b1;
PO_in = 1'b1;
end
end
if (Config_reg0[2] == 1'b0)
HYBRID = 1'b1;
if (Config_reg0[1:0] == 2'b00)
begin
BurstLength = 64;
end else if (Config_reg0[1:0] == 2'b01) begin
ALTERNATE_64 = 1'b1;
BurstLength = 32;
end
else if (Config_reg0[1:0] == 2'b10)
BurstLength = 8;
else if (Config_reg0[1:0] == 2'b11)
BurstLength = 16;
if (Config_reg0[7:4] == 4'b0000)
BurstDelay = 5;
else if (Config_reg0[7:4] == 4'b0001)
BurstDelay = 6;
else if (Config_reg0[7:4] == 4'b0010)
BurstDelay = 7;
else if (Config_reg0[7:4] == 4'b1111)
BurstDelay = 4;
else if (Config_reg0[7:4] == 4'b1110)
BurstDelay = 3;
RefreshDelay = BurstDelay;
end
else if (ca_cnt == 8)
begin