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

Subversion Repositories socwire

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

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

Line No. Rev Author Line
1 13 bjoerno
---====================== Start Copyright Notice ========================---
2
--==                                                                    ==--
3
--== Filename ..... codec_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, Karel Kotarowski                    ==--
7
--== Contact ...... Björn Osterloh (b.osterloh@tu-bs.de)                ==--
8
--== Copyright .... Copyright (c) 2008 IDA                              ==--
9
--== Project ...... SoCWire CODEC Testbench                             ==--
10
--== Version ...... 1.00                                                ==--
11
--== Conception ... 22 April 2009                                       ==--
12
--== Modified ..... N/A                                                 ==--
13
--==                                                                    ==--
14
---======================= End Copyright Notice =========================---
15
 
16
---====================== CODEC Loopback Testbench ======================---
17
--== 1 SoCWire CODEC with 8 Bit data word width is operated in Loobpack
18
--== mode. Packets from 1 Byte to 64KByte length increased by 1 Byte 
19
--== are send over the link. Each packet is terminated with EOP marker. 
20
--== The packets are compared and errors reported. 
21
--== The active signal is monitored to report link errors.                                                                                                                              
22
--========================================================================--
23
 
24
LIBRARY ieee;
25
USE ieee.std_logic_1164.ALL;
26
USE ieee.numeric_std.ALL;
27
USE ieee.std_logic_unsigned.all;
28
USE ieee.std_logic_textio.all;
29
USE STD.TEXTIO.all;
30
 
31
ENTITY CODEC_Loopback_tb_vhd IS
32
GENERIC (
33
         --== USE GEREIC MAPPING FROM TOPLEVEL!!! ==--
34
              datawidth            : NATURAL RANGE 8 TO 8192:=8;
35
         speed                      : NATURAL RANGE 1 TO 100:=10;               -- Set CODEC speed to system clock in nanoseconds !
36
         after64              : NATURAL RANGE 1 TO 6400:=64;   -- Spacewire Standard 6400 = 6.4 us
37
         after128             : NATURAL RANGE 1 TO 12800:=128; -- Spacewire Standard 12800 = 12.8 us                              
38
              disconnect_detection : NATURAL RANGE 1 TO 850:=85     -- Spacewire Standard 850 = 850 ns
39
         );
40
END CODEC_Loopback_tb_vhd;
41
 
42
ARCHITECTURE behavior OF CODEC_Loopback_tb_vhd IS
43
 
44
        COMPONENT socwire_codec
45
        GENERIC(
46
              --== USE GEREIC MAPPING FROM TOPLEVEL!!!==--
47
              datawidth            : NATURAL RANGE 8 TO 8192:=8;
48
         speed                        : NATURAL RANGE 1 TO 100:=10;             -- Set CODEC speed to system clock in nanoseconds !
49
         after64              : NATURAL RANGE 1 TO 6400:=64;   -- Spacewire Standard 6400 = 6.4 us
50
         after128             : NATURAL RANGE 1 TO 12800:=128; -- Spacewire Standard 12800 = 12.8 us                              
51
              disconnect_detection : NATURAL RANGE 1 TO 850:=85     -- Spacewire Standard 850 = 850 ns
52
         );
53
        PORT(
54
                rst : IN std_logic;
55
                clk : IN std_logic;
56
                socw_en : IN std_logic;
57
                socw_dis : IN std_logic;
58
                rx : IN std_logic_vector(9 downto 0);
59
                rx_valid : IN std_logic;
60
                dat_nwrite : IN std_logic;
61
                dat_din : IN std_logic_vector(8 downto 0);
62
                dat_nread : IN std_logic;
63
                tx : OUT std_logic_vector(9 downto 0);
64
                tx_valid : OUT std_logic;
65
                dat_full : OUT std_logic;
66
                dat_empty : OUT std_logic;
67
                dat_dout : OUT std_logic_vector(8 downto 0);
68
                active : OUT std_logic
69
                );
70
        END COMPONENT;
71
 
72
        --Inputs
73
        SIGNAL rst :  std_logic := '0';
74
        SIGNAL clk :  std_logic := '0';
75
        SIGNAL socw_en :  std_logic := '0';
76
        SIGNAL socw_dis :  std_logic := '0';
77
        SIGNAL rx_valid :  std_logic := '0';
78
        SIGNAL dat_nwrite :  std_logic := '0';
79
        SIGNAL dat_nread :  std_logic := '0';
80
        SIGNAL rx :  std_logic_vector(9 downto 0) := (others=>'0');
81
        SIGNAL dat_din :  std_logic_vector(8 downto 0) := (others=>'0');
82
 
83
        --Outputs
84
        SIGNAL tx :  std_logic_vector(9 downto 0);
85
        SIGNAL tx_valid :  std_logic;
86
        SIGNAL dat_full :  std_logic;
87
        SIGNAL dat_empty :  std_logic;
88
        SIGNAL dat_dout :  std_logic_vector(8 downto 0);
89
        SIGNAL active :  std_logic;
90
 
91
        --Testbench
92
        constant clk_per        : time      := 10 ns; -- 10 ns -> 100 MHz clock   
93
   signal   clk_cnt  : integer   := 0;     -- clock counter      
94
        signal   dat_cnt  : integer   := 0;     -- data counter    
95
        signal flag : std_logic:='0';
96
        signal data_gen : std_logic_vector (8 downto 0);
97
        signal data8bit : std_logic_vector (7 downto 0):=(others=>'0');
