OpenCores
URL https://opencores.org/ocsvn/wb2axip/wb2axip/trunk

Subversion Repositories wb2axip

[/] [wb2axip/] [trunk/] [rtl/] [wbm2axisp.v] - Blame information for rev 4

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    wbm2axisp.v
4
//
5
// Project:     Pipelined Wishbone to AXI converter
6
//
7
// Purpose:     The B4 Wishbone SPEC allows transactions at a speed as fast as
8
//              one per clock.  The AXI bus allows transactions at a speed of
9
//      one read and one write transaction per clock.  These capabilities work
10
//      by allowing requests to take place prior to responses, such that the
11
//      requests might go out at once per clock and take several clocks, and
12
//      the responses may start coming back several clocks later.  In other
13
//      words, both protocols allow multiple transactions to be "in flight" at
14
//      the same time.  Current wishbone to AXI converters, however, handle only
15
//      one transaction at a time: initiating the transaction, and then waiting
16
//      for the transaction to complete before initiating the next.
17
//
18
//      The purpose of this core is to maintain the speed of both busses, while
19
//      transiting from the Wishbone (as master) to the AXI bus (as slave) and
20
//      back again.
21
//
22
//      Since the AXI bus allows transactions to be reordered, whereas the 
23
//      wishbone does not, this core can be configured to reorder return
24
//      transactions as well.
25
//
26
// Creator:     Dan Gisselquist, Ph.D.
27
//              Gisselquist Technology, LLC
28
//
29
////////////////////////////////////////////////////////////////////////////////
30
//
31 3 dgisselq
// Copyright (C) 2016, Gisselquist Technology, LLC
32 2 dgisselq
//
33
// This program is free software (firmware): you can redistribute it and/or
34
// modify it under the terms of  the GNU General Public License as published
35
// by the Free Software Foundation, either version 3 of the License, or (at
36
// your option) any later version.
37
//
38
// This program is distributed in the hope that it will be useful, but WITHOUT
39
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
40
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
41
// for more details.
42
//
43
// You should have received a copy of the GNU General Public License along
44
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
45
// target there if the PDF file isn't present.)  If not, see
46
// <http://www.gnu.org/licenses/> for a copy.
47
//
48
// License:     GPL, v3, as defined and found on www.gnu.org,
49
//              http://www.gnu.org/licenses/gpl.html
50
//
51
//
52
////////////////////////////////////////////////////////////////////////////////
53
//
54
//
55
module wbm2axisp #(
56
        parameter C_AXI_ID_WIDTH        = 6, // The AXI id width used for R&W
57
                                             // This is an int between 1-16
58
        parameter C_AXI_DATA_WIDTH      = 128,// Width of the AXI R&W data
59
        parameter AW                    = 28,   // Wishbone address width
60 4 dgisselq
        parameter DW                    = 128,  // Wishbone data width
61 3 dgisselq
        parameter STRICT_ORDER          = 0      // Reorder, or not? 0 -> Reorder
