| 1 | ///////////////////////////////////////////////////////////////////// |
|---|
| 2 | //// //// |
|---|
| 3 | //// General Round Robin Arbiter //// |
|---|
| 4 | //// //// |
|---|
| 5 | //// //// |
|---|
| 6 | //// Author: Rudolf Usselmann //// |
|---|
| 7 | //// rudi@asics.ws //// |
|---|
| 8 | //// //// |
|---|
| 9 | //// //// |
|---|
| 10 | //// Downloaded from: http://www.opencores.org/cores/wb_conmax/ //// |
|---|
| 11 | //// //// |
|---|
| 12 | ///////////////////////////////////////////////////////////////////// |
|---|
| 13 | //// //// |
|---|
| 14 | //// Copyright (C) 2000-2002 Rudolf Usselmann //// |
|---|
| 15 | //// www.asics.ws //// |
|---|
| 16 | //// rudi@asics.ws //// |
|---|
| 17 | //// //// |
|---|
| 18 | //// This source file may be used and distributed without //// |
|---|
| 19 | //// restriction provided that this copyright statement is not //// |
|---|
| 20 | //// removed from the file and that any derivative work contains //// |
|---|
| 21 | //// the original copyright notice and the associated disclaimer.//// |
|---|
| 22 | //// //// |
|---|
| 23 | //// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// |
|---|
| 24 | //// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// |
|---|
| 25 | //// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// |
|---|
| 26 | //// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// |
|---|
| 27 | //// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// |
|---|
| 28 | //// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// |
|---|
| 29 | //// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// |
|---|
| 30 | //// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// |
|---|
| 31 | //// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// |
|---|
| 32 | //// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// |
|---|
| 33 | //// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// |
|---|
| 34 | //// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// |
|---|
| 35 | //// POSSIBILITY OF SUCH DAMAGE. //// |
|---|
| 36 | //// //// |
|---|
| 37 | ///////////////////////////////////////////////////////////////////// |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | // |
|---|
| 41 | // copy from wb_conmax |
|---|
| 42 | // |
|---|
| 43 | // |
|---|
| 44 | // |
|---|
| 45 | // |
|---|
| 46 | // |
|---|
| 47 | |
|---|
| 48 | `include "wb_conbus_defines.v" |
|---|
| 49 | |
|---|
| 50 | module wb_conbus_arb(clk, rst, req, gnt); |
|---|
| 51 | |
|---|
| 52 | input clk; |
|---|
| 53 | input rst; |
|---|
| 54 | input [7:0] req; // Req input |
|---|
| 55 | output [2:0] gnt; // Grant output |
|---|
| 56 | //input next; // Next Target |
|---|
| 57 | |
|---|
| 58 | /////////////////////////////////////////////////////////////////////// |
|---|
| 59 | // |
|---|
| 60 | // Parameters |
|---|
| 61 | // |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | parameter [2:0] |
|---|
| 65 | grant0 = 3'h0, |
|---|
| 66 | grant1 = 3'h1, |
|---|
| 67 | grant2 = 3'h2, |
|---|
| 68 | grant3 = 3'h3, |
|---|
| 69 | grant4 = 3'h4, |
|---|
| 70 | grant5 = 3'h5, |
|---|
| 71 | grant6 = 3'h6, |
|---|
| 72 | grant7 = 3'h7; |
|---|
| 73 | |
|---|
| 74 | /////////////////////////////////////////////////////////////////////// |
|---|
| 75 | // |
|---|
| 76 | // Local Registers and Wires |
|---|
| 77 | // |
|---|
| 78 | |
|---|
| 79 | reg [2:0] state, next_state; |
|---|
| 80 | |
|---|
| 81 | /////////////////////////////////////////////////////////////////////// |
|---|
| 82 | // |
|---|
| 83 | // Misc Logic |
|---|
| 84 | // |
|---|
| 85 | |
|---|
| 86 | assign gnt = state; |
|---|
| 87 | |
|---|
| 88 | always@(posedge clk or posedge rst) |
|---|
| 89 | if(rst) state <= #1 grant0; |
|---|
| 90 | else state <= #1 next_state; |
|---|
| 91 | |
|---|
| 92 | /////////////////////////////////////////////////////////////////////// |
|---|
| 93 | // |
|---|
| 94 | // Next State Logic |
|---|
| 95 | // - implements round robin arbitration algorithm |
|---|
| 96 | // - switches grant if current req is dropped or next is asserted |
|---|
| 97 | // - parks at last grant |
|---|
| 98 | // |
|---|
| 99 | |
|---|
| 100 | always@(state or req ) |
|---|
| 101 | begin |
|---|
| 102 | next_state = state; // Default Keep State |
|---|
| 103 | case(state) // synopsys parallel_case full_case |
|---|
| 104 | grant0: |
|---|
| 105 | // if this req is dropped or next is asserted, check for other req's |
|---|
| 106 | if(!req[0] ) |
|---|
| 107 | begin |
|---|
| 108 | if(req[1]) next_state = grant1; |
|---|
| 109 | else |
|---|
| 110 | if(req[2]) next_state = grant2; |
|---|
| 111 | else |
|---|
| 112 | if(req[3]) next_state = grant3; |
|---|
| 113 | else |
|---|
| 114 | if(req[4]) next_state = grant4; |
|---|
| 115 | else |
|---|
| 116 | if(req[5]) next_state = grant5; |
|---|
| 117 | else |
|---|
| 118 | if(req[6]) next_state = grant6; |
|---|
| 119 | else |
|---|
| 120 | if(req[7]) next_state = grant7; |
|---|
| 121 | end |
|---|
| 122 | grant1: |
|---|
| 123 | // if this req is dropped or next is asserted, check for other req's |
|---|
| 124 | if(!req[1] ) |
|---|
| 125 | begin |
|---|
| 126 | if(req[2]) next_state = grant2; |
|---|
| 127 | else |
|---|
| 128 | if(req[3]) next_state = grant3; |
|---|
| 129 | else |
|---|
| 130 | if(req[4]) next_state = grant4; |
|---|
| 131 | else |
|---|
| 132 | if(req[5]) next_state = grant5; |
|---|
| 133 | else |
|---|
| 134 | if(req[6]) next_state = grant6; |
|---|
| 135 | else |
|---|
| 136 | if(req[7]) next_state = grant7; |
|---|
| 137 | else |
|---|
| 138 | if(req[0]) next_state = grant0; |
|---|
| 139 | end |
|---|
| 140 | grant2: |
|---|
| 141 | // if this req is dropped or next is asserted, check for other req's |
|---|
| 142 | if(!req[2] ) |
|---|
| 143 | begin |
|---|
| 144 | if(req[3]) next_state = grant3; |
|---|
| 145 | else |
|---|
| 146 | if(req[4]) next_state = grant4; |
|---|
| 147 | else |
|---|
| 148 | if(req[5]) next_state = grant5; |
|---|
| 149 | else |
|---|
| 150 | if(req[6]) next_state = grant6; |
|---|
| 151 | else |
|---|
| 152 | if(req[7]) next_state = grant7; |
|---|
| 153 | else |
|---|
| 154 | if(req[0]) next_state = grant0; |
|---|
| 155 | else |
|---|
| 156 | if(req[1]) next_state = grant1; |
|---|
| 157 | end |
|---|
| 158 | grant3: |
|---|
| 159 | // if this req is dropped or next is asserted, check for other req's |
|---|
| 160 | if(!req[3] ) |
|---|
| 161 | begin |
|---|
| 162 | if(req[4]) next_state = grant4; |
|---|
| 163 | else |
|---|
| 164 | if(req[5]) next_state = grant5; |
|---|
| 165 | else |
|---|
| 166 | if(req[6]) next_state = grant6; |
|---|
| 167 | else |
|---|
| 168 | if(req[7]) next_state = grant7; |
|---|
| 169 | else |
|---|
| 170 | if(req[0]) next_state = grant0; |
|---|
| 171 | else |
|---|
| 172 | if(req[1]) next_state = grant1; |
|---|
| 173 | else |
|---|
| 174 | if(req[2]) next_state = grant2; |
|---|
| 175 | end |
|---|
| 176 | grant4: |
|---|
| 177 | // if this req is dropped or next is asserted, check for other req's |
|---|
| 178 | if(!req[4] ) |
|---|
| 179 | begin |
|---|
| 180 | if(req[5]) next_state = grant5; |
|---|
| 181 | else |
|---|
| 182 | if(req[6]) next_state = grant6; |
|---|
| 183 | else |
|---|
| 184 | if(req[7]) next_state = grant7; |
|---|
| 185 | else |
|---|
| 186 | if(req[0]) next_state = grant0; |
|---|
| 187 | else |
|---|
| 188 | if(req[1]) next_state = grant1; |
|---|
| 189 | else |
|---|
| 190 | if(req[2]) next_state = grant2; |
|---|
| 191 | else |
|---|
| 192 | if(req[3]) next_state = grant3; |
|---|
| 193 | end |
|---|
| 194 | grant5: |
|---|
| 195 | // if this req is dropped or next is asserted, check for other req's |
|---|
| 196 | if(!req[5] ) |
|---|
| 197 | begin |
|---|
| 198 | if(req[6]) next_state = grant6; |
|---|
| 199 | else |
|---|
| 200 | if(req[7]) next_state = grant7; |
|---|
| 201 | else |
|---|
| 202 | if(req[0]) next_state = grant0; |
|---|
| 203 | else |
|---|
| 204 | if(req[1]) next_state = grant1; |
|---|
| 205 | else |
|---|
| 206 | if(req[2]) next_state = grant2; |
|---|
| 207 | else |
|---|
| 208 | if(req[3]) next_state = grant3; |
|---|
| 209 | else |
|---|
| 210 | if(req[4]) next_state = grant4; |
|---|
| 211 | end |
|---|
| 212 | grant6: |
|---|
| 213 | // if this req is dropped or next is asserted, check for other req's |
|---|
| 214 | if(!req[6] ) |
|---|
| 215 | begin |
|---|
| 216 | if(req[7]) next_state = grant7; |
|---|
| 217 | else |
|---|
| 218 | if(req[0]) next_state = grant0; |
|---|
| 219 | else |
|---|
| 220 | if(req[1]) next_state = grant1; |
|---|
| 221 | else |
|---|
| 222 | if(req[2]) next_state = grant2; |
|---|
| 223 | else |
|---|
| 224 | if(req[3]) next_state = grant3; |
|---|
| 225 | else |
|---|
| 226 | if(req[4]) next_state = grant4; |
|---|
| 227 | else |
|---|
| 228 | if(req[5]) next_state = grant5; |
|---|
| 229 | end |
|---|
| 230 | grant7: |
|---|
| 231 | // if this req is dropped or next is asserted, check for other req's |
|---|
| 232 | if(!req[7] ) |
|---|
| 233 | begin |
|---|
| 234 | if(req[0]) next_state = grant0; |
|---|
| 235 | else |
|---|
| 236 | if(req[1]) next_state = grant1; |
|---|
| 237 | else |
|---|
| 238 | if(req[2]) next_state = grant2; |
|---|
| 239 | else |
|---|
| 240 | if(req[3]) next_state = grant3; |
|---|
| 241 | else |
|---|
| 242 | if(req[4]) next_state = grant4; |
|---|
| 243 | else |
|---|
| 244 | if(req[5]) next_state = grant5; |
|---|
| 245 | else |
|---|
| 246 | if(req[6]) next_state = grant6; |
|---|
| 247 | end |
|---|
| 248 | endcase |
|---|
| 249 | end |
|---|
| 250 | |
|---|
| 251 | endmodule |
|---|
| 252 | |
|---|