98
   signal   dat_len  : integer  :=0;
99
        signal loop_cnt : integer := 0;
100
        signal compare_cnt : std_logic_vector ( 7 downto 0):="00000001";
101
        signal monitoractive : std_logic:='0';
102
   Signal StartDatGen : std_logic:='0';
103
        Signal EndDatGen: std_logic;
104
 
105
 
106
BEGIN
107
 
108
        uut: socwire_codec
109
        GENERIC MAP (
110
              datawidth            =>datawidth,
111
         speed                      =>speed,
112
         after64              =>after64,
113
         after128             =>after128,
114
              disconnect_detection =>disconnect_detection)
115
        PORT MAP(
116
                rst => rst,
117
                clk => clk,
118
                socw_en => socw_en,
119
                socw_dis => socw_dis,
120
                rx => rx,
121
                rx_valid => rx_valid,
122
                tx => rx,
123
                tx_valid => rx_valid,
124
                dat_full => dat_full,
125
                dat_nwrite => dat_nwrite,
126
                dat_din => dat_din,
127
                dat_nread => dat_nread,
128
                dat_empty => dat_empty,
129
                dat_dout => dat_dout,
130
                active => active
131
        );
132
 
133
   -- clock generation 
134
   clk_gen : process
135
    begin
136
      wait for clk_per / 2;
137
      clk <= not clk;
138
   end process;
139
 
140
   -- read data  
141
        read_core: process(clk,dat_empty)
142
        begin
143
         If clk ='1' and clk'event then
144
          If dat_empty = '0' and active = '1' then
145
                dat_nread<='0';
146
          else
147
                dat_nread<='1';
148
          end if;
149
         end if;
150
        end process;
151
 
152
        -- Compare data
153
   compare_core: Process (clk,dat_nread)
154
   Begin
155
         If CLK = '1' and CLK'event then
156
          If dat_nread = '0' and dat_empty = '0' then
157
           If dat_dout = 256 then
158
                 compare_cnt<="00000001";
159
                elsif dat_dout <= 255 then
160
                  If compare_cnt = dat_dout (7 downto 0) then
161
                   compare_cnt<=compare_cnt + '1';
162
                  else
163
                        ASSERT False
164
         Report "Data Error"
165
         Severity Failure;
166
                  end if;
167
                end if;
168
          end if;
169
         end if;
170
        end process;
171
 
172
        -- clock counter
173
   clk_counter : process(clk)
174
     begin
175
       if CLK ='0' and CLK'event then
176
         clk_cnt <= clk_cnt + 1;
177
       end if;
178
   end process;
179
 
180
        -- generate reset
181
   ctrl_sig_gen : process (clk, clk_cnt)
182
   begin
183
   If CLK='1' and CLK'event then
184
    case clk_cnt is
185
      when 1        => rst <= '1';
186
           when 10           => rst <= '0';
187
        when others => null;
188
    end case;
189
   end if;
190
   end process;
191
 
192
        -- data generation
193
        data_gen_p: Process (clk,rst,active,clk_cnt,dat_cnt,StartDatGen)
194
        begin
195
         If rst = '1' then
196
          data_gen<="000000000";
197
          dat_nwrite<='1';
198
          dat_cnt<= 0;
199
          EndDatGen<='0';
200
          data8bit<="00000001";
201
         elsif Clk = '1' and clk'event then
202
          If active = '1' and dat_full = '0' and StartDatGen ='1' then
203
             EndDatGen<='0';
204
                  dat_cnt<=dat_cnt + 1;
205
                  If dat_cnt >= 1 and dat_cnt < dat_len then
206
                          dat_nwrite<='0';
207
                data8Bit<=data8bit +'1';
208
                          dat_din<='0' & data8bit;
209
                  elsif dat_cnt = dat_len then
210
                     dat_din<="100000000";
211
                  elsif dat_cnt = dat_len+1 then
212
                      dat_nwrite<='1';
213
                                dat_cnt<= 0 ;
214
                                EndDatGen<= '1';
215
                                data_gen<="000000000";
216
                                data8bit<="00000001";
217
                  end if;
218
          end if;
219
         end if;
220
        end process;
221
 
222
 
223
  -- observe active
224
  Process ( monitoractive,active)
225
  Begin
226
   If monitoractive = '1' then
227
                If active = '0' then
228
                 ASSERT False
229
       Report "Link Error"
230
       Severity Failure;
231
                 end if;
232
        end if;
233
 
234
 end Process;
235
 
236
 
237
 
238
 
239
        tb : PROCESS
240
        BEGIN
241
          StartDatGen<='0';
242
     dat_len <=1;
243
          socw_en<='1';
244
          wait until active = '1';
245
          wait for 2 us;
246
          StartDatGen<='1';
247
          monitoractive<='1';
248
          wait until EndDatGen = '1';
249
          StartDatGen<='0';
250
          wait for 200 ns;
251
  -- up to 64 KByte Packet length
252
     for index IN 0 to 65536 LOOP
253
     loop_cnt<=index;
254
          dat_len <=dat_len +1;
255
          StartDatGen<='1';
256
          wait until EndDatGen = '1';
257
          StartDatGen<='0';
258
          wait for 500 ns;
259
     END LOOP;
260
 
261
          wait for 5 us;
262
     ASSERT False
263
       Report "End of Test "
264
       Severity Failure;
265
     END PROCESS;
266
 
267
END;

powered by: WebSVN 2.1.0

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