62 2 dgisselq
        ) (
63
        input                           i_clk,  // System clock
64
        input                           i_reset,// Wishbone reset signal
65
 
66
// AXI write address channel signals
67
        input                           i_axi_wready, // Slave is ready to accept
68
        output  wire    [C_AXI_ID_WIDTH-1:0]     o_axi_wid,      // Write ID
69
        output  reg     [AW-1:0] o_axi_waddr,    // Write address
70
        output  wire    [7:0]            o_axi_wlen,     // Write Burst Length
71
        output  wire    [2:0]            o_axi_wsize,    // Write Burst size
72
        output  wire    [1:0]            o_axi_wburst,   // Write Burst type
73
        output  wire    [1:0]            o_axi_wlock,    // Write lock type
74
        output  wire    [3:0]            o_axi_wcache,   // Write Cache type
75
        output  wire    [2:0]            o_axi_wprot,    // Write Protection type
76
        output  reg                     o_axi_wvalid,   // Write address valid
77
 
78
// AXI write data channel signals
79
        input                           i_axi_wd_wready,  // Write data ready
80
        output  wire    [C_AXI_ID_WIDTH-1:0]     o_axi_wd_wid,   // Write ID tag
81 3 dgisselq
        output  reg     [C_AXI_DATA_WIDTH-1:0]   o_axi_wd_data,  // Write data
82
        output  reg     [C_AXI_DATA_WIDTH/8-1:0] o_axi_wd_strb,  // Write strobes
83 2 dgisselq
        output  wire                    o_axi_wd_last,  // Last write transaction   
84
        output  reg                     o_axi_wd_valid, // Write valid
85
 
86
// AXI write response channel signals
87
        input   [C_AXI_ID_WIDTH-1:0]     i_axi_wd_bid,   // Response ID
88
        input   [1:0]                    i_axi_wd_bresp, // Write response
89
        input                           i_axi_wd_bvalid,  // Write reponse valid
90
        output  wire                    o_axi_wd_bready,  // Response ready
91
 
92
// AXI read address channel signals
93
        input                           i_axi_rready,   // Read address ready
94
        output  wire    [C_AXI_ID_WIDTH-1:0]     o_axi_rid,      // Read ID
95
        output  wire    [AW-1:0] o_axi_raddr,    // Read address
96
        output  wire    [7:0]            o_axi_rlen,     // Read Burst Length
97
        output  wire    [2:0]            o_axi_rsize,    // Read Burst size
98
        output  wire    [1:0]            o_axi_rburst,   // Read Burst type
99
        output  wire    [1:0]            o_axi_rlock,    // Read lock type
100
        output  wire    [3:0]            o_axi_rcache,   // Read Cache type
101
        output  wire    [2:0]            o_axi_rprot,    // Read Protection type
102
        output  reg                     o_axi_rvalid,   // Read address valid
103
 
104
// AXI read data channel signals   
105
        input   [C_AXI_ID_WIDTH-1:0]     i_axi_rd_bid,     // Response ID
106
        input   [1:0]                    i_axi_rd_rresp,   // Read response
107
        input                           i_axi_rd_rvalid,  // Read reponse valid
108 3 dgisselq
        input   [C_AXI_DATA_WIDTH-1:0]           i_axi_rd_data,    // Read data
109 2 dgisselq
        input                           i_axi_rd_last,    // Read last
110
        output  wire                    o_axi_rd_rready,  // Read Response ready
111
 
112
        // We'll share the clock and the reset
113 3 dgisselq
        input                           i_wb_cyc,
114
        input                           i_wb_stb,
115
        input                           i_wb_we,
116
        input           [AW-1:0] i_wb_addr,
117
        input           [DW-1:0] i_wb_data,
118 4 dgisselq
        input           [(DW/8-1):0]     i_wb_sel,
119 3 dgisselq
        output  reg                     o_wb_ack,
120
        output  wire                    o_wb_stall,
121
        output  reg     [DW-1:0] o_wb_data,
122
        output  reg                     o_wb_err
123 2 dgisselq
);
124
 
125
//*****************************************************************************
126
// Parameter declarations
127
//*****************************************************************************
128
 
129
        localparam      CTL_SIG_WIDTH   = 3;    // Control signal width
130
        localparam      RD_STS_WIDTH    = 16;   // Read status signal width
131
        localparam      WR_STS_WIDTH    = 16;   // Write status signal width
132
 
133
//*****************************************************************************
134
// Internal register and wire declarations
135
//*****************************************************************************
136
 
137
        wire                                    cmd_en;
138
        wire    [2:0]                            cmd;
139
        wire    [7:0]                            blen;
140
        wire    [31:0]                           addr;
141
        wire    [CTL_SIG_WIDTH-1:0]              ctl;
142
        wire                                    cmd_ack;
143
 
144
// User interface write ports
145
        wire                                    wrdata_vld;
146
        wire    [C_AXI_DATA_WIDTH-1:0]           wrdata;
147
        wire    [C_AXI_DATA_WIDTH/8-1:0] wrdata_bvld;
148
        wire                                    wrdata_cmptd;
