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

Subversion Repositories t400

[/] [t400/] [trunk/] [bench/] [vhdl/] [tb_microbus.vhd] - Blame information for rev 180

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

Line No. Rev Author Line
1 117 arniml
-------------------------------------------------------------------------------
2
--
3
-- Testbench for MICROBUS evaluation.
4
--
5 179 arniml
-- $Id: tb_microbus.vhd 179 2009-04-01 19:48:38Z arniml $
6 117 arniml
--
7
-- Copyright (c) 2006 Arnim Laeuger (arniml@opencores.org)
8
--
9
-- All rights reserved
10
--
11
-- Redistribution and use in source and synthezised forms, with or without
12
-- modification, are permitted provided that the following conditions are met:
13
--
14
-- Redistributions of source code must retain the above copyright notice,
15
-- this list of conditions and the following disclaimer.
16
--
17
-- Redistributions in synthesized form must reproduce the above copyright
18
-- notice, this list of conditions and the following disclaimer in the
19
-- documentation and/or other materials provided with the distribution.
20
--
21
-- Neither the name of the author nor the names of other contributors may
22
-- be used to endorse or promote products derived from this software without
23
-- specific prior written permission.
24
--
25
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
29
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
-- POSSIBILITY OF SUCH DAMAGE.
36
--
37
-- Please report bugs to the author, but before you do so, please
38
-- make sure that this is not a derivative work and that
39
-- you have the latest version of this file.
40
--
41
-- The latest version of this file can be found at:
42
--      http://www.opencores.org/cvsweb.shtml/t400/
43
--
44
-------------------------------------------------------------------------------
45
 
46
entity tb_microbus is
47
 
48
end tb_microbus;
49
 
50
 
51
library ieee;
52
use ieee.std_logic_1164.all;
53
use ieee.numeric_std.all;
54
 
55
use work.t400_system_comp_pack.t420;
56
use work.tb_pack.all;
57
use work.t400_opt_pack.all;
58
 
59
architecture behav of tb_microbus is
60
 
61
  -- 5 MHz clock
62
  constant period_c : time := 200 ns;
63
  signal   ck_s     : std_logic;
64
  signal   en_ck_s  : std_logic := '0';
65
 
66
  signal reset_n_s  : std_logic;
67
 
68
  signal io_l_s     : std_logic_vector(7 downto 0);
69
  signal io_d_s     : std_logic_vector(3 downto 0);
70
  signal io_g_s     : std_logic_vector(3 downto 0);
71
  signal io_in_s    : std_logic_vector(3 downto 0);
72
 
73
  signal si_s,
74
         so_s,
75
         sk_s       : std_logic;
76
 
77
  signal cs_n_s,
78
         rd_n_s,
79
         wr_n_s     : std_logic;
80
 
81
  signal tb_io_l_s  : std_logic_vector(7 downto 0);
82
 
83
begin
84
 
85
 
86
  reset_n_s <= '1';
87
 
88
  -----------------------------------------------------------------------------
89
  -- DUT
90
  -----------------------------------------------------------------------------
91
  t420_b : t420
92
    generic map (
93
      opt_ck_div_g   => t400_opt_ck_div_4_c,
94
      opt_microbus_g => t400_opt_microbus_c
95
    )
96
    port map (
97
      ck_i      => ck_s,
98
      ck_en_i   => en_ck_s,
99
      reset_n_i => reset_n_s,
100
      cko_i     => io_in_s(2),
101
      si_i      => si_s,
102
      so_o      => so_s,
103
      sk_o      => sk_s,
104
      io_l_b    => io_l_s,
105
      io_d_o    => io_d_s,
106
      io_g_b    => io_g_s,
107
      io_in_i   => io_in_s
108
    );
109
 
110
  io_l_s  <= (others => 'H');
111
  io_d_s  <= (others => 'H');
112
  io_g_s  <= (others => 'H');
113
  io_in_s <= (others => 'H');
114
 
115
 
116
  -----------------------------------------------------------------------------
117
  -- Testbench elements
118
  -----------------------------------------------------------------------------
119
  tb_elems_b : tb_elems
120
    generic map (
121
      period_g  => period_c,
122
      d_width_g => 4,
123
      g_width_g => 4
124
    )
