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

Subversion Repositories round_robin_arbiter

[/] [round_robin_arbiter/] [trunk/] [round_robin_arbiter.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 rainrhythm
//Rotate -> Priority -> Rotate
2
//author: dongjun_luo@hotmail.com
3
module round_robin_arbiter (
4
        rst_an,
5
        clk,
6
        req,
7
        grant
8
);
9
 
10
 
11
input           rst_an;
12
input           clk;
13
input   [3:0]    req;
14
output  [3:0]    grant;
15
 
16
reg     [1:0]    rotate_ptr;
17
reg     [3:0]    shift_req;
18
reg     [3:0]    shift_grant;
19
reg     [3:0]    grant_comb;
20
reg     [3:0]    grant;
21
 
22
// shift req to round robin the current priority
23
always @ (*)
24
begin
25
        case (rotate_ptr[1:0])
26
                2'b00: shift_req[3:0] = req[3:0];
27
                2'b01: shift_req[3:0] = {req[0],req[3:1]};
28
                2'b10: shift_req[3:0] = {req[1:0],req[3:2]};
29
                2'b11: shift_req[3:0] = {req[2:0],req[3]};
30
        endcase
31
end
32
 
33
// simple priority arbiter
34
always @ (*)
35
begin
36
        shift_grant[3:0] = 4'b0;
37
        if (shift_req[0])        shift_grant[0] = 1'b1;
38
        else if (shift_req[1])  shift_grant[1] = 1'b1;
39
        else if (shift_req[2])  shift_grant[2] = 1'b1;
40
        else if (shift_req[3])  shift_grant[3] = 1'b1;
41
end
42
 
43
// generate grant signal
44
always @ (*)
45
begin
46
        case (rotate_ptr[1:0])
47
                2'b00: grant_comb[3:0] = shift_grant[3:0];
48
                2'b01: grant_comb[3:0] = {shift_grant[2:0],shift_grant[3]};
49
                2'b10: grant_comb[3:0] = {shift_grant[1:0],shift_grant[3:2]};
50
                2'b11: grant_comb[3:0] = {shift_grant[0],shift_grant[3:1]};
51
        endcase
52
end
53
 
54
always @ (posedge clk or negedge rst_an)
55
begin
56
        if (!rst_an)    grant[3:0] <= 4'b0;
57
        else            grant[3:0] <= grant_comb[3:0] & ~grant[3:0];
58
end
59
 
60
// update the rotate pointer
61
// rotate pointer will move to the one after the current granted
62
always @ (posedge clk or negedge rst_an)
63
begin
64
        if (!rst_an)
65
                rotate_ptr[1:0] <= 2'b0;
66
        else
67
                case (1'b1) // synthesis parallel_case
68
                        grant[0]: rotate_ptr[1:0] <= 2'd1;
69
                        grant[1]: rotate_ptr[1:0] <= 2'd2;
70
                        grant[2]: rotate_ptr[1:0] <= 2'd3;
71
                        grant[3]: rotate_ptr[1:0] <= 2'd0;
72
                endcase
73
end
74
endmodule

powered by: WebSVN 2.1.0

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