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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v7/] [rtl/] [lib/] [round_robin.v] - Blame information for rev 60

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 60 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2005-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// This source file is free software: you can redistribute it and/or modify 
9
// it under the terms of the GNU Lesser General Public License as published 
10
// by the Free Software Foundation, either version 3 of the License, or     
11
// (at your option) any later version.                                      
12
//                                                                          
13
// This source file is distributed in the hope that it will be useful,      
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
16
// GNU General Public License for more details.                             
17
//                                                                          
18
// You should have received a copy of the GNU General Public License        
19
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
20
//
21
// ============================================================================
22
//
23
module round_robin(rst, clk, ce, req, lock, sel);
24
parameter N=12;
25
localparam B=$clog2(N);
26
input rst;                              // reset
27
input clk;                              // clock
28
input ce;                               // clock enable
29
input [N-1:0] req;               // request
30
input [N-1:0] lock;              // lock selection
31
output [N-1:0] sel;              // select
32
 
33
integer n;
34
reg [N-1:0] sel;
35
 
36
reg [B-1:0] rot;                 // forward rotate applied to request lines
37
reg [B-1:0] amt;                 // how much to rotate forward after a grant
38
reg [N-1:0] rgrnt;               // rotated value of grant
39
wire [N-1:0] nextGrant;  // unrotated value of grant
40
wire [N-1:0] rr1;                        // rotated request imtermediate
41
wire [N-1:0] ng1;                        // intermediate grant rotation
42
wire [N-1:0] rreq;               // rotated request
43
 
44
// rotate the request lines to set priority
45
wire [2*N-1:0] rreq1 = {req,{N{1'b0}}} >> rot;
46
assign rreq = rreq1[2*N-1:N]|rreq1[N-1:0];
47
 
48
// rotate the rotated grant value back into place
49
wire [2*N-1:0] rgnt1 = {{N{1'b0}},rgrnt} << rot;
50
assign nextGrant = rgnt1[2*N-1:N]|rgnt1[N-1:0];
51
 
52
// If there is a request, determine how far the request
53
// lines should be rotated when there is a grant
54
always @*
55
begin
56
        amt <= 0;
57
        for (n = N-1; n >= 0; n = n - 1)
58
                if (rreq[n])
59
                        amt <= n;
60
end
61
 
62
// set grant (if request present) based on which request
63
// was honored.
64
always @*
65
        rgrnt <= {{N{1'b0}},|rreq} << ((amt-1) % N);
66
 
67
// rotate the priorities on a grant
68
always @(posedge clk)
69
if (rst)
70
        rot = 0;
71
else if (ce)
72
        if (!(lock & sel))
73
                rot = rot + amt;
74
 
75
// Assign the next owner, if bus isn't locked
76
always @(posedge clk)
77
if (rst)
78
        sel = 0;
79
else if (ce)
80
        if (!(lock & sel))
81
                sel = nextGrant;
82
 
83
endmodule
84
 
85
 

powered by: WebSVN 2.1.0

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