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.interface/] [button_messenger/] [1.0/] [tb/] [tb_button_messenger.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : Testbench for button logic that sends a message every time a
3
--              button pressed. Pressing button means falling edge in its input.
4
-- Project    : 
5
-------------------------------------------------------------------------------
6
-- File       : tb_button_messenger.vhd
7
-- Author     : ege
8
-- Created    : 2010/03/16
9
-- Last update: 2012-02-10
10
-- Description: 
11
--
12
-------------------------------------------------------------------------------
13
-- Copyright (c) 2010 
14
-------------------------------------------------------------------------------
15
-- Revisions  :
16
-- Date        Version  Author  Description
17
-- 2012-02-10  1.0      ES      Created
18
--
19
-------------------------------------------------------------------------------
20
-------------------------------------------------------------------------------
21
-- Funbase IP library Copyright (C) 2011 TUT Department of Computer Systems
22
--
23
--
24
-- This source file may be used and distributed without
25
-- restriction provided that this copyright statement is not
26
-- removed from the file and that any derivative work contains
27
-- the original copyright notice and the associated disclaimer.
28
--
29
-- This source file is free software; you can redistribute it
30
-- and/or modify it under the terms of the GNU Lesser General
31
-- Public License as published by the Free Software Foundation;
32
-- either version 2.1 of the License, or (at your option) any
33
-- later version.
34
--
35
-- This source is distributed in the hope that it will be
36
-- useful, but WITHOUT ANY WARRANTY; without even the implied
37
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
38
-- PURPOSE.  See the GNU Lesser General Public License for more
39
-- details.
40
--
41
-- You should have received a copy of the GNU Lesser General
42
-- Public License along with this source; if not, download it
43
-- from http://www.opencores.org/lgpl.shtml
44
-------------------------------------------------------------------------------
45
 
46
library ieee;
47
use ieee.std_logic_1164.all;
48
use ieee.numeric_std.all;
49
 
50
use ieee.std_logic_misc.all;
51
use std.textio.all;
52
 
53
--use work.txt_util.all;
54
use work.hibiv3_pkg.all;
55
 
56
entity tb_button_messenger is
57
end tb_button_messenger;
58
 
59
 
60
 
61
architecture structural of tb_button_messenger is
62
 
63
  constant n_ag_c          : integer := 3;   -- number of agents (=IPs)
64
 
65
  -- HIBI parameters
66
  constant data_width_c    : integer := 32;  -- bits
67
  constant addr_width_c    : integer := 32;  -- bits
68
  constant counter_width_c : integer := 16;  -- bits
69
  constant id_width_c      : integer := 6;   -- bits
70
  constant max_send_c      : integer := 40;  -- words
71
  constant arb_type_c      : integer := 0;   -- 0-3
72
  constant tx_fifo_size_c  : integer := 4;   -- words
73
  constant rx_fifo_size_c  : integer := 4;   -- words
74
 
75
  type gen_addr_array_type    is array (0 to 3) of integer;
76
  constant addresses_c : gen_addr_array_type :=
77
    (16#00000010#,      -- video_gen
78
     16#00000030#,      -- pic manipulator
79
     16#00000050#,      -- ddr
80
     16#00000070#       -- currently unused
81
     );
82
 
83
 
84
  -- IPs and wrappers can run on different frequencies
85
  -- (All Ips using one clock and all wrappers unsing the other)
86
  -- Frequencies must be integer multiple of each other.
87
  -- Edit both period and frequencies manually and ensure consistency.
88
  constant PERIOD_IP_C      : time    := 1*10 ns;
89
  constant PERIOD_HIBI_C    : time    := 1*10 ns;
90
  constant rel_agent_freq_c : integer := 1;
91
  constant rel_bus_freq_c   : integer := 1;
92
 
93
 
94
  -- Global signals
95
  signal clk_ip  : std_logic := '1';
96
  signal clk_noc : std_logic := '1';
97
  signal rst_n   : std_logic := '0';
98
 
99
  -- Define types for arrays. Transposed versions are needed for or_reduce
100
  -- function in bus resolution.
101
  type data_vec_type is array (n_ag_c-1 downto 0) of std_logic_vector (data_width_c-1 downto 0);
102
  type comm_vec_type is array (n_ag_c-1 downto 0) of std_logic_vector (comm_width_c-1 downto 0);
103
  type trnsp_data_vec is array (data_width_c-1 downto 0) of std_logic_vector (n_ag_c-1 downto 0);
104
  type trnsp_comm_vec is array (comm_width_c-1 downto 0) of std_logic_vector (n_ag_c-1 downto 0);
105
 
106
 
107
  -- Signals going from the IPs to the wrappers.
108
  -- Note that full and one_p actually come from wrapper but they are grouped
109
  -- here due their purpose.
110
  signal av_ip_wra    : std_logic_vector ( n_ag_c-1 downto 0);
111
  signal data_ip_wra  : data_vec_type;
112
  signal comm_ip_wra  : comm_vec_type;
113
  signal we_ip_wra    : std_logic_vector ( n_ag_c-1 downto 0);
114
  signal full_wra_ip  : std_logic_vector ( n_ag_c-1 downto 0);
115
  signal one_p_wra_ip : std_logic_vector ( n_ag_c-1 downto 0);
116
 
117
  -- Signals going from the wrappers to the IPs.
118
  signal av_wra_ip    : std_logic_vector ( n_ag_c-1 downto 0);
119
  signal data_wra_ip  : data_vec_type;
120
  signal comm_wra_ip  : comm_vec_type;
121
  signal re_ip_wra    : std_logic_vector ( n_ag_c-1 downto 0);
122
  signal empty_wra_ip : std_logic_vector ( n_ag_c-1 downto 0);
123
  signal one_d_wra_ip : std_logic_vector ( n_ag_c-1 downto 0);
124
 
125
  -- Signals going from the wrappers to the OR ports.
126
  signal av_wra_bus     : std_logic_vector ( n_ag_c-1 downto 0);
127
  signal data_wra_bus   : data_vec_type;
128
  signal comm_wra_bus   : comm_vec_type;
129
  signal trnsp_data_out : trnsp_data_vec;
130
  signal trnsp_comm_out : trnsp_comm_vec;
131
  signal full_wra_bus   : std_logic_vector ( n_ag_c-1 downto 0);
132
  signal lock_wra_bus   : std_logic_vector ( n_ag_c-1 downto 0);
133
 
134
  -- Signals going from the OR ports to the wrappers.
135
  signal av_bus_wra   : std_logic;
136
  signal data_bus_wra : std_logic_vector(data_width_c-1 downto 0);
137
  signal comm_bus_wra : std_logic_vector(comm_width_c-1 downto 0);
138
  signal full_bus_wra : std_logic;
139
  signal lock_bus_wra : std_logic;
140
 
141
 
142
  -- 2007/04/16
143
  constant dbg_width_c  : integer := 1;
144
  signal   debug_tb_wra : std_logic_vector ( dbg_width_c-1 downto 0);
145
 
146
 
147
  --  constant arb_type_c   : integer := 0;
148
  constant delay_c     : integer := 6;
149
  constant n_buttons_c : integer := 4;
150
  signal   keys_tb_duv : unsigned (4-1 downto 0);
151
  signal   counter_r   : integer range 0 to delay_c-1;
152
  signal   leds        : std_logic_vector (8-1 downto 0);
153
begin  -- structural
154
 
155
 
156
 
157
 
158
 
159
  DUV : entity work.button_messenger
160
    generic map (
161
      n_buttons_g     => n_buttons_c,
162
      data_width_g    => data_width_c,
163
      comm_width_g    => comm_width_c,                      -- from hibiv3_pkg
164
      write_command_g => to_integer (unsigned(DATA_WR_c)),  -- from hibiv3_pkg
165
      --dst_addr_g      => addresses_c(0)                     -- sends to leds
166
      dst_addr_g      => addresses_c(1)  -- sends to basic_tester_rx
167
      )
168
    port map (
169
      clk   => clk_ip,
170
      rst_n => rst_n,
171
 
172
      tx_av_out   => av_ip_wra (0),
173
      tx_data_out => data_ip_wra (0),
174
      tx_comm_out => comm_ip_wra (0),
175
      tx_we_out   => we_ip_wra (0),
176
      tx_full_in  => full_wra_ip (0),
177
 
178
      buttons_in => std_logic_vector(keys_tb_duv)
179
      );
180
 
181
  leds_rx_1 : entity work.led_rx
182
    generic map (
183
      comm_width_g => comm_width_c,     -- from hibiv3_pkg
184
      data_width_g => data_width_c
185
      )
186
    port map (
187
      clk   => clk_ip,
188
      rst_n => rst_n,
189
 
190
      leds_out       => leds,
191
      agent_av_in    => av_wra_ip (0),
192
      agent_data_in  => data_wra_ip (0),
193
      agent_comm_in  => comm_wra_ip (0),
194
      agent_re_out   => re_ip_wra (0),
195
      agent_empty_in => empty_wra_ip (0),
196
      agent_one_d_in => one_d_wra_ip (0)
197
      );
198
 
199
  --re_ip_wra (0)   <= '0';
200
 
201
 
202
  -- Component 1
203
  av_ip_wra (1)   <= '0';
204
  data_ip_wra (1) <= (others => 'Z');
205
  comm_ip_wra (1) <= (others => 'Z');
206
  we_ip_wra (1)   <= '0';
207
 
208
 
209
  press_buttons : process (clk_ip, rst_n)
210
  begin  -- process press_buttons
211
    if rst_n = '0' then                 -- asynchronous reset (active low)
212
      keys_tb_duv <= (others => '0');
213
      counter_r     <= 0;
214
    elsif clk_ip'event and clk_ip = '1' then  -- rising clock edge
215
 
216
      if counter_r = delay_c-1 then
217
        keys_tb_duv <= keys_tb_duv + 1;
218
        counter_r <= 0;
219
      else
220
        counter_r <= counter_r +1;
221
      end if;
222
 
223
 
224
    end if;
225
  end process press_buttons;
226
 
227
 
228
  receiver: entity work.basic_tester_rx
229
 
230
    generic map(
231
      conf_file_g  => "test_rx.txt",
232
      comm_width_g => comm_width_c, --3,
233
      data_width_g => data_width_c
234
      )
235
    port map(
236
      clk          => clk_ip,
237
      rst_n        => rst_n,
238
 
239
      -- done_out     => ,
240
 
241
      -- HIBI WRAPPER PORTS
242
      agent_av_in    => av_wra_ip (1),
243
      agent_data_in  => data_wra_ip (1),
244
      agent_comm_in  => comm_wra_ip (1),
245
      agent_re_out   => re_ip_wra (1),
246
      agent_empty_in => empty_wra_ip (1),
247
      agent_one_d_in => one_d_wra_ip (1)
248
      );
249
 
250
 
251
  -- Component 2
252
  av_ip_wra (2)   <= '0';
253
  data_ip_wra (2) <= (others => 'Z');
254
  comm_ip_wra (2) <= (others => 'Z');
255
  we_ip_wra (2)   <= '0';
256
 
257
  re_ip_wra (2)   <= '1';
258
 
259
 
260
 
261
  hibi_net : for ag in 0 to n_ag_c-1 generate
262
    hibi_wrapper_r4_1 : entity work.hibi_wrapper_r4
263
      generic map (
264
        id_g          => ag+1,
265
        id_min_g      => 0,             -- not in hibi_V2
266
        id_max_g      => 0,             -- not supported in hibi_v3
267
        --base_id_g           => 2**id_width_c-1,  not supported in hibi_v3
268
        inv_addr_en_g => 0,
269
        -- first parameter to addresses_c is the segment, 
270
        -- second is the agents number within the segment
271
        addr_g        => addresses_c (ag),
272
 
273
        id_width_g      => id_width_c,
274
        addr_width_g    => addr_width_c,
275
        data_width_g    => data_width_c,
276
        comm_width_g    => comm_width_c, --3,
277
        counter_width_g => counter_width_c,
278
 
279
        rx_fifo_depth_g     => rx_fifo_size_c,
280
        rx_msg_fifo_depth_g => 3, --0,  -- fifo_size_c
281
        tx_fifo_depth_g     => tx_fifo_size_c,
282
        tx_msg_fifo_depth_g => 3,-- 0,  -- fifo_size_c
283
 
284
        rel_agent_freq_g => rel_agent_freq_c,
285
        rel_bus_freq_g   => rel_bus_freq_c,
286
        arb_type_g       => arb_type_c,  --13.4.2007
287
 
288
 
289
        prior_g    => ag +1,
290
        max_send_g => max_send_c,
291
        n_agents_g => n_ag_c,
292
 
293
        n_cfg_pages_g    => 1,
294
        n_time_slots_g   => 0,
295
        n_extra_params_g => 1,
296
        -- multicast_en_g   => 0, not supported in hibi_v3
297
        cfg_re_g         => 0,
298
        cfg_we_g         => 1,  --0,
299
 
300
        debug_width_g => dbg_width_c  --2007/04/16
301
        )
302
      port map (
303
        agent_clk      => clk_ip,
304
        bus_clk        => clk_noc,
305
        bus_sync_clk   => clk_noc,
306
        agent_sync_clk => clk_ip,
307
        rst_n          => rst_n,
308
 
309
        bus_av_in    => av_bus_wra,
310
        bus_data_in  => data_bus_wra,
311
        bus_comm_in  => comm_bus_wra,
312
        bus_full_in  => full_bus_wra,
313
        bus_lock_in  => lock_bus_wra,
314
        bus_av_out   => av_wra_bus   (ag),
315
        bus_data_out => data_wra_bus (ag),
316
        bus_comm_out => comm_wra_bus (ag),
317
        bus_full_out => full_wra_bus (ag),
318
        bus_lock_out => lock_wra_bus (ag),
319
 
320
        agent_av_in      => av_ip_wra    (ag),
321
        agent_data_in    => data_ip_wra  (ag),
322
        agent_comm_in    => comm_ip_wra  (ag),
323
        agent_we_in      => we_ip_wra    (ag),
324
        agent_full_out   => full_wra_ip  (ag),
325
        agent_one_p_out  => one_p_wra_ip (ag),
326
 
327
        agent_re_in      => re_ip_wra    (ag),
328
        agent_av_out     => av_wra_ip    (ag),
329
        agent_data_out   => data_wra_ip  (ag),
330
        agent_comm_out   => comm_wra_ip  (ag),
331
        agent_empty_out  => empty_wra_ip (ag),
332
        agent_one_d_out  => one_d_wra_ip (ag),
333
 
334
        --debug_out => dummy,
335
        debug_in => debug_tb_wra
336
 
337
        );
338
 
339
  end generate hibi_net;
340
 
341
 
342
 
343
 
344
 
345
  -- assign the bus signals. bus signals are first transposed, eg.
346
  -- 3*32b buses -> 32*3b buses
347
  trnsp_bus : for j in 0 to n_ag_c-1 generate
348
 
349
      i : for i in 0 to data_width_c-1 generate
350
        trnsp_data_out (i)(j) <= data_wra_bus (j)(i);
351
      end generate i;
352
 
353
      k : for k in 0 to comm_width_c-1 generate
354
        trnsp_comm_out (k)(j) <= comm_wra_bus (j)(k);
355
      end generate k;
356
  end generate trnsp_bus;
357
 
358
 
359
 
360
 
361
    -- here we or_reduce the transposed signals, so we get the in-signals
362
    -- for wrappers.
363
    or_reduce_data : for i in 0 to data_width_c-1 generate
364
      data_bus_wra (i) <= or_reduce(trnsp_data_out (i));
365
    end generate or_reduce_data;
366
 
367
 
368
    chk_lock: process (lock_wra_bus)
369
      variable n_locks_v : integer := 0;
370
    begin  -- process chk_lock
371
 
372
      n_locks_v := 0;
373
 
374
      for i in 0 to n_ag_c -1 loop
375
        if lock_wra_bus (i) = '1' then
376
          n_locks_v := n_locks_v +1;
377
        end if;
378
      end loop;  -- i
379
 
380
      if n_locks_v > 1 then
381
        assert false report "Multiple drivers for lock signal!!!" severity error;
382
      end if;
383
    end process chk_lock;
384
 
385
    or_reduce_comm : for i in 0 to comm_width_c-1 generate
386
        comm_bus_wra(i) <= or_reduce(trnsp_comm_out(i));
387
    end generate or_reduce_comm;
388
 
389
 
390
    or_reduce_rest : for i in 0 to comm_width_c-1 generate
391
      av_bus_wra   <= or_reduce(av_wra_bus);
392
      lock_bus_wra <= or_reduce(lock_wra_bus);
393
      full_bus_wra <= or_reduce(full_wra_bus);
394
    end generate or_reduce_rest;
395
 
396
    clk_ip  <= not clk_ip  after PERIOD_IP_C/2;
397
    clk_noc <= not clk_noc after PERIOD_HIBI_C/2;
398
    rst_n <= '0', '1'    after 4.6 * PERIOD_HIBI_C;
399
 
400
 
401
end structural;
402
 

powered by: WebSVN 2.1.0

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