Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / model / verilog / mem / fbdimm / design / training_sequence_fsm.v
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: training_sequence_fsm.v
4// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
5// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
6//
7// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8//
9// This program is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; version 2 of the License.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21//
22// For the avoidance of doubt, and except that if any non-GPL license
23// choice is available it will apply instead, Sun elects to use only
24// the General Public License version 2 (GPLv2) at this time for any
25// software where a choice of GPL license versions is made
26// available with the language indicating that GPLv2 or any later version
27// may be used, or where a choice of which version of the GPL is applied is
28// otherwise unspecified.
29//
30// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
31// CA 95054 USA or visit www.sun.com if you need additional information or
32// have any questions.
33//
34// ========== Copyright Header End ============================================
35`ifdef AXIS_FBDIMM_NO_FSR
36`else
37module training_sequence_fsm(ps_bit,
38 ps_bit_bar,
39 link_clk,amb_id,
40 training_sequence_start,
41 training_sequence_end,
42 amb_id_ok,
43 frm_align);
44
45
46parameter DS=0;
47
48input ps_bit,ps_bit_bar;
49input link_clk;
50output [3:0] amb_id;
51output training_sequence_end;
52input training_sequence_start;
53output amb_id_ok;
54output frm_align;
55
56reg [2:0] SB2NB_Map;
57
58reg [11:0] tr_reg;
59reg [4:0] tr_state;
60reg [4:0] tr_count;
61reg [11:0] clk_trn_ptrn;
62reg [3:0] clk_grp;
63reg ts0_ready_reg;
64reg [3:0] amb_id_reg;
65reg [23:0] test_param_reg;
66reg [7:8] test_param_count;
67reg frm_align_reg;
68
69assign frm_align = frm_align_reg;
70
71assign amb_id=amb_id_reg;
72//assign amb_id_ok = (amb_id_reg == DS) ? 1'b1 : 1'b0;
73
74wire training_sequence_start_d12;
75assign training_sequence_end=ts0_ready_reg;
76initial begin
77tr_state=0;
78tr_count=0;
79test_param_count=0;
80end
81
82wire [9:0] delay_reg = 10'd12;
83
84
85shifter_p #(1) train_delay (.signal_in ( training_sequence_start ),
86 .signal_out ( training_sequence_start_d12),
87 .delay_cycles (delay_reg),
88 .clk (link_clk));
89
90
91initial
92 amb_id_reg=0;
93
94always@(negedge link_clk) if ( training_sequence_start ) // _d12 && ( ps_bit !== ps_bit_bar) )
95begin
96 case(tr_state)
97 `IDLE: begin
98 tr_reg[11:0] = {ps_bit, tr_reg[11:1] };
99
100 if ( training_sequence_start_d12 && ( ps_bit !== ps_bit_bar) )
101 begin
102 // if beginning of ts1 is detected
103 if ( {ps_bit, tr_reg[11:1] } == 12'b111111111110 )
104 ts0_ready_reg<=1;
105 else
106 ts0_ready_reg<=0;
107
108 if ( {ps_bit, tr_reg[11:1] } == 12'b101111111110 ) begin
109 tr_state<=`TS_TRAIN_1;
110
111`ifdef FBD_DBG
112 // `PR_ALWAYS ("amb_init",`DBG_0,"Detected TRAINING");
113`endif
114 frm_align_reg<=1;
115 end
116 else
117 frm_align_reg<=0;
118 end // if training_sequence_start_d12
119
120 end
121 `TS_TRAIN_1: begin
122 case(tr_count)
123 4'b0000: begin tr_reg[0] = ps_bit; tr_count=tr_count+1; end
124 4'b0001: begin tr_reg[1] = ps_bit; tr_count=tr_count+1; end
125 4'b0010: begin tr_reg[2] = ps_bit; tr_count=tr_count+1;end
126 4'b0011: begin tr_reg[3] = ps_bit; tr_count=tr_count+1; end
127 4'b0100: begin tr_reg[4] = ps_bit; tr_count=tr_count+1; end
128 4'b0101: begin tr_reg[5] = ps_bit; tr_count=tr_count+1; end
129 4'b0110: begin tr_reg[6] = ps_bit; tr_count=tr_count+1; end
130 4'b0111: begin tr_reg[7] = ps_bit; tr_count=tr_count+1; end
131 4'b1000: begin tr_reg[8] = ps_bit; tr_count=tr_count+1; end
132 4'b1001: begin tr_reg[9] = ps_bit; tr_count=tr_count+1; end
133 4'b1010: begin tr_reg[10] = ps_bit; tr_count=tr_count+1; end
134 4'b1011: begin tr_reg[11] = ps_bit; tr_state<=`TS_TRAIN_2;
135 tr_count=1;clk_grp=0; amb_id_reg[3:0]={tr_reg[11],tr_reg[9],tr_reg[7],tr_reg[5]};
136
137`ifdef FBD_DBG
138 // `PR_ALWAYS ("amb_init",`DBG_4,"Control values: pattern = %h ambid=%h",{tr_reg[10],tr_reg[8],tr_reg[6],tr_reg[4:0]},{tr_reg[11],tr_reg[9],tr_reg[7],tr_reg[5]});
139`endif
140 end
141 endcase
142 // tr_count=tr_count+1;
143 end
144 `TS_TRAIN_2: begin // group 11-2: pg 27 of Jedec Spec
145
146 case(tr_count)
147 4'b0001: begin clk_trn_ptrn[0] = ps_bit; tr_count=tr_count+1; end
148 4'b0010: begin clk_trn_ptrn[1] = ps_bit; tr_count=tr_count+1; end
149 4'b0011: begin clk_trn_ptrn[2] = ps_bit; tr_count=tr_count+1; end
150 4'b0100: begin clk_trn_ptrn[3] = ps_bit; tr_count=tr_count+1; end
151 4'b0101: begin clk_trn_ptrn[4] = ps_bit; tr_count=tr_count+1; end
152 4'b0110: begin clk_trn_ptrn[5] = ps_bit; tr_count=tr_count+1; end
153 4'b0111: begin clk_trn_ptrn[6] = ps_bit; tr_count=tr_count+1; end
154 4'b1000: begin clk_trn_ptrn[7] = ps_bit; tr_count=tr_count+1; end
155 4'b1001: begin clk_trn_ptrn[8] = ps_bit; tr_count=tr_count+1; end
156 4'b1010: begin clk_trn_ptrn[9] = ps_bit; tr_count=tr_count+1; end
157 4'b1011: begin clk_trn_ptrn[10] = ps_bit; tr_count=tr_count+1; end
158 4'b1100: begin clk_trn_ptrn[11] = ps_bit; clk_grp=clk_grp+1; tr_count=1;
159`ifdef FBD_DBG
160// `PR_ALWAYS ("amb_init",`DBG_4,"Getting clock training sequence_%h-> %b",clk_grp,clk_trn_ptrn);
161`endif
162 end
163 endcase
164 if ( clk_grp == 4'ha )
165 begin
166 tr_state<=`IDLE;
167 end
168 end
169 endcase
170
171
172end
173else
174 ts0_ready_reg<=0;
175
176endmodule
177
178
179
180
181module training_sequence_fsm_chk(ps_bit,ps_bit_bar,link_clk,training_sequence_start);
182
183
184parameter DS=0;
185
186input ps_bit,ps_bit_bar;
187input link_clk;
188input training_sequence_start;
189
190
191reg [2:0] SB2NB_Map;
192
193reg [143:0] tr_reg;
194reg [4:0] tr_state;
195reg [8:0] tr_count;
196reg [11:0] clk_trn_ptrn;
197reg [3:0] clk_grp;
198reg ts0_ready_reg;
199reg [3:0] amb_id_reg;
200reg [23:0] test_param_reg;
201reg [7:8] test_param_count;
202reg frm_align_reg;
203reg [9:0] ts0_frm_cnt;
204
205
206initial begin
207tr_state=0;
208tr_count=0;
209ts0_frm_cnt=0;
210test_param_count=0;
211end
212
213
214initial
215 tr_count=0;
216
217always@(posedge link_clk) if ( training_sequence_start && (ps_bit !== ps_bit_bar) )
218begin
219 case(tr_state)
220 `IDLE: begin
221 //ts0_ready_reg=0;
222 tr_reg[142:0] = tr_reg[143:1];
223 tr_reg[143] = ps_bit;
224
225 if (tr_reg[143:132] == 12'b101111111110 )
226 tr_state=`TS_TRAIN_1;
227
228 // if beginning of ts1 is detected
229 if (tr_reg[11:0] == 12'b111111111110 )
230 begin
231`ifdef AXIS_FBDIMM_HW
232`else
233 if ( ts0_frm_cnt < 200 )
234 `PR_ALWAYS ("ch_mon",`DBG_0,"ERROR: Approximate # of TS0 Patterns(268) not met => Only %d frames ",ts0_frm_cnt);
235`endif
236
237 end
238
239 end
240 `TS_TRAIN_1: begin
241 tr_reg[142:0] = tr_reg[143:1];
242 tr_reg[143] = ps_bit;
243 tr_count=tr_count+1;
244
245 if ( (tr_count == 8'h84) && (tr_reg[143:0] != 0 ) ) begin
246 ts0_frm_cnt= ts0_frm_cnt +1;
247`ifdef AXIS_FBDIMM_HW
248`else
249 if ( tr_reg[11:0] != 12'hbfe )
250 `PR_ALWAYS ("ch_mon",`DBG_0,"ERROR: bfe pattern not found for training state ");
251
252 if ( {tr_reg[22],tr_reg[20],tr_reg[18],tr_reg[16:12]} != {1'b0,1'b0,1'b0,5'b01010} )
253 `PR_ALWAYS ("ch_mon",`DBG_0,"ERROR: grp1 pattern in training is wrong! ");
254
255 if ( tr_reg[143:24] != 120'haaaaaaaaaaaaaaaaaaaaaaaaaaaaaa )
256 `PR_ALWAYS ("ch_mon",`DBG_0,"ERROR: clock training patterns has errors in training state ");
257`endif
258
259 tr_count=0;
260 tr_state=`IDLE;
261 end
262 end
263
264 endcase
265end
266
267
268endmodule
269
270
271`endif // AXIS_FBDIMM_HW