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

Subversion Repositories t400

[/] [t400/] [trunk/] [bench/] [vhdl/] [tb_elems.vhd] - Blame information for rev 179

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 18 arniml
-------------------------------------------------------------------------------
2
--
3
-- Generic testbench elements
4
--
5 179 arniml
-- $Id: tb_elems.vhd 179 2009-04-01 19:48:38Z arniml $
6 18 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
library ieee;
47
use ieee.std_logic_1164.all;
48
 
49
entity tb_elems is
50
 
51
  generic (
52
    period_g  : time := 4.75 us;
53
    d_width_g : integer := 4;
54
    g_width_g : integer := 4
55
  );
56
  port (
57 56 arniml
    io_l_i  : in  std_logic_vector(7 downto 0);
58
    io_d_i  : in  std_logic_vector(d_width_g-1 downto 0);
59
    io_g_i  : in  std_logic_vector(g_width_g-1 downto 0);
60
    io_in_o : out std_logic_vector(g_width_g-1 downto 0);
61
    so_i    : in  std_logic;
62
    si_o    : out std_logic;
63
    sk_i    : in  std_logic;
64
    ck_o    : out std_logic
65 18 arniml
  );
66
 
67
end tb_elems;
68
 
69
 
70
library ieee;
71
use ieee.numeric_std.all;
72
 
73
architecture behav of tb_elems is
74
 
75
  signal en_ck_s : std_logic;
76
 
77
begin
78
 
79
  en_ck_s   <= 'H';
80
 
81
  -----------------------------------------------------------------------------
82
  -- Pass/fail catcher
83
  -----------------------------------------------------------------------------
84
  pass_fail: process (io_l_i)
85
    type pass_fail_t is (IDLE,
86
                         GOT_0, GOT_A, GOT_5);
87
    variable state_v : pass_fail_t := IDLE;
88
    variable sig_v   : std_logic_vector(3 downto 0);
89
  begin
90
    sig_v := to_X01(io_l_i(7 downto 4));
91
 
92
    case state_v is
93
      when IDLE =>
94
        en_ck_s <= 'Z';
95
        if sig_v = "0000" then
96
          state_v := GOT_0;
97
        end if;
98
      when GOT_0 =>
99
        if    sig_v = "1010" then
100
          state_v := GOT_A;
101
        elsif sig_v /= "0000" then
102
          state_v := IDLE;
103
        end if;
104
      when GOT_A =>
105
        if    sig_v = "0101" then
106
          state_v := GOT_5;
107
        elsif sig_v /= "1010" then
108
          state_v := IDLE;
109
        end if;
110
      when GOT_5 =>
111
        if    sig_v = "0000" then
112
          en_ck_s <= '0';
113
          assert false
114
            report "Simulation finished with PASS."
115
            severity note;
116
        elsif sig_v = "1111" then
117
          en_ck_s <= '0';
118
          assert false
119
            report "Simulation finished with FAIL."
120
            severity note;
121
        elsif sig_v /= "0101" then
122
          state_v := IDLE;
123
        end if;
124
    end case;
125
  end process pass_fail;
126
 
127
 
128
  -----------------------------------------------------------------------------
129
  -- D monitor
130
  -----------------------------------------------------------------------------
131
  d_moni: process (io_d_i)
132
    type d_moni_t is (IDLE,
133 31 arniml
                      STEP_1, STEP_2,
134
                      STEP_3, STEP_4);
135 18 arniml
    variable state_v : d_moni_t := IDLE;
136
    variable sig_v   : unsigned(3 downto 0);
137
  begin
138
    sig_v := (others => '0');
