-
Notifications
You must be signed in to change notification settings - Fork 1
/
rbcp_bridge.v
193 lines (171 loc) · 5.71 KB
/
rbcp_bridge.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
`timescale 1ns / 1ps
module rbcp_bridge(
input wire clk,
input wire rst,
// RBCP
input wire rbcp_act,
input wire [31:0] rbcp_addr,
input wire [7:0] rbcp_wd,
input wire rbcp_we,
input wire rbcp_re,
output wire rbcp_ack,
output wire [7:0] rbcp_rd,
// AXI
output wire [31:0] m_axi_awaddr, // write address
output wire [2:0] m_axi_awprot, // write channel protection type
output wire m_axi_awvalid,// write address valid
input wire m_axi_awready,// write address ready
output wire [31:0] m_axi_wdata, // write data channel
output wire [3:0] m_axi_wstrb, // valid lanes
output wire m_axi_wvalid, // write valid
input wire m_axi_wready, // write ready
input wire [1:0] m_axi_bresp, // write response channel
input wire m_axi_bvalid, // write response channel valid
output wire m_axi_bready, // write response channel ready
output wire [31:0] m_axi_araddr, // read address
output wire [2:0] m_axi_arprot, // read channel protection type
output wire m_axi_arvalid,// read address valid
input wire m_axi_arready,// read address ready
input wire [31:0] m_axi_rdata, // read data
input wire m_axi_rvalid, // read valid
output wire m_axi_rready, // read ready
input wire [1:0] m_axi_rresp, // read response
// control signal
output wire [3:0] araddr_res, // residual
output wire [1:0] debug_rresp,
output wire [1:0] debug_bresp
);
// debug
assign debug_rresp = m_axi_rresp;
assign debug_bresp = m_axi_bresp;
/////////////////////////////////// Address handling
// address buffer
reg [31:0] addr_buf;
wire [1:0] addr_res;
always @(posedge clk) begin
if (rst) begin
addr_buf <= 32'd0;
end else begin
if (rbcp_we || rbcp_re) begin
addr_buf <= rbcp_addr;
end
end
end
assign m_axi_awaddr = {addr_buf[31:2], 2'b00};
assign m_axi_araddr = {addr_buf[31:2], 2'b00};
assign addr_res = addr_buf[1:0];
// Assuming little endian
assign m_axi_wstrb[0] = (addr_res == 2'd0);
assign m_axi_wstrb[1] = (addr_res == 2'd1);
assign m_axi_wstrb[2] = (addr_res == 2'd2);
assign m_axi_wstrb[3] = (addr_res == 2'd3);
assign araddr_res = m_axi_wstrb;
// awvalid
reg awvalid_buf;
always @(posedge clk) begin
if (rst) begin
awvalid_buf <= 1'b0;
end else begin
if (rbcp_we) begin
awvalid_buf <= 1'b1;
end else if (awvalid_buf && m_axi_awready) begin
// Address transaction finish
awvalid_buf <= 1'b0;
end
end
end
assign m_axi_awvalid = awvalid_buf;
// arvalid
reg arvalid_buf;
always @(posedge clk) begin
if (rst) begin
arvalid_buf <= 1'b0;
end else begin
if (rbcp_re) begin
arvalid_buf <= 1'b1;
end else if (arvalid_buf && m_axi_arready) begin
// Address transaction finish
arvalid_buf <= 1'b0;
end
end
end
assign m_axi_arvalid = arvalid_buf;
/////////////////////////////////// Write data handling
reg [7:0] wdata_buf;
always @(posedge clk) begin
if (rst) begin
wdata_buf <= 32'd0;
end else begin
wdata_buf <= rbcp_wd;
end
end
assign m_axi_wdata = {4{wdata_buf}};
reg wvalid_buf;
always @(posedge clk) begin
if (rst) begin
wvalid_buf <= 1'b0;
end else begin
if (rbcp_we) begin
wvalid_buf <= 1'b1;
end else if (wvalid_buf && m_axi_wready) begin
wvalid_buf <= 1'b0;
end
end
end
assign m_axi_wvalid = wvalid_buf;
/////////////////////////////////// Write response handling
reg bready_buf;
always @(posedge clk) begin
if (rst) begin
bready_buf <= 1'b0;
end else begin
if (m_axi_bvalid && ~bready_buf) begin
bready_buf <= 1'b1;
end else if (bready_buf) begin
bready_buf <= 1'b0;
end else begin
bready_buf <= bready_buf;
end
end
end
assign m_axi_bready = bready_buf;
/////////////////////////////////// Read data handling
reg [7:0] rdata_buf;
always @(posedge clk) begin
if (rst) begin
rdata_buf <= 8'd0;
end else begin
if (m_axi_rvalid) begin
case (addr_res)// little endian
2'b00: rdata_buf <= m_axi_rdata[7:0];
2'b01: rdata_buf <= m_axi_rdata[15:8];
2'b10: rdata_buf <= m_axi_rdata[23:16];
2'b11: rdata_buf <= m_axi_rdata[31:24];
default: rdata_buf <= 0;
endcase
end
end
end
assign rbcp_rd = rdata_buf;
/////////////////////////////////// Read response handling
reg rready_buf;
always @(posedge clk) begin
if (rst) begin
rready_buf <= 1'b0;
end else begin
if (m_axi_rvalid && ~rready_buf) begin
rready_buf <= 1'b1;
end else if (rready_buf) begin
rready_buf <= 1'b0;
end else begin
rready_buf <= rready_buf;
end
end
end
assign m_axi_rready = rready_buf;
/////////////////////////////////// RBCP acknowledge
assign rbcp_ack = m_axi_rready | m_axi_bready;
/////////////////////////////////// Protection type
assign m_axi_awprot = 3'b000;
assign m_axi_arprot = 3'b000;
endmodule