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

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.communication/] [basic_tester/] [1.0/] [vhd/] [basic_tester_rx.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : A block which reads and checks data coming via HIBI
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : basic_tester_rx.vhd
6
-- Author     : ege
7
-- Created    : 2010-03-30
8
-- Last update: 2012-02-06
9
--
10
-- Description: Reads ASCII file where each line describes reception of 1 word.
11
--              Each transfers needs 4 hexadecimal parameters:
12
--               - 4 max delay (clock cycles) after previous 
13
--               - expected incoming address
14
--               - expected incoming data value
15
--               - expected incoming command
16
--              Mismatches will be reported into stdout.
17
-------------------------------------------------------------------------------
18
-- Copyright (c) 2010
19
-------------------------------------------------------------------------------
20
-- Revisions  :
21
-- Date        Version  Author  Description
22
-- 2011            1.0     ege     First version
23
-------------------------------------------------------------------------------
24
-------------------------------------------------------------------------------
25
-- Funbase IP library Copyright (C) 2011 TUT Department of Computer Systems
26
--
27
--
28
-- This source file may be used and distributed without
29
-- restriction provided that this copyright statement is not
30
-- removed from the file and that any derivative work contains
31
-- the original copyright notice and the associated disclaimer.
32
--
33
-- This source file is free software; you can redistribute it
34
-- and/or modify it under the terms of the GNU Lesser General
35
-- Public License as published by the Free Software Foundation;
36
-- either version 2.1 of the License, or (at your option) any
37
-- later version.
38
--
39
-- This source is distributed in the hope that it will be
40
-- useful, but WITHOUT ANY WARRANTY; without even the implied
41
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
42
-- PURPOSE.  See the GNU Lesser General Public License for more
43
-- details.
44
--
45
-- You should have received a copy of the GNU Lesser General
46
-- Public License along with this source; if not, download it
47
-- from http://www.opencores.org/lgpl.shtml
48
-------------------------------------------------------------------------------
49
 
50
library ieee;
51
use ieee.std_logic_1164.all;
52
use ieee.numeric_std.all;
53
 
54
library std;
55
use std.textio.all;
56
use work.txt_util.all;                  -- for function sgtr(std_log_vec)
57
 
58
use work.basic_tester_pkg.all;            -- read_conf_file()
59
 
60
entity basic_tester_rx is
61
 
62
  generic (
63
    conf_file_g  : string  := "";
64
    comm_width_g : integer := 5;
65
    data_width_g : integer := 0
66
    );
67
  port (
68
    clk   : in std_logic;
69
    rst_n : in std_logic;
70
 
71
    done_out : out std_logic;           -- if this has finished
72
 
73
    -- HIBI wrapper ports
74
    agent_av_in    : in  std_logic;
75
    agent_data_in  : in  std_logic_vector (data_width_g-1 downto 0);
76
    agent_comm_in  : in  std_logic_vector (comm_width_g-1 downto 0);
77
    agent_re_out   : out std_logic;
78
    agent_empty_in : in  std_logic;
79
    agent_one_d_in : in  std_logic
80
    );
81
 
82
end basic_tester_rx;
83
 
84
 
85
architecture rtl of basic_tester_rx is
86
 
87
  -- Keep reading even if cannot check the data?
88
  constant allow_more_data_than_in_file_c : integer := 0;
89
 
90
  -- State machine
91
  type   control_states is (read_conf, wait_data, rd_addr, rd_data, finish);
92
  signal curr_state_r : control_states := read_conf;
93
 
94
  -- Registers for parameters
95
  signal delay_r    : integer;
96
  signal dst_addr_r : integer;
97
  signal data_val_r : integer;
98
  signal comm_r     : integer;
99
 
100
  -- Other registers
101
  signal re_r            : std_logic;
102
  signal last_addr_r     : std_logic_vector (data_width_g-1 downto 0);
103
  signal cycle_counter_r : integer;     -- measure delay
104
  signal n_addr_r        : integer;     -- count words
105
  signal n_data_r        : integer;     -- count words
106
  signal addr_correct_r  : std_logic;
107
  signal error_r         : std_logic;
108
 
109
  -- Registers may be reset to 'Z' to 'X' so that reset state is clearly
110
  -- distinguished from active state. Using dbg_level+Rst_Value array, the rst value may
111
  -- be easily set to '0'=no debug for synthesis.
112
  constant dbg_level_c   : integer range 0 to 3          := 0;
113
  constant rst_val_arr_c : std_logic_vector (6 downto 0) :=
114
    'X' & 'Z' & 'X' & 'Z' & 'X' & 'Z' & '0';
115
  -- Right now gives a lot of warnings when other than 0
116
 
117
 
118
begin  -- rtl
119
 
120
  agent_re_out <= re_r;
121
 
122
  main : process (clk, rst_n)
123
    file conf_data_file : text open read_mode is conf_file_g;
124
 
125
    -- The read values from file are stored into these
126
    variable delay_v    : integer;
127
    variable dst_ag_v   : integer;
128
    variable data_val_v : integer;
129
    variable cmd_v      : integer;
130
 
131
  begin  -- process main
132
 
133
    if rst_n = '0' then                 -- asynchronous reset (active low)
134
 
135
      curr_state_r    <= read_conf;
136
      last_addr_r     <= (others => rst_val_arr_c (dbg_level_c * 1));
137
      cycle_counter_r <= 0;
138
      re_r            <= '0';
139
      done_out        <= '0';
140
 
141
      n_addr_r       <= 0;
142
      n_data_r       <= 0;
143
      addr_correct_r <= '0';
144
      error_r        <= '0';
145
 
146
      delay_v    := 0;
147
      dst_ag_v   := 0;
148
      data_val_v := 0;
149
      cmd_v      := 0;
150
 
151
    elsif clk'event and clk = '1' then  -- rising clock edge
152
 
153
      case curr_state_r is
154
 
155
        when read_conf =>
156
          -- Read the file to see what data should arrive next
157
 
158
          if endfile(conf_data_file) then
159
            curr_state_r   <= finish;
160
            re_r           <= '1';
161
            addr_correct_r <= '0';
162
            error_r        <= '0';
163
            assert false report "End of the configuration file reached"
164
              severity note;
165
          else
166
            read_conf_file (
167
              delay        => delay_v,
168
              dest_agent_n => dst_ag_v,
169
              value        => data_val_v,
170
              cmd          => cmd_v,
171
              conf_dat     => conf_data_file);
172
 
173
            delay_r         <= delay_v;
174
            dst_addr_r      <= dst_ag_v;
175
            data_val_r      <= data_val_v;
176
            comm_r          <= cmd_v;
177
            error_r         <= '0';
178
            re_r            <= '0';
179
            cycle_counter_r <= 0;
180
            curr_state_r    <= wait_data;
181
 
182
            if dst_ag_v /= 0 then
183
              addr_correct_r <= '0';
184
              -- else keep the the old value  
185
            end if;
186
          end if;  -- endfile
187
 
188
 
189
        when wait_data =>
190
 
191
          if agent_empty_in = '0' then
192
            if agent_av_in = '1' then
193
              curr_state_r <= rd_addr;
194
            else
195
              if addr_correct_r = '1' then
196
                curr_state_r <= rd_data;
197
              else
198
                error_r      <= '1';
199
                assert false
200
                  report "Data received but addr could not be checked"
201
                  severity warning;
202
                curr_state_r <= read_conf;
203
              end if;
204
            end if;
205
            re_r <= '1';
206
 
207
          else
208
            re_r <= '0';
209
          end if;
210
 
211
          -- Increment the delay counter
212
          cycle_counter_r <= cycle_counter_r +1;
213
 
214
 
215
        when rd_addr =>
216
 
217
          -- Check the incoming address: a) no change, b) as in file
