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

Subversion Repositories pcie_sg_dma

[/] [pcie_sg_dma/] [branches/] [Virtex6/] [ML605_ISE12.3/] [ipcore_dir_ISE12.1/] [v6_pcie_v1_3/] [source/] [gtx_tx_sync_rate_v6.v] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 barabba
 
2
//-----------------------------------------------------------------------------
3
//
4
// (c) Copyright 2009 Xilinx, Inc. All rights reserved.
5
//
6
// This file contains confidential and proprietary information of Xilinx, Inc.
7
// and is protected under U.S. and international copyright and other
8
// intellectual property laws.
9
//
10
// DISCLAIMER
11
//
12
// This disclaimer is not a license and does not grant any rights to the
13
// materials distributed herewith. Except as otherwise provided in a valid
14
// license issued to you by Xilinx, and to the maximum extent permitted by
15
// applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL
16
// FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,
17
// IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
18
// MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;
19
// and (2) Xilinx shall not be liable (whether in contract or tort, including
20
// negligence, or under any other theory of liability) for any loss or damage
21
// of any kind or nature related to, arising under or in connection with these
22
// materials, including for any direct, or any indirect, special, incidental,
23
// or consequential loss or damage (including loss of data, profits, goodwill,
24
// or any type of loss or damage suffered as a result of any action brought by
25
// a third party) even if such damage or loss was reasonably foreseeable or
26
// Xilinx had been advised of the possibility of the same.
27
//
28
// CRITICAL APPLICATIONS
29
//
30
// Xilinx products are not designed or intended to be fail-safe, or for use in
31
// any application requiring fail-safe performance, such as life-support or
32
// safety devices or systems, Class III medical devices, nuclear facilities,
33
// applications related to the deployment of airbags, or any other
34
// applications that could lead to death, personal injury, or severe property
35
// or environmental damage (individually and collectively, "Critical
36
// Applications"). Customer assumes the sole risk and liability of any use of
37
// Xilinx products in Critical Applications, subject only to applicable laws
38
// and regulations governing limitations on product liability.
39
//
40
// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
41
// AT ALL TIMES.
42
//
43
//-----------------------------------------------------------------------------
44
// Project    : Virtex-6 Integrated Block for PCI Express
45
// File       : gtx_tx_sync_rate_v6.v
46
//////////////////////////////////////////////////////////////////////////////
47
 
48
`timescale 1ns / 1ps
49
`define DLY #1
50
 
51
module GTX_TX_SYNC_RATE_V6
52
#(
53
    parameter           C_SIMULATION    = 0 // Set to 1 for simulation
54
)
55
(
56
    output              ENPMAPHASEALIGN,
57
    output              PMASETPHASE,
58
    output              SYNC_DONE,
59
    output              OUT_DIV_RESET,
60
    output              PCS_RESET,
61
    output              USER_PHYSTATUS,
62
    output              RATE_CLK_SEL,
63
    input               USER_CLK,
64
    input               RESET,
65
    input               RATE,
66
    input               RATEDONE,
67
    input               GT_PHYSTATUS,
68
    input               RESETDONE,
69
 
70
    // Test bits / status
71
    output      [53:0]  DEBUG_STATUS,
72
    input       [2:0]   ENPMA_STATE_MASK,
73
    input       [2:0]   OUTDIV_STATE_MASK
74
 
75
);
76
 
77
// synthesis attribute X_CORE_INFO of TX_SYNC is "v6_gtxwizard_v1_0, Coregen v11.1_ip1";
78
 
79
//*******************************Register Declarations************************
80
 
81
    reg           begin_r;
82
    reg           phase_align_r;
83
    reg           ready_r;
84
    reg   [15:0]  sync_counter_r;
85
    reg   [5:0]   count_32_cycles_r;
86
    reg           wait_stable_r;
87
    reg           phase_align_reset_r;
88
    reg           out_div_reset_r;
89
    reg           wait_phase_align_reset_r;
90
    reg           pcs_reset_r;
91
    reg           wait_reset_done_r;
92
    reg           gen_phystatus_r;
93
    reg           rate_r;
94
    reg           guard_r;
95
    reg           resetdone_r;
96
    reg           resetdone_r2;
97
    reg           ratedone_r;
98
    reg           ratedone_r2;
99
    reg           rate_sel_r;
100
 
101
    reg           enpmaphasealign_r;
102
    reg           reg_out_div_reset_r;
103
    reg   [24:0]  rate_duration_count_r;
104
 
105
 
106
//*******************************Wire Declarations****************************
107
 
108
    wire          count_setphase_complete_i;
109
    wire          count_32_complete_i;
110
    wire          next_phase_align_c;
111
    wire          next_ready_c;
112
    wire          next_wait_stable_c;
113
    wire          next_phase_align_reset_c;
