| 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 |
13 |
jdoin |
s_do_o : out std_logic_vector (7 downto 0);
|
| 40 |
|
|
m_do_o : out std_logic_vector (7 downto 0);
|
| 41 |
|
|
m_state_o : out std_logic_vector (3 downto 0);
|
| 42 |
|
|
s_state_o : out std_logic_vector (3 downto 0);
|
| 43 |
12 |
jdoin |
dbg_o : out std_logic_vector(11 downto 0)
|
| 44 |
|
|
);
|
| 45 |
|
|
end component;
|
| 46 |
|
|
|
| 47 |
|
|
--=============================================================================================
|
| 48 |
|
|
-- Signals for state machine control
|
| 49 |
|
|
--=============================================================================================
|
| 50 |
|
|
|
| 51 |
|
|
--=============================================================================================
|
| 52 |
|
|
-- Signals for internal operation
|
| 53 |
|
|
--=============================================================================================
|
| 54 |
|
|
--- clock signals ---
|
| 55 |
|
|
signal sysclk : std_logic := '0'; -- 100MHz clock
|
| 56 |
|
|
--- switch debouncer signals ---
|
| 57 |
|
|
signal sw_data : std_logic_vector (7 downto 0) := (others => '0'); -- switch data
|
| 58 |
|
|
--- pushbutton debouncer signals ---
|
| 59 |
|
|
signal btn_data : std_logic_vector (5 downto 0) := (others => '0'); -- pushbuttons
|
| 60 |
|
|
--- spi port signals ---
|
| 61 |
|
|
signal spi_ssel : std_logic;
|
| 62 |
|
|
signal spi_sck : std_logic;
|
| 63 |
|
|
signal spi_mosi : std_logic;
|
| 64 |
|
|
signal spi_miso : std_logic;
|
| 65 |
|
|
-- debug output signals
|
| 66 |
|
|
signal leds : std_logic_vector (7 downto 0) := (others => '0');
|
| 67 |
|
|
signal dbg : std_logic_vector (11 downto 0) := (others => '0');
|
| 68 |
13 |
jdoin |
-- debug ports --
|
| 69 |
|
|
signal s_do_reg : std_logic_vector (7 downto 0);
|
| 70 |
|
|
signal m_do_reg : std_logic_vector (7 downto 0);
|
| 71 |
|
|
-- master signals mapped on dbg
|
| 72 |
|
|
signal wren_m : std_logic;
|
| 73 |
|
|
signal wr_ack_m : std_logic;
|
| 74 |
|
|
signal di_req_m : std_logic;
|
| 75 |
|
|
signal do_valid_m : std_logic;
|
| 76 |
|
|
signal master_state : std_logic_vector (3 downto 0);
|
| 77 |
|
|
-- slave signals mapped on dbg
|
| 78 |
|
|
signal wren_s : std_logic;
|
| 79 |
|
|
signal wr_ack_s : std_logic;
|
| 80 |
|
|
signal di_req_s : std_logic;
|
| 81 |
|
|
signal do_valid_s : std_logic;
|
| 82 |
|
|
signal slave_state : std_logic_vector (3 downto 0);
|
| 83 |
12 |
jdoin |
begin
|
| 84 |
|
|
|
| 85 |
|
|
--=============================================================================================
|
| 86 |
|
|
-- COMPONENT INSTANTIATIONS FOR THE CORES UNDER TEST
|
| 87 |
|
|
--=============================================================================================
|
| 88 |
|
|
-- spi_master_atlys_top:
|
| 89 |
|
|
-- receives the 100 MHz clock from the board clock oscillator
|
| 90 |
|
|
-- receives the 8 slide switches and 5 pushbuttons as test stimuli
|
| 91 |
|
|
-- connects to 4 spi signals
|
| 92 |
|
|
-- connects to 8 board LEDs
|
| 93 |
|
|
-- connects to 12 debug pins
|
| 94 |
|
|
inst_spi_master_atlys_top: spi_master_atlys_top
|
| 95 |
|
|
port map(
|
| 96 |
|
|
gclk_i => sysclk,
|
| 97 |
|
|
spi_ssel_o => spi_ssel,
|
| 98 |
|
|
spi_sck_o => spi_sck,
|
| 99 |
|
|
spi_mosi_o => spi_mosi,
|
| 100 |
|
|
spi_miso_o => spi_miso,
|
| 101 |
|
|
sw_i => sw_data,
|
| 102 |
|
|
btn_i => btn_data,
|
| 103 |
|
|
led_o => leds,
|
| 104 |
13 |
jdoin |
m_state_o => master_state,
|
| 105 |
|
|
s_state_o => slave_state,
|
| 106 |
12 |
jdoin |
dbg_o => dbg
|
| 107 |
|
|
);
|
| 108 |
|
|
|
| 109 |
13 |
jdoin |
-- master signals mapped on dbg
|
| 110 |
|
|
wren_m <= dbg(11);
|
| 111 |
|
|
wr_ack_m <= dbg(10);
|
| 112 |
|
|
di_req_m <= dbg(9);
|
| 113 |
|
|
do_valid_m <= dbg(8);
|
| 114 |
|
|
-- slave signals mapped on dbg
|
| 115 |
|
|
wren_s <= dbg(7);
|
| 116 |
|
|
wr_ack_s <= dbg(6);
|
| 117 |
|
|
di_req_s <= dbg(5);
|
| 118 |
|
|
do_valid_s <= dbg(4);
|
| 119 |
|
|
|
| 120 |
12 |
jdoin |
|
| 121 |
|
|
--=============================================================================================
|
| 122 |
|
|
-- CLOCK GENERATION
|
| 123 |
|
|
--=============================================================================================
|
| 124 |
|
|
gclk_proc: process is
|
| 125 |
|
|
begin
|
| 126 |
|
|
loop
|
| 127 |
|
|
sysclk <= not sysclk;
|
| 128 |
|
|
wait for CLK_PERIOD / 2;
|
| 129 |
|
|
end loop;
|
| 130 |
|
|
end process gclk_proc;
|
| 131 |
|
|
|
| 132 |
|
|
--=============================================================================================
|
| 133 |
|
|
-- TEST BENCH STIMULI
|
| 134 |
|
|
--=============================================================================================
|
| 135 |
|
|
tb : process
|
| 136 |
|
|
begin
|
| 137 |
|
|
wait for 100 ns; -- wait until global set/reset completes
|
| 138 |
|
|
|
| 139 |
13 |
jdoin |
btn_data(btRESET) <= '1';
|
| 140 |
|
|
wait for 1 us;
|
| 141 |
|
|
btn_data(btRESET) <= '0';
|
| 142 |
|
|
wait for 900 ns;
|
| 143 |
|
|
|
| 144 |
12 |
jdoin |
sw_data <= X"5A";
|
| 145 |
|
|
|
| 146 |
|
|
wait; -- will wait forever
|
| 147 |
|
|
end process tb;
|
| 148 |
|
|
-- End Test Bench
|
| 149 |
|
|
END;
|