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

Subversion Repositories sgmii

[/] [sgmii/] [trunk/] [sim/] [BFMs/] [SGMII_altera/] [triple_speed_ethernet-library/] [altera_tse_xcvr_resync.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 jefflieu
// Module: altera_tse_xcvr_resync
2
//
3
// Description:
4
//  A general purpose resynchronization module.
5
//  
6
//  Parameters:
7
//    SYNC_CHAIN_LENGTH
8
//      - Specifies the length of the synchronizer chain for metastability
9
//        retiming.
10
//    WIDTH
11
//      - Specifies the number of bits you want to synchronize. Controls the width of the
12
//        d and q ports.
13
//    SLOW_CLOCK - USE WITH CAUTION. 
14
//      - Leaving this setting at its default will create a standard resynch circuit that
15
//        merely passes the input data through a chain of flip-flops. This setting assumes
16
//        that the input data has a pulse width longer than one clock cycle sufficient to
17
//        satisfy setup and hold requirements on at least one clock edge.
18
//      - By setting this to 1 (USE CAUTION) you are creating an asynchronous
19
//        circuit that will capture the input data regardless of the pulse width and 
20
//        its relationship to the clock. However it is more difficult to apply static
21
//        timing constraints as it ties the data input to the clock input of the flop.
22
//        This implementation assumes the data rate is slow enough
23
//
24
module altera_tse_xcvr_resync #(
25
    parameter SYNC_CHAIN_LENGTH = 2,  // Number of flip-flops for retiming
26
    parameter WIDTH             = 1,  // Number of bits to resync
27
    parameter SLOW_CLOCK        = 0   // See description above
28
  ) (
29
  input   wire              clk,
30
  input   wire  [WIDTH-1:0] d,
31
  output  wire  [WIDTH-1:0] q
32
  );
33
 
34
localparam  INT_LEN   = (SYNC_CHAIN_LENGTH > 0) ? SYNC_CHAIN_LENGTH : 1;
35
 
36
genvar ig;
37
 
38
// Generate a synchronizer chain for each bit
39
generate begin
40
  for(ig=0;ig<WIDTH;ig=ig+1) begin : resync_chains
41
    wire                d_in;   // Input to sychronization chain.
42
    reg   [INT_LEN-1:0] r = {INT_LEN{1'b0}};
43
    wire  [INT_LEN  :0] next_r; // One larger real chain
44
 
45
    assign  q[ig]   = r[INT_LEN-1]; // Output signal
46
    assign  next_r  = {r,d_in};
47
 
48
    always @(posedge clk)
49
      r <= next_r[INT_LEN-1:0];
50
 
51
    // Generate asynchronous capture circuit if specified.
52
    if(SLOW_CLOCK == 0) begin
53
      assign  d_in = d[ig];
54
    end else begin
55
      wire  d_clk;
56
      reg   d_r;
57
      wire  clr_n;
58
 
59
      assign  d_clk = d[ig];
60
      assign  d_in  = d_r;
61
      assign  clr_n = ~q[ig] | d_clk; // Clear when output is logic 1 and input is logic 0
62
 
63
      // Asynchronously latch the input signal.
64
      always @(posedge d_clk or negedge clr_n)
65
        if(!clr_n)      d_r <= 1'b0;
66
        else if(d_clk)  d_r <= 1'b1;
67
    end // SLOW_CLOCK
68
  end // for loop
69
end // generate
70
endgenerate
71
 
72
endmodule

powered by: WebSVN 2.1.0

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