| 1 |
12 |
jdoin |
-- TestBench Template
|
| 2 |
|
|
|
| 3 |
|
|
library ieee;
|
| 4 |
|
|
use ieee.std_logic_1164.all;
|
| 5 |
|
|
use ieee.numeric_std.all;
|
| 6 |
|
|
|
| 7 |
|
|
entity testbench is
|
| 8 |
|
|
end testbench;
|
| 9 |
|
|
|
| 10 |
|
|
architecture behavior of testbench is
|
| 11 |
|
|
|
| 12 |
|
|
--=============================================================================================
|
| 13 |
|
|
-- Constants
|
| 14 |
|
|
--=============================================================================================
|
| 15 |
|
|
-- clock period
|
| 16 |
|
|
constant CLK_PERIOD : time := 10 ns;
|
| 17 |
|
|
|
| 18 |
|
|
-- button definitions
|
| 19 |
|
|
constant btRESET : integer := 0; -- these are constants to use as btn_i(x)
|
| 20 |
|
|
constant btUP : integer := 1;
|
| 21 |
|
|
constant btLEFT : integer := 2;
|
| 22 |
|
|
constant btDOWN : integer := 3;
|
| 23 |
|
|
constant btRIGHT : integer := 4;
|
| 24 |
|
|
constant btCENTER : integer := 5;
|
| 25 |
|
|
|
| 26 |
|
|
--=============================================================================================
|
| 27 |
|
|
-- COMPONENT DECLARATIONS
|
| 28 |
|
|
--=============================================================================================
|
| 29 |
|
|
component spi_master_atlys_top
|
| 30 |
|
|
port(
|
| 31 |
|
|
gclk_i : in std_logic;
|
| 32 |
|
|
sw_i : in std_logic_vector(7 downto 0);
|
| 33 |
|
|
btn_i : in std_logic_vector(5 downto 0);
|
| 34 |
|
|
spi_ssel_o : out std_logic;
|
| 35 |
|
|
spi_sck_o : out std_logic;
|
| 36 |
|
|
spi_mosi_o : out std_logic;
|
| 37 |
|
|
spi_miso_o : out std_logic;
|
| 38 |
|
|
led_o : out std_logic_vector(7 downto 0);
|
| 39 |
|
|
dbg_o : out std_logic_vector(11 downto 0)
|
| 40 |
|
|
);
|
| 41 |
|
|
end component;
|
| 42 |
|
|
|
| 43 |
|
|
--=============================================================================================
|
| 44 |
|
|
-- Signals for state machine control
|
| 45 |
|
|
--=============================================================================================
|
| 46 |
|
|
|
| 47 |
|
|
--=============================================================================================
|
| 48 |
|
|
-- Signals for internal operation
|
| 49 |
|
|
--=============================================================================================
|
| 50 |
|
|
--- clock signals ---
|
| 51 |
|
|
signal sysclk : std_logic := '0'; -- 100MHz clock
|
| 52 |
|
|
--- switch debouncer signals ---
|
| 53 |
|
|
signal sw_data : std_logic_vector (7 downto 0) := (others => '0'); -- switch data
|
| 54 |
|
|
--- pushbutton debouncer signals ---
|
| 55 |
|
|
signal btn_data : std_logic_vector (5 downto 0) := (others => '0'); -- pushbuttons
|
| 56 |
|
|
--- spi port signals ---
|
| 57 |
|
|
signal spi_ssel : std_logic;
|
| 58 |
|
|
signal spi_sck : std_logic;
|
| 59 |
|
|
signal spi_mosi : std_logic;
|
| 60 |
|
|
signal spi_miso : std_logic;
|
| 61 |
|
|
-- debug output signals
|
| 62 |
|
|
signal leds : std_logic_vector (7 downto 0) := (others => '0');
|
| 63 |
|
|
signal dbg : std_logic_vector (11 downto 0) := (others => '0');
|
| 64 |
|
|
-- debug ports
|
| 65 |
|
|
signal spi_do_s : std_logic_vector (7 downto 0) := (others => '0');
|
| 66 |
|
|
signal spi_state_s : std_logic_vector (3 downto 0) := (others => '0');
|
| 67 |
|
|
begin
|
| 68 |
|
|
|
| 69 |
|
|
--=============================================================================================
|
| 70 |
|
|
-- COMPONENT INSTANTIATIONS FOR THE CORES UNDER TEST
|
| 71 |
|
|
--=============================================================================================
|
| 72 |
|
|
-- spi_master_atlys_top:
|
| 73 |
|
|
-- receives the 100 MHz clock from the board clock oscillator
|
| 74 |
|
|
-- receives the 8 slide switches and 5 pushbuttons as test stimuli
|
| 75 |
|
|
-- connects to 4 spi signals
|
| 76 |
|
|
-- connects to 8 board LEDs
|
| 77 |
|
|
-- connects to 12 debug pins
|
| 78 |
|
|
inst_spi_master_atlys_top: spi_master_atlys_top
|
| 79 |
|
|
port map(
|
| 80 |
|
|
gclk_i => sysclk,
|
| 81 |
|
|
spi_ssel_o => spi_ssel,
|
| 82 |
|
|
spi_sck_o => spi_sck,
|
| 83 |
|
|
spi_mosi_o => spi_mosi,
|
| 84 |
|
|
spi_miso_o => spi_miso,
|
| 85 |
|
|
sw_i => sw_data,
|
| 86 |
|
|
btn_i => btn_data,
|
| 87 |
|
|
led_o => leds,
|
| 88 |
|
|
dbg_o => dbg
|
| 89 |
|
|
);
|
| 90 |
|
|
|
| 91 |
|
|
spi_do_s <= dbg(7 downto 0);
|
| 92 |
|
|
spi_state_s <= dbg(11 downto 8);
|
| 93 |
|
|
|
| 94 |
|
|
--=============================================================================================
|
| 95 |
|
|
-- CLOCK GENERATION
|
| 96 |
|
|
--=============================================================================================
|
| 97 |
|
|
gclk_proc: process is
|
| 98 |
|
|
begin
|
| 99 |
|
|
loop
|
| 100 |
|
|
sysclk <= not sysclk;
|
| 101 |
|
|
wait for CLK_PERIOD / 2;
|
| 102 |
|
|
end loop;
|
| 103 |
|
|
end process gclk_proc;
|
| 104 |
|
|
|
| 105 |
|
|
--=============================================================================================
|
| 106 |
|
|
-- TEST BENCH STIMULI
|
| 107 |
|
|
--=============================================================================================
|
| 108 |
|
|
tb : process
|
| 109 |
|
|
begin
|
| 110 |
|
|
wait for 100 ns; -- wait until global set/reset completes
|
| 111 |
|
|
|
| 112 |
|
|
sw_data <= X"5A";
|
| 113 |
|
|
btn_data(btRIGHT) <= '1';
|
| 114 |
|
|
|
| 115 |
|
|
wait; -- will wait forever
|
| 116 |
|
|
end process tb;
|
| 117 |
|
|
-- End Test Bench
|
| 118 |
|
|
END;
|