114
    wire          next_out_div_reset_c;
115
    wire          next_wait_phase_align_reset_c;
116
    wire          next_pcs_reset_c;
117
    wire          next_wait_reset_done_c;
118
    wire          next_gen_phystatus_c;
119
    wire          ratedone_pulse_i;
120
 
121
    wire          enpmaphasealign_i;
122
    wire          out_div_reset_i;
123
 
124
//*******************************Main Body of Code****************************
125
 
126
 
127
 
128
 
129
    //________________________________ State machine __________________________
130
    // This state machine manages the phase alingment procedure of the GTX.
131
    // The module is held in reset till the usrclk source is stable.  In the 
132
    // case of buffer bypass where the refclkout is used to clock the usrclks,
133
    // the usrclk stable indication is given the pll_locked signal.
134
    // Once the pll_lock is asserted, state machine goes into the
135
    // wait_stable_r for 32 clock cycles to allow some time to ensure the pll
136
    // is stable. After this, it goes into the phase_align_r state where the
137
    // phase alignment procedure is executed. This involves asserting the
138
    // ENPMAPHASEALIGN and PMASETPHASE for 32768 clock cycles.
139
    //
140
    // If there is a line rate change, the module resets the output divider by
141
    // asserting the signal for 16 clock cycles and resets the phase alignment
142
    // block by de-asserting ENPMAPHASEALIGN signal for 16 clock cycles.  The
143
    // phase alignment procedure as stated above is repeated.  Afterwards, the
144
    // PCS is reset and a user PHYSTATUS is generated to notify the completion
145
    // of a line rate change procedure.
146
 
147
    // State registers
148
    always @(posedge USER_CLK)
149
        if(RESET)
150
            {begin_r, wait_stable_r, phase_align_r, ready_r,
151
             phase_align_reset_r, out_div_reset_r, wait_phase_align_reset_r,
152
             pcs_reset_r, wait_reset_done_r,
153
             gen_phystatus_r}  <=  `DLY 10'b10_0000_0000;
154
        else
155
        begin
156
            begin_r                   <=  `DLY  1'b0;
157
            wait_stable_r             <=  `DLY  next_wait_stable_c;
158
            phase_align_r             <=  `DLY  next_phase_align_c;
159
            ready_r                   <=  `DLY  next_ready_c;
160
            phase_align_reset_r       <=  `DLY  next_phase_align_reset_c;
161
            out_div_reset_r           <=  `DLY  next_out_div_reset_c;
162
            wait_phase_align_reset_r  <=  `DLY  next_wait_phase_align_reset_c;
163
            pcs_reset_r               <=  `DLY  next_pcs_reset_c;
164
            wait_reset_done_r         <=  `DLY  next_wait_reset_done_c;
165
            gen_phystatus_r           <=  `DLY  next_gen_phystatus_c;
166
        end
167
 
168
    // Next state logic
169
    assign next_ready_c              = (((phase_align_r & count_setphase_complete_i) & !guard_r) | gen_phystatus_r) |
170
                                      (!ratedone_pulse_i & ready_r);
171
 
172
    assign next_phase_align_reset_c = (ratedone_pulse_i & ready_r) |
173
                                      (phase_align_reset_r & !count_32_complete_i);
174
 
175
    assign next_out_div_reset_c     = (phase_align_reset_r & count_32_complete_i)|
176
                                      (out_div_reset_r & !count_32_complete_i);
177
 
178
    assign next_wait_phase_align_reset_c = (out_div_reset_r & count_32_complete_i) |
179
                                           (wait_phase_align_reset_r & !count_32_complete_i);
180
 
181
    assign next_wait_stable_c       = begin_r | (wait_phase_align_reset_r & count_32_complete_i) |
182
                                      (wait_stable_r & !count_32_complete_i);
183
 
184
    assign next_phase_align_c       = (wait_stable_r & count_32_complete_i) |
185
                                      (phase_align_r & !count_setphase_complete_i);
186
 
187
    assign next_pcs_reset_c         = ((phase_align_r & count_setphase_complete_i) & guard_r);
188
 
189
    assign next_wait_reset_done_c   = pcs_reset_r |
190
                                      (!resetdone_r2 & wait_reset_done_r);
191
 
192
    assign next_gen_phystatus_c     = resetdone_r2 & wait_reset_done_r;
193
 
194
 
195
        //_________ Counter for to wait for pll to be stable before sync __________
196
    always @(posedge USER_CLK)
197
    begin
198
        if (RESET || count_32_complete_i)
199
            count_32_cycles_r <= `DLY  6'b000000;
200
        else if (wait_stable_r || out_div_reset_r || phase_align_reset_r || wait_phase_align_reset_r)
