VHDL-verification
Package to ease directed testing of HDL entities
clkmanager.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @author Hipolito Guzman-Miranda
4 --! @brief Generates reset and clock for simulation purposes.
5 -------------------------------------------------------------------------------
6 
7 --! Use IEEE standard definitions library
8 LIBRARY ieee;
9 --! Use std_logic* signal types
10 USE ieee.std_logic_1164.ALL;
11 
12 --! @brief Generates a clock and reset for simulation purposes
13 --!
14 --! @details Generates a clock, \c clk, with period \c CLK_PERIOD, and also a \c reset pulse, which
15 --! takes the value \c RST_ACTIVE_VALUE during \c RST_CYCLES (of the generated clock), and
16 --! after that time switches to the opposite value
17 entity clkmanager is
18  generic (
19  CLK_PERIOD : time := 10 ns; --! Period of generated clock
20  RST_ACTIVE_VALUE : std_logic := '0'; --! Reset polarity
21  RST_CYCLES : integer := 10 --! Number of cycles that reset will be asserted at the beginning of the simulation
22  );
23  port (
24  endsim : in std_logic; --! \c clk stops changing when endsim='1', which effectively stops the simulation
25  clk : out std_logic; --! Generated clock
26  rst : out std_logic --! Generated reset
27  );
28 end clkmanager;
29 
30 --! @brief Architecture is based on two different non-synthesizable processes to manage \c clk and \c rst
31 --!
32 --! @detailed A process is dedicated to toggle \c clk while \c endsim is not \c '1', and another one manages \c rst
33 architecture two_simulation_processes of clkmanager is
34 
35 begin
36 
37  -- CLK_PERIOD must be positive and non-zero
38  assert CLK_PERIOD > 0 ns
39  report "clkmanager: CLK_PERIOD must be positive and non-zero"
40  severity failure;
41 
42  -- RST_ACTIVE_VALUE must be either '0' or '1' (no other values supported)
43  assert RST_ACTIVE_VALUE = '0' or RST_ACTIVE_VALUE = '1'
44  report "clkmanager: RST_ACTIVE_VALUE must be either '0' or '1'"
45  severity failure;
46 
47  -- RST_CYCLES must be positive and non-zero
48  assert RST_CYCLES > 0
49  report "clkmanager: RST_CYCLES must be a positive non-zero integer"
50  severity failure;
51 
52  --! @brief Manage clk
53  --!
54  --! @details To stop the simulation without a failure message,
55  --! stop toggling the clk when endsim = '1',
56  clk_process: process
57  begin
58  if(endsim /= '1') then
59  clk <= '0';
60  wait for CLK_PERIOD/2;
61  clk <= '1';
62  wait for CLK_PERIOD/2;
63  else
64  wait;
65  end if;
66  end process;
67 
68  --! @brief Manage reset
69  --!
70  --! @details Sets rst to RST_ACTIVE_VALUE for CLK_PERIOD*RST_CYCLES
71  --! and toggles it to NOT RST_ACTIVE_VALUE after that time
72  rst_process: process
73  begin
75  wait for CLK_PERIOD*RST_CYCLES;
76  rst <= NOT RST_ACTIVE_VALUE;
77  wait;
78  end process;
79 
80 end two_simulation_processes;
RST_ACTIVE_VALUEstd_logic := '0'
Reset polarity.
Definition: clkmanager.vhd:20
out rststd_logic
Generated reset.
Definition: clkmanager.vhd:27
out clkstd_logic
Generated clock.
Definition: clkmanager.vhd:25
Generates a clock and reset for simulation purposes.
Definition: clkmanager.vhd:17
in endsimstd_logic
clk stops changing when endsim=&#39;1&#39;, which effectively stops the simulation
Definition: clkmanager.vhd:24
RST_CYCLESinteger := 10
Number of cycles that reset will be asserted at the beginning of the simulation.
Definition: clkmanager.vhd:22
CLK_PERIODtime := 10 ns
Period of generated clock.
Definition: clkmanager.vhd:19