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

Subversion Repositories gecko3

[/] [gecko3/] [trunk/] [GECKO3COM/] [gecko3com-ip/] [core/] [USB_TMC_IP_tb.vhd] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 nussgipfel
--  GECKO3COM IP Core
2
--
3
--  Copyright (C) 2009 by
4
--   ___    ___   _   _
5
--  (  _ \ (  __)( ) ( )
6
--  | (_) )| (   | |_| |   Bern University of Applied Sciences
7
--  |  _ < |  _) |  _  |   School of Engineering and
8
--  | (_) )| |   | | | |   Information Technology
9
--  (____/ (_)   (_) (_)
10
--
11
--  This program is free software: you can redistribute it and/or modify
12
--  it under the terms of the GNU General Public License as published by
13
--  the Free Software Foundation, either version 3 of the License, or
14
--  (at your option) any later version.
15
--
16
--  This program is distributed in the hope that it will be useful,
17
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
--  GNU General Public License for more details. 
20
--  You should have received a copy of the GNU General Public License
21
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
--
23
--  URL to the project description: 
24
--    http://labs.ti.bfh.ch/gecko/wiki/systems/gecko3com/start
25
----------------------------------------------------------------------------------
26
--
27
--  Author:  Andreas Habegger, Christoph Zimmermann
28
--  Date of creation: 8. April 2009
29
--  Description:
30
--      F
31
--
32
--  Target Devices:     Xilinx Spartan3 FPGA's (usage of BlockRam in the Datapath)
33
--  Tool versions:      11.1
34
--  Dependencies:
35
--
36
----------------------------------------------------------------------------------
37
 
38
 
39 11 nussgipfel
library ieee;
40
use ieee.std_logic_1164.all;
41
use ieee.std_logic_arith.all;
42
 
43
---- Uncomment the following library declaration if instantiating
44
---- any Xilinx primitives in this code.
45
library UNISIM;
46
use UNISIM.VComponents.all;
47
 
48
library XilinxCoreLib;
49
 
50
library work;
51
use work.USB_TMC_IP_Defs.all;
52 12 nussgipfel
use work.USB_TMC_cmp.all;
53 11 nussgipfel
 
54
entity USB_TMC_IP_tb is
55
end USB_TMC_IP_tb;
56
 
57
 
58
 
59
architecture simulation of USB_TMC_IP_tb is
60
 
61
  -- components
62
 
63
 
64
component USB_TMC_IP
65
 port (
66
    i_nReset,
67
    i_IFCLK,                                                                     -- GPIF CLK (is Master)
68
         i_SYSCLK,                                                                       -- FPGA System CLK
69
    i_WRU,                              -- write from GPIF
70
    i_RDYU        : in          std_logic;        -- GPIF is ready
71
--       i_ENAIP          : in          std_logic;               -- enable the IP core
72
--       i_RDYD2IP : in         std_logic;                       -- data RDY 2 the IP core   
73
--       i_d2USB   : in         std_logic_vector(SIZE_DBUS_FPGA-1 downto 0);  -- FPGA DBUS
74
--       i_RxD    : in          std_logic;
75
--       o_TxD     : out                std_logic;
76
--       i_Switches: in         std_logic_vector(NUMBER_OF_SW-1 downto 0);
77
    o_WRX,                              -- To write to GPIF
78
    o_RDYX    : out     std_logic;      -- Core is ready
79
--       o_RDYIP   : out        std_logic;               -- IP ready FPGA site
80
--       o_DAVIP   : out        std_logic;               -- Data available for FPGA
81
         o_LEDrx,                            -- controll LED rx __DEB_INFO__
82
         o_LEDtx : out          std_logic;               -- controll LED tx __DEB_INFO__
83
         o_LEDrun  : out        std_logic;      -- controll LED running signalisation __DEB_INFO__
84
--       o_d2FPGA  : out        std_logic_vector(SIZE_DBUS_FPGA-1 downto 0);  -- FPGA DBUS
85
    b_dbus        : inout       std_logic_vector(SIZE_DBUS_GPIF-1 downto 0));  -- bidirect data bus
86
end component USB_TMC_IP;
87
 
88
 
89
 
90
        -- simulation types
91
        type TsimSend is (finish, sending, waiting);
92
  -- simulation constants
93
 
94
 --constant TIME_BASE  : time := 1 ns;
95
 
96
  constant CLK_PERIOD : time := 20 ns;
97
 
98
  constant DATA_BUS_SIZE  : integer                                     := SIZE_DBUS_GPIF;
99
  constant WORD_VALUE1    : std_logic_vector(DATA_BUS_SIZE-1 downto 0) := x"FF00";
100
  constant WORD_VALUE2    : std_logic_vector(DATA_BUS_SIZE-1 downto 0) := x"B030";
101
  constant WORD_VALUE3    : std_logic_vector(DATA_BUS_SIZE-1 downto 0) := x"50A0";
102
  -- signals
103
 
104
  signal sim_clk : std_logic;
105
  signal sim_rst : std_logic;
106
 
107 12 nussgipfel
  signal s_LEDrun, s_LEDtx, s_LEDrx : std_logic;
108 11 nussgipfel
  signal s_Switches : std_logic_vector(NUMBER_OF_SW-1 downto 0);
109
 
110
 
111
  signal sim_1      : boolean := false;
112
 
113
  signal send_data  : TsimSend := finish;
114
 
115
 
116
  signal WRU  : std_logic;
117
  signal RDYU : std_logic;
118
 
119
  signal WRX  : std_logic;
120
  signal RDYX : std_logic;
121
 
122
 
123
  signal data_bus : std_logic_vector(DATA_BUS_SIZE-1 downto 0);
124
 
125
 
126
begin  -- simulation
127
 
128
-------------------------------------------------------------------------------
129
-- Design maps
130
-------------------------------------------------------------------------------
131
 
132
DUT : USB_TMC_IP
133
  port map(
134
    i_nReset   => sim_rst,
135
    i_IFCLK    => sim_clk,                                                                       -- GPIF CLK (is Master)
136
         i_SYSCLK   => sim_clk,                                                                  -- FPGA System CLK
137
    i_WRU      => WRU,                             -- write from GPIF
138
    i_RDYU         => RDYU,        -- GPIF is ready
139
--       i_ENAIP           => ,                  -- enable the IP core
140
--       i_RDYD2IP      => ,     -- data RDY 2 the IP core   
141
--       i_d2USB    => ,   -- FPGA DBUS
142
--       i_RxD     => s_RxD, 
143
--       o_TxD      => s_TxD,
144
--       i_Switches => s_Switches,
145
    o_WRX      => WRX,                        -- To write to GPIF
146
    o_RDYX     => RDYX,   -- Core is ready
147
--       o_RDYIP    => ,         -- IP ready FPGA site
148
--       o_DAVIP    => ,                 -- Data available for FPGA
149
         o_LEDrx    => s_LEDrx,                  -- controll LED rx
150
         o_LEDtx    => s_LEDtx,                  -- controll LED tx
151
         o_LEDrun   => s_LEDrun,        -- controll LED running signalisation
152
--       o_d2FPGA   => ,  -- FPGA DBUS
153
    b_dbus         => data_bus -- bidirect data bus
154
        );
155
 
156
-------------------------------------------------------------------------------
157
-- monitoring FSM
158
------------------------------------------------------------------------------
159
 --state_monitor : entity work.state_monitor(tracing);
160
 
161
-- monitor: process (fsm_clk)
162
--  use std.textio.all;
163
--  file state_file : TEXT open WRITE_MODE is "FSM_STATES.txt";
164
--  
165
-- -- alias fsm_state is byte_com_tb.dut.pr_state;      
166
-- -- alias fsm_clk is DUT.i_IFCLK;
167
--      
168
--  begin  -- process monitor
169
--    if falling_edge(fsm_clk) then
170
--      report to_string(now) & ": " & to_string(fsm_state);
171
--    end if;
172
--  end process monitor;
173
 
174
 
175
-------------------------------------------------------------------------------
176
-- CLK process
177
-------------------------------------------------------------------------------
178
   clk_process: process
179
        begin
180
                sim_clk<='0';
181
                wait for CLK_PERIOD/2;
182
                sim_clk<='1';
183
                wait for CLK_PERIOD/2;
184
                if sim_1 then
185
                        wait;
186
                end if;
187
        end process;
188
 
189
 
190
 
191
        rst_process: process
192
        begin
193
                sim_rst<='0';
194
                wait for CLK_PERIOD;
195
                sim_rst<='1';
196
                wait;
197
        end process;
198
 
199
 
200
 
201
 
202
  assert not(WRX = '1' and RDYX = '1') report "WRX and RDYX are high on the same time" severity warning;
203
 
204
  assert not(WRU = '1' and RDYU = '1') report "WRU and RDYU -> DATA delet" severity note;
205
 
206
 
207
  assert sim_rst = '0' report "system reset" severity note;
208
 
209
-------------------------------------------------------------------------------
210
-- Send Data
211
-------------------------------------------------------------------------------
212
   sendData: process(sim_clk)
213
                variable v_toggle : integer range 0 to 3 := 0;
214
        begin
215
                if rising_edge(sim_clk) then
216
                        if send_data = sending then
217
                                if v_toggle = 0 then
218
                                        v_toggle := 1;
219
                                        data_bus <= WORD_VALUE1;
220
                                elsif v_toggle = 1 then
221
                                        v_toggle := 2;
222
                                        data_bus <= WORD_VALUE2;
223
                                elsif v_toggle = 2 then
224
                                        v_toggle := 0;
225
                                        data_bus <= WORD_VALUE3;
226
                                end if;
227
                        elsif send_data = finish then
228
                                data_bus <= (others => 'Z');
229
 
230
                        end if;
231
                end if;
232
        end process sendData;
233
-------------------------------------------------------------------------------
234
-- stimuli
235
-------------------------------------------------------------------------------
236
 
237
 
238
 
239
  stimuli : process
240
  begin
241
    WRU  <= '0';
242
    RDYU <= '0';
243
         send_data <= finish;
244
 
245
 
246
    assert sim_rst = '1' report "system ready to start" severity note;
247
 
248
    wait for 10 ns;
249
 
250
    assert sim_1 report "Simulation started" severity note;
251
 
252
    wait for  2*CLK_PERIOD;
253
 
254
 
255
    WRU <= '1';
256
 
257
    wait for CLK_PERIOD;
258
 
259
    if(WRX = '1') then
260
      assert WRX = '1' report "WRX : busreservation during a GPIF reservation" severity warning;
261
         else
262
           assert WRX = '0' report "WRX : no buscolision" severity warning;
263
    end if;
264
 
265
         wait for CLK_PERIOD;
266
 
267
         send_data <= sending;
268
 
269
         wait for CLK_PERIOD;
270
 
271
         if(RDYX = '0') then
272
                send_data <= waiting;
273
      assert RDYX = '0' report "RDYX : wait on IP ready ...." severity note;
274
      wait on RDYX until RDYX = '1';
275
                assert RDYX = '1' report "CORE is ready for data >>>" severity note;
276
    else
277
       assert RDYX = '1' report "CORE is ready for data >>>" severity note;
278
    end if;
279
 
280
         for i in 1 to 15 loop -- then wait for a few clock periods...
281
                if RDYX = '1' then
282
                        send_data <= sending;
283
                else
284
                        send_data <= waiting;
285
                end if;
286
                wait until rising_edge(sim_clk);
287
         end loop;
288
 
289
    WRU <= '0';
290
         send_data <= finish;
291
    assert WRU = '0' report "DATA written" severity note;
292
    wait for CLK_PERIOD;
293
 
294
    assert WRU = '0' report "output Z" severity note;
295
 
296
    wait for CLK_PERIOD;
297
 
298
 
299
  --end process writeData;
300
 
301
    if(WRX = '0') then
302
      assert WRX = '0' report "WRX : Waiting on incoming MSG ...." severity note;
303
      wait on WRX until WRX= '1';
304 12 nussgipfel
                wait for 7*CLK_PERIOD;
305 11 nussgipfel
                RDYU <= '1';
306
                assert WRX = '1' report "CORE send data RQ >>>" severity note;
307
    else
308 12 nussgipfel
           wait for 7*CLK_PERIOD;
309 11 nussgipfel
                RDYU <= '1';
310
                assert WRX = '1' report "CORE send data RQ >>>" severity note;
311
    end if;
312
 
313
 
314
 
315
                while WRX = '1' loop
316
                        RDYU <= '1';
317
                        send_data <= finish;
318
                        assert WRX = '1' report "CORE sended Data >>>" severity note;
319
                        wait until rising_edge(sim_clk);
320
                end loop;
321
 
322
                RDYU <= '0';
323
 
324
      wait for CLK_PERIOD;
325
 
326
      sim_1 <= false;
327
 
328
                assert sim_1 report "<<< End of simulation >>>" severity note;
329
 
330
  --  end process readData;
331
  end process stimuli;
332
 
333
end simulation;

powered by: WebSVN 2.1.0

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