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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [wbm2axisp.v] - Blame information for rev 25

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

Line No. Rev Author Line
1 25 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
// Copyright (C) 2016, Gisselquist Technology, LLC
32
//
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 C_AXI_ADDR_WIDTH      = 28,   // AXI Address width
60
        parameter DW                    = 32,   // Wishbone data width
61
        parameter AW                    = 26,   // Wishbone address width
62
        parameter STRICT_ORDER          = 0      // Reorder, or not? 0 -> Reorder
63
        ) (
64
        input                           i_clk,  // System clock
65
        // input                        i_reset,// Wishbone reset signal--unused
66
 
67
// AXI write address channel signals
68
        input                           i_axi_awready, // Slave is ready to accept
69
        output  reg     [C_AXI_ID_WIDTH-1:0]     o_axi_awid,     // Write ID
70
        output  reg     [C_AXI_ADDR_WIDTH-1:0]   o_axi_awaddr,   // Write address
71
        output  wire    [7:0]            o_axi_awlen,    // Write Burst Length
72
        output  wire    [2:0]            o_axi_awsize,   // Write Burst size
73
        output  wire    [1:0]            o_axi_awburst,  // Write Burst type
74
        output  wire    [0:0]             o_axi_awlock,   // Write lock type
75
        output  wire    [3:0]            o_axi_awcache,  // Write Cache type
76
        output  wire    [2:0]            o_axi_awprot,   // Write Protection type
77
        output  wire    [3:0]            o_axi_awqos,    // Write Quality of Svc
78
        output  reg                     o_axi_awvalid,  // Write address valid
79
 
80
// AXI write data channel signals
81
        input                           i_axi_wready,  // Write data ready
82
        output  reg     [C_AXI_DATA_WIDTH-1:0]   o_axi_wdata,    // Write data
83
        output  reg     [C_AXI_DATA_WIDTH/8-1:0] o_axi_wstrb,    // Write strobes
84
        output  wire                    o_axi_wlast,    // Last write transaction   
85
        output  reg                     o_axi_wvalid,   // Write valid
86
 
87
// AXI write response channel signals
88
        input   [C_AXI_ID_WIDTH-1:0]     i_axi_bid,      // Response ID
89
        input   [1:0]                    i_axi_bresp,    // Write response
90
        input                           i_axi_bvalid,  // Write reponse valid
91
        output  wire                    o_axi_bready,  // Response ready
92
 
93
// AXI read address channel signals
94
        input                           i_axi_arready,  // Read address ready
95
        output  wire    [C_AXI_ID_WIDTH-1:0]     o_axi_arid,     // Read ID
96
        output  wire    [C_AXI_ADDR_WIDTH-1:0]   o_axi_araddr,   // Read address
97
        output  wire    [7:0]            o_axi_arlen,    // Read Burst Length
98
        output  wire    [2:0]            o_axi_arsize,   // Read Burst size
99
        output  wire    [1:0]            o_axi_arburst,  // Read Burst type
100
        output  wire    [0:0]             o_axi_arlock,   // Read lock type
101
        output  wire    [3:0]            o_axi_arcache,  // Read Cache type
102
        output  wire    [2:0]            o_axi_arprot,   // Read Protection type
103
        output  wire    [3:0]            o_axi_arqos,    // Read Protection type
104
        output  reg                     o_axi_arvalid,  // Read address valid
105
 
106
// AXI read data channel signals   
107
        input   [C_AXI_ID_WIDTH-1:0]     i_axi_rid,     // Response ID
108
        input   [1:0]                    i_axi_rresp,   // Read response
109
        input                           i_axi_rvalid,  // Read reponse valid
110
        input   [C_AXI_DATA_WIDTH-1:0]   i_axi_rdata,    // Read data
111
        input                           i_axi_rlast,    // Read last
112
        output  wire                    o_axi_rready,  // Read Response ready
113
 
114
        // We'll share the clock and the reset
115
        input                           i_wb_cyc,
116
        input                           i_wb_stb,
117
        input                           i_wb_we,
118
        input           [(AW-1):0]       i_wb_addr,
119
        input           [(DW-1):0]       i_wb_data,
120
        input           [(DW/8-1):0]     i_wb_sel,
121
        output  reg                     o_wb_ack,
122
        output  wire                    o_wb_stall,
123
        output  reg     [(DW-1):0]       o_wb_data,
124
        output  reg                     o_wb_err,
125
 
126
        output  wire    [31:0]           o_dbg
127
);
128
 
