Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
drv8711_spi_tb.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief DRV8711 SPI 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 DRV8711 SPI test bench
13 ENTITY drv8711_spi_tb IS
14 END ENTITY drv8711_spi_tb;
15 
16 --! Architecture tb of drv8711_spi_tb entity
17 ARCHITECTURE tb OF drv8711_spi_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  data_wr : std_logic_vector(15 DOWNTO 0); --! Write data to gpio_device
26  data_rd : std_logic_vector(15 DOWNTO 0); --! Expected read data from gpio_device
27  END RECORD t_stimulus;
28 
29  --! Stimulus array type
30  TYPE t_stimulus_array IS ARRAY(natural RANGE <>) OF t_stimulus;
31 
32  --! Test stimulus
34  (
35  (
36  name => "Transfer ",
37  data_wr => X"A501",
38  data_rd => X"0000"
39  ),
40  (
41  name => "Transfer ",
42  data_wr => X"AAAA",
43  data_rd => X"0000"
44  ),
45  (
46  name => "Transfer ",
47  data_wr => X"5555",
48  data_rd => X"0000"
49  )
50  );
51 
52  -- Signals to uut
53  SIGNAL clk : std_logic; --! Clock input to uut
54  SIGNAL rst : std_logic; --! Reset input to uut
55  SIGNAL data_send : std_logic_vector(15 DOWNTO 0); --! Data to send
56  SIGNAL data_recv : std_logic_vector(15 DOWNTO 0); --! Data received
57  SIGNAL xfer_adv : std_logic; --! Transfer advance pulse
58  SIGNAL xfer_start : std_logic; --! Transfer start flag
59  SIGNAL xfer_done : std_logic; --! Transfer done pulse
60  SIGNAL spi_scs : std_logic; --! SPI chip-select line
61  SIGNAL spi_sclk : std_logic; --! SPI clock line
62  SIGNAL spi_mosi : std_logic; --! SPI mosi line
63  SIGNAL spi_miso : std_logic; --! SPI miso line
64 
65  -- Signals to transfer clock
66  SIGNAL xfer_clk_rst : std_logic; --! Reset transfer clock
67 
68  --! Function to create string from std_logic_vector
69  FUNCTION to_string (
70  vector : std_logic_vector) RETURN string
71  IS
72 
73  VARIABLE v_str : string(1 TO vector'length);
74 
75  BEGIN
76 
77  FOR i IN vector'range LOOP
78  v_str(i + 1) := std_logic'image(vector(i))(2);
79  END LOOP;
80 
81  RETURN v_str;
82 
83  END FUNCTION to_string;
84 
85 BEGIN
86 
87  --! Instantiate DRV8711 SPI as uut
88  i_uut : ENTITY work.drv8711_spi
89  PORT MAP (
90  clk_in => clk,
91  rst_in => rst,
101  );
102 
103  --! Instantiate clk_div_n for transfer clock
104  i_xfer_clk : ENTITY work.clk_div_n
105  GENERIC MAP (
106  clk_div => 14
107  )
108  PORT MAP (
109  clk_in => clk,
110  rst_in => xfer_clk_rst,
111  div_clr_in => '0',
112  div_adv_in => '1',
113  div_end_out => OPEN,
115  );
116 
117  --! @brief Clock generator process
118  --!
119  --! This generates the clk signal and the adv signal
120  pr_clock : PROCESS IS
121  BEGIN
122 
123  clk <= '0';
124  WAIT FOR c_clk_period / 2;
125 
126  clk <= '1';
127  WAIT FOR c_clk_period / 2;
128 
129  END PROCESS pr_clock;
130 
131  --! @brief Stimulus process to drive PWM unit under test
132  pr_stimulus : PROCESS IS
133  BEGIN
134 
135  -- Initialize entity inputs
136  rst <= '1';
137  data_send <= (OTHERS => '0');
138  xfer_start <= '0';
139  spi_miso <= '0';
140  WAIT FOR c_clk_period;
141 
142  rst <= '0';
143  WAIT FOR c_clk_period;
144 
145  -- Loop over stimulus
146  FOR s IN c_stimulus'range LOOP
147 
148  -- Log start of stimulus
149  REPORT "Starting: " & c_stimulus(s).name SEVERITY note;
150 
151  -- Perform write to device
153 
154  -- Pulse transfer-start
155  xfer_start <= '1';
156  WAIT FOR c_clk_period * 32;
157  xfer_start <= '0';
158 
159  WAIT UNTIL xfer_done = '1';
160  WAIT FOR c_clk_period;
161 
162  -- Wait for transfer
163  WAIT FOR c_clk_period * 100;
164  END LOOP;
165 
166  -- Log end of test
167  REPORT "Finished" SEVERITY note;
168 
169  -- Finish the simulation
170  std.env.finish;
171 
172  END PROCESS pr_stimulus;
173 
174 END ARCHITECTURE tb;
out div_pls_outstd_logic
Divider pulse flag.
Definition: clk_div_n.vhd:30
std_logic spi_scs
SPI chip-select line.
out spi_mosi_outstd_logic
SPI mosi.
Definition: drv8711_spi.vhd:24
string to_stringvector,
Function to create string from std_logic_vector.
std_logic spi_mosi
SPI mosi line.
out div_end_outstd_logic
Divider end flag.
Definition: clk_div_n.vhd:28
std_logic xfer_adv
Transfer advance pulse.
in clk_instd_logic
Clock.
Definition: clk_div_n.vhd:24
std_logic_vector( 15 DOWNTO 0) data_send
Data to send.
in spi_miso_instd_logic
SPI miso.
Definition: drv8711_spi.vhd:26
in xfer_start_instd_logic
Transfer start flag.
Definition: drv8711_spi.vhd:20
std_logic_vector( 15 DOWNTO 0) data_recv
Data received.
std_logic rst
Reset input to uut.
t_stimulus_array :=((name => "Transfer ",data_wr => X"A501",data_rd => X"0000"),(name => "Transfer ",data_wr => X"AAAA",data_rd => X"0000"),(name => "Transfer ",data_wr => X"5555",data_rd => X"0000")) c_stimulus
Test stimulus.
DRV8711 spi entity.
Definition: drv8711_spi.vhd:13
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 xfer_adv_instd_logic
Transfer advance flag.
Definition: drv8711_spi.vhd:19
std_logic xfer_start
Transfer start flag.
in data_send_instd_logic_vector( 15 DOWNTO 0)
Data to send.
Definition: drv8711_spi.vhd:17
std_logic spi_miso
SPI miso line.
in div_clr_instd_logic
Divider clear flag.
Definition: clk_div_n.vhd:26
out spi_sclk_outstd_logic
SPI clock.
Definition: drv8711_spi.vhd:23
std_logic spi_sclk
SPI clock line.
t_stimulus
Stimulus record type.
std_logic clk
Clock input to uut.
in rst_instd_logic
Asynchronous reset.
Definition: drv8711_spi.vhd:16
time := 10 ns c_clk_period
Test bench clock period.
out data_recv_outstd_logic_vector( 15 DOWNTO 0)
Data received.
Definition: drv8711_spi.vhd:18
std_logic xfer_clk_rst
Reset transfer clock.
string( 1 TO 30) name
Stimulus name.
Clock divider entity.
Definition: clk_div_n.vhd:19
_library_ ieeeieee
Using IEEE library.
Definition: spi_slave.vhd:7
std_logic_vector( 15 DOWNTO 0) data_rd
Expected read data from gpio_device.
out xfer_done_outstd_logic
Transfer done flag.
Definition: drv8711_spi.vhd:21
DRV8711 SPI test bench.
std_logic_vector( 15 DOWNTO 0) data_wr
Write data to gpio_device.
std_logic xfer_done
Transfer done pulse.
out spi_scs_outstd_logic
SPI chip-select.
Definition: drv8711_spi.vhd:22
in rst_instd_logic
Asynchronous reset.
Definition: clk_div_n.vhd:25
array(natural range <> ) of t_stimulus t_stimulus_array
Stimulus array type.
in clk_instd_logic
Clock.
Definition: drv8711_spi.vhd:15