forked from kaushanr/System-Bus-Design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArbiter.v
185 lines (157 loc) · 3.79 KB
/
Arbiter.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*##########Script Information###############################
# Purpose: Arbiter RTL For System Bus Design
# Updated: 07-08-2022
# Author : Rumesh
###########################################################*/
`timescale 1ns / 1ps
module Arbiter(
CLK,
RST,
HREQ_1,
HLOCK_1,
HREQ_2,
HLOCK_2,
HSPLIT,
HRESP,
HGRANT_1,
HGRANT_2,
HMAS,
MLOCK,
SEL,AB,
HREADY
);
input CLK;
input RST;
input HREQ_1;
input HLOCK_1;
input HREQ_2;
input HLOCK_2;
input [1:0] HSPLIT;
input [1:0] HRESP;
input HREADY;
output reg HGRANT_1;
output reg HGRANT_2;
output reg [1:0] HMAS;
output reg MLOCK;
output reg [1:0] SEL;
output reg AB;
//----------------------------
parameter SPLIT = 2'b11;
parameter IDLE = 2'b00;
parameter GRANT1 = 2'b01;
parameter GRANT2 = 2'b10;
reg [1:0] state;
reg g1;
reg g2;
reg [1:0] grant_save;
initial begin
AB = 1'bz;
state = IDLE;
end
always@(posedge CLK or posedge RST)
begin
if(RST == 1)
begin
HGRANT_1 <= 0;
HGRANT_2 <= 0;
HMAS <= 0;
MLOCK <= 0;
SEL <= 2'b00;
grant_save <= 0; // saves info about the previous master granted access to the bus
state <= IDLE;
end
else
begin
state <= IDLE;
case(state)
IDLE:begin
HGRANT_1 <= 0;
HGRANT_2 <= 0;
HMAS <= 0;
MLOCK <= 0;
SEL <= 2'b00;
// Priority order = Split request > Locked request > normal request
// Master 1 - 01, Master 2 - 10
if(HSPLIT == 2'b01) // Split request from slave 1 asking master 1 to connect
begin
state <= GRANT1;
end
else if(HSPLIT == 2'b10) // split request from slave 1 asking master 2 to connect
begin
state <= GRANT2;
end
else if(HREQ_1 == 1 && HREQ_2 == 0) // normal request only from master 1
begin
state <= GRANT1;
end
else if(HREQ_1 == 0 && HREQ_2 == 1) // normal request only from master 2
begin
state <= GRANT2;
end
else if(HREQ_1 == 1 && HREQ_2 == 1) //Priority selection of masters
begin
if(HSPLIT == 2'b01 || HLOCK_1) // checks for split request from slave 1 asking master 1 to connect OR a locked request from master 1
begin
state <= GRANT1;
end
else if(HSPLIT == 2'b10 || HLOCK_2) // checks for split request from slave 1 asking master 2 to connect OR a locked request from master 2
begin
state <= GRANT2;
end
else // signals with equal normal priority
begin
if (grant_save == 2'b01) // variable storing previous master ID
begin
state <= GRANT2;
end
else if(grant_save == 2'b10)
begin
state <= GRANT1;
end
else
begin
state <= GRANT1; // Default grant to master 1 on start
end
end
end
else
begin
state <= IDLE;
end
end
GRANT1:begin // access given to Master 1
HGRANT_1 <= 1;
HGRANT_2 <= 0;
HMAS <= 2'b01; // unique ID of Master 1 - 01
MLOCK <= HLOCK_1;
SEL <= 2'b01; // goes to the address and write muxes
grant_save <= 2'b01;
if(HRESP == SPLIT) // If split response issued, grant switched to other master
begin
state <= GRANT2;
end
else
begin
state <= (HLOCK_1 || HRESP == 2'b00 || HREADY == 1'b0)?GRANT1:IDLE; // (some condition)?if_TRUE:if_FALSE Ternery operator
end
end
GRANT2:begin
HGRANT_1 <= 0;
HGRANT_2 <= 1;
HMAS <= 2'b10;
MLOCK <= HLOCK_2;
SEL <= 2'b10;
grant_save <= 2'b10;
if(HRESP == SPLIT)
begin
state <= GRANT1;
end
else
begin
state <= (HLOCK_2 || HRESP == 2'b00 || HREADY == 1'b0)?GRANT2:IDLE;
end
end
endcase
end
end
endmodule