129
//*****************************************************************************
130
// Parameter declarations
131
//*****************************************************************************
132
 
133
        localparam      CTL_SIG_WIDTH   = 3;    // Control signal width
134
        localparam      RD_STS_WIDTH    = 16;   // Read status signal width
135
        localparam      WR_STS_WIDTH    = 16;   // Write status signal width
136
 
137
//*****************************************************************************
138
// Internal register and wire declarations
139
//*****************************************************************************
140
 
141
// Things we're not changing ...
142
        assign o_axi_awlen = 8'h0;      // Burst length is one
143
        assign o_axi_awsize = 3'b101;   // maximum bytes per burst is 32
144
        assign o_axi_awburst = 2'b01;   // Incrementing address (ignored)
145
        assign o_axi_arburst = 2'b01;   // Incrementing address (ignored)
146
        assign o_axi_awlock  = 1'b0;    // Normal signaling
147
        assign o_axi_arlock  = 1'b0;    // Normal signaling
148
        assign o_axi_awcache = 4'h2;    // Normal: no cache, no buffer
149
        assign o_axi_arcache = 4'h2;    // Normal: no cache, no buffer
150
        assign o_axi_awprot  = 3'b010;  // Unpriviledged, unsecure, data access
151
        assign o_axi_arprot  = 3'b010;  // Unpriviledged, unsecure, data access
152
        assign o_axi_awqos  = 4'h0;     // Lowest quality of service (unused)
153
        assign o_axi_arqos  = 4'h0;     // Lowest quality of service (unused)
154
 
155
// Command logic
156
// Write address logic
157
 
158
        always @(posedge i_clk)
159
                o_axi_awvalid <= (!o_wb_stall)&&(i_wb_stb)&&(i_wb_we)
160
                        ||(o_wb_stall)&&(o_axi_awvalid)&&(!i_axi_awready);
161
 
162
        generate
163
        if (DW == 32)
164
        begin
165
                always @(posedge i_clk)
166
                        if (!o_wb_stall) // 26 bit address becomes 28 bit ...
167
                                o_axi_awaddr <= { i_wb_addr[AW-1:2], 4'b00 };
168
        end else if (DW == 128)
169
        begin
170
                always @(posedge i_clk)
171
                        if (!o_wb_stall) // 28 bit address ...
172
                                o_axi_awaddr <= { i_wb_addr[AW-1:0], 4'b00 };
173
        end endgenerate
174
 
175
        reg     [5:0]    transaction_id;
176
        always @(posedge i_clk)
177
                if (!i_wb_cyc)
178
                        transaction_id <= 6'h00;
179
                else if ((i_wb_stb)&&(~o_wb_stall))
180
                        transaction_id <= transaction_id + 6'h01;
181
        always @(posedge i_clk)
182
                if ((i_wb_stb)&&(~o_wb_stall))
183
                        o_axi_awid <= transaction_id;
184
 
185
// Read address logic
186
        assign  o_axi_arid = o_axi_awid;
187
        assign  o_axi_araddr = o_axi_awaddr;
188
        assign  o_axi_arlen  = o_axi_awlen;
189
        assign  o_axi_arsize = 3'b101;  // maximum bytes per burst is 32
190
        always @(posedge i_clk)
191
                o_axi_arvalid <= (!o_wb_stall)&&(i_wb_stb)&&(!i_wb_we)
192
                        ||(o_wb_stall)&&(o_axi_arvalid)&&(!i_axi_arready);
193
 
194
 
195
// Write data logic
196
        generate
197
        if (DW == 32)
198
        begin
199
                always @(posedge i_clk)
200
                        if (!o_wb_stall)
201
                                o_axi_wdata <= { i_wb_data, i_wb_data, i_wb_data, i_wb_data };
202
                always @(posedge i_clk)
203
                        if (!o_wb_stall)
204
                        case(i_wb_addr[1:0])
205
                        2'b00:o_axi_wstrb<={    4'h0,    4'h0,   4'h0,i_wb_sel};
206
                        2'b01:o_axi_wstrb<={    4'h0,    4'h0,i_wb_sel,   4'h0};
207
                        2'b10:o_axi_wstrb<={    4'h0,i_wb_sel,    4'h0,   4'h0};
208
                        2'b11:o_axi_wstrb<={i_wb_sel,    4'h0,    4'h0,   4'h0};
209
                        endcase
210
        end else if (DW == 128)
211
        begin
212
                always @(posedge i_clk)
213
                        if (!o_wb_stall)
