SURF  1.0
Synchronizer.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : Synchronizer.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2013-05-13
5 -- Last update: 2016-09-13
6 -------------------------------------------------------------------------------
7 -- Description: A simple multi Flip FLop synchronization module.
8 -- Sets attributes to keep synthesis for mucking with FF chain.
9 -------------------------------------------------------------------------------
10 -- This file is part of 'SLAC Firmware Standard Library'.
11 -- It is subject to the license terms in the LICENSE.txt file found in the
12 -- top-level directory of this distribution and at:
13 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
14 -- No part of 'SLAC Firmware Standard Library', including this file,
15 -- may be copied, modified, propagated, or distributed except according to
16 -- the terms contained in the LICENSE.txt file.
17 -------------------------------------------------------------------------------
18 
19 library ieee;
20 use ieee.std_logic_1164.all;
21 
22 use work.StdRtlPkg.all;
23 
24 --! @see entity
25  --! @ingroup base_sync
26 entity Synchronizer is
27  generic (
28  TPD_G : time := 1 ns;
29  RST_POLARITY_G : sl := '1'; -- '1' for active HIGH reset, '0' for active LOW reset
30  OUT_POLARITY_G : sl := '1'; -- 0 for active LOW, 1 for active HIGH
31  RST_ASYNC_G : boolean := false; -- Reset is asynchronous
32  STAGES_G : positive := 2;
33  BYPASS_SYNC_G : boolean := false; -- Bypass Synchronizer module for synchronous data configuration
34  INIT_G : slv := "0");
35  port (
36  clk : in sl; -- clock to be SYNC'd to
37  rst : in sl := not RST_POLARITY_G; -- Optional reset
38  dataIn : in sl; -- Data to be 'synced'
39  dataOut : out sl); -- synced data
40 end Synchronizer;
41 
42 architecture rtl of Synchronizer is
43 
44  constant INIT_C : slv(STAGES_G-1 downto 0) := ite(INIT_G = "0", slvZero(STAGES_G), INIT_G);
45 
46  signal crossDomainSyncReg : slv(STAGES_G-1 downto 0) := INIT_C;
47  signal rin : slv(STAGES_G-1 downto 0);
48 
49  -------------------------------
50  -- XST/Synplify Attributes
51  -------------------------------
52 
53  -- ASYNC_REG require for Vivado but breaks ISE/XST synthesis
54  attribute ASYNC_REG : string;
55  attribute ASYNC_REG of crossDomainSyncReg : signal is "TRUE";
56 
57  -- Synplify Pro: disable shift-register LUT (SRL) extraction
58  attribute syn_srlstyle : string;
59  attribute syn_srlstyle of crossDomainSyncReg : signal is "registers";
60 
61  -- These attributes will stop timing errors being reported on the target flip-flop during back annotated SDF simulation.
62  attribute MSGON : string;
63  attribute MSGON of crossDomainSyncReg : signal is "FALSE";
64 
65  -- These attributes will stop XST translating the desired flip-flops into an
66  -- SRL based shift register.
67  attribute shreg_extract : string;
68  attribute shreg_extract of crossDomainSyncReg : signal is "no";
69 
70  -- Don't let register balancing move logic between the register chain
71  attribute register_balancing : string;
72  attribute register_balancing of crossDomainSyncReg : signal is "no";
73 
74  -------------------------------
75  -- Altera Attributes
76  -------------------------------
77  attribute altera_attribute : string;
78  attribute altera_attribute of crossDomainSyncReg : signal is "-name AUTO_SHIFT_REGISTER_RECOGNITION OFF";
79 
80 begin
81 
82  assert (STAGES_G >= 2) report "STAGES_G must be >= 2" severity failure;
83 
84  GEN : if (BYPASS_SYNC_G = false) generate
85 
86  comb : process (crossDomainSyncReg, dataIn, rst) is
87  begin
88  rin <= crossDomainSyncReg(STAGES_G-2 downto 0) & dataIn;
89 
90  if (OUT_POLARITY_G = '1') then
91  dataOut <= crossDomainSyncReg(STAGES_G-1);
92  else
93  dataOut <= not(crossDomainSyncReg(STAGES_G-1));
94  end if;
95 
96  end process comb;
97 
98  ASYNC_RST : if (RST_ASYNC_G) generate
99  seq : process (clk, rst) is
100  begin
101  if (rising_edge(clk)) then
102  crossDomainSyncReg <= rin after TPD_G;
103  end if;
104  if (rst = RST_POLARITY_G) then
105  crossDomainSyncReg <= INIT_C after TPD_G;
106  end if;
107  end process seq;
108  end generate ASYNC_RST;
109 
110  SYNC_RST : if (not RST_ASYNC_G) generate
111  seq : process (clk) is
112  begin
113  if (rising_edge(clk)) then
114  if (rst = RST_POLARITY_G) then
115  crossDomainSyncReg <= INIT_C after TPD_G;
116  else
117  crossDomainSyncReg <= rin after TPD_G;
118  end if;
119  end if;
120  end process seq;
121  end generate SYNC_RST;
122 
123  end generate;
124 
125  BYPASS : if (BYPASS_SYNC_G = true) generate
126 
127  dataOut <= dataIn when(OUT_POLARITY_G = '1') else not(dataIn);
128 
129  end generate;
130 
131 end architecture rtl;
INIT_Gslv := "0"
std_logic sl
Definition: StdRtlPkg.vhd:28
in rstsl :=not RST_POLARITY_G
BYPASS_SYNC_Gboolean := false
STAGES_Gpositive := 2
RST_POLARITY_Gsl := '1'
_library_ ieeeieee
out dataOutsl
TPD_Gtime := 1 ns
OUT_POLARITY_Gsl := '1'
RST_ASYNC_Gboolean := false
std_logic_vector slv
Definition: StdRtlPkg.vhd:29