218
          addr_correct_r <= '1';        -- default that may be overriden
219
 
220
          if dst_addr_r = 0 then
221
            -- Assume that addr has not changed
222
 
223
            if agent_data_in /= last_addr_r then
224
              addr_correct_r <= '0';
225
              error_r        <= '1';
226
 
227
              assert false
228
                report "Addr does not match. Expected "
229
                & str(to_integer(signed(last_addr_r)))
230
                & " but got " & str(to_integer(unsigned(agent_data_in)))
231
                severity warning;
232
 
233
            end if;
234
 
235
 
236
          elsif dst_addr_r /= -1 then
237
            --  Expected addr was given in the file
238
 
239
            if to_integer(unsigned(agent_data_in)) /= dst_addr_r then
240
              addr_correct_r <= '0';
241
              error_r        <= '1';
242
 
243
              assert false
244
                report "Addr does not match. Expected 0d"
245
                & str(dst_addr_r) & " but got 0d"
246
                & str(to_integer(unsigned(agent_data_in)))
247
                severity warning;
248
 
249
            end if;
250
          end if;
251
 
252
          -- Check the incoming command
253
          if comm_r /= -1 then
254
 
255
            if to_integer(unsigned(agent_comm_in)) /= comm_r then
256
              error_r <= '1';