214
                                o_axi_wdata <= i_wb_data;
215
                always @(posedge i_clk)
216
                        if (!o_wb_stall)
217
                                o_axi_wstrb <= i_wb_sel;
218
        end endgenerate
219
 
220
        assign  o_axi_wlast = 1'b1;
221
        always @(posedge i_clk)
222
                o_axi_wvalid <= ((!o_wb_stall)&&(i_wb_stb)&&(i_wb_we))
223
                        ||(o_wb_stall)&&(o_axi_wvalid)&&(!i_axi_wready);
224
 
225
// Read data channel / response logic
226
        assign  o_axi_rready = 1'b1;
227
        assign  o_axi_bready = 1'b1;
228
 
229
        wire    w_fifo_full;
230
        generate
231
        if (STRICT_ORDER == 0)
232
        begin
233
                // Reorder FIFO
234
                //
235
                localparam      LGFIFOLN = C_AXI_ID_WIDTH;
236
                localparam      FIFOLN = (1<<LGFIFOLN);
237
                // FIFO reorder buffer
238
                reg     [(LGFIFOLN-1):0] fifo_tail;
239
                reg     [(C_AXI_DATA_WIDTH-1):0] reorder_fifo_data [0:(FIFOLN-1)];
240
                reg     [(FIFOLN-1):0]   reorder_fifo_valid;
241
                reg     [(FIFOLN-1):0]   reorder_fifo_err;
242
 
243
                initial reorder_fifo_valid = 0;
244
                initial reorder_fifo_err = 0;
245
 
246
                if (DW == 32)
247
                begin
248
                        reg     [1:0]    reorder_fifo_addr [0:(FIFOLN-1)];
249
 
250
 
251
                        reg     [1:0]    low_addr;
252
                        always @(posedge i_clk)
253
                                if ((i_wb_stb)&&(!o_wb_stall))
254
                                        low_addr <= i_wb_addr[1:0];
255
                        always @(posedge i_clk)
256
                                if ((o_axi_arvalid)&&(i_axi_arready))
257
                                        reorder_fifo_addr[o_axi_arid] <= low_addr;
258
 
259
                        always @(posedge i_clk)
260
                        case(reorder_fifo_addr[fifo_tail][1:0])
261
                        2'b00: o_wb_data <=reorder_fifo_data[fifo_tail][ 31: 0];
262
                        2'b01: o_wb_data <=reorder_fifo_data[fifo_tail][ 63:32];
263
                        2'b10: o_wb_data <=reorder_fifo_data[fifo_tail][ 95:64];
264
                        2'b11: o_wb_data <=reorder_fifo_data[fifo_tail][127:96];
265
                        endcase
266
 
267
                end else if (DW == 128)
268
                begin
269
                        always @(posedge i_clk)
270
                                o_wb_data <= reorder_fifo_data[fifo_tail];
271
                end
272
 
273
 
274
                wire    [(LGFIFOLN-1):0] fifo_head;
275
                assign  fifo_head = transaction_id;
276
 
277
                // Let's do some math to figure out where the FIFO head will
278
                // point to next, but let's also insist that it be LGFIFOLN
279
                // bits in size as well.  This'll be part of the fifo_full
280
                // calculation below.
281
                wire    [(LGFIFOLN-1):0] n_fifo_head, nn_fifo_head;
282
                assign  n_fifo_head = fifo_head+1'b1;
