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 24

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 24 jdoin
    constant SCLK_PERIOD : time := 11 ns;           -- serial high speed clock
17
    constant PCLK_PERIOD : time := 10 ns;           -- parallel high-speed clock
18 12 jdoin
 
19
    -- button definitions
20
    constant btRESET    : integer := 0;             -- these are constants to use as btn_i(x)
21
    constant btUP       : integer := 1;
22
    constant btLEFT     : integer := 2;
23
    constant btDOWN     : integer := 3;
24
    constant btRIGHT    : integer := 4;
25
    constant btCENTER   : integer := 5;
26
 
27
    --=============================================================================================
28
    -- COMPONENT DECLARATIONS
29
    --=============================================================================================
30
    component spi_master_atlys_top
31
    port(
32 24 jdoin
        sclk_i : in std_logic;
33
        pclk_i : in std_logic;
34 12 jdoin
        sw_i : in std_logic_vector(7 downto 0);
35
        btn_i : in std_logic_vector(5 downto 0);
36
        spi_ssel_o : out std_logic;
37
        spi_sck_o : out std_logic;
38
        spi_mosi_o : out std_logic;
39
        spi_miso_o : out std_logic;
40
        led_o : out std_logic_vector(7 downto 0);
41 13 jdoin
        s_do_o : out std_logic_vector (7 downto 0);
42
        m_do_o : out std_logic_vector (7 downto 0);
43
        m_state_o : out std_logic_vector (3 downto 0);
44
        s_state_o : out std_logic_vector (3 downto 0);
45 12 jdoin
        dbg_o : out std_logic_vector(11 downto 0)
46
    );
47
    end component;
48
 
49
    --=============================================================================================
50
    -- Signals for state machine control
51
    --=============================================================================================
52
 
53
    --=============================================================================================
54
    -- Signals for internal operation
55
    --=============================================================================================
56
    --- clock signals ---
57
    signal sysclk           : std_logic := '0';                                 -- 100MHz clock
58 24 jdoin
    signal pclk             : std_logic := '0';                                 -- 100MHz clock
59 12 jdoin
    --- switch debouncer signals ---
60
    signal sw_data          : std_logic_vector (7 downto 0) := (others => '0'); -- switch data
61
    --- pushbutton debouncer signals ---
62
    signal btn_data         : std_logic_vector (5 downto 0) := (others => '0'); -- pushbuttons
63
    --- spi port signals ---
64
    signal spi_ssel         : std_logic;
65
    signal spi_sck          : std_logic;
66
    signal spi_mosi         : std_logic;
67
    signal spi_miso         : std_logic;
68
    -- debug output signals
69
    signal leds             : std_logic_vector (7 downto 0) := (others => '0');
70
    signal dbg              : std_logic_vector (11 downto 0) := (others => '0');
71 13 jdoin
    -- debug ports --
72
    signal s_do_reg       : std_logic_vector (7 downto 0);
73
    signal m_do_reg       : std_logic_vector (7 downto 0);
74
    -- master signals mapped on dbg
75
    signal wren_m           : std_logic;
76
    signal wr_ack_m         : std_logic;
77
    signal di_req_m         : std_logic;
78
    signal do_valid_m       : std_logic;
79
    signal master_state     : std_logic_vector (3 downto 0);
80
    -- slave signals mapped on dbg
81
    signal wren_s           : std_logic;
82
    signal wr_ack_s         : std_logic;
83
    signal di_req_s         : std_logic;
84
    signal do_valid_s       : std_logic;
85
    signal slave_state      : std_logic_vector (3 downto 0);
86 12 jdoin
begin
87
 
88
    --=============================================================================================
89
    -- COMPONENT INSTANTIATIONS FOR THE CORES UNDER TEST
90
    --=============================================================================================
91
    -- spi_master_atlys_top:
92
    --      receives the 100 MHz clock from the board clock oscillator
93
    --      receives the 8 slide switches and 5 pushbuttons as test stimuli
94
    --      connects to 4 spi signals
95
    --      connects to 8 board LEDs
96
    --      connects to 12 debug pins
97 22 jdoin
    --      set debounce time to 2 us to save simulation time
98
        Inst_spi_master_atlys_top: spi_master_atlys_top
99
        port map(
100 24 jdoin
            sclk_i => sysclk,
101
            pclk_i => pclk,
102 22 jdoin
            spi_ssel_o => spi_ssel,
103
            spi_sck_o => spi_sck,
104
            spi_mosi_o => spi_mosi,
105
            spi_miso_o => spi_miso,
106
            sw_i => sw_data,
107
            btn_i => btn_data,
108
            led_o => leds,
109
            m_do_o => m_do_reg,
110
            s_do_o => s_do_reg,
111
            m_state_o => master_state,
112
            s_state_o => slave_state,
113
            dbg_o => dbg
114
        );
115 12 jdoin
 
116 13 jdoin
    -- master signals mapped on dbg
117
    wren_m      <= dbg(11);
118
    wr_ack_m    <= dbg(10);
119
    di_req_m    <= dbg(9);
120
    do_valid_m  <= dbg(8);
121 20 jdoin
 
122 13 jdoin
    -- slave signals mapped on dbg
123
    wren_s      <= dbg(7);
124
    wr_ack_s    <= dbg(6);
125
    di_req_s    <= dbg(5);
126
    do_valid_s  <= dbg(4);
127
 
128 12 jdoin
 
129
    --=============================================================================================
130
    -- CLOCK GENERATION
131
    --=============================================================================================
132 24 jdoin
    sysclk_proc: process is
133 12 jdoin
    begin
134
        loop
135
            sysclk <= not sysclk;
136 24 jdoin
            wait for SCLK_PERIOD / 2;
137 12 jdoin
        end loop;
138 24 jdoin
    end process sysclk_proc;
139 12 jdoin
 
140 24 jdoin
    pclk_proc: process is
141
    begin
142
        loop
143
            pclk <= not pclk;
144
            wait for PCLK_PERIOD / 2;
145
        end loop;
146
    end process pclk_proc;
147
 
148 12 jdoin
    --=============================================================================================
149
    -- TEST BENCH STIMULI
150
    --=============================================================================================
151
    tb : process
152
    begin
153
        wait for 100 ns; -- wait until global set/reset completes
154
 
155 20 jdoin
        btn_data(btUP) <= '1';
156 13 jdoin
        wait for 1 us;
157 20 jdoin
        btn_data(btUP) <= '0';
158
        sw_data <= X"81";
159
        wait for 5 us;
160 22 jdoin
        sw_data <= X"65";
161 20 jdoin
        wait for 5 us;
162
        sw_data <= X"C9";
163
        wait for 5 us;
164
        sw_data <= X"55";
165
        wait for 5 us;
166 24 jdoin
        sw_data <= X"AA";
167
        wait for 5 us;
168
        sw_data <= X"1e";
169
        wait for 5 us;
170
        sw_data <= X"79";
171
        wait for 5 us;
172
        sw_data <= X"40";
173
        wait for 5 us;
174 20 jdoin
        assert false report "End Simulation" severity failure; -- stop simulation
175 12 jdoin
    end process tb;
176
    --  End Test Bench 
177
END;

powered by: WebSVN 2.1.0

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