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

Subversion Repositories ahb_system_generator

[/] [ahb_system_generator/] [trunk/] [src/] [ahb_funct.vhd] - Blame information for rev 4

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

Line No. Rev Author Line
1 2 federico.a
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_arith.all;
4
 
5
package ahb_funct is
6
 
7
function nb_bits (A : std_logic_vector) return NATURAL;
8
function nb_bits (A : INTEGER) return NATURAL;
9
 
10
procedure fixed_priority(
11
t_turn: out integer;
12
t_grant: out integer;
13
req: in std_logic_vector;
14
turn: in integer);
15
procedure round_robin(
16
def_elem: in integer;
17
t_turn: out integer;
18
t_grant: out integer;
19
req: in std_logic_vector;
20
turn: in integer);
21
procedure random_priority(
22
def_elem: in integer;
23
t_turn: out integer;
24
t_grant: out integer;
25
random: in integer;
26
req: in std_logic_vector;
27
turn: in integer);
28
 
29
end ahb_funct;
30
 
31
package body ahb_funct is
32
 
33
  function nb_bits (A : std_logic_vector) return NATURAL is
34
    variable logres : NATURAL ;
35
    begin
36
     logres := 1;
37
     for i in A'length-1 downto 0 loop
38
      if A(i) = '1' then
39
        logres := i;
40
        exit;
41
      end if;
42
     end loop;
43
     return logres;
44
   end nb_bits;
45
 
46
   function nb_bits (A : INTEGER) return NATURAL is
47
    variable logres : NATURAL ;
48
    begin
49
     logres := 1;
50
     for i in 0 to 30 loop
51
      if 2**i <= A then
52
        logres := i+1;
53
      end if;
54
     end loop;
55
     return logres;
56
   end nb_bits;
57
 
58
procedure fixed_priority(
59
t_turn: out integer;-- range 0 to num_elem-1; 
60
t_grant: out integer;
61
req: in std_logic_vector;
62
turn: in integer-- range 0 to num_elem-1 
63
) is
64
begin
65
  t_grant := 0;
66
  t_turn := 0;
67
  req_for:for i in req'length-1 downto 0 loop
68
    if req(i) = '1' then
69
      t_grant := i;
70
    end if;
71
  end loop;
72
end fixed_priority;
73
 
74
procedure round_robin(
75
def_elem: in integer;
76
t_turn: out integer;-- range 0 to num_elem-1; 
77
t_grant: out integer;-- range 0 to num_elem-1; 
78
req: in std_logic_vector;
79
turn: in integer-- range 0 to num_elem-1 
80
) is
81
constant req_size: integer:= req'length;
82
variable v_req: std_logic_vector(req_size*2-1 downto 0);
83
type turn_array  is array (req_size-1 downto 0) of std_logic_vector(req_size-1 downto 0);
84
variable v_turn: turn_array;
85
begin
86
  t_grant := def_elem;
87
  t_turn := turn;
88
  v_req := req&req;--concatenation
89
  for i in 0 to req_size-1 loop
90
    v_turn(i) := v_req(i+req_size-1 downto i);
91
  end loop;
92
  for j in 0 to req_size-1 loop
93
    if j=turn then
94
      for jj in 0 to req_size-1 loop
95
        if v_turn(j)(jj)='1' then
96
          if turn+jj >=req'length then
97
            t_turn := turn+jj-req_size;
98
            t_grant := turn+jj-req_size;
99
          else
100
            t_turn := turn+jj;
101
            t_grant := turn+jj;
102
          end if;
103
        end if;
104
      end loop;  -- jj
105
    end if;
106
  end loop;  -- j    
107
end round_robin;
108
 
109
 
110
procedure random_priority(
111
def_elem: in integer;
112
t_turn: out integer;-- range 0 to num_elem-1; 
113
t_grant: out integer;-- range 0 to num_elem-1; 
114
random: in integer;-- range 0 to 2**(nb_bits(num_elem));
115
req: in std_logic_vector;
116
turn: in integer-- range 0 to num_elem-1
117
) is
118
constant req_size: integer:= req'length;
119
variable j, v_turn, upper_limit: integer;
120
begin
121
  t_grant := def_elem;
122
  upper_limit := 2**(nb_bits(req_size))-1;
123
  v_turn := turn;
124
  req_for:for i in upper_limit downto 0 loop
125
    if ((i >= random) and (i <= random+upper_limit)) then
126
      j := i mod req_size;
127
      if req(j) = '1' then
128
        t_grant := j;
129
        if turn=req_size-1 then
130
          v_turn := 0;
131
        else
132
          v_turn := turn+1;
133
        end if;
134
      end if;
135
        t_turn := v_turn;
136
    --synopsys translate_off
137
        assert (v_turn>=0 and v_turn<req_size) report "####ERROR: WRONG ARBITRATION!!!" severity failure;
138
    --synopsys translate_on
139
    end if;
140
  end loop;
141
end random_priority;
142
 
143
 
144
end ahb_funct;
145
 
146
 
147
 

powered by: WebSVN 2.1.0

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