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/] [2.0/] [vhd/] [dyn_arb.vhd] - Blame information for rev 159

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

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

powered by: WebSVN 2.1.0

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