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/] [hibi/] [3.0/] [vhd/] [dyn_arb.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Descritpion: Dynamic arbitration algorith, includes lfsr+lut.
3
--              This block grants turns to agents. Each agents has "lottery
4
--              tickets" and linear feedabck shift register selects the winner
5
--              pseudorandomly.
6
--              Part of the tickets are given statically and part are given
7
--              to the most active agents. Having more tickets increases the
8
--              probability of winning.
9
-- Project    : Nocbench, Funbase
10
-------------------------------------------------------------------------------
11
-- File       : dyn_arb.vhd
12
-- Author     : Ari Kulmala
13
-- Created    : 22.05.2006
14
-- Last update: 2011-10-12
15
-- Description: dynamic arbitration algorithm
16
-------------------------------------------------------------------------------
17
-- Copyright (c) 2006 
18
-------------------------------------------------------------------------------
19
-- Revisions  :
20
-- Date        Version  Author  Description
21
-- 22.05.2006  1.0      AK      Created
22
-------------------------------------------------------------------------------
23
-- Funbase IP library Copyright (C) 2011 TUT Department of Computer Systems
24
--
25
-- This file is part of HIBI
26
--
27
-- This source file may be used and distributed without
28
-- restriction provided that this copyright statement is not
29
-- removed from the file and that any derivative work contains
30
-- the original copyright notice and the associated disclaimer.
31
--
32
-- This source file is free software; you can redistribute it
33
-- and/or modify it under the terms of the GNU Lesser General
34
-- Public License as published by the Free Software Foundation;
35
-- either version 2.1 of the License, or (at your option) any
36
-- later version.
37
--
38
-- This source is distributed in the hope that it will be
39
-- useful, but WITHOUT ANY WARRANTY; without even the implied
40
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
41
-- PURPOSE.  See the GNU Lesser General Public License for more
42
-- details.
43
--
44
-- You should have received a copy of the GNU Lesser General
45
-- Public License along with this source; if not, download it
46
-- from http://www.opencores.org/lgpl.shtml
47
-------------------------------------------------------------------------------
48
 
49
library ieee;
50
use ieee.std_logic_1164.all;
51
--use ieee.std_logic_unsigned.all;
52
use ieee.numeric_std.all;
53
 
54
entity dyn_arb is
55
 
56
  generic (
57
    id_width_g : integer := 0;
58
    n_agents_g : integer := 0);
59
 
60
  port (
61
    clk           : in  std_logic;
62
    rst_n         : in  std_logic;
63
    bus_lock_in   : in  std_logic;
64
    arb_agent_out : out std_logic_vector(id_width_g-1 downto 0)  -- values  1..n
65
    );
66
 
67
end dyn_arb;
68
 
69
architecture rtl of dyn_arb is
70
 
71
  component lfsr
72
    generic (
73
      width_g : integer range 1 to 36);
74
    port (
75
      rst_n     : in  std_logic;
76
      enable_in : in  std_logic;
77
      q_out     : out std_logic_vector(width_g-1 downto 0);
78
      clk       : in  std_logic);
79
  end component;
80
 
81
  -- LUT is divided inot two halves: fixed (qos) and dunamically updated part
82
  -- Define how many fixed slots per agent
83
  constant qos_slots_c   : integer := 1;
84
  -- move this constant to generic (note by ES 2011-10-12)
85
 
86
 
87
 
88
  -- Signals for Linear Feedback Shift Register (LFSR) that generates (pseudo)
89
  -- random numbers
90
  constant lfsr_width_c : integer := 5;
91
  signal   q_from_lfsr  : std_logic_vector(lfsr_width_c-1 downto 0);  --(pseudo-)rand value
92
  signal   enable_lfsr  : std_logic;
93
 
94
 
95
  -- Look-up table that stores the "lottery tickets"
96
--  constant lut_size_c     : integer := 2**(lfsr_width_c-1);
97
  constant lut_size_c     : integer := 2**(lfsr_width_c);
98
  type     turn_lut_array is array (lut_size_c-1 downto 0) of std_logic_vector(id_width_g-1 downto 0);
99
  signal   adaptive_lut_r : turn_lut_array;
100
 
101
 
102
  signal prev_lock_r   : std_logic;     -- for edge detection
103
  signal winner        : std_logic_vector(id_width_g-1 downto 0);  -- winner
104
 
105
  --signal prev_winner_r : std_logic_vector(id_width_g-1 downto 0);
106
 
107
 
108
  -- ES 2009-04-06
109
  -- Calculate LUT statistics for debug. Simulation purposes only.
110
  -- Modelsim may obtimize this away, so you must start simulation with
111
  -- optimizations disabled : vsim -novopt tb_hibiv2_lat etc.
112
  type   ticket_count_table_type is array (n_agents_g+1-1 downto 0) of integer;
113
  signal ticket_count_table_r : ticket_count_table_type;
114
 
115
 
116
begin  -- rtl
117
 
118
  assert lut_size_c >= n_agents_g * qos_slots_c report "Too many qos slots" severity failure;
119
 
120
 
121
 
122
  -- Generate random numbers
123
  lfsr_1 : lfsr
124
    generic map (
125
      width_g => lfsr_width_c
126
      )
127
    port map (
128
      rst_n     => rst_n,
129
      enable_in => enable_lfsr,
130
      q_out     => q_from_lfsr,
131
      clk       => clk
132
      );
133
  enable_lfsr <= not bus_lock_in;
134
 
135
  -- Select the winner from LUT
136
  -- This creates a rather large multiplexer tree. Critical path comes from
137
  -- LFSR and goes then through muxes
138
  winner <= adaptive_lut_r(to_integer(unsigned(q_from_lfsr)));
139
  --  winner <= adaptive_lut_r(conv_integer(q_from_lfsr(lfsr_width_c-1 downto 1)));
140
  --  winner <= adaptive_lut_r(to_integer(unsigned(q_from_lfsr(lfsr_width_c-1 downto 1))));
141
 
142
  arb_agent_out <= winner;
143
  -- arb_agent_out <= prev_winner_r; -- test what happens
144
 
145
 
146
 
147
 
148
  -- Update the LUT dynamically
149
  main : process (clk, rst_n)
150
  begin  -- process main
151
    if rst_n = '0' then                 -- asynchronous reset (active low)
152
 
153
      -- Initialize the both parts of the LUT
154
      dyn_slots: for i in 0 to lut_size_c-(n_agents_g * qos_slots_c)-1 loop
155
        adaptive_lut_r(i) <= std_logic_vector(to_unsigned ((i mod n_agents_g) +1, id_width_g)); -- 2009-04-06
156
      end loop dyn_slots;
157
 
158
      qos : for i in lut_size_c-(n_agents_g * qos_slots_c) to lut_size_c-1 loop
159
        adaptive_lut_r(i) <= std_logic_vector(to_unsigned ((i mod n_agents_g)+1, id_width_g));
160
      end loop qos;
161
 
162
 
163
      prev_lock_r   <= '0';
164
      --prev_winner_r <= (others => '0');
165
 
166
 
167
    elsif clk'event and clk = '1' then  -- rising clock edge
168
 
169
      adaptive_lut_r <= adaptive_lut_r;
170
      --prev_winner_r  <= winner;        
171
 
172
      -- Update the LUT when owner uses its turn, i.e. when lock goes 0 -> 1
173
      -- Updating inserts owner ID to slot(0) and shift the dynamic slots left
174
      -- (towards bigger indices) by 1.
175
      if bus_lock_in = '0' then
176
        prev_lock_r <= '0';
177
      else
178
        prev_lock_r <= '1';
179
 
180
        if prev_lock_r = '0' then
181
          for i in 0 to lut_size_c-(n_agents_g*qos_slots_c)-2 loop
182
            adaptive_lut_r(i+1) <= adaptive_lut_r(i);
183
          end loop;  -- i
184
          adaptive_lut_r(0) <= winner; --prev_winner_r;
185
        end if;
186
      end if;                           -- bus_lock_in
187
    end if;                             -- rst_n/clk'event
188
  end process main;
189
 
190
 
191
 
192
  -- Count on every clk cycle how many tickets each agents has
193
  -- This is just for debugging! 
194
  count_tickets : process (clk, rst_n)
195
    variable ticket_owner_v       : integer := 0;
196
    variable ticket_count_table_v : ticket_count_table_type;
197
 
198
  begin  -- process count_tickets
199
    if rst_n = '0' then                 -- asynchronous reset (active low)
200
      ticket_count_table_r <= (others => 0);
201
 
202
    elsif clk'event and clk = '1' then  -- rising clock edge
203
 
204
      ticket_count_table_v := (others => 0);
205
 
206
      for i in 0 to lut_size_c-1 loop
207
        ticket_owner_v                        := to_integer(signed(adaptive_lut_r(i)));
208
        ticket_count_table_v (ticket_owner_v) := ticket_count_table_v (ticket_owner_v) +1;
209
      end loop;  -- i
210
 
211
      ticket_count_table_r <= ticket_count_table_v;
212
 
213
    end if;
214
  end process count_tickets;
215
 
216
 
217
end rtl;

powered by: WebSVN 2.1.0

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