201
            count_32_cycles_r <= `DLY  count_32_cycles_r + 1'b1;
202
    end
203
 
204
    assign count_32_complete_i = count_32_cycles_r[5];
205
 
206
    //_______________ Counter for holding SYNC for SYNC_CYCLES ________________
207
    always @(posedge USER_CLK)
208
    begin
209
        if (!phase_align_r)
210
            sync_counter_r <= `DLY  16'h0000;
211
        else
212
            sync_counter_r <= `DLY  sync_counter_r + 1'b1;
213
    end
214
 
215
    generate
216
        if (C_SIMULATION) begin: for_simulation
217
            // Shorten the cycle to 32 clock cycles for simulation
218
            assign count_setphase_complete_i = sync_counter_r[5];
219
        end
220
        else begin: for_hardware
221
            // For TXPMASETPHASE:
222
            //  - If RATE[0] = 0, PLL_DIVSEL_OUT = 2 => 16,384 USRCLK2 cycles
223
            //  - If RATE[0] = 1, PLL_DIVSEL_OUT = 1 => 8,192 USRCLK2 cycles
224
            assign count_setphase_complete_i = (rate_r) ? sync_counter_r[13] :
225
                                                          sync_counter_r[14];
226
        end
227
    endgenerate
228
 
229
 
230
    //_______________ Assign the phase align ports into the GTX _______________
231
 
232
    // Assert the ENPMAPHASEALIGN signal when the reset of this module
233
    // gets de-asserted and after a reset of the output dividers.  Disabling
234
    // this signal after reset of the output dividers will reset the phase
235
    // alignment module.
236
    //assign ENPMAPHASEALIGN = !(begin_r | phase_align_reset_r | out_div_reset_r | wait_phase_align_reset_r);
237
 
238
    // Masking the bits of each state to play around with the pulse of the
239
    // TXENPMAPHASEALIGN reset (active low signal)
240
    assign enpmaphasealign_i = ~((begin_r ||
241
                               (phase_align_reset_r && ENPMA_STATE_MASK[2]) ||
242
                               (out_div_reset_r && ENPMA_STATE_MASK[1]) ||
243
                               (wait_phase_align_reset_r && ENPMA_STATE_MASK[0])));
244
 
245
    always @(posedge USER_CLK)
246
        if (RESET)
247
            enpmaphasealign_r <= `DLY 1'b0;
248
        else
249
            enpmaphasealign_r <= enpmaphasealign_i;
250
 
251
    assign ENPMAPHASEALIGN = enpmaphasealign_r;
252
 
253
    assign PMASETPHASE     = phase_align_r;
254
 
255
 
256
    //_______________________ Assign the sync_done port _______________________
257
 
258
    // Assert the SYNC_DONE signal when the phase alignment procedure is
259
    // complete after initialization and when line rate change procedure
260
    // is complete.
261
    assign SYNC_DONE = ready_r & !guard_r;
262
 
263
 
264
    //_______________________ Assign the rest of the ports ____________________
265
    // Assert the output divider reset for 32 USRCLK2 clock cycles
266
    //assign OUT_DIV_RESET = out_div_reset_r;
267
 
268
    // Masking the bits of each state to play around with the pulse of the
269
    // output divider reset
270
    assign out_div_reset_i= (phase_align_reset_r && OUTDIV_STATE_MASK[2]) ||
271
                           (out_div_reset_r && OUTDIV_STATE_MASK[1]) ||
272
                           (wait_phase_align_reset_r && OUTDIV_STATE_MASK[0]);
273
 
274
    always @(posedge USER_CLK)
275
        if (RESET)
276
            reg_out_div_reset_r <= `DLY 1'b0;
277
        else
278
            reg_out_div_reset_r <= out_div_reset_i;
279
 
280
    assign OUT_DIV_RESET = reg_out_div_reset_r;
281
 
282
    // Assert the PCS reset for 1 USRCLK2 clock cycle
283
    assign PCS_RESET = pcs_reset_r;
284
 
285
 
286
    // Assert user phystatus at the end of the line rate change.  It is also
287
    // a pass through signal from the GTX when the pulse is not associated
288
    // with a line rate change (in this module this signal is gated by
289
    // guard_r signal)
290
    assign USER_PHYSTATUS = gen_phystatus_r | (GT_PHYSTATUS & !guard_r);
291
 
292
 
293
    //////////////////////////////////////////////////////////////////////////
294
    // Register the RESETDONE input
295
    //////////////////////////////////////////////////////////////////////////
296
    always @(posedge USER_CLK)
297
 
298
    begin
299
        if (RESET | pcs_reset_r)
300
        begin
301
            resetdone_r   <= `DLY 1'b0;
302
            resetdone_r2  <= `DLY 1'b0;
303
        end
304
        else
305
        begin
306
            resetdone_r   <= `DLY RESETDONE;