257
 
258
              assert false
259
                report "Comm does not match  Expected 0d"
260
                & str(comm_r) & " but got 0d"
261
                & str(to_integer(unsigned(agent_comm_in)))
262
                severity warning;
263
            end if;
264
          end if;
265
 
266
          last_addr_r     <= agent_data_in;
267
          n_addr_r        <= n_addr_r +1;
268
          cycle_counter_r <= cycle_counter_r +1;
269
 
270
          if agent_empty_in = '0' then
271
            re_r         <= '1';
272
            curr_state_r <= rd_data;
273
          else
274
            re_r         <= '0';
275
            curr_state_r <= wait_data;
276
          end if;
277
 
278
 
279
        when rd_data =>
280
          if agent_empty_in = '0' then
281
 
282
            re_r         <= '0';
283
            n_data_r     <= n_data_r +1;
284
            curr_state_r <= read_conf;
285
 
286
            -- Check
287
            --  a) if data arrived before wait time has expired
288
            if delay_r /= -1 then
289
 
290
              if delay_r < cycle_counter_r then
291
                error_r <= '1';
292
 
293
                assert false
294
                  report "Data arrived too late. Expected duration "
295
                  & str(delay_r) & " cycles, but it took "
296
                  & str(cycle_counter_r) & " cycles."
297
                  severity warning;
298
              end if;
299
            end if;
300
 
301
            --  b) if value is as expected
302
            if data_val_r /= -1 then
303
              if to_integer(signed(agent_data_in)) /= data_val_r then
304
                error_r <= '1';
305
 
306
                assert false
307
                  report "Wrong data value.  Expected 0d"
308
                  & str(data_val_r) & " but got 0d"
309
                  & str(to_integer(unsigned(agent_data_in)))
310
                  severity warning;
311
              end if;
312
            end if;
313
 
314
            --  c) command is as expected
315
            if comm_r /= -1 then
316
 
317
              if to_integer(unsigned(agent_comm_in)) /= comm_r then
318
                error_r <= '1';
319
 
320
                assert false
321
                  report "Comm does not match  Expected 0d"
322
                  & str(comm_r) & " but got 0d"
323
                  & str(to_integer(unsigned(agent_comm_in)))
324
                  severity warning;
325
              end if;
326
            end if;
327
 
328
          end if;
329
 
330
 
331
        when finish =>
332
          -- Notify that we're done.
333
          done_out        <= '1';
334
          cycle_counter_r <= 0;
335
          delay_r         <= 0;
336
          dst_addr_r      <= 0;
337
          data_val_r      <= 0;
338
          comm_r          <= 0;
339
          re_r            <= '1';
340
 
341
          if allow_more_data_than_in_file_c = 1 then
342
            -- Keep reading and counting if some data still arrives
343
            -- but cannot check anything
344
 
345
            if agent_empty_in = '0' and re_r = '1' then
346
              if agent_av_in = '1' then
347
                n_addr_r    <= n_addr_r +1;
348
                last_addr_r <= agent_data_in;
349
              else
350
                n_data_r <= n_data_r +1;
351
              end if;
352
            end if;
353
          else
354
            -- There should not be anymore data
355
            if agent_empty_in = '0' then
356
              error_r <= '1';
357
              assert false report "Unexpected data arrives"
358
                severity warning;
359
            end if;
360
 
361
          end if;
362
 
363
        when others => null;
364
      end case;                         -- curr_state_r
365
 
366
    end if;                             -- rst_n / clk'event
367
  end process main;
368
 
369
end rtl;

powered by: WebSVN 2.1.0

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