SURF  1.0
Heartbeat.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : Heartbeat.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2013-04-30
5 -- Last update: 2014-10-28
6 -------------------------------------------------------------------------------
7 -- Description: Heartbeat LED output
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 Heartbeat is
28  generic (
29  TPD_G : time := 1 ns;
30  USE_DSP48_G : string := "no";
31  PERIOD_IN_G : real := 6.4E-9; --units of seconds
32  PERIOD_OUT_G : real := 1.0E-0); --units of seconds
33  port (
34  clk : in sl;
35  rst : in sl := '0';
36  o : out sl);
37 end entity Heartbeat;
38 
39 architecture rtl of Heartbeat is
40 
41  constant CNT_MAX_C : natural := getTimeRatio(PERIOD_OUT_G, (2.0 * PERIOD_IN_G));
42  constant CNT_SIZE_C : natural := bitSize(CNT_MAX_C);
43 
44  type RegType is record
45  cnt : slv(CNT_SIZE_C-1 downto 0);
46  o : sl;
47  end record RegType;
48 
49  constant REG_INIT_C : RegType := (
50  cnt => (others => '0'),
51  o => '0');
52 
53  signal r : RegType := REG_INIT_C;
54  signal rin : RegType;
55 
56  -- Attribute for XST
57  attribute use_dsp48 : string;
58  attribute use_dsp48 of r : signal is USE_DSP48_G;
59 
60 begin
61 
62  -- USE_DSP48_G check
63  assert ((USE_DSP48_G = "yes") or (USE_DSP48_G = "no") or (USE_DSP48_G = "auto") or (USE_DSP48_G = "automax"))
64  report "USE_DSP48_G must be either yes, no, auto, or automax"
65  severity failure;
66 
67 
68  comb : process (r, rst) is
69  variable v : RegType;
70  begin
71  v := r;
72 
73  v.cnt := r.cnt + 1;
74  if (r.cnt = CNT_MAX_C) then
75  v.cnt := (others => '0');
76  if (r.o = '1') then
77  v.o := '0';
78  else
79  v.o := '1';
80  end if;
81  end if;
82 
83  if (rst = '1') then
84  v := REG_INIT_C;
85  end if;
86 
87  rin <= v;
88  o <= r.o;
89 
90  end process comb;
91 
92  seq : process (clk) is
93  begin
94  if (rising_edge(clk)) then
95  r <= rin after TPD_G;
96  end if;
97  end process seq;
98 
99 end architecture rtl;
std_logic sl
Definition: StdRtlPkg.vhd:28
PERIOD_OUT_Greal := 1.0E-0
Definition: Heartbeat.vhd:32
USE_DSP48_Gstring := "no"
Definition: Heartbeat.vhd:30
in rstsl := '0'
Definition: Heartbeat.vhd:35
TPD_Gtime := 1 ns
Definition: Heartbeat.vhd:29
_library_ ieeeieee
PERIOD_IN_Greal := 6.4E-9
Definition: Heartbeat.vhd:31
in clksl
Definition: Heartbeat.vhd:34
out osl
Definition: Heartbeat.vhd:36
std_logic_vector slv
Definition: StdRtlPkg.vhd:29