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

Subversion Repositories socwire

[/] [socwire/] [trunk/] [Testbench/] [switch_tb.vhd] - Blame information for rev 24

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 bjoerno
---====================== Start Copyright Notice ========================---
2
--==                                                                    ==--
3
--== Filename ..... switch_tb.vhd                                       ==--
4
--== Download ..... http://www.ida.ing.tu-bs.de                         ==--
5
--== Company ...... IDA TU Braunschweig, Prof. Dr.-Ing. Harald Michalik ==--
6
--== Authors ...... Björn Osterloh                                      ==--
7
--== Contact ...... Björn Osterloh (b.osterloh@tu-bs.de)                ==--
8
--== Copyright .... Copyright (c) 2008 IDA                              ==--
9
--== Project ...... SoCWire Switch Testbench                            ==--
10
--== Version ...... 1.00                                                ==--
11
--== Conception ... 22 April 2009                                       ==--
12 24 bjoerno
--== Modified ..... holgerm : minor bug fix marked with holgerm         ==--
13 13 bjoerno
--==                                                                    ==--
14
---======================= End Copyright Notice =========================---
15
 
16
LIBRARY ieee;
17
USE ieee.std_logic_1164.ALL;
18
USE ieee.std_logic_unsigned.all;
19
USE ieee.numeric_std.ALL;
20
 
21
USE WORK.ALL;
22
 
23
 
24
ENTITY switch_tb IS
25
  GENERIC(
26
          --== Number Of Ports ==--
27
          nports     : NATURAL RANGE 2 TO 32 := 4;
28
          --== Set Codec Speed to system clock in nanoseconds! ==--
29
                    --== DO NOT CHANGE THE GENERICS IN THE SUB MODULES!! ==--          
30
         datawidth            : NATURAL RANGE 8 TO 8192:=8;
31
         speed                      : NATURAL RANGE 1 TO 100:=10;               -- Set CODEC speed to system clock in nanoseconds !
32
         after64              : NATURAL RANGE 1 TO 6400:=64;   -- Spacewire Standard 6400 = 6.4 us
33
         after128             : NATURAL RANGE 1 TO 12800:=128; -- Spacewire Standard 12800 = 12.8 us                              
34
              disconnect_detection : NATURAL RANGE 1 TO 850:=85     -- Spacewire Standard 850 = 850 ns
35
         );
36
END switch_tb;
37
 
38
ARCHITECTURE behavior OF switch_tb IS
39
 
40
COMPONENT socwire_switch IS
41
  GENERIC(
42
          datawidth : NATURAL RANGE 8 TO 8192;
43
          nports     : NATURAL RANGE 2 TO 32;
44 24 bjoerno
          speed : NATURAL RANGE  1 TO 100;
45
          -- holgerm
46
               after64              : NATURAL RANGE 1 TO 6400:=6400;   -- Spacewire Standard 6400 = 6.4 us
47
          after128             : NATURAL RANGE 1 TO 12800:=12800; -- Spacewire Standard 12800 = 12.8 us
48
          disconnect_detection : NATURAL RANGE 1 TO 850:=850     -- Spacewire Standard 850 = 850 ns
49
          -- holgerm
50 13 bjoerno
         );
51
  PORT(
52
       --==  General Interface (Sync Rst, 50MHz Clock) ==--
53
 
54
       rst        : IN  STD_LOGIC;
55
       clk        : IN  STD_LOGIC;
56
 
57
       --== Serial Receive Interface ==--
58
 
59
       rx         : IN  STD_LOGIC_VECTOR((datawidth+2)*nports-1 DOWNTO 0);
60
       rx_valid   : IN  STD_LOGIC_VECTOR(nports-1 DOWNTO 0);
61
 
62
       --== Serial Transmit Interface ==--
63
 
64
       tx         : OUT STD_LOGIC_VECTOR((datawidth+2)*nports-1 DOWNTO 0);
65
       tx_valid   : OUT STD_LOGIC_VECTOR(nports-1 DOWNTO 0);
66
 
67
       --== Active Interface ==--
68
 
69
       active     : OUT STD_LOGIC_VECTOR(nports-1 DOWNTO 0)
70
      );
