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

Subversion Repositories t400

[/] [t400/] [trunk/] [bench/] [vhdl/] [tb_t411.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 arniml
-------------------------------------------------------------------------------
2
--
3
-- Testbench for the T411 system toplevel.
4
--
5
-- $Id: tb_t411.vhd,v 1.1.1.1 2006-05-06 01:56:44 arniml Exp $
6
--
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_t411 is
47
 
48
end tb_t411;
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.t411;
56
 
57
architecture behav of tb_t411 is
58
 
59
  -- 210.4 kHz clock
60
  --  -> 52.6 kHz internal clock
61
  constant period_c : time := 4.75 us;
62
  signal   ck_s     : std_logic;
63
  signal   en_ck_s  : std_logic;
64
 
65
  signal reset_n_s  : std_logic;
66
 
67
  signal io_l_s     : std_logic_vector(7 downto 0);
68
  signal io_d_s     : std_logic_vector(1 downto 0);
69
  signal io_g_s     : std_logic_vector(2 downto 0);
70
 
71
  signal si_s,
72
         so_s,
73
         sk_s       : std_logic;
74
  signal sk_flt_s   : std_logic;
75
 
76
  signal vdd_s      : std_logic;
77
 
78
begin
79
 
80
  en_ck_s   <= 'H';
81
 
82
  vdd_s     <= '1';
83
  reset_n_s <= '1';
84
 
85
  -----------------------------------------------------------------------------
86
  -- DUT
87
  -----------------------------------------------------------------------------
88
  t411_b : t411
89
    port map (
90
      ck_i      => ck_s,
91
      ck_en_i   => vdd_s,
92
      reset_n_i => reset_n_s,
93
      si_i      => si_s,
94
      so_o      => so_s,
95
      sk_o      => sk_s,
96
      io_l_b    => io_l_s,
97
      io_d_o    => io_d_s,
98
      io_g_b    => io_g_s
99
    );
100
 
101
  io_l_s <= (others => 'H');
102
  io_d_s <= (others => 'H');
103
  io_g_s <= (others => 'H');
104
 
105
 
106
  -----------------------------------------------------------------------------
107
  -- Pass/fail catcher
108
  -----------------------------------------------------------------------------
109
  pass_fail: process (io_l_s)
110
    type pass_fail_t is (IDLE,
111
                         GOT_0, GOT_A, GOT_5);
112
    variable state_v : pass_fail_t := IDLE;
113
    variable sig_v   : std_logic_vector(3 downto 0);
114
  begin
115
    sig_v := to_X01(io_l_s(7 downto 4));
116
 
117
    case state_v is
118
      when IDLE =>
119
        en_ck_s <= 'Z';
120
        if sig_v = "0000" then
121
          state_v := GOT_0;
122
        end if;
123
      when GOT_0 =>
124
        if    sig_v = "1010" then
125
          state_v := GOT_A;
126
        elsif sig_v /= "0000" then
127
          state_v := IDLE;
128
        end if;
129
      when GOT_A =>
130
        if    sig_v = "0101" then
131
          state_v := GOT_5;
132
        elsif sig_v /= "1010" then
133
          state_v := IDLE;
134
        end if;
135
      when GOT_5 =>
136
        if    sig_v = "0000" then
137
          en_ck_s <= '0';
138
          assert false
139
            report "Simulation finished with PASS."
140
            severity note;
141
        elsif sig_v = "1111" then
142
          en_ck_s <= '0';
143
          assert false
144
            report "Simulation finished with FAIL."
145
            severity note;
146
        elsif sig_v /= "0101" then
147
          state_v := IDLE;
148
        end if;
149
    end case;
150
  end process pass_fail;
151
 
152
 
153
  -----------------------------------------------------------------------------
154
  -- D monitor
155
  -----------------------------------------------------------------------------
156
  d_moni: process (io_d_s)
157
    type d_moni_t is (IDLE,
158
                      STEP_1, STEP_2);
159
    variable state_v : d_moni_t := IDLE;
160
    variable sig_v   : unsigned(3 downto 0);
161
  begin
162
    sig_v := (others => '0');
163
    sig_v(io_d_s'range) := unsigned(to_X01(io_d_s));
164
 
165
    case state_v is
166
      when IDLE =>
167
        en_ck_s   <= 'Z';
168
        if sig_v = 1 then
169
          state_v := STEP_1;
170
        end if;
171
      when STEP_1 =>
172
        if sig_v = 2 then
173
          state_v := STEP_2;
174
        else
175
          state_v := IDLE;
176
        end if;
177
      when STEP_2 =>
178
        if sig_v /= 0 then
179
          state_v := IDLE;
180
        else
181
          en_ck_s <= '0';
182
          assert false
183
            report "Simulation finished with PASS (D-Port)."
184
            severity note;
185
        end if;
186
 
187
      when others =>
188
        null;
189
    end case;
190
 
191
  end process d_moni;
192
 
193
 
194
  -----------------------------------------------------------------------------
195
  -- G monitor
196
  -----------------------------------------------------------------------------
197
  g_moni: process (io_g_s)
198
    type d_moni_t is (IDLE,
199
                      STEP_1, STEP_2, STEP_3);
200
    variable state_v : d_moni_t := IDLE;
201
    variable sig_v   : unsigned(3 downto 0);
202
  begin
203
    sig_v := (others => '0');
204
    sig_v(io_g_s'range) := unsigned(to_X01(io_g_s));
205
 
206
    case state_v is
207
      when IDLE =>
208
        en_ck_s   <= 'Z';
209
        if sig_v = 1 then
210
          state_v := STEP_1;
211
        end if;
212
      when STEP_1 =>
213
        if sig_v = 2 then
214
          state_v := STEP_2;
215
        else
216
          state_v := IDLE;
217
        end if;
218
      when STEP_2 =>
219
        if sig_v = 4 then
220
          state_v := STEP_3;
221
        else
222
          state_v := IDLE;
223
        end if;
224
      when STEP_3 =>
225
        if sig_v /= 0 then
226
          state_v := IDLE;
227
        else
228
          en_ck_s <= '0';
229
          assert false
230
            report "Simulation finished with PASS (G-Port)."
231
            severity note;
232
        end if;
233
 
234
      when others =>
235
        null;
236
    end case;
237
 
238
  end process g_moni;
239
 
240
 
241
  -----------------------------------------------------------------------------
242
  -- Delta cycle filter on sk_s
243
  -----------------------------------------------------------------------------
244
  sk_flt: process
245
  begin
246
    wait until sk_s'event;
247
 
248
    wait for 1 ns;
249
 
250
    sk_flt_s <= sk_s;
251
  end process sk_flt;
252
 
253
 
254
  -----------------------------------------------------------------------------
255
  -- SIO peer
256
  -----------------------------------------------------------------------------
257
  sio_peer: process
258
  begin
259
    si_s <= '0';
260
 
261
    wait until io_l_s(4) = '0';
262
 
263
    while io_l_s(4) = '0' loop
264
      wait for 10 us;
265
      si_s <= so_s xor sk_s;
266
 
267
      wait until io_l_s'event or so_s'event or sk_s'event;
268
    end loop;
269
 
270
    -- now feed SO back to SI upon SK edge
271
    loop
272
      wait until sk_flt_s'event and sk_flt_s = '1';
273
      wait for 10 us;
274
      si_s <= so_s;
275
    end loop;
276
 
277
    wait;
278
  end process sio_peer;
279
 
280
 
281
  -----------------------------------------------------------------------------
282
  -- Clock generator
283
  -----------------------------------------------------------------------------
284
  clk: process
285
  begin
286
    ck_s <= '0';
287
    wait for period_c / 2;
288
    ck_s <= '1';
289
    wait for period_c / 2;
290
 
291
    if to_X01(en_ck_s) /= '1' then
292
      wait;
293
    end if;
294
  end process clk;
295
 
296
end behav;
297
 
298
 
299
-------------------------------------------------------------------------------
300
-- File History:
301
--
302
-- $Log: not supported by cvs2svn $
303
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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