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