71
END COMPONENT;
72
 
73
 
74
COMPONENT socwire_codec
75
  GENERIC(
76
         datawidth            : NATURAL RANGE 8 TO 8192;
77
         speed                      : NATURAL RANGE 1 TO 100;
78
         after64              : NATURAL RANGE 1 TO 6400;
79
         after128             : NATURAL RANGE 1 TO 12800;
80
              disconnect_detection : NATURAL RANGE 1 TO 850
81
         );
82
 
83
        PORT(
84
                rst : IN std_logic;
85
                clk : IN std_logic;
86
                socw_en : IN std_logic;
87
                socw_dis : IN std_logic;
88
                rx : IN std_logic_vector(datawidth+1 downto 0);
89
                rx_valid : IN std_logic;
90
                dat_nwrite : IN std_logic;
91
                dat_din : IN std_logic_vector(datawidth downto 0);
92
                dat_nread : IN std_logic;
93
                tx : OUT std_logic_vector(datawidth+1 downto 0);
94
                tx_valid : OUT std_logic;
95
                dat_full : OUT std_logic;
96
                dat_empty : OUT std_logic;
97
                dat_dout : OUT std_logic_vector(datawidth downto 0);
98
                active : OUT std_logic
99
                );
100
        END COMPONENT;
101
 
102
 
103
 
104
 
105
SIGNAL rst :   STD_LOGIC;
106
SIGNAL clk :   STD_LOGIC:= '0';
107
 
108
SIGNAL rx         : STD_LOGIC_VECTOR((datawidth+2)*nports-1 DOWNTO 0);
109
SIGNAL rx_valid   : STD_LOGIC_VECTOR(nports-1 DOWNTO 0);
110
SIGNAL tx         : STD_LOGIC_VECTOR((datawidth+2)*nports-1 DOWNTO 0);
111
SIGNAL tx_valid   : STD_LOGIC_VECTOR(nports-1 DOWNTO 0);
112
SIGNAL active_i   : STD_LOGIC_VECTOR(nports-1 DOWNTO 0);
113
SIGNAL active_ii  : STD_LOGIC_VECTOR(nports-1 DOWNTO 0);
114
 
115
SIGNAL socw_en     : STD_LOGIC;
116
SIGNAL socw_dis    : STD_LOGIC;
117
 
118
SIGNAL dat_full   : STD_LOGIC_VECTOR(nports-1 DOWNTO 0);
119
SIGNAL dat_nwrite : STD_LOGIC_VECTOR(nports-1 DOWNTO 0);
120
SIGNAL dat_din    : STD_LOGIC_VECTOR((datawidth+1)*nports-1 DOWNTO 0);
121
SIGNAL dat_nread  : STD_LOGIC_VECTOR(nports-1 DOWNTO 0);
122
SIGNAL dat_empty  : STD_LOGIC_VECTOR(nports-1 DOWNTO 0);
123
SIGNAL dat_dout   : STD_LOGIC_VECTOR((datawidth+1)*nports-1 DOWNTO 0);
124
 
125
SIGNAL dat_nwrite_P0 : STD_LOGIC;
126
SIGNAL dat_nwrite_P1 : STD_LOGIC;
127
SIGNAL dat_nwrite_P2 : STD_LOGIC;
128
SIGNAL dat_nwrite_P3 : STD_LOGIC;
129
SIGNAL dat_din_P0 : STD_LOGIC_VECTOR (datawidth downto 0);
130
SIGNAL dat_din_P1 : STD_LOGIC_VECTOR (datawidth downto 0);
131
SIGNAL dat_din_P2 : STD_LOGIC_VECTOR (datawidth downto 0);
132
SIGNAL dat_din_P3 : STD_LOGIC_VECTOR (datawidth downto 0);
133
 