149
        wire                                    wrdata_rdy;
150
        wire                                    wrdata_sts_vld;
151
        wire    [WR_STS_WIDTH-1:0]              wrdata_sts;
152
 
153
// User interface read ports
154
        wire                                    rddata_rdy;
155
        wire                                    rddata_vld;
156
        wire    [C_AXI_DATA_WIDTH-1:0]           rddata;
157
        wire    [C_AXI_DATA_WIDTH/8-1:0] rddata_bvld;
158
        wire                                    rddata_cmptd;
159
        wire    [RD_STS_WIDTH-1:0]               rddata_sts;
160
        reg                                     cmptd_one_wr;
161
        reg                                     cmptd_one_rd;
162
 
163
 
164
// Things we're not changing ...
165
        assign o_axi_wlen = 8'h0;       // Burst length is one
166
        assign o_axi_wsize = 3'b101;    // maximum bytes per burst is 32
167
        assign o_axi_wburst = 2'b01;    // Incrementing address (ignored)
168
        assign o_axi_rburst = 2'b01;    // Incrementing address (ignored)
169
        assign o_axi_wlock  = 2'b00;    // Normal signaling
170
        assign o_axi_rlock  = 2'b00;    // Normal signaling
171
        assign o_axi_wcache = 4'h2;     // Normal: no cache, no buffer
172
        assign o_axi_rcache = 4'h2;     // Normal: no cache, no buffer
173
        assign o_axi_wprot  = 3'h010;   // Unpriviledged, unsecure, data access
174
        assign o_axi_rprot  = 3'h010;   // Unpriviledged, unsecure, data access
175
 
176
// Command logic
177
        assign  o_wb_stall = (i_wb_we)&&(~i_axi_wready)
178
                        ||(~i_wb_we)&&(!i_axi_rready);
179
// Write address logic
180
 
181
        always @(posedge i_clk)
182
                o_axi_wvalid <= (!o_wb_stall)&&(i_wb_stb)&&(i_wb_we)
183
                                ||(o_wb_stall)&&(o_axi_wvalid)&&(!i_axi_wready);
184
        always @(posedge i_clk)
185
                if (!o_wb_stall)
186
                        o_axi_waddr <= { i_wb_addr[AW-1:2], 2'b00 }; // 28 bits
187
 
188
        reg     [5:0]    transaction_id;
189
        always @(posedge i_clk)
190
                if (!i_wb_cyc)
191
                        transaction_id <= 6'h00;
192
                else if ((i_wb_stb)&&(~o_wb_stall))
193
                        transaction_id <= transaction_id + 6'h01;
194
        assign  o_axi_wid = transaction_id;
195
 
196
// Read address logic
197
        assign  o_axi_rid = transaction_id;
198
        assign  o_axi_raddr = o_axi_waddr;
199
        assign  o_axi_rlen  = o_axi_wlen;
200
        assign  o_axi_rsize = 3'b101;   // maximum bytes per burst is 32
201
        always @(posedge i_clk)
202
                o_axi_rvalid <= (!o_wb_stall)&&(i_wb_stb)&&(!i_wb_we)
203
                        ||(o_wb_stall)&&(o_axi_rvalid)&&(!i_axi_rready);
204
 
205
 
206
// Write data logic
207
        assign  o_axi_wd_wid = transaction_id;
208 4 dgisselq
 
209
        generate
210
        if (DW == 32)
211
        begin
212
                always @(posedge i_clk)
213
                        if (!o_wb_stall)
214
                                o_axi_wd_data <= { i_wb_data, i_wb_data, i_wb_data, i_wb_data };
215
                always @(posedge i_clk)
216
                        if (!o_wb_stall)
217
                        case(i_wb_addr[1:0])
218
                        2'b00:o_axi_wd_strb<={     4'h0,     4'h0,     4'h0, i_wb_sel };
219
                        2'b01:o_axi_wd_strb<={     4'h0,     4'h0, i_wb_sel,     4'h0 };
220
                        2'b10:o_axi_wd_strb<={     4'h0, i_wb_sel,     4'h0,     4'h0 };
