1 |
21 |
dinesha |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// Wishbone Arbitor ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the YIFive cores project ////
|
6 |
|
|
//// http://www.opencores.org/cores/yifive/ ////
|
7 |
|
|
//// ////
|
8 |
|
|
//// Description ////
|
9 |
|
|
//// This block implement simple round robine request ////
|
10 |
|
|
// arbitor for wishbone interface. ////
|
11 |
|
|
//// ////
|
12 |
|
|
//// To Do: ////
|
13 |
|
|
//// nothing ////
|
14 |
|
|
//// ////
|
15 |
|
|
//// Author(s): ////
|
16 |
|
|
//// - Dinesh Annayya, dinesha@opencores.org ////
|
17 |
|
|
//// ////
|
18 |
|
|
//// Revision : ////
|
19 |
|
|
//// 0.1 - 12th June 2021, Dinesh A ////
|
20 |
|
|
//// ////
|
21 |
|
|
//////////////////////////////////////////////////////////////////////
|
22 |
|
|
//// ////
|
23 |
|
|
//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
|
24 |
|
|
//// ////
|
25 |
|
|
//// This source file may be used and distributed without ////
|
26 |
|
|
//// restriction provided that this copyright statement is not ////
|
27 |
|
|
//// removed from the file and that any derivative work contains ////
|
28 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
29 |
|
|
//// ////
|
30 |
|
|
//// This source file is free software; you can redistribute it ////
|
31 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
32 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
33 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
34 |
|
|
//// later version. ////
|
35 |
|
|
//// ////
|
36 |
|
|
//// This source is distributed in the hope that it will be ////
|
37 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
38 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
39 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
40 |
|
|
//// details. ////
|
41 |
|
|
//// ////
|
42 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
43 |
|
|
//// Public License along with this source; if not, download it ////
|
44 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
45 |
|
|
//// ////
|
46 |
|
|
//////////////////////////////////////////////////////////////////////
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
module wb_arb(clk, rstn, req, gnt);
|
50 |
|
|
|
51 |
|
|
input clk;
|
52 |
|
|
input rstn;
|
53 |
|
|
input [2:0] req; // Req input
|
54 |
|
|
output [1:0] gnt; // Grant output
|
55 |
|
|
|
56 |
|
|
///////////////////////////////////////////////////////////////////////
|
57 |
|
|
//
|
58 |
|
|
// Parameters
|
59 |
|
|
//
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
parameter [1:0]
|
63 |
|
|
grant0 = 3'h0,
|
64 |
|
|
grant1 = 3'h1,
|
65 |
|
|
grant2 = 3'h2;
|
66 |
|
|
|
67 |
|
|
///////////////////////////////////////////////////////////////////////
|
68 |
|
|
// Local Registers and Wires
|
69 |
|
|
//////////////////////////////////////////////////////////////////////
|
70 |
|
|
|
71 |
|
|
reg [1:0] state, next_state;
|
72 |
|
|
|
73 |
|
|
///////////////////////////////////////////////////////////////////////
|
74 |
|
|
// Misc Logic
|
75 |
|
|
//////////////////////////////////////////////////////////////////////
|
76 |
|
|
|
77 |
|
|
assign gnt = state;
|
78 |
|
|
|
79 |
|
|
always@(posedge clk or negedge rstn)
|
80 |
|
|
if(!rstn) state <= grant0;
|
81 |
|
|
else state <= next_state;
|
82 |
|
|
|
83 |
|
|
///////////////////////////////////////////////////////////////////////
|
84 |
|
|
//
|
85 |
|
|
// Next State Logic
|
86 |
|
|
// - implements round robin arbitration algorithm
|
87 |
|
|
// - switches grant if current req is dropped or next is asserted
|
88 |
|
|
// - parks at last grant
|
89 |
|
|
//////////////////////////////////////////////////////////////////////
|
90 |
|
|
|
91 |
|
|
always@(state or req )
|
92 |
|
|
begin
|
93 |
|
|
next_state = state; // Default Keep State
|
94 |
|
|
case(state)
|
95 |
|
|
grant0:
|
96 |
|
|
// if this req is dropped or next is asserted, check for other req's
|
97 |
|
|
if(!req[0] ) begin
|
98 |
|
|
if(req[1]) next_state = grant1;
|
99 |
|
|
else if(req[2]) next_state = grant2;
|
100 |
|
|
end
|
101 |
|
|
grant1:
|
102 |
|
|
// if this req is dropped or next is asserted, check for other req's
|
103 |
|
|
if(!req[1] ) begin
|
104 |
|
|
if(req[2]) next_state = grant2;
|
105 |
|
|
else if(req[0]) next_state = grant0;
|
106 |
|
|
end
|
107 |
|
|
grant2:
|
108 |
|
|
// if this req is dropped or next is asserted, check for other req's
|
109 |
|
|
if(!req[2] ) begin
|
110 |
|
|
if(req[0]) next_state = grant0;
|
111 |
|
|
else if(req[1]) next_state = grant1;
|
112 |
|
|
end
|
113 |
|
|
endcase
|
114 |
|
|
end
|
115 |
|
|
|
116 |
|
|
endmodule
|
117 |
|
|
|