134 24 bjoerno
-- holgerm
135
-- compile with "vsim -novopt switch_tb" otherwise optimization will delete these signals
136
SIGNAL dat_empty_P0 : STD_LOGIC;
137
SIGNAL dat_empty_P1 : STD_LOGIC;
138
SIGNAL dat_empty_P2 : STD_LOGIC;
139
SIGNAL dat_empty_P3 : STD_LOGIC;
140
SIGNAL dat_dout_P0 : STD_LOGIC_VECTOR (datawidth downto 0);
141
SIGNAL dat_dout_P1 : STD_LOGIC_VECTOR (datawidth downto 0);
142
SIGNAL dat_dout_P2 : STD_LOGIC_VECTOR (datawidth downto 0);
143
SIGNAL dat_dout_P3 : STD_LOGIC_VECTOR (datawidth downto 0);
144
-- holgerm
145 13 bjoerno
 
146
BEGIN
147
 
148
        -- Component Declaration for the Unit Under Test (UUT)
149
 
150
  U0 : socwire_switch
151
    GENERIC MAP
152
      (
153
       datawidth =>datawidth,
154
       nports    => nports,
155 24 bjoerno
       speed      => speed,
156
       -- holgerm
157
       after64              =>after64,
158
       after128             =>after128,
159
       disconnect_detection =>disconnect_detection
160
       -- holgerm
161 13 bjoerno
      )
162
    PORT MAP
163
      (--==  General Interface (Sync Rst) ==--
164
       clk      => clk,
165
       rst      => rst,
166
       rx       => tx,
167
       rx_valid => tx_valid,
168
       tx       => rx,
169
       tx_valid => rx_valid,
170
       active   => active_i
171
      );
172
 
173
  G0 : FOR i IN 0 TO nports-1 GENERATE
174
    U1 : socwire_codec
175
      GENERIC MAP
176
        (
177
         datawidth            =>datawidth,
178
         speed                      =>speed,
179
         after64              =>after64,
180
         after128             =>after128,
181
              disconnect_detection =>disconnect_detection
182
        )
183
      PORT MAP
184
        (--==  General Interface (Sync Rst, 50MHz Clock) ==--
185
         rst        => rst,
186
         clk        => clk,
187
         --== Link Enable Interface ==--
188
         socw_en     => socw_en,
189
         socw_dis    => socw_dis,
190
         --== Serial Receive Interface ==--
191
         rx         => rx((i+1)*10-1 DOWNTO i*10),
192
         rx_valid   => rx_valid(i),
193
         --== Serial Transmit Interface ==--
194
         tx         => tx((i+1)*10-1 DOWNTO i*10),
195
                 tx_valid   => tx_valid(i),
196
         --== Data Input Interface ==--
197
         dat_full   => dat_full(i),
198
         dat_nwrite => dat_nwrite(i),
199
         dat_din    => dat_din((i+1)*9-1 DOWNTO i*9),
200
         --== Data Output Interface ==--
201
         dat_nread  => dat_nread(i),
202
         dat_empty  => dat_empty(i),
203
         dat_dout   => dat_dout((i+1)*9-1 DOWNTO i*9),
204
         --== Active Interface ==--
205
         active     => active_ii(i)
206
        );
207
  END GENERATE G0;
208
 
209
    socw_en  <= '1';
210
    socw_dis <= '0';
211
 
212
 
213
        clk <= not clk after 5 ns;
214
 
215
        dat_nwrite(0)<=dat_nwrite_P0;
216
        dat_nwrite(1)<=dat_nwrite_P1;
217
        dat_nwrite(2)<=dat_nwrite_P2;
218
        dat_nwrite(3)<=dat_nwrite_P3;
219
        dat_din(8 downto 0)  <=dat_din_P0;
220
        dat_din(17 downto 9) <=dat_din_P1;
221
        dat_din(26 downto 18)<=dat_din_P2;
222
        dat_din(35 downto 27)<=dat_din_P3;
223 24 bjoerno
 
224
   -- holgerm