139
    sig_v(io_d_i'range) := unsigned(to_X01(io_d_i));
140
 
141
    case state_v is
142
      when IDLE =>
143
        en_ck_s   <= 'Z';
144
        if sig_v = 1 then
145
          state_v := STEP_1;
146
        end if;
147
      when STEP_1 =>
148
        if sig_v = 2 then
149
          state_v := STEP_2;
150
        else
151
          state_v := IDLE;
152
        end if;
153
      when STEP_2 =>
154 31 arniml
        if    sig_v = 4 then
155
          state_v := STEP_3;
156
        elsif sig_v /= 0 then
157 18 arniml
          state_v := IDLE;
158
        else
159 31 arniml
          -- sim finished for 2-bit D ports
160 18 arniml
          en_ck_s <= '0';
161
          assert false
162 31 arniml
            report "Simulation finished with PASS (D-Port 2 bit)."
163 18 arniml
            severity note;
164
        end if;
165 31 arniml
      when STEP_3 =>
166
        if    sig_v = 8 then
167
          state_v := STEP_4;
168
        elsif sig_v /= 0 then
169
          state_v := IDLE;
170
        else
171
          -- sim finished for 3-bit D ports
172
          en_ck_s <= '0';
173
          assert false
174
            report "Simulation finished with PASS (D-Port 3 bit)."
175
            severity note;
176
        end if;
177
      when STEP_4 =>
178 64 arniml
        if sig_v = 15 then
179
          -- sim finished pass for 4-bit D ports
180 31 arniml
          en_ck_s <= '0';
181
          assert false
182
            report "Simulation finished with PASS (D-Port 4 bit)."
183
            severity note;
184 64 arniml
        elsif sig_v = 0 then
185
          -- sim finished fail for 4-bit D ports
186
          en_ck_s <= '0';
187
          assert false
188
            report "Simulation finished with FAIL (D-Port 4 bit)."
189
            severity note;
190
        else
191
          state_v := IDLE;
192 31 arniml
        end if;
193 18 arniml
 
194
      when others =>
195
        null;
196
    end case;
197
 
198
  end process d_moni;
199
 
200
 
201
  -----------------------------------------------------------------------------
202
  -- G monitor
203
  -----------------------------------------------------------------------------
204
  g_moni: process (io_g_i)
205
    type d_moni_t is (IDLE,
206 29 arniml
                      STEP_1, STEP_2, STEP_3,
207
                      STEP_4);
208 18 arniml
    variable state_v : d_moni_t := IDLE;
209
    variable sig_v   : unsigned(3 downto 0);
210
  begin
211
    sig_v := (others => '0');
212
    sig_v(io_g_i'range) := unsigned(to_X01(io_g_i));
213
 
214
    case state_v is
215
      when IDLE =>
216
        en_ck_s   <= 'Z';
217
        if sig_v = 1 then
218
          state_v := STEP_1;
219
        end if;
220
      when STEP_1 =>
221
        if sig_v = 2 then
222
          state_v := STEP_2;
223
        else
224
          state_v := IDLE;
225
        end if;
226
      when STEP_2 =>
227
        if sig_v = 4 then
228
          state_v := STEP_3;
229
        else
230
          state_v := IDLE;
231
        end if;
232
      when STEP_3 =>
233 29 arniml
        if    sig_v = 8 then
234
          state_v := STEP_4;
235
        elsif sig_v /= 0 then
236 18 arniml
          state_v := IDLE;
237
        else
238 31 arniml
          -- sim finished for 3-bit G ports
239 18 arniml
          en_ck_s <= '0';
240
          assert false
241 31 arniml
            report "Simulation finished with PASS (G-Port 3 bit)."
242 18 arniml
            severity note;
243
        end if;
244 29 arniml
      when STEP_4 =>
245
        if sig_v /= 15 then
246
          state_v := IDLE;
247
        else
248 31 arniml
          -- sim finished for 4-bit G ports
249 29 arniml
          en_ck_s <= '0';
250
          assert false
251 31 arniml
            report "Simulation finished with PASS (G-Port 4 bit)."
252 29 arniml
            severity note;
253
        end if;
254 18 arniml
 
255
      when others =>
256
        null;
257
    end case;
258
 
259
  end process g_moni;
260
 
261
 
262 56 arniml
  -- feed back G on IN
263
  io_in_o <= io_g_i;
264
 
265
 
266 18 arniml
  -----------------------------------------------------------------------------
267
  -- SIO peer
268
  -----------------------------------------------------------------------------
269
  sio_peer: process
270
  begin
271
    si_o <= '0';
272
 
273
    wait until io_l_i(4) = '0';
274
 
275
    while io_l_i(4) = '0' loop
276 73 arniml
      si_o <= so_i xor sk_i after 10 us;
277 18 arniml
 
278
      wait until io_l_i'event or so_i'event or sk_i'event;
279
    end loop;
280
 
281
    -- now feed SO back to SI upon SK edge
282
    loop
283
      wait until sk_i'event and sk_i = '1';
284 73 arniml
      si_o <= so_i after 10 us;
285 18 arniml
    end loop;
286
 
287
    wait;
288
  end process sio_peer;
289
 
290
 
291
  -----------------------------------------------------------------------------
292
  -- Clock generator
293
  -----------------------------------------------------------------------------
294
  clk: process
295
  begin
296
    ck_o <= '0';
297
    wait for period_g / 2;
298
    ck_o <= '1';
299
    wait for period_g / 2;
300
 
301
    if to_X01(en_ck_s) /= '1' then
302
      wait;
303
    end if;
304
  end process clk;
305
 
306
end behav;

powered by: WebSVN 2.1.0

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