283
                assign  nn_fifo_head = { fifo_head[(LGFIFOLN-1):1]+1'b1, fifo_head[0] };
284
 
285
                always @(posedge i_clk)
286
                begin
287
                        if ((i_axi_rvalid)&&(o_axi_rready))
288
                                reorder_fifo_data[i_axi_rid]<= i_axi_rdata;
289
                        if ((i_axi_rvalid)&&(o_axi_rready))
290
                        begin
291
                                reorder_fifo_valid[i_axi_rid] <= 1'b1;
292
                                reorder_fifo_err[i_axi_rid] <= i_axi_rresp[1];
293
                        end
294
                        if ((i_axi_bvalid)&&(o_axi_bready))
295
                        begin
296
                                reorder_fifo_valid[i_axi_bid] <= 1'b1;
297
                                reorder_fifo_err[i_axi_bid] <= i_axi_bresp[1];
298
                        end
299
 
300
                        if (reorder_fifo_valid[fifo_tail])
301
                        begin
302
                                o_wb_ack <= 1'b1;
303
                                o_wb_err <= reorder_fifo_err[fifo_tail];
304
                                fifo_tail <= fifo_tail + 6'h1;
305
                                reorder_fifo_valid[fifo_tail] <= 1'b0;
306
                                reorder_fifo_err[fifo_tail]   <= 1'b0;
307
                        end else begin
308
                                o_wb_ack <= 1'b0;
309
                                o_wb_err <= 1'b0;
310
                        end
311
 
312
                        if (!i_wb_cyc)
313
                        begin
314
                                reorder_fifo_valid <= {(FIFOLN){1'b0}};
315
                                reorder_fifo_err   <= {(FIFOLN){1'b0}};
316
                                fifo_tail <= 6'h0;
317
                                o_wb_err <= 1'b0;
318
                                o_wb_ack <= 1'b0;
319
                        end
320
                end
321
 
322
                assign o_dbg = {
323
                        i_wb_stb, o_wb_stall, o_wb_ack, o_wb_err,
324
                        fifo_head, fifo_tail,   // 12 bits
325
                        { ((i_axi_rvalid)&&(o_axi_rready)) ? i_axi_rid
326
                        : ((i_axi_bvalid)&&(o_axi_bready)) ? i_axi_bid
327
                        : 6'hf }, // 6 bits
328
                        o_axi_arvalid, i_axi_arready,
329
                        o_axi_awvalid, i_axi_awready,
330
                        o_axi_wvalid, i_axi_wready,     // 28 bits so far ...
331
                        i_axi_rvalid, i_axi_bvalid, 2'b00
332
                };
333
 
334
 
335
                reg     r_fifo_full;
336
                always @(posedge i_clk)
337
                begin
338
                        if (!i_wb_cyc)
339
                                r_fifo_full <= 1'b0;
340
                        else if ((i_wb_stb)&&(~o_wb_stall)
341
                                        &&(reorder_fifo_valid[fifo_tail]))
342
                                r_fifo_full <= (fifo_tail==n_fifo_head);
343
                        else if ((i_wb_stb)&&(~o_wb_stall))
344
                                r_fifo_full <= (fifo_tail==nn_fifo_head);
345
                        else if (reorder_fifo_valid[fifo_tail])
346
                                r_fifo_full <= 1'b0;
347
                        else
348
                                r_fifo_full <= (fifo_tail==n_fifo_head);
349
                end
350
                assign w_fifo_full = r_fifo_full;
351
        end else begin
352
                //
353
                // Strict ordering, but can only read every fourth addresses
354
                //
355
                assign w_fifo_full = 1'b0;
356
                always @(posedge i_clk)
357
                        o_wb_data <= i_axi_rdata[31:0];
358
                always @(posedge i_clk)
359
                        o_wb_ack <= (i_wb_cyc)&&(
360
                                ((i_axi_rvalid)&&(o_axi_rready))
361
                                  ||((i_axi_bvalid)&&(o_axi_bready)));
362
                always @(posedge i_clk)
363
                        o_wb_err <= (i_wb_cyc)&&((o_wb_err)
364
                                ||((i_axi_rvalid)&&(i_axi_rresp[1]))
365
                                ||((i_axi_bvalid)&&(i_axi_bresp[1])));
366
 
367
                assign o_dbg = {
368
                        i_wb_stb, o_wb_stall, o_wb_ack, o_wb_err,
369
                        12'h00,         // 12 bits
370
                        { ((i_axi_rvalid)&&(o_axi_rready)) ? i_axi_rid
371
                        : ((i_axi_bvalid)&&(o_axi_bready)) ? i_axi_bid
372
                        : 6'hf }, // 6 bits
373
                        o_axi_arvalid, i_axi_arready,
374
                        o_axi_awvalid, i_axi_awready,
375
                        o_axi_wvalid, i_axi_wready,     // 28 bits so far ...
376
                        i_axi_rvalid, i_axi_bvalid, 2'b00
377
                };
378
        end endgenerate
379
 
380
 
381
        // Now, the difficult signal ... the stall signal
382
        // Let's build for a single cycle input ... and only stall if something
383
        // outgoing is valid and nothing is ready.
384
        assign  o_wb_stall = (i_wb_cyc)&&(
385
                                (w_fifo_full)
386
                                ||((o_axi_awvalid)&&(!i_axi_awready))
387
                                ||((o_axi_wvalid )&&(!i_axi_wready ))
388
                                ||((o_axi_arvalid)&&(!i_axi_arready)));
389
endmodule
390
 

powered by: WebSVN 2.1.0

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