225
   -- compile with "vsim -novopt switch_tb" otherwise optimization will delete these signals
226
   dat_empty_P0 <= dat_empty(0);
227
   dat_empty_P1 <= dat_empty(1);
228
   dat_empty_P2 <= dat_empty(2);
229
   dat_empty_P3 <= dat_empty(3);
230
   dat_dout_P0 <= dat_dout(8  downto  0);
231
   dat_dout_P1 <= dat_dout(17 downto  9);
232
   dat_dout_P2 <= dat_dout(26 downto 18);
233
   dat_dout_P3 <= dat_dout(35 downto 27);
234
   -- holgerm
235
 
236 13 bjoerno
 
237
 
238
        tb : PROCESS
239
 
240
        BEGIN
241
 
242
                rst <= '1';
243
                dat_nwrite_P0<='1';
244
                dat_nwrite_P1<='1';
245
                dat_nwrite_P2<='1';
246
                dat_nwrite_P3<='1';
247
                dat_din_P0<=(others=>'0');
248
                dat_din_P1<=(others=>'0');
249
                dat_din_P2<=(others=>'0');
250
                dat_din_P3<=(others=>'0');
251
                dat_nread  <= (others => '1');
252
                wait for 100 ns;
253
                rst <= '0';
254
                wait for 1 us;
255
                dat_nread  <= (others => '0');
256
 
257
--         Send Packet from Port 0 to Port 1                    
258
      dat_nwrite_P0<='0';
259
                dat_din_P0<="000000001"; -- Port 1
260
                wait for 10 ns;
261
      dat_din_P0<="000001010"; -- Data 0                
262
                wait for 10 ns;
263
                dat_din_P0<="000001011"; -- Data 1                      
264
                wait for 10 ns;
265
                dat_din_P0<="100000000"; -- EOP                 
266
           wait for 10 ns;
267 24 bjoerno
                dat_nwrite_P0<='1';
268
 
269 13 bjoerno
--         Send Packet from Port 2 to Port 3                    
270
      dat_nwrite_P2<='0';
271
                dat_din_P2<="000000011"; -- Port 3
272
                wait for 10 ns;
273
      dat_din_P2<="000001100"; -- Data 0                
274
                wait for 10 ns;
275
                dat_din_P2<="000001101"; -- Data 1                      
276
                wait for 10 ns;
277
                dat_din_P2<="100000000"; -- EOP                 
278
           wait for 10 ns;
279 24 bjoerno
                dat_nwrite_P2<='1';
280
 
281 13 bjoerno
--         Send Packet from Port 0 and Port 1 to Port 2 and Port 3                      
282
      dat_nwrite_P0<='0';
283 24 bjoerno
                dat_din_P0<="000000010"; -- Port 2
284 13 bjoerno
                dat_nwrite_P1<='0';
285
                dat_din_P1<="000000011"; -- Port 3
286
                wait for 10 ns;
287 24 bjoerno
      dat_din_P0<="000001110"; -- Data 0                
288 13 bjoerno
                dat_din_P1<="000001010"; -- Data 0              
289
                wait for 10 ns;
290
                dat_din_P0<="000001111"; -- Data 1                      
291 24 bjoerno
                dat_din_P1<="000001011"; -- Data 1              
292 13 bjoerno
                wait for 10 ns;
293 24 bjoerno
                dat_din_P0<="100000000"; -- EOP                 
294 13 bjoerno
                dat_din_P1<="100000000"; -- EOP                 
295
           wait for 10 ns;
296 24 bjoerno
                dat_nwrite_P0<='1';
297 13 bjoerno
                dat_nwrite_P1<='1';
298
 
299
 
300
 
301
 
302 24 bjoerno
 
303 13 bjoerno
 
304
 
305
 
306
 
307 24 bjoerno
 
308
 
309 13 bjoerno
                wait for 1000 ms; --wait very long      
310
 
311
        END PROCESS;
312
 
313
END;

powered by: WebSVN 2.1.0

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