OpenCores
URL https://opencores.org/ocsvn/spi_master_slave/spi_master_slave/trunk

Subversion Repositories spi_master_slave

[/] [spi_master_slave/] [trunk/] [syn/] [spi_master_atlys_test.vhd] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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 20 jdoin
        m_do_o => m_do_reg,
105
        s_do_o => s_do_reg,
106 13 jdoin
        m_state_o => master_state,
107
        s_state_o => slave_state,
108 12 jdoin
        dbg_o => dbg
109
        );
110
 
111 13 jdoin
    -- master signals mapped on dbg
112
    wren_m      <= dbg(11);
113
    wr_ack_m    <= dbg(10);
114
    di_req_m    <= dbg(9);
115
    do_valid_m  <= dbg(8);
116 20 jdoin
 
117 13 jdoin
    -- slave signals mapped on dbg
118
    wren_s      <= dbg(7);
119
    wr_ack_s    <= dbg(6);
120
    di_req_s    <= dbg(5);
121
    do_valid_s  <= dbg(4);
122
 
123 12 jdoin
 
124
    --=============================================================================================
125
    -- CLOCK GENERATION
126
    --=============================================================================================
127
    gclk_proc: process is
128
    begin
129
        loop
130
            sysclk <= not sysclk;
131
            wait for CLK_PERIOD / 2;
132
        end loop;
133
    end process gclk_proc;
134
 
135
    --=============================================================================================
136
    -- TEST BENCH STIMULI
137
    --=============================================================================================
138
    tb : process
139
    begin
140
        wait for 100 ns; -- wait until global set/reset completes
141
 
142 20 jdoin
        btn_data(btUP) <= '1';
143 13 jdoin
        wait for 1 us;
144 20 jdoin
        btn_data(btUP) <= '0';
145
        sw_data <= X"81";
146
        wait for 5 us;
147
        sw_data <= X"C1";
148
        wait for 5 us;
149
        sw_data <= X"C9";
150
        wait for 5 us;
151
        sw_data <= X"55";
152
        wait for 5 us;
153
        assert false report "End Simulation" severity failure; -- stop simulation
154 12 jdoin
    end process tb;
155
    --  End Test Bench 
156
END;

powered by: WebSVN 2.1.0

© copyright 1999-2020 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.