-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapb_master.v
105 lines (93 loc) · 2.82 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
module apb_master (pclk, rstn, psel, penable, pwrite, paddr, pwdata, prdata,
done, ip_din, sink_data, sink_addr);
input pclk;
input rstn;
output psel;
output penable;
output pwrite;
output [`ADDR_WIDTH-1:0] paddr;
output [`DATA_WIDTH-1:0] pwdata;
input [`DATA_WIDTH-1:0] prdata;
output [`DATA_WIDTH-1:0] ip_din;
input [`DATA_WIDTH-1:0] sink_data;
input [`ADDR_WIDTH-1:0] sink_addr;
input done;
`ifdef APB3
input pslverr;
input pready;
`endif
wire wr, rd;
reg [`DATA_WIDTH-1:0] din_r;
//-------------Output Ports Data Type------------------
reg psel, penable;
//-------------Internal Constants--------------------------
parameter IDLE = 1, SETUP = 3, ACCESS = 2;
//-------------Internal Variables---------------------------
reg [1:0] state ; // Seq part of the FSM
reg [1:0] next_state; // combo part of FSM
//----------State machine combinational logic--------------
always @ (state or done)
begin : FSM_COMBO
next_state = IDLE;
case(state)
IDLE :
if (!done)
next_state = SETUP;
else
next_state = IDLE;
SETUP :
next_state = ACCESS;
ACCESS :
if (done)
next_state = IDLE;
else
next_state = SETUP;
// with wait states add ACCESS => ACCESS loop
default :
next_state = IDLE;
endcase
end
//----------Seq Logic-----------------------------
always @ (posedge pclk)
begin : FSM_SEQ
if (!rstn) begin
state <= #1 IDLE;
end else begin
state <= #1 next_state;
end
end
//----------Output Registers---------------------
//
// Can be avoided using combinational assign instead of register process
//
always @ (posedge pclk)
begin : OUTPUT_LOGIC
if (!rstn) begin
psel <= #1 1'b0;
penable <= #1 1'b0;
end
else begin
case(state)
IDLE : begin
psel <= #1 1'b0;
penable <= #1 1'b0;
end
SETUP : begin
psel <= #1 1'b1;
penable <= #1 1'b0;
end
ACCESS : begin
psel <= #1 1'b1;
penable <= #1 1'b1;
end
default : begin
psel <= #1 1'b0;
penable <= #1 1'b0;
end
endcase
end
end
assign pwrite = 1;
assign paddr = sink_addr;
assign pwdata = sink_data;
endmodule