SURF  1.0
SynchronizerOneShot.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SynchronizerOneShot.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2014-02-06
5 -- Last update: 2016-11-04
6 -------------------------------------------------------------------------------
7 -- Description: One-Shot Pulser that has to cross clock domains
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; -- Simulation FF output delay
28  RST_POLARITY_G : sl := '1'; -- '1' for active HIGH reset, '0' for active LOW reset
29  RST_ASYNC_G : boolean := false; -- Reset is asynchronous
30  BYPASS_SYNC_G : boolean := false; -- Bypass RstSync module for synchronous data configuration
31  RELEASE_DELAY_G : positive := 3; -- Delay between deassertion of async and sync resets
32  IN_POLARITY_G : sl := '1'; -- 0 for active LOW, 1 for active HIGH
33  OUT_POLARITY_G : sl := '1'; -- 0 for active LOW, 1 for active HIGH
34  PULSE_WIDTH_G : positive := 1); -- one-shot pulse width duration (units of clk cycles)
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; -- Trigger to be sync'd
39  dataOut : out sl); -- synced one-shot pulse
40 end SynchronizerOneShot;
41 
42 architecture rtl of SynchronizerOneShot is
43 
44  type StateType is (
45  IDLE_S,
46  CNT_S);
47 
48  type RegType is record
49  cnt : natural range 0 to (PULSE_WIDTH_G-1);
50  dataOut : sl;
51  state : StateType;
52  end record RegType;
53 
54  constant REG_INIT_C : RegType := (
55  cnt => 0,
56  dataOut => not(OUT_POLARITY_G),
57  state => IDLE_S);
58 
59  signal r : RegType := REG_INIT_C;
60  signal rin : RegType;
61 
62  signal pulseRst : sl;
63  signal edgeDet : sl;
64 
65  -- attribute dont_touch : string;
66  -- attribute dont_touch of r : signal is "true";
67 
68 begin
69 
70  RstSync_Inst : entity work.RstSync
71  generic map (
72  TPD_G => TPD_G,
76  OUT_POLARITY_G => '1')
77  port map (
78  clk => clk,
79  asyncRst => dataIn,
80  syncRst => pulseRst);
81 
82  Sync_Pulse : entity work.SynchronizerEdge
83  generic map (
84  TPD_G => TPD_G,
89  port map (
90  clk => clk,
91  dataIn => pulseRst,
92  risingEdge => edgeDet);
93 
94  U_OnlyCyclePulse : if (PULSE_WIDTH_G = 1) generate
95  dataOut <= edgeDet;
96  end generate;
97 
98  U_PulseStretcher : if (PULSE_WIDTH_G > 1) generate
99 
100  comb : process (edgeDet, r, rst) is
101  variable v : RegType;
102  begin
103  -- Latch the current value
104  v := r;
105 
106  -- State Machine
107  case r.state is
108  ----------------------------------------------------------------------
109  when IDLE_S =>
110  -- Reset the flag
111  v.dataOut := not(OUT_POLARITY_G);
112  -- Check for edge detection
113  if (edgeDet = OUT_POLARITY_G) then
114  -- Next state
115  v.state := CNT_S;
116  end if;
117  ----------------------------------------------------------------------
118  when CNT_S =>
119  -- Set the flag
120  v.dataOut := OUT_POLARITY_G;
121  -- Check the counter
122  if r.cnt = (PULSE_WIDTH_G-1) then
123  -- Reset the counter
124  v.cnt := 0;
125  -- Next state
126  v.state := IDLE_S;
127  else
128  -- Increment the counter
129  v.cnt := r.cnt + 1;
130  end if;
131  ----------------------------------------------------------------------
132  end case;
133 
134  -- Reset
135  if (rst = RST_POLARITY_G) then
136  v := REG_INIT_C;
137  end if;
138 
139  -- Register the variable for next clock cycle
140  rin <= v;
141 
142  -- Outputs
143  dataOut <= v.dataOut;
144 
145  end process;
146 
147  seq : process (clk) is
148  begin
149  if rising_edge(clk) then
150  r <= rin after TPD_G;
151  end if;
152  end process seq;
153 
154  end generate;
155 
156 end architecture rtl;
out syncRstsl
Definition: RstSync.vhd:36
RST_ASYNC_Gboolean := false
IN_POLARITY_Gsl := '1'
Definition: RstSync.vhd:28
std_logic sl
Definition: StdRtlPkg.vhd:28
in asyncRstsl
Definition: RstSync.vhd:35
in clksl
Definition: RstSync.vhd:34
OUT_POLARITY_Gsl := '1'
Definition: RstSync.vhd:29
BYPASS_SYNC_Gboolean := false
Definition: RstSync.vhd:30
RST_ASYNC_Gboolean := false
in rstsl :=not RST_POLARITY_G
RELEASE_DELAY_Ginteger range 3 to positive'high:= 3
Definition: RstSync.vhd:31
BYPASS_SYNC_Gboolean := false
TPD_Gtime := 1 ns
Definition: RstSync.vhd:27
_library_ ieeeieee
BYPASS_SYNC_Gboolean := false