221
                        2'b11:o_axi_wd_strb<={ i_wb_sel,     4'h0,     4'h0,     4'h0 };
222
                        endcase
223
        end else if (DW == 128)
224
        begin
225
                always @(posedge i_clk)
226
                        if (!o_wb_stall)
227
                                o_axi_wd_data <= i_wb_data;
228
                always @(posedge i_clk)
229
                        if (!o_wb_stall)
230
                                o_axi_wd_strb <= i_wb_sel;
231
        end endgenerate
232
 
233 2 dgisselq
        assign  o_axi_wd_last = 1'b1;
234
        always @(posedge i_clk)
235
                o_axi_wd_valid <= ((!o_wb_stall)&&(i_wb_stb)&&(i_wb_we))
236
                        ||(o_wb_stall)&&(o_axi_wd_valid)&&(!i_axi_wd_wready);
237
 
238
// Read data channel / response logic
239
        assign  o_axi_rd_rready = 1'b1;
240
        assign  o_axi_wd_bready = 1'b1;
241
 
242
        wire    w_fifo_full;
243
        generate
244
        if (STRICT_ORDER == 0)
245
        begin
246
                // Reorder FIFO
247
                //
248
                localparam      LGFIFOLN = C_AXI_ID_WIDTH;
249
                localparam      FIFOLN = (1<<LGFIFOLN);
250
                // FIFO reorder buffer
251 3 dgisselq
                reg     [(LGFIFOLN-1):0] fifo_tail;
252
                reg     [(C_AXI_DATA_WIDTH-1):0] reorder_fifo_data [0:(FIFOLN-1)];
253
                reg     [(FIFOLN-1):0]   reorder_fifo_valid;
254
                reg     [(FIFOLN-1):0]   reorder_fifo_err;
255
 
256 4 dgisselq
                if (DW == 32)
257
                begin
258
                        reg     [1:0]    reorder_fifo_addr [0:(FIFOLN-1)];
259 3 dgisselq
 
260
 
261 4 dgisselq
                        reg     [1:0]    low_addr;
262
                        always @(posedge i_clk)
263
                                if ((i_wb_stb)&&(!o_wb_stall))
264
                                        low_addr <= i_wb_addr[1:0];
265
                        always @(posedge i_clk)
266
                                if ((o_axi_rvalid)&&(i_axi_rready))
267
                                        reorder_fifo_addr[o_axi_rid] <= low_addr;
268 3 dgisselq
 
269 4 dgisselq
                        always @(posedge i_clk)
270
                        case(reorder_fifo_addr[1:0])
271
                        2'b00: o_wb_data <=reorder_fifo_data[fifo_tail][ 31: 0];
272
                        2'b01: o_wb_data <=reorder_fifo_data[fifo_tail][ 63:32];
273
                        2'b10: o_wb_data <=reorder_fifo_data[fifo_tail][ 95:64];
274
                        2'b11: o_wb_data <=reorder_fifo_data[fifo_tail][127:96];
275
                        endcase
276
 
277
                end else if (DW == 128)
278
                begin
279
                        always @(posedge i_clk)
280
                                o_wb_data <= reorder_fifo_data[fifo_tail];
281
                end
282
 
283
 
284 3 dgisselq
                wire    [(LGFIFOLN-1):0] fifo_head;
285 2 dgisselq
                assign  fifo_head = transaction_id;
286
 
287
                // Let's do some math to figure out where the FIFO head will
288
                // point to next, but let's also insist that it be LGFIFOLN
289
                // bits in size as well.  This'll be part of the fifo_full
290
                // calculation below.
291
                wire    [(LGFIFOLN-1):0] n_fifo_head, nn_fifo_head;
292
                assign  n_fifo_head = fifo_head+1'b1;
293
 
294
                always @(posedge i_clk)
295
                begin
296
                        if ((i_axi_rd_rvalid)&&(o_axi_rd_rready))
297
                                reorder_fifo_data[i_axi_rd_bid]<= i_axi_rd_data;