307
            resetdone_r2  <= `DLY resetdone_r;
308
        end
309
    end
310
 
311
    //////////////////////////////////////////////////////////////////////////
312
    // Detect an edge on the RATEDONE signal and generate a pulse from it.
313
    // The RATEDONE signal by default is initialized to 1'b1.
314
    //////////////////////////////////////////////////////////////////////////
315
    always @(posedge USER_CLK)
316
 
317
    begin
318
        if (RESET)
319
        begin
320
            ratedone_r  <= `DLY 1'b0;
321
            ratedone_r2 <= `DLY 1'b0;
322
        end
323
        else
324
        begin
325
            ratedone_r  <= `DLY RATEDONE;
326
            ratedone_r2 <= `DLY ratedone_r;
327
        end
328
    end
329
 
330
    assign ratedone_pulse_i = ratedone_r & !ratedone_r2;
331
 
332
    //////////////////////////////////////////////////////////////////////////
333
    // Detect a line rate change.  Since this is targeted for PCIe, we only
334
    // need to detect a change on TXRATE[0]/RXRATE[0]:
335
    // TXRATE[1:0] / RXRATE[1:0] = 10 for output divider /2
336
    // TXRATE[1:0] / RXRATE[1:0] = 11 for output divider /1
337
    //////////////////////////////////////////////////////////////////////////
338
    always @(posedge USER_CLK)
339
    begin
340
        rate_r <= `DLY RATE;
341
    end
342
 
343
    assign rate_change_i = rate_r ^ RATE;
344
 
345
 
346
    //////////////////////////////////////////////////////////////////////////
347
    // Generate an internal "guard" signal to denote that the line rate
348
    // sequence of operation initiated.  This signal is driven High when the
349
    // there is a rate change trigger by a change in TXRATE or RXRATE ports.
350
    //////////////////////////////////////////////////////////////////////////
351
    always @(posedge USER_CLK)
352
    begin
353
        if (RESET | gen_phystatus_r)
354
            guard_r <= `DLY 1'b0;
355
        else if (rate_change_i == 1'b1)
356
            guard_r <= `DLY 1'b1;
357
    end
358
 
359
 
360
    //////////////////////////////////////////////////////////////////////////
361
    // Generate the BUFGMUX select signal that selects the correct clock to
362
    // used based on a rate change.  For PCIe:
363
    //  - RATE[0] = 0 => Use 125 MHz USRCLK2 with RATE_CLK_SEL = 0
364
    //  - RATE[0] = 1 => Use 250 MHz USRCLK2 with RATE_CLK_SEL = 1
365
    // The RATE_CLK_SEL changes based on the RATEDONE signal from the GTX.
366
    // The default of this pin is set to 1'b0.  Someone can change it to grab
367
    // the value from a parameter if the reset value has to be another value
368
    // other than 1'b0.
369
    //////////////////////////////////////////////////////////////////////////
370
    always @(posedge USER_CLK)
371
    begin
372
        if (RESET)
373
            rate_sel_r <= `DLY 1'b0;
374
        else if (ratedone_pulse_i == 1'b1)
375
            rate_sel_r <= `DLY rate_r;
376
    end
377
 
378
    assign RATE_CLK_SEL = rate_sel_r;
379
 
380
    //////////////////////////////////////////////////////////////////////////
381
    // Create a counter that starts when guard_r is High.  After
382
    // guard_r gets de-asserted, the counter stops counting.  The counter gets
383
    // reset when there is a rate change applied from the user; this rate
384
    // change pulse occurs one USER_CLK cycle earlier than guard_r.  
385
    //////////////////////////////////////////////////////////////////////////
386
    always @(posedge USER_CLK)
387
    begin
388
        if (RESET | rate_change_i)
389
            rate_duration_count_r <= `DLY 25'b0_0000_0000_0000_0000_0000_0000;
390
        else if (guard_r)
391
            rate_duration_count_r <= `DLY rate_duration_count_r + 1'b1;
392
        else
393
            rate_duration_count_r <= `DLY rate_duration_count_r;
394
    end
395
 
396
 
397
    //Monitoring the signals on ILa
398
    assign DEBUG_STATUS= {sync_counter_r[15:0],       //[53:38]
399
                          rate_r,                     //[37]
400
                          rate_duration_count_r[24:0],//[36:12]
401
                          begin_r,                    //[11]
402
                          wait_stable_r,              //[10]
403
                          phase_align_r,              //[9]
404
                          ready_r,                    //[8]
405
                          phase_align_reset_r,        //[7]
406
                          out_div_reset_r,            //[6]
407
                          wait_phase_align_reset_r,   //[5]
408
                          pcs_reset_r,                //[4]
409
                          wait_reset_done_r,          //[3]
410
                          gen_phystatus_r,            //[2]
411
                          guard_r,                    //[1]
412
                          rate_change_i};             //[0]
413
endmodule

powered by: WebSVN 2.1.0

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