SURF  1.0
SlvDelay.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SlvDelay.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-09-14
5 -- Last update: 2016-06-03
6 -------------------------------------------------------------------------------
7 -- Description: Shift Register Delay module for std_logic_vectors
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 use ieee.std_logic_unsigned.all;
21 use ieee.std_logic_arith.all;
22 
23 use work.StdRtlPkg.all;
24 
25 --! @see entity
26  --! @ingroup base_general
27 entity SlvDelay is
28  generic (
29  TPD_G : time := 1 ns;
30  RST_POLARITY_G : sl := '1'; -- '1' for active HIGH reset, '0' for active LOW reset
31  SRL_EN_G : boolean := false; -- Allow an SRL to be inferred. Disables reset.
32  DELAY_G : natural := 1; --number of clock cycle delays. MAX delay stages when using
33  --delay input
34  REG_OUTPUT_G : boolean := false; -- For use with Dynamic SRLs, adds extra delay register on output
35  WIDTH_G : positive := 1;
36  INIT_G : slv := "0");
37  port (
38  clk : in sl;
39  rst : in sl := not RST_POLARITY_G; -- Optional reset
40  en : in sl := '1'; -- Optional clock enable
41  delay : in slv(log2(DELAY_G)-1 downto 0) := toSlv(DELAY_G-1, log2(DELAY_G));
42  din : in slv(WIDTH_G-1 downto 0);
43  dout : out slv(WIDTH_G-1 downto 0));
44 end entity SlvDelay;
45 
46 architecture rtl of SlvDelay is
47 
48  constant INIT_C : slv(WIDTH_G-1 downto 0) := ite(INIT_G = "0", slvZero(WIDTH_G), INIT_G);
49 
50  type VectorArray is array (DELAY_G-1 downto 0) of slv(WIDTH_G-1 downto 0);
51 
52  type RegType is record
53  shift : VectorArray;
54  end record RegType;
55  constant REG_INIT_C : RegType := (
56  shift => (others => INIT_C));
57 
58  signal r : RegType := REG_INIT_C;
59  signal rin : RegType;
60 
61  signal iDelay : natural;
62  signal iDout : slv(WIDTH_G-1 downto 0);
63 
64  constant SRL_C : string := ite(SRL_EN_G, "YES", "NO");
65  attribute shreg_extract : string;
66  attribute shreg_extract of r : signal is SRL_C;
67 
68 begin
69 
70  NO_DELAY : if (DELAY_G = 0) generate
71  dout <= din;
72  end generate NO_DELAY;
73 
74  YES_DELAY : if (DELAY_G > 0) generate
75 
76  iDelay <= conv_integer(delay);
77 
78  comb : process (din, en, iDelay, r, rst) is
79  variable v : RegType;
80  begin
81  -- Latch the current value
82  v := r;
83 
84  -- Check for clock enable
85  if en = '1' then
86  -- Add new data
87  v.shift(0) := din;
88  -- Check for multi-stage delay
89  if DELAY_G > 1 then
90  -- Shift old data
91  v.shift(DELAY_G-1 downto 1) := r.shift(DELAY_G-2 downto 0);
92  end if;
93  end if;
94 
95  -- Reset
96  if (rst = RST_POLARITY_G and not SRL_EN_G) then
97  v := REG_INIT_C;
98  end if;
99 
100  -- Register the variable for next clock cycle
101  rin <= v;
102 
103  -- Outputs
104  iDout <= r.shift(iDelay);
105 
106  end process comb;
107 
108  seq : process (clk) is
109  begin
110  if rising_edge(clk) then
111  r <= rin after TPD_G;
112  end if;
113  end process seq;
114 
115  OUT_REG: if (REG_OUTPUT_G) generate
116  REG: process (clk) is
117  begin
118  if (rising_edge(clk)) then
119  if (rst = '1') then
120  dout <= INIT_C;
121  else
122  dout <= iDout;
123  end if;
124  end if;
125  end process REG;
126  end generate OUT_REG;
127 
128  NO_OUT_REG: if (not REG_OUTPUT_G) generate
129  dout <= iDout;
130  end generate NO_OUT_REG;
131 
132  end generate YES_DELAY;
133 
134 end rtl;
in dinslv( WIDTH_G- 1 downto 0)
Definition: SlvDelay.vhd:42
std_logic sl
Definition: StdRtlPkg.vhd:28
REG_OUTPUT_Gboolean := false
Definition: SlvDelay.vhd:34
RST_POLARITY_Gsl := '1'
Definition: SlvDelay.vhd:30
in rstsl :=not RST_POLARITY_G
Definition: SlvDelay.vhd:39
in clksl
Definition: SlvDelay.vhd:38
WIDTH_Gpositive := 1
Definition: SlvDelay.vhd:35
TPD_Gtime := 1 ns
Definition: SlvDelay.vhd:29
in delayslv( log2(DELAY_G )- 1 downto 0) := toSlv( DELAY_G- 1, log2(DELAY_G ))
Definition: SlvDelay.vhd:41
out doutslv( WIDTH_G- 1 downto 0)
Definition: SlvDelay.vhd:43
DELAY_Gnatural := 1
Definition: SlvDelay.vhd:32
in ensl := '1'
Definition: SlvDelay.vhd:40
_library_ ieeeieee
SRL_EN_Gboolean := false
Definition: SlvDelay.vhd:31
INIT_Gslv := "0"
Definition: SlvDelay.vhd:36
std_logic_vector slv
Definition: StdRtlPkg.vhd:29