125
    port map (
126
      io_l_i  => tb_io_l_s,
127
      io_d_i  => io_d_s,
128
      io_g_i  => io_g_s,
129
      io_in_o => open,
130
      so_i    => so_s,
131
      si_o    => si_s,
132
      sk_i    => sk_s,
133
      ck_o    => ck_s
134
    );
135
 
136
 
137
  -----------------------------------------------------------------------------
138
  -- Process ck_div
139
  --
140
  -- Purpose:
141
  --   Generates the en_ck_s signal from the high frequency clock.
142
  --
143
  ck_div: process (ck_s)
144
    variable cnt_v : natural := 0;
145
  begin
146
    if ck_s'event and ck_s = '1' then
147
      en_ck_s <= '0';
148
 
149
      if cnt_v = 25 then
150
        cnt_v := 0;
151
        en_ck_s <= '1';
152
      else
153
        cnt_v := cnt_v + 1;
154
      end if;
155
    end if;
156
  end process ck_div;
157
  --
158
  -----------------------------------------------------------------------------
159
 
160
 
161
  -----------------------------------------------------------------------------
162
  -- Process microbus
163
  --
164
  -- Purpose:
165
  --   Implements the microbus testbench element.
166
  --   a) sends twelve bytes of data to the DUT
167
  --        HELLO WORLD!
168
  --   b) reads twelve bytes from the DUT and compares them against
169
  --      the original sequence
170
  --
171
  microbus: process
172
    procedure tb_pass_fail(pass : in boolean) is
173
    begin
174
      tb_io_l_s <= "00000000";
175
      wait for 1 us;
176
      tb_io_l_s <= "10100000";
177
      wait for 1 us;
178
      tb_io_l_s <= "01010000";
179
      wait for 1 us;
180
 
181
      if pass then
182
        tb_io_l_s <= "00000000";
183
      else
184
        tb_io_l_s <= "11110000";
185
      end if;
186
      wait for 1 us;
187
    end;
188
 
189
    constant msg_c : string := string'("HELLO WORLD!");
190
  begin
191
    -- default settings
192
    cs_n_s    <= '1';
193
    rd_n_s    <= '1';
194
    wr_n_s    <= '1';
195
    io_l_s    <= (others => 'H');
196
    tb_io_l_s <= (others => '0');
197
 
198
    --
199
    -- send the message string
200
    --
201
    for idx in msg_c'range loop
202
      wait until io_g_s(0)'event and io_g_s(0) = '1';
203
      if idx mod 2 = 0 then
204
        -- short wait for even positions
205
        wait for 1 us;
206
      else
207
        -- long wait for odd positions
208
        wait for 1 ms;
209
      end if;
210
 
211
      io_l_s <= std_logic_vector(to_unsigned(character'pos(msg_c(idx)), 8));
212
      wait for 10 ns;
213
      cs_n_s <= '0';
214
      wr_n_s <= '0';
215
      wait for 400 ns;
216
      cs_n_s <= '1';
217
      wr_n_s <= '1';
218
      wait for 10 ns;
219
      io_l_s <= (others => 'H');
220
    end loop;
221
 
222
    --
223
    -- and receive it again
224
    --
225
    for idx in msg_c'range loop
226
      wait until io_g_s(0)'event and io_g_s(0) = '1';
227
      if idx mod 2 = 0 then
228
        -- short wait for even positions
229
        wait for 1 us;
230
      else
231
        -- long wait for odd positions
232
        wait for 1 ms;
233
      end if;
234
 
235
      cs_n_s <= '0';
236
      rd_n_s <= '0';
237
      wait for 400 ns;
238
      if character'pos(msg_c(idx)) /= to_integer(unsigned(io_l_s)) then
239
        tb_pass_fail(pass => false);
240
      end if;
241
      cs_n_s <= '1';
242
      rd_n_s <= '1';
243
 
244
      -- ack with dummy write
245
      wait for 1 us;
246
      cs_n_s <= '0';
247
      wr_n_s <= '0';
248
      wait for 400 ns;
249
      cs_n_s <= '1';
250
      wr_n_s <= '1';
251
    end loop;
252
 
253
    tb_pass_fail(pass => true);
254
    wait;
255
  end process microbus;
256
  --
257
  io_in_s(1) <= rd_n_s;
258
  io_in_s(2) <= cs_n_s;
259
  io_in_s(3) <= wr_n_s;
260
  --
261
  -----------------------------------------------------------------------------
262
 
263
 
264
end behav;

powered by: WebSVN 2.1.0

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