298
                        if ((i_axi_rd_rvalid)&&(o_axi_rd_rready))
299
                        begin
300
                                reorder_fifo_valid[i_axi_rd_bid] <= 1'b1;
301 3 dgisselq
                                reorder_fifo_err[i_axi_rd_bid] <= i_axi_rd_rresp[1];
302 2 dgisselq
                        end
303
                        if ((i_axi_wd_bvalid)&&(o_axi_wd_bready))
304
                        begin
305 3 dgisselq
                                reorder_fifo_valid[i_axi_wd_bid] <= 1'b1;
306
                                reorder_fifo_err[i_axi_wd_bid] <= i_axi_wd_bresp[1];
307 2 dgisselq
                        end
308
 
309
                        if (reorder_fifo_valid[fifo_tail])
310
                        begin
311
                                o_wb_ack <= 1'b1;
312
                                o_wb_err <= reorder_fifo_err[fifo_tail];
313
                                fifo_tail <= fifo_tail + 6'h1;
314
                                reorder_fifo_valid[fifo_tail] <= 1'b0;
315
                                reorder_fifo_err[fifo_tail]   <= 1'b0;
316
                        end else begin
317
                                o_wb_ack <= 1'b0;
318
                                o_wb_err <= 1'b0;
319
                        end
320
 
321
                        if (!i_wb_cyc)
322
                        begin
323
                                reorder_fifo_valid <= {(FIFOLN){1'b0}};
324
                                reorder_fifo_err   <= {(FIFOLN){1'b0}};
325
                                fifo_tail <= 6'h0;
326
                                o_wb_err <= 1'b0;
327
                                o_wb_ack <= 1'b0;
328
                        end
329
                end
330
 
331 3 dgisselq
                reg     r_fifo_full;
332 2 dgisselq
                always @(posedge i_clk)
333
                begin
334
                        if (!i_wb_cyc)
335
                                r_fifo_full <= 1'b0;
336
                        else if ((i_wb_stb)&&(~o_wb_stall)
337
                                        &&(reorder_fifo_valid[fifo_tail]))
338
                                r_fifo_full <= (fifo_tail==n_fifo_head);
339
                        else if ((i_wb_stb)&&(~o_wb_stall))
340
                                r_fifo_full <= (fifo_tail==nn_fifo_head);
341
                        else if (reorder_fifo_valid[fifo_tail])
342
                                r_fifo_full <= 1'b0;
343
                        else
344
                                r_fifo_full <= (fifo_tail==n_fifo_head);
345
                end
346
                assign w_fifo_full = r_fifo_full;
347
        end else begin
348 3 dgisselq
                assign w_fifo_full = 1'b0;
349 2 dgisselq
                always @(posedge i_clk)
350
                        o_wb_data <= i_axi_rd_data;
351
                always @(posedge i_clk)
352
                        o_wb_ack <= ((i_axi_rd_rvalid)&&(o_axi_rd_rready))
353
                                  ||((i_axi_wd_bvalid)&&(o_axi_wd_bready));
354
                always @(posedge i_clk)
355
                        o_wb_err <= (!i_wb_cyc)&&((o_wb_err)
356 3 dgisselq
                                ||((i_axi_rd_rvalid)&&(i_axi_rd_rresp[1]))
357 2 dgisselq
                                ||((i_axi_wd_bvalid)&&(i_axi_wd_bresp[1])));
358 3 dgisselq
        end endgenerate
359 2 dgisselq
 
360
 
361
        // Now, the difficult signal ... the stall signal
362
        // Let's build for a single cycle input ... and only stall if something
363
        // outgoing is valid and nothing is ready.
364
        assign  o_wb_stall = (i_wb_cyc)&&(
365
                                (w_fifo_full)
366
                                ||((o_axi_wvalid)&&(!i_axi_wready))
367 3 dgisselq
                                ||((o_axi_wd_valid)&&(!i_axi_wd_wready))
368 2 dgisselq
                                ||((o_axi_rvalid)&&(!i_axi_rready)));
369
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.