forked from yashgupta26/AMBA_APB_Protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPB_master.v
84 lines (71 loc) · 2.9 KB
/
APB_master.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
module APB_master(input Transfer, //temp signals for master input
input Wr_Rd, //temp signals for master input
input [4:0] Address, //temp signals for master input
input [31:0] write_data, //temp signals for master input
output reg [31:0] read_data, //temp signals for master input
input PCLK, //clock
input PRESETn, //active low async reset
input PREADY, //input by slave
input [31:0] PRDATA, //32 bit bus to read data
input PSLVERR, //Error signal by slave
output reg [4:0] PADDR, //32 bit address
output reg PSELx, //select slave
output reg PENABLE, //indicate 2nd or subsequent cycle
output reg PWRITE, //high->write, low->read
output reg [31:0] PWDATA); //32 bit bus to write data
parameter IDLE = 2'b00, SETUP = 2'b01, ACCESS = 2'b10;
reg [1:0] ps,ns;
always @(posedge PCLK) begin
if (!PRESETn)
ps <= IDLE;
else
ps <= ns;
end
always @(ps,Transfer,PREADY) begin
if (!PRESETn || !Transfer)
ns <= IDLE;
else
begin
PWRITE = Wr_Rd;
case (ps)
IDLE:begin
PSELx = 0;
PENABLE = 0;
ns <= SETUP;
end
SETUP:begin
PSELx = 1;
PENABLE = 0;
PADDR = Address;
if (PWRITE)
PWDATA <= write_data;
if (!PSLVERR)
ns <= ACCESS;
else
ns <= IDLE;
end
ACCESS:begin
PSELx = 1;
PENABLE = 1;
if (!PSLVERR)
begin
if (!PREADY) begin
if (PWRITE) begin
ns <= ACCESS;
end
else if (!PWRITE) begin
read_data = PRDATA;
ns <= ACCESS;
end
end
else if (PREADY)
ns <= SETUP;
end
else
ns <= IDLE;
end
default: ns <= IDLE;
endcase
end
end
endmodule