forked from kaushanr/System-Bus-Design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlave_2K_Split.v
227 lines (186 loc) · 4.18 KB
/
Slave_2K_Split.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
`timescale 1ns / 1ps
`define IDLE 1'b0
`define START 1'b1
// Responses
`define OKAY 2'b00
`define ERROR 2'b01
`define RETRY 2'b10
`define SPLIT 2'b11
module Slave_2K_Split(SEL,HADDR,HWDATA,HRDATA,HRESP,CLK,HREADY,HSPLIT,RST,HMAS,MLOCK,USPLIT,AB);
input [15:0] HADDR;
input [31:0] HWDATA;
input SEL;
input RST,CLK;
input [1:0] HMAS;
input MLOCK;
input USPLIT;
//input HWRITE;
output reg [31:0] HRDATA;
output reg [1:0] HRESP;
output reg [1:0] HSPLIT;
output reg HREADY;
output reg AB;
// Slave States
parameter IDLE = 3'd0;
parameter ACTIVE = 3'd1;
parameter WRITE = 3'd2;
parameter READ = 3'd3;
parameter SPLITX = 3'd4;
parameter MSB_ADDR = 10; // MSB for 2K Address
reg [2:0] state;
reg [10:0] S_ADDR;
reg HWRITE;
reg rand_split;
reg [1:0] save_master;
reg TRANS;
// 2K Memory Addresses
reg [31:0] S_REG [2047:0]; //2K, 32-bit registers
initial begin
HREADY = 1'bz;
AB = 1'bz;
state = IDLE;
end
always @ (posedge CLK or posedge RST )
begin
if(RST == 1)
begin
HRDATA <= 32'bx;
HRESP <= `OKAY;
HSPLIT <= 0;
HREADY <= 1'bz;
S_ADDR <= 11'bx;
HWRITE <= 1'bx;
save_master <= 0;
TRANS <= 1'bx;
state <= IDLE;
end
else
begin
state <= IDLE;
case(state)
IDLE:begin
HRDATA <= 32'bx;
HRESP <= `OKAY;
HSPLIT <= 0;
HREADY <= 1'bz;
state <= (SEL == 1)?ACTIVE:IDLE;
end
ACTIVE:begin
rand_split <= USPLIT;
save_master <= HMAS;
HRESP <= `OKAY;
HREADY <= 1'b1;
S_ADDR <= HADDR[MSB_ADDR:0];
HWRITE <= HADDR[12];
TRANS <= HADDR[15];
if(TRANS == 1'b1)
begin
HREADY <= 1'b1; // toggles the HREADY line only if selected as active device
HRESP <= `OKAY;
HSPLIT <= 0;
state <= (HWRITE == 1)?WRITE:READ;
end
else
begin
HRESP <= `ERROR;
state <= (SEL == 1)?ACTIVE:IDLE;
end
end
WRITE:begin
S_ADDR <= HADDR[MSB_ADDR:0];
HWRITE <= HADDR[12];
TRANS <= HADDR[15];
if(TRANS == `START)
begin
S_REG[S_ADDR] <= HWDATA;
if(HWDATA == S_REG[S_ADDR])
begin
HRESP <= `OKAY;
HREADY <= 1'b1;
state <= ACTIVE;
end
else if(HWDATA !== S_REG[S_ADDR] && MLOCK == 1)
begin
HRESP <= `RETRY;
HREADY <= 1'b0;
state <= WRITE;
end
else
begin
HRESP <= `ERROR;
HREADY <= 1'b0;
state <= ACTIVE;
end
end
else
begin
HRESP <= `RETRY;
state <= ACTIVE;
end
end
READ:begin
S_ADDR <= HADDR[MSB_ADDR:0];
HWRITE <= HADDR[12];
TRANS <= HADDR[15];
rand_split <= USPLIT;
if(TRANS == `START && rand_split != 1'b1)
begin
HRDATA <= S_REG[S_ADDR];
end
else
begin
HRESP <= `RETRY;
state <= ACTIVE;
end
if(HRDATA == S_REG[S_ADDR] && rand_split != 1'b1)
begin
HRESP <= `OKAY;
HREADY <= 1'b1;
state <= ACTIVE;
end
else if(HRDATA != S_REG[S_ADDR] && MLOCK == 1 && rand_split != 1'b1)
begin
HRESP <= `RETRY;
HREADY <= 1'b0;
state <= READ;
end
else if(rand_split == 1'b1)
begin
HRESP <= `SPLIT;
state <= SPLITX;
end
else
begin
HRESP <= `ERROR;
HREADY <= 1'b0;
state <= ACTIVE;
end
end
SPLITX:begin
HREADY <= 1'bz;
rand_split <= USPLIT;
if (rand_split == 0)
begin
HSPLIT <= save_master;
HRESP <= `OKAY;
if(SEL == 1 && HMAS == save_master)
begin
HREADY <= 1'b0;
HRESP <= `OKAY;
state <= READ;
end
else
begin
state <= SPLITX;
HRESP <= `ERROR;
end
end
else
begin
state <= SPLITX;
end
end
endcase
end
end
endmodule