SURF  1.0
SynchronizerEdge.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SynchronizerEdge.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2013-05-13
5 -- Last update: 2016-09-22
6 -------------------------------------------------------------------------------
7 -- Description: A simple multi Flip FLop synchronization module.
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  BYPASS_SYNC_G : boolean := false; -- Bypass Synchronizer module for synchronous data configuration
32  STAGES_G : positive := 3;
33  INIT_G : slv := "0");
34  port (
35  clk : in sl; -- clock to be SYNC'd to
36  rst : in sl := not RST_POLARITY_G; -- Optional reset
37  dataIn : in sl; -- Data to be 'synced'
38  dataOut : out sl; -- synced data
39  risingEdge : out sl; -- Rising edge detected
40  fallingEdge : out sl); -- Falling edge detected
41 end SynchronizerEdge;
42 
43 architecture rtl of SynchronizerEdge is
44 
45  constant INIT_C : slv(STAGES_G-1 downto 0) := ite(INIT_G = "0", slvZero(STAGES_G), INIT_G);
46 
47  type RegType is record
48  syncDataDly : sl;
49  dataOut : sl;
50  risingEdge : sl;
51  fallingEdge : sl;
52  end record RegType;
53  constant REG_INIT_C : RegType := (
54  '0',
55  (not OUT_POLARITY_G),
56  (not OUT_POLARITY_G),
57  (not OUT_POLARITY_G));
58  signal r : RegType := REG_INIT_C;
59  signal rin : RegType;
60  signal syncData : sl;
61 
62 begin
63 
64  assert (STAGES_G >= 3) report "STAGES_G must be >= 3" severity failure;
65 
66  Synchronizer_Inst : entity work.Synchronizer
67  generic map (
68  TPD_G => TPD_G,
70  OUT_POLARITY_G => '1',
72  STAGES_G => (STAGES_G-1),
74  INIT_G => INIT_C(STAGES_G-2 downto 0))
75  port map (
76  clk => clk,
77  rst => rst,
78  dataIn => dataIn,
79  dataOut => syncData);
80 
81  comb : process (r, rst, syncData) is
82  variable v : RegType;
83  begin
84  -- Latch the current value
85  v := r;
86 
87  -- Reset strobe signals
88  v.risingEdge := not OUT_POLARITY_G;
89  v.fallingEdge := not OUT_POLARITY_G;
90 
91  -- Keep a record of the last syncData
92  v.syncDataDly := syncData;
93 
94  -- Set the polarity of the output
95  if (OUT_POLARITY_G = '1') then
96  v.dataOut := syncData;
97  else
98  v.dataOut := not(syncData);
99  end if;
100 
101  -- Check for a rising edge of the syncData
102  if (syncData = '1') and (r.syncDataDly = '0') then
104  end if;
105 
106  -- Check for a rising edge of the syncData
107  if (syncData = '0') and (r.syncDataDly = '1') then
109  end if;
110 
111  -- Sync Reset
112  if (RST_ASYNC_G = false and rst = RST_POLARITY_G) then
113  v := REG_INIT_C;
114  v.syncDataDly := syncData; -- prevent accidental edge detection
115  end if;
116 
117  -- Register the variable for next clock cycle
118  rin <= v;
119 
120  -- Outputs
121  dataOut <= r.dataOut;
122  risingEdge <= r.risingEdge;
124 
125  end process comb;
126 
127  seq : process (clk, rst, syncData) is
128  begin
129  if rising_edge(clk) then
130  r <= rin after TPD_G;
131  end if;
132  -- Async Reset
133  if (RST_ASYNC_G and rst = RST_POLARITY_G) then
134  r <= REG_INIT_C after TPD_G;
135  r.syncDataDly <= syncData after TPD_G; -- prevent accidental edge detection
136  end if;
137  end process seq;
138 
139 end architecture rtl;
INIT_Gslv := "0"
RST_ASYNC_Gboolean := false
std_logic sl
Definition: StdRtlPkg.vhd:28
in rstsl :=not RST_POLARITY_G
BYPASS_SYNC_Gboolean := false
STAGES_Gpositive := 2
_library_ ieeeieee
RST_POLARITY_Gsl := '1'
out dataOutsl
in rstsl :=not RST_POLARITY_G
TPD_Gtime := 1 ns
STAGES_Gpositive := 3
OUT_POLARITY_Gsl := '1'
RST_ASYNC_Gboolean := false
BYPASS_SYNC_Gboolean := false
std_logic_vector slv
Definition: StdRtlPkg.vhd:29