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

Subversion Repositories t400

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

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

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

powered by: WebSVN 2.1.0

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