Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
gpio_device_tb.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief GPIO device 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 --! @brief GPIO device test bench
13 ENTITY gpio_device_tb IS
14 END ENTITY gpio_device_tb;
15 
16 --! Architecture tb of gpio_device_tb entity
17 ARCHITECTURE tb OF gpio_device_tb IS
18 
19  --! Test bench clock period
20  CONSTANT c_clk_period : time := 10 ns;
21 
22  --! Stimulus record type
23  TYPE t_stimulus IS RECORD
24  name : string(1 TO 30); --! Stimulus name
25  rst : std_logic; --! Reset input to gpio_device
26  data_wr : std_logic_vector(31 DOWNTO 0); --! Write data to gpio_device
27  data_rd : std_logic_vector(31 DOWNTO 0); --! Expected read data from gpio_device
28  gpio_in : std_logic_vector(31 DOWNTO 0); --! GPIO inputs
29  gpio_out : std_logic_vector(31 DOWNTO 0); --! Expected GPIO outputs
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 stimulus
37  (
38  (
39  name => "Reset ",
40  rst => '1',
41  data_wr => X"00000000",
42  data_rd => X"00000000",
43  gpio_in => X"00000000",
44  gpio_out => X"00000000"
45  ),
46  (
47  name => "Transfer ",
48  rst => '0',
49  data_wr => X"DEADBEEF",
50  data_rd => X"AA550011",
51  gpio_in => X"AA550011",
52  gpio_out => X"DEADBEEF"
53  )
54  );
55 
56  -- Signals to uut
57  SIGNAL clk : std_logic; --! Clock input to uut
58  SIGNAL rst : std_logic; --! Reset input to uut
59  SIGNAL dat_wr_done : std_logic; --! Data write done input to uut
60  SIGNAL dat_wr_reg : std_logic_vector(31 DOWNTO 0); --! Data write register input to uut
61  SIGNAL dat_rd_reg : std_logic_vector(31 DOWNTO 0); --! Data read register output from uut
62  SIGNAL gpio_in : std_logic_vector(31 DOWNTO 0); --! GPIO inputs
63  SIGNAL gpio_out : std_logic_vector(31 DOWNTO 0); --! GPIO outputs
64 
65  --! Function to create string from std_logic_vector
66  FUNCTION to_string (
67  vector : std_logic_vector) RETURN string
68  IS
69 
70  VARIABLE v_str : string(1 TO vector'length);
71 
72  BEGIN
73 
74  FOR i IN vector'range LOOP
75  v_str(i + 1) := std_logic'image(vector(i))(2);
76  END LOOP;
77 
78  RETURN v_str;
79 
80  END FUNCTION to_string;
81 
82 BEGIN
83 
84  --! Instantiate GPIO device as uut
85  i_uut : ENTITY work.gpio_device(rtl)
86  PORT MAP (
87  clk_in => clk,
88  rst_in => rst,
94  );
95 
96  --! @brief Clock generator process
97  --!
98  --! This generates the clk signal and the adv signal
99  pr_clock : PROCESS IS
100  BEGIN
101 
102  clk <= '0';
103  WAIT FOR c_clk_period / 2;
104 
105  clk <= '1';
106  WAIT FOR c_clk_period / 2;
107 
108  END PROCESS pr_clock;
109 
110  --! @brief Stimulus process to drive PWM unit under test
111  pr_stimulus : PROCESS IS
112  BEGIN
113 
114  -- Initialize entity inputs
115  rst <= '1';
116  dat_wr_reg <= (OTHERS => '0');
117  dat_wr_done <= '0';
118  gpio_in <= (OTHERS => '0');
119  WAIT FOR c_clk_period;
120 
121  -- Loop over stimulus
122  FOR s IN c_stimulus'range LOOP
123 
124  -- Log start of stimulus
125  REPORT "Starting: " & c_stimulus(s).name SEVERITY note;
126 
127  -- Perform write to device
128  rst <= c_stimulus(s).rst;
130  gpio_in <= c_stimulus(s).gpio_in;
131  dat_wr_done <= '1';
132  WAIT FOR c_clk_period;
133  dat_wr_done <= '0';
134 
135  -- Assert read from device
136  ASSERT dat_rd_reg = c_stimulus(s).data_rd
137  REPORT "Expected read of " &
138  to_string(c_stimulus(s).data_rd) &
139  " but got " &
140  to_string(dat_rd_reg)
141  SEVERITY error;
142 
143  -- Assert read from device
144  ASSERT gpio_out = c_stimulus(s).gpio_out
145  REPORT "Expected gpio_out of " &
146  to_string(c_stimulus(s).gpio_out) &
147  " but got " &
148  to_string(gpio_out)
149  SEVERITY error;
150  END LOOP;
151 
152  -- Log end of test
153  REPORT "Finished" SEVERITY note;
154 
155  -- Finish the simulation
156  std.env.finish;
157 
158  END PROCESS pr_stimulus;
159 
160 END ARCHITECTURE tb;
std_logic_vector( 31 DOWNTO 0) data_rd
Expected read data from gpio_device.
out dat_rd_reg_outstd_logic_vector( 31 DOWNTO 0)
Device Read Register value.
Definition: gpio_device.vhd:18
std_logic_vector( 31 DOWNTO 0) gpio_out
Expected GPIO outputs.
std_logic dat_wr_done
Data write done input to uut.
in clk_instd_logic
Clock.
Definition: gpio_device.vhd:14
out gpio_bus_outstd_logic_vector( 31 DOWNTO 0)
GPIO outputs.
Definition: gpio_device.vhd:21
in rst_instd_logic
Asynchronous reset.
Definition: gpio_device.vhd:15
in dat_wr_done_instd_logic
Device Write Done flag.
Definition: gpio_device.vhd:16
std_logic rst
Reset input to gpio_device.
GPIO device test bench.
time := 10 ns c_clk_period
Test bench clock period.
std_logic_vector( 31 DOWNTO 0) dat_wr_reg
Data write register input to uut.
string( 1 TO 30) name
Stimulus name.
string to_stringvector,
Function to create string from std_logic_vector.
t_stimulus_array :=((name => "Reset ",rst => '1',data_wr => X"00000000",data_rd => X"00000000",gpio_in => X"00000000",gpio_out => X"00000000"),(name => "Transfer ",rst => '0',data_wr => X"DEADBEEF",data_rd => X"AA550011",gpio_in => X"AA550011",gpio_out => X"DEADBEEF")) c_stimulus
Test stimulus.
std_logic clk
Clock input to uut.
in dat_wr_reg_instd_logic_vector( 31 DOWNTO 0)
Device Write Register value.
Definition: gpio_device.vhd:17
in gpio_bus_instd_logic_vector( 31 DOWNTO 0)
GPIO inputs.
Definition: gpio_device.vhd:19
_library_ ieeeieee
Using IEEE library.
std_logic_vector( 31 DOWNTO 0) gpio_in
GPIO inputs.
std_logic_vector( 31 DOWNTO 0) data_wr
Write data to gpio_device.
t_stimulus
Stimulus record type.
std_logic_vector( 31 DOWNTO 0) dat_rd_reg
Data read register output from uut.
array(natural range <> ) of t_stimulus t_stimulus_array
Stimulus array type.