SURF  1.0
RegisterVector.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : RegisterVector.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2017-04-15
5 -- Last update: 2017-06-05
6 -------------------------------------------------------------------------------
7 -- Description: 1 c-c register delay
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 RegisterVector 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  WIDTH_G : positive := 1;
32  INIT_G : slv := "0");
33  port (
34  clk : in sl;
35  rst : in sl := not RST_POLARITY_G; -- Optional reset
36  en : in sl := '1'; -- Optional clock enable
37  sig_i : in slv(WIDTH_G-1 downto 0);
38  reg_o : out slv(WIDTH_G-1 downto 0));
39 end entity RegisterVector;
40 
41 architecture rtl of RegisterVector is
42 
43  constant INIT_C : slv(WIDTH_G-1 downto 0) := ite(INIT_G = "0", slvZero(WIDTH_G), INIT_G);
44 
45  type RegType is record
46  reg : slv(WIDTH_G-1 downto 0);
47  end record RegType;
48 
49  constant REG_INIT_C : RegType := (
50  reg => INIT_C);
51 
52  signal r : RegType := REG_INIT_C;
53  signal rin : RegType;
54 
55 begin
56 
57  comb : process (en, r, rst, sig_i) is
58  variable v : RegType;
59  begin
60  -- Latch the current value
61  v := r;
62 
63  -- Check the clock enable
64  if en = '1' then
65  -- Register/Delay for 1 clock cycle
66  v.reg := sig_i;
67  end if;
68 
69  if (rst = '1') then
70  v := REG_INIT_C;
71  end if;
72 
73  -- Register the variable for next clock cycle
74  rin <= v;
75 
76  -- Outputs
77  reg_o <= r.reg;
78  end process comb;
79 
80  seq : process (clk) is
81  begin
82  if (rising_edge(clk)) then
83  r <= rin after TPD_G;
84  end if;
85  end process seq;
86 
87 end architecture rtl;
in sig_islv( WIDTH_G- 1 downto 0)
std_logic sl
Definition: StdRtlPkg.vhd:28
WIDTH_Gpositive := 1
in ensl := '1'
RST_POLARITY_Gsl := '1'
TPD_Gtime := 1 ns
_library_ ieeeieee
Definition: PwrUpRst.vhd:19
in rstsl :=not RST_POLARITY_G
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
INIT_Gslv := "0"