Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
clk_div_n_tb.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief Clock divider test bench
4 -------------------------------------------------------------------------------
5 
6 --! Using IEEE library
7 LIBRARY ieee;
8 
9 --! Using IEEE standard logic components
10 USE ieee.std_logic_1164.ALL;
11 
12 --! Using IEE standard numeric components
13 USE ieee.numeric_std.ALL;
14 
15 --! @brief clk_div_n test bench
16 ENTITY clk_div_n_tb IS
17 END ENTITY clk_div_n_tb;
18 
19 --! Architecture tb of clk_div_n_tb entity
20 ARCHITECTURE tb OF clk_div_n_tb IS
21 
22  --! Stimulus record type
23  TYPE t_stimulus IS RECORD
24  name : string(1 TO 20); --! Stimulus name
25  rst : std_logic_vector(0 TO 7); --! rst input to uut
26  div_clr : std_logic_vector(0 TO 7); --! div_clr input to uut
27  div_adv : std_logic_vector(0 TO 7); --! div_adv input to uut
28  div_end : std_logic_vector(0 TO 7); --! div_end expected from uut
29  div_pls : std_logic_vector(0 TO 7); --! div_pls expected from uut
30  END RECORD t_stimulus;
31 
32  --! Stimulus array type
33  TYPE t_stimulus_array IS ARRAY(natural RANGE <>) OF t_stimulus;
34 
35  --! Test bench clock period
36  CONSTANT c_clk_period : time := 10 ns;
37 
38  --! Test stimulus
40  (
41  (
42  name => "Hold in reset ",
43  rst => "11111111",
44  div_clr => "00000000",
45  div_adv => "00000000",
46  div_end => "00000000",
47  div_pls => "00000000"
48  ),
49  (
50  name => "Not enabled ",
51  rst => "00000000",
52  div_clr => "00000000",
53  div_adv => "00000000",
54  div_end => "00000000",
55  div_pls => "00000000"
56  ),
57  (
58  name => "Clear ",
59  rst => "00000000",
60  div_clr => "11111111",
61  div_adv => "00000000",
62  div_end => "00000000",
63  div_pls => "00000000"
64  ),
65  (
66  name => "Normal counting 1 ",
67  rst => "00000000",
68  div_clr => "00000000",
69  div_adv => "11111111",
70  div_end => "00010001",
71  div_pls => "00010001"
72  ),
73  (
74  name => "Normal counting 2 ",
75  rst => "00000000",
76  div_clr => "00000000",
77  div_adv => "11111111",
78  div_end => "00010001",
79  div_pls => "00010001"
80  ),
81  (
82  name => "Freezing count ",
83  rst => "00000000",
84  div_clr => "00000000",
85  div_adv => "00001111",
86  div_end => "11110001",
87  div_pls => "00000001"
88  ),
89  (
90  name => "Count and clear ",
91  rst => "00000000",
92  div_clr => "00110000",
93  div_adv => "11111111",
94  div_end => "00000001",
95  div_pls => "00000001"
96  )
97  );
98 
99  -- Signals to clk_div_n uut
100  SIGNAL clk : std_logic; --! Clock
101  SIGNAL rst : std_logic; --! Reset
102  SIGNAL div_clr : std_logic; --! Divider clear to uut
103  SIGNAL div_adv : std_logic; --! Divider advance to uut
104  SIGNAL div_end : std_logic; --! Divider end from uut
105  SIGNAL div_pls : std_logic; --! Divider pulse from uut
106 
107 BEGIN
108 
109  --! Instantiate clk_div_n as unit under test
110  i_uut : ENTITY work.clk_div_n(rtl)
111  GENERIC MAP (
112  clk_div => 4
113  )
114  PORT MAP (
115  clk_in => clk,
116  rst_in => rst,
117  div_clr_in => div_clr,
118  div_adv_in => div_adv,
119  div_end_out => div_end,
121  );
122 
123  --! @brief Clock generation process
124  pr_clock : PROCESS IS
125  BEGIN
126 
127  -- Low for 1/2 clock period
128  clk <= '0';
129  WAIT FOR c_clk_period / 2;
130 
131  -- High for 1/2 clock period
132  clk <= '1';
133  WAIT FOR c_clk_period / 2;
134 
135  END PROCESS pr_clock;
136 
137  --! @brief Stimulus process to drive PWM unit under test
138  pr_stimulus : PROCESS IS
139  BEGIN
140 
141  -- Initialize entity inputs
142  rst <= '1';
143  div_clr <= '0';
144  div_adv <= '0';
145  WAIT FOR c_clk_period;
146 
147  -- Loop over stimulus
148  FOR s IN c_stimulus'range LOOP
149  -- Log start of stimulus
150  REPORT "Starting: " & c_stimulus(s).name SEVERITY note;
151 
152  -- Loop for test stimulus
153  FOR t IN 0 TO 7 LOOP
154  -- Set inputs then wait for clock to rise
155  rst <= c_stimulus(s).rst(t);
156  div_clr <= c_stimulus(s).div_clr(t);
157  div_adv <= c_stimulus(s).div_adv(t);
158  WAIT UNTIL clk = '1';
159 
160  -- Wait for clk to fall
161  WAIT UNTIL clk = '0';
162 
163  -- Assert outputs
164  ASSERT div_end = c_stimulus(s).div_end(t)
165  REPORT "At time " & integer'image(t)
166  & " expected div_end = " & std_logic'image(c_stimulus(s).div_end(t))
167  & " but got " & std_logic'image(div_end)
168  SEVERITY error;
169  ASSERT div_pls = c_stimulus(s).div_pls(t)
170  REPORT "At time " & integer'image(t)
171  & " expected div_pls = " & std_logic'image(c_stimulus(s).div_pls(t))
172  & " but got " & std_logic'image(div_pls)
173  SEVERITY error;
174  END LOOP;
175  END LOOP;
176 
177  -- Log end of test
178  REPORT "Finished" SEVERITY note;
179 
180  -- Finish the simulation
181  std.env.finish;
182 
183  END PROCESS pr_stimulus;
184 
185 END ARCHITECTURE tb;
out div_pls_outstd_logic
Divider pulse flag.
Definition: clk_div_n.vhd:30
time := 10 ns c_clk_period
Test bench clock period.
out div_end_outstd_logic
Divider end flag.
Definition: clk_div_n.vhd:28
std_logic_vector( 0 TO 7) div_adv
div_adv input to uut
std_logic clk
Clock.
clk_div_n test bench
in clk_instd_logic
Clock.
Definition: clk_div_n.vhd:24
t_stimulus_array :=((name => "Hold in reset ",rst => "11111111",div_clr => "00000000",div_adv => "00000000",div_end => "00000000",div_pls => "00000000"),(name => "Not enabled ",rst => "00000000",div_clr => "00000000",div_adv => "00000000",div_end => "00000000",div_pls => "00000000"),(name => "Clear ",rst => "00000000",div_clr => "11111111",div_adv => "00000000",div_end => "00000000",div_pls => "00000000"),(name => "Normal counting 1 ",rst => "00000000",div_clr => "00000000",div_adv => "11111111",div_end => "00010001",div_pls => "00010001"),(name => "Normal counting 2 ",rst => "00000000",div_clr => "00000000",div_adv => "11111111",div_end => "00010001",div_pls => "00010001"),(name => "Freezing count ",rst => "00000000",div_clr => "00000000",div_adv => "00001111",div_end => "11110001",div_pls => "00000001"),(name => "Count and clear ",rst => "00000000",div_clr => "00110000",div_adv => "11111111",div_end => "00000001",div_pls => "00000001")) c_stimulus
Test stimulus.
t_stimulus
Stimulus record type.
std_logic_vector( 0 TO 7) div_end
div_end expected from uut
std_logic_vector( 0 TO 7) rst
rst input to uut
in div_adv_instd_logic
Divider advance flag.
Definition: clk_div_n.vhd:27
clk_divinteger range 2 TO integer'high:= 4
Divider amount.
Definition: clk_div_n.vhd:22
in div_clr_instd_logic
Divider clear flag.
Definition: clk_div_n.vhd:26
std_logic_vector( 0 TO 7) div_clr
div_clr input to uut
Clock divider entity.
Definition: clk_div_n.vhd:19
string( 1 TO 20) name
Stimulus name.
std_logic_vector( 0 TO 7) div_pls
div_pls expected from uut
array(natural range <> ) of t_stimulus t_stimulus_array
Stimulus array type.
_library_ ieeeieee
Using IEEE library.
Definition: sdm_device.vhd:7
in rst_instd_logic
Asynchronous reset.
Definition: clk_div_n.vhd:25