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

Subversion Repositories wb2axip

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

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

Line No. Rev Author Line
1 2 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3 8 dgisselq
// Filename:    wbm2axisp.v (Wishbone master to AXI slave, pipelined)
4 2 dgisselq
//
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 8 dgisselq
//      Since the AXI bus allows transactions to be reordered, whereas the
23 2 dgisselq
//      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 14 dgisselq
// Copyright (C) 2016-2018, 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 8 dgisselq
`default_nettype        none
56
//
57 2 dgisselq
module wbm2axisp #(
58 13 dgisselq
        parameter C_AXI_ID_WIDTH        =   3, // The AXI id width used for R&W
59 2 dgisselq
                                             // This is an int between 1-16
60 13 dgisselq
        parameter C_AXI_DATA_WIDTH      = 128,// Width of the AXI R&W data
61
        parameter C_AXI_ADDR_WIDTH      =  28,  // AXI Address width (log wordsize)
62
        parameter DW                    =  32,  // Wishbone data width
63
        parameter AW                    =  26,  // Wishbone address width (log wordsize)
64 8 dgisselq
        parameter [0:0] STRICT_ORDER      = 1     // Reorder, or not? 0 -> Reorder
65 2 dgisselq
        ) (
66 13 dgisselq
        input   wire                    i_clk,  // System clock
67 14 dgisselq
        input   wire                    i_reset,// Reset signal,drives AXI rst
68 2 dgisselq
 
69
// AXI write address channel signals
70 13 dgisselq
        input   wire                    i_axi_awready, // Slave is ready to accept
71 6 dgisselq
        output  reg     [C_AXI_ID_WIDTH-1:0]     o_axi_awid,     // Write ID
72
        output  reg     [C_AXI_ADDR_WIDTH-1:0]   o_axi_awaddr,   // Write address
73 5 dgisselq
        output  wire    [7:0]            o_axi_awlen,    // Write Burst Length
74
        output  wire    [2:0]            o_axi_awsize,   // Write Burst size
75
        output  wire    [1:0]            o_axi_awburst,  // Write Burst type
76 6 dgisselq
        output  wire    [0:0]             o_axi_awlock,   // Write lock type
77 5 dgisselq
        output  wire    [3:0]            o_axi_awcache,  // Write Cache type
78
        output  wire    [2:0]            o_axi_awprot,   // Write Protection type
79
        output  wire    [3:0]            o_axi_awqos,    // Write Quality of Svc
80
        output  reg                     o_axi_awvalid,  // Write address valid
81 8 dgisselq
 
82 2 dgisselq
// AXI write data channel signals
83 13 dgisselq
        input   wire                    i_axi_wready,  // Write data ready
84 5 dgisselq
        output  reg     [C_AXI_DATA_WIDTH-1:0]   o_axi_wdata,    // Write data
85
        output  reg     [C_AXI_DATA_WIDTH/8-1:0] o_axi_wstrb,    // Write strobes
86 13 dgisselq
        output  wire                    o_axi_wlast,    // Last write transaction   
87 5 dgisselq
        output  reg                     o_axi_wvalid,   // Write valid
88 8 dgisselq
 
89 2 dgisselq
// AXI write response channel signals
90 13 dgisselq
        input wire [C_AXI_ID_WIDTH-1:0]  i_axi_bid,      // Response ID
91
        input   wire [1:0]               i_axi_bresp,    // Write response
92
        input   wire                    i_axi_bvalid,  // Write reponse valid
93 5 dgisselq
        output  wire                    o_axi_bready,  // Response ready
94 8 dgisselq
 
95 2 dgisselq
// AXI read address channel signals
96 13 dgisselq
        input   wire                    i_axi_arready,  // Read address ready
97 5 dgisselq
        output  wire    [C_AXI_ID_WIDTH-1:0]     o_axi_arid,     // Read ID
98 6 dgisselq
        output  wire    [C_AXI_ADDR_WIDTH-1:0]   o_axi_araddr,   // Read address
99 5 dgisselq
        output  wire    [7:0]            o_axi_arlen,    // Read Burst Length
100
        output  wire    [2:0]            o_axi_arsize,   // Read Burst size
101
        output  wire    [1:0]            o_axi_arburst,  // Read Burst type
102 6 dgisselq
        output  wire    [0:0]             o_axi_arlock,   // Read lock type
103 5 dgisselq
        output  wire    [3:0]            o_axi_arcache,  // Read Cache type
104
        output  wire    [2:0]            o_axi_arprot,   // Read Protection type
105
        output  wire    [3:0]            o_axi_arqos,    // Read Protection type
106
        output  reg                     o_axi_arvalid,  // Read address valid
107 8 dgisselq
 
108 13 dgisselq
// AXI read data channel signals   
109
        input wire [C_AXI_ID_WIDTH-1:0]  i_axi_rid,     // Response ID
110
        input   wire    [1:0]            i_axi_rresp,   // Read response
111
        input   wire                    i_axi_rvalid,  // Read reponse valid
112
        input wire [C_AXI_DATA_WIDTH-1:0] i_axi_rdata,    // Read data
113
        input   wire                    i_axi_rlast,    // Read last
114 5 dgisselq
        output  wire                    o_axi_rready,  // Read Response ready
115 2 dgisselq
 
116
        // We'll share the clock and the reset
117 13 dgisselq
        input   wire                    i_wb_cyc,
118
        input   wire                    i_wb_stb,
119
        input   wire                    i_wb_we,
120
        input   wire    [(AW-1):0]       i_wb_addr,
121
        input   wire    [(DW-1):0]       i_wb_data,
122
        input   wire    [(DW/8-1):0]     i_wb_sel,
123 3 dgisselq
        output  reg                     o_wb_ack,
124
        output  wire                    o_wb_stall,
125 6 dgisselq
        output  reg     [(DW-1):0]       o_wb_data,
126 3 dgisselq
        output  reg                     o_wb_err
127 2 dgisselq
);
128
 
129
//*****************************************************************************
130
// Parameter declarations
131
//*****************************************************************************
132
 
133 8 dgisselq
        localparam      LG_AXI_DW       = ( C_AXI_DATA_WIDTH ==   8) ? 3
134
                                        : ((C_AXI_DATA_WIDTH ==  16) ? 4
135
                                        : ((C_AXI_DATA_WIDTH ==  32) ? 5
136
                                        : ((C_AXI_DATA_WIDTH ==  64) ? 6
137
                                        : ((C_AXI_DATA_WIDTH == 128) ? 7
138
                                        : 8))));
139 2 dgisselq
 
140 8 dgisselq
        localparam      LG_WB_DW        = ( DW ==   8) ? 3
141
                                        : ((DW ==  16) ? 4
142
                                        : ((DW ==  32) ? 5
143
                                        : ((DW ==  64) ? 6
144
                                        : ((DW == 128) ? 7
145
                                        : 8))));
146
        localparam      LGFIFOLN = C_AXI_ID_WIDTH;
147
        localparam      FIFOLN = (1<<LGFIFOLN);
148
 
149
 
150 2 dgisselq
//*****************************************************************************
151
// Internal register and wire declarations
152
//*****************************************************************************
153
 
154
// Things we're not changing ...
155 8 dgisselq
        assign o_axi_awlen   = 8'h0;    // Burst length is one
156
        assign o_axi_awsize  = 3'b101;  // maximum bytes per burst is 32
157 5 dgisselq
        assign o_axi_awburst = 2'b01;   // Incrementing address (ignored)
158
        assign o_axi_arburst = 2'b01;   // Incrementing address (ignored)
159 6 dgisselq
        assign o_axi_awlock  = 1'b0;    // Normal signaling
160
        assign o_axi_arlock  = 1'b0;    // Normal signaling
161 5 dgisselq
        assign o_axi_awcache = 4'h2;    // Normal: no cache, no buffer
162
        assign o_axi_arcache = 4'h2;    // Normal: no cache, no buffer
163 6 dgisselq
        assign o_axi_awprot  = 3'b010;  // Unpriviledged, unsecure, data access
164
        assign o_axi_arprot  = 3'b010;  // Unpriviledged, unsecure, data access
165 8 dgisselq
        assign o_axi_awqos   = 4'h0;    // Lowest quality of service (unused)
166
        assign o_axi_arqos   = 4'h0;    // Lowest quality of service (unused)
167 2 dgisselq
 
168 15 dgisselq
        reg     wb_mid_cycle, wb_mid_abort;
169 13 dgisselq
        wire    wb_abort;
170
 
171 2 dgisselq
// Command logic
172 8 dgisselq
// Transaction ID logic
173
        wire    [(LGFIFOLN-1):0] fifo_head;
174
        reg     [(C_AXI_ID_WIDTH-1):0]   transaction_id;
175
 
176
        initial transaction_id = 0;
177
        always @(posedge i_clk)
178 14 dgisselq
        if (i_reset)
179
                transaction_id <= 0;
180
        else if ((i_wb_stb)&&(!o_wb_stall))
181
                transaction_id <= transaction_id + 1'b1;
182 8 dgisselq
 
183
        assign  fifo_head = transaction_id;
184
 
185
        wire    [(DW/8-1):0]                     no_sel;
186
        wire    [(LG_AXI_DW-4):0]        axi_bottom_addr;
187
        assign  no_sel = 0;
188
        assign  axi_bottom_addr = 0;
189
 
190
 
191 2 dgisselq
// Write address logic
192
 
193 8 dgisselq
        initial o_axi_awvalid = 0;
194 2 dgisselq
        always @(posedge i_clk)
195 14 dgisselq
        if (i_reset)
196
                o_axi_awvalid <= 0;
197
        else
198 5 dgisselq
                o_axi_awvalid <= (!o_wb_stall)&&(i_wb_stb)&&(i_wb_we)
199 8 dgisselq
                        ||(o_axi_awvalid)&&(!i_axi_awready);
200 2 dgisselq
 
201 6 dgisselq
        generate
202 8 dgisselq
 
203
        initial o_axi_awid = -1;
204
        always @(posedge i_clk)
205 14 dgisselq
        if (i_reset)
206
                o_axi_awid <= -1;
207
        else if ((i_wb_stb)&&(!o_wb_stall))
208
                o_axi_awid <= transaction_id;
209 8 dgisselq
 
210
        if (C_AXI_DATA_WIDTH == DW)
211 6 dgisselq
        begin
212
                always @(posedge i_clk)
213 14 dgisselq
                if ((i_wb_stb)&&(!o_wb_stall)) // 26 bit address becomes 28 bit ...
214
                        o_axi_awaddr <= { i_wb_addr[AW-1:0], axi_bottom_addr };
215 8 dgisselq
        end else if (C_AXI_DATA_WIDTH / DW == 2)
216 6 dgisselq
        begin
217 8 dgisselq
 
218 6 dgisselq
                always @(posedge i_clk)
219 14 dgisselq
                if ((i_wb_stb)&&(!o_wb_stall)) // 26 bit address becomes 28 bit ...
220
                        o_axi_awaddr <= { i_wb_addr[AW-1:1], axi_bottom_addr };
221 8 dgisselq
 
222
        end else if (C_AXI_DATA_WIDTH / DW == 4)
223
        begin
224
                always @(posedge i_clk)
225 13 dgisselq
                if ((i_wb_stb)&&(!o_wb_stall)) // 26 bit address becomes 28 bit ...
226
                        o_axi_awaddr <= { i_wb_addr[AW-1:2], axi_bottom_addr };
227 6 dgisselq
        end endgenerate
228
 
229 2 dgisselq
 
230
// Read address logic
231 8 dgisselq
        assign  o_axi_arid   = o_axi_awid;
232 5 dgisselq
        assign  o_axi_araddr = o_axi_awaddr;
233
        assign  o_axi_arlen  = o_axi_awlen;
234
        assign  o_axi_arsize = 3'b101;  // maximum bytes per burst is 32
235 8 dgisselq
        initial o_axi_arvalid = 1'b0;
236 2 dgisselq
        always @(posedge i_clk)
237 14 dgisselq
        if (i_reset)
238
                o_axi_arvalid <= 1'b0;
239
        else
240 5 dgisselq
                o_axi_arvalid <= (!o_wb_stall)&&(i_wb_stb)&&(!i_wb_we)
241 8 dgisselq
                        ||(o_axi_arvalid)&&(!i_axi_arready);
242 2 dgisselq
 
243
// Write data logic
244 4 dgisselq
        generate
245 8 dgisselq
        if (C_AXI_DATA_WIDTH == DW)
246 4 dgisselq
        begin
247 8 dgisselq
 
248 4 dgisselq
                always @(posedge i_clk)
249 8 dgisselq
                        if ((i_wb_stb)&&(!o_wb_stall))
250
                                o_axi_wdata <= i_wb_data;
251
 
252 4 dgisselq
                always @(posedge i_clk)
253 8 dgisselq
                        if ((i_wb_stb)&&(!o_wb_stall))
254
                                o_axi_wstrb<= i_wb_sel;
255
 
256
        end else if (C_AXI_DATA_WIDTH/2 == DW)
257
        begin
258
 
259
                always @(posedge i_clk)
260
                        if ((i_wb_stb)&&(!o_wb_stall))
261
                                o_axi_wdata <= { i_wb_data, i_wb_data };
262
 
263
                always @(posedge i_clk)
264
                        if ((i_wb_stb)&&(!o_wb_stall))
265
                        case(i_wb_addr[0])
266
                        1'b0:o_axi_wstrb<={  no_sel,i_wb_sel };
267
                        1'b1:o_axi_wstrb<={i_wb_sel,  no_sel };
268 4 dgisselq
                        endcase
269 8 dgisselq
 
270
        end else if (C_AXI_DATA_WIDTH/4 == DW)
271 4 dgisselq
        begin
272 8 dgisselq
 
273 4 dgisselq
                always @(posedge i_clk)
274 8 dgisselq
                        if ((i_wb_stb)&&(!o_wb_stall))
275
                                o_axi_wdata <= { i_wb_data, i_wb_data, i_wb_data, i_wb_data };
276
 
277 4 dgisselq
                always @(posedge i_clk)
278 8 dgisselq
                        if ((i_wb_stb)&&(!o_wb_stall))
279
                        case(i_wb_addr[1:0])
280
                        2'b00:o_axi_wstrb<={   no_sel,   no_sel,   no_sel, i_wb_sel };
281
                        2'b01:o_axi_wstrb<={   no_sel,   no_sel, i_wb_sel,   no_sel };
282
                        2'b10:o_axi_wstrb<={   no_sel, i_wb_sel,   no_sel,   no_sel };
283
                        2'b11:o_axi_wstrb<={ i_wb_sel,   no_sel,   no_sel,   no_sel };
284
                        endcase
285
 
286 4 dgisselq
        end endgenerate
287
 
288 5 dgisselq
        assign  o_axi_wlast = 1'b1;
289 8 dgisselq
        initial o_axi_wvalid = 0;
290 2 dgisselq
        always @(posedge i_clk)
291 14 dgisselq
        if (i_reset)
292
                o_axi_wvalid <= 0;
293
        else
294 5 dgisselq
                o_axi_wvalid <= ((!o_wb_stall)&&(i_wb_stb)&&(i_wb_we))
295 8 dgisselq
                        ||(o_axi_wvalid)&&(!i_axi_wready);
296 2 dgisselq
 
297 8 dgisselq
        // Read data channel / response logic
298 5 dgisselq
        assign  o_axi_rready = 1'b1;
299
        assign  o_axi_bready = 1'b1;
300 2 dgisselq
 
301 8 dgisselq
        wire    [(LGFIFOLN-1):0] n_fifo_head, nn_fifo_head;
302
        assign  n_fifo_head = fifo_head+1'b1;
303
        assign  nn_fifo_head = { fifo_head[(LGFIFOLN-1):1]+1'b1, fifo_head[0] };
304
 
305
 
306 2 dgisselq
        wire    w_fifo_full;
307 8 dgisselq
        reg     [(LGFIFOLN-1):0] fifo_tail;
308
 
309 2 dgisselq
        generate
310 8 dgisselq
        if (C_AXI_DATA_WIDTH == DW)
311 2 dgisselq
        begin
312 8 dgisselq
                if (STRICT_ORDER == 0)
313
                begin
314
                        reg     [(C_AXI_DATA_WIDTH-1):0] reorder_fifo_data [0:(FIFOLN-1)];
315 3 dgisselq
 
316 8 dgisselq
                        always @(posedge i_clk)
317
                                if ((o_axi_rready)&&(i_axi_rvalid))
318
                                        reorder_fifo_data[i_axi_rid] <= i_axi_rdata;
319
                        always @(posedge i_clk)
320
                                o_wb_data <= reorder_fifo_data[fifo_tail];
321
                end else begin
322
                        reg     [(C_AXI_DATA_WIDTH-1):0] reorder_fifo_data;
323 6 dgisselq
 
324 8 dgisselq
                        always @(posedge i_clk)
325
                                reorder_fifo_data <= i_axi_rdata;
326
                        always @(posedge i_clk)
327
                                o_wb_data <= reorder_fifo_data;
328
                end
329
        end else if (C_AXI_DATA_WIDTH / DW == 2)
330
        begin
331
                reg             reorder_fifo_addr [0:(FIFOLN-1)];
332
 
333
                reg             low_addr;
334
                always @(posedge i_clk)
335
                        if ((i_wb_stb)&&(!o_wb_stall))
336
                                low_addr <= i_wb_addr[0];
337
                always @(posedge i_clk)
338
                        if ((o_axi_arvalid)&&(i_axi_arready))
339
                                reorder_fifo_addr[o_axi_arid] <= low_addr;
340
 
341
                if (STRICT_ORDER == 0)
342 4 dgisselq
                begin
343 8 dgisselq
                        reg     [(C_AXI_DATA_WIDTH-1):0] reorder_fifo_data [0:(FIFOLN-1)];
344 3 dgisselq
 
345 8 dgisselq
                        always @(posedge i_clk)
346
                                if ((o_axi_rready)&&(i_axi_rvalid))
347
                                        reorder_fifo_data[i_axi_rid] <= i_axi_rdata;
348
                        always @(posedge i_clk)
349
                                reorder_fifo_data[i_axi_rid] <= i_axi_rdata;
350
                        always @(posedge i_clk)
351
                        case(reorder_fifo_addr[fifo_tail])
352
                        1'b0: o_wb_data <=reorder_fifo_data[fifo_tail][(  DW-1):    0 ];
353
                        1'b1: o_wb_data <=reorder_fifo_data[fifo_tail][(2*DW-1):(  DW)];
354
                        endcase
355
                end else begin
356
                        reg     [(C_AXI_DATA_WIDTH-1):0] reorder_fifo_data;
357 3 dgisselq
 
358 4 dgisselq
                        always @(posedge i_clk)
359 8 dgisselq
                                reorder_fifo_data <= i_axi_rdata;
360 4 dgisselq
                        always @(posedge i_clk)
361 8 dgisselq
                        case(reorder_fifo_addr[fifo_tail])
362
                        1'b0: o_wb_data <=reorder_fifo_data[(  DW-1):    0 ];
363
                        1'b1: o_wb_data <=reorder_fifo_data[(2*DW-1):(  DW)];
364
                        endcase
365
                end
366
        end else if (C_AXI_DATA_WIDTH / DW == 4)
367
        begin
368
                reg     [1:0]    reorder_fifo_addr [0:(FIFOLN-1)];
369 3 dgisselq
 
370 8 dgisselq
 
371
                reg     [1:0]    low_addr;
372
                always @(posedge i_clk)
373
                        if ((i_wb_stb)&&(!o_wb_stall))
374
                                low_addr <= i_wb_addr[1:0];
375
                always @(posedge i_clk)
376
                        if ((o_axi_arvalid)&&(i_axi_arready))
377
                                reorder_fifo_addr[o_axi_arid] <= low_addr;
378
 
379
                if (STRICT_ORDER == 0)
380
                begin
381
                        reg     [(C_AXI_DATA_WIDTH-1):0] reorder_fifo_data [0:(FIFOLN-1)];
382
 
383 4 dgisselq
                        always @(posedge i_clk)
384 8 dgisselq
                                if ((o_axi_rready)&&(i_axi_rvalid))
385
                                        reorder_fifo_data[i_axi_rid] <= i_axi_rdata;
386
                        always @(posedge i_clk)
387 6 dgisselq
                        case(reorder_fifo_addr[fifo_tail][1:0])
388 8 dgisselq
                        2'b00: o_wb_data <=reorder_fifo_data[fifo_tail][(  DW-1):    0 ];
389
                        2'b01: o_wb_data <=reorder_fifo_data[fifo_tail][(2*DW-1):(  DW)];
390
                        2'b10: o_wb_data <=reorder_fifo_data[fifo_tail][(3*DW-1):(2*DW)];
391
                        2'b11: o_wb_data <=reorder_fifo_data[fifo_tail][(4*DW-1):(3*DW)];
392 4 dgisselq
                        endcase
393 8 dgisselq
                end else begin
394
                        reg     [(C_AXI_DATA_WIDTH-1):0] reorder_fifo_data;
395 4 dgisselq
 
396
                        always @(posedge i_clk)
397 8 dgisselq
                                reorder_fifo_data <= i_axi_rdata;
398
                        always @(posedge i_clk)
399
                        case(reorder_fifo_addr[fifo_tail][1:0])
400
                        2'b00: o_wb_data <=reorder_fifo_data[(  DW-1): 0];
401
                        2'b01: o_wb_data <=reorder_fifo_data[(2*DW-1):(  DW)];
402
                        2'b10: o_wb_data <=reorder_fifo_data[(3*DW-1):(2*DW)];
403
                        2'b11: o_wb_data <=reorder_fifo_data[(4*DW-1):(3*DW)];
404
                        endcase
405 4 dgisselq
                end
406 8 dgisselq
        end
407 4 dgisselq
 
408 8 dgisselq
        endgenerate
409 4 dgisselq
 
410 13 dgisselq
        // verilator lint_off UNUSED
411 8 dgisselq
        wire    axi_rd_ack, axi_wr_ack, axi_ard_req, axi_awr_req, axi_wr_req,
412
                axi_rd_err, axi_wr_err;
413 13 dgisselq
        // verilator lint_on  UNUSED
414
 
415 8 dgisselq
        //
416
        assign  axi_ard_req = (o_axi_arvalid)&&(i_axi_arready);
417
        assign  axi_awr_req = (o_axi_awvalid)&&(i_axi_awready);
418
        assign  axi_wr_req  = (o_axi_wvalid )&&(i_axi_wready);
419
        //
420
        assign  axi_rd_ack = (i_axi_rvalid)&&(o_axi_rready);
421
        assign  axi_wr_ack = (i_axi_bvalid)&&(o_axi_bready);
422
        assign  axi_rd_err = (axi_rd_ack)&&(i_axi_rresp[1]);
423
        assign  axi_wr_err = (axi_wr_ack)&&(i_axi_bresp[1]);
424 2 dgisselq
 
425 8 dgisselq
        //
426
        // We're going to need a FIFO on the return to make certain that we can
427
        // select the right bits from the return value, in the case where
428
        // DW != the axi data width.
429
        //
430
        // If we aren't using a strict order, this FIFO is can be used as a
431
        // reorder buffer as well, to place our out of order bus responses
432
        // back into order.  Responses on the wishbone, however, are *always*
433
        // done in order.
434
        generate
435
        if (STRICT_ORDER == 0)
436
        begin
437
                // Reorder FIFO
438
                //
439
                // FIFO reorder buffer
440
                reg     [(FIFOLN-1):0]   reorder_fifo_valid;
441
                reg     [(FIFOLN-1):0]   reorder_fifo_err;
442 2 dgisselq
 
443 8 dgisselq
                initial reorder_fifo_valid = 0;
444
                initial reorder_fifo_err = 0;
445
 
446
 
447
                initial fifo_tail = 0;
448
                initial o_wb_ack  = 0;
449
                initial o_wb_err  = 0;
450 2 dgisselq
                always @(posedge i_clk)
451 14 dgisselq
                if (i_reset)
452 2 dgisselq
                begin
453 14 dgisselq
                        reorder_fifo_valid <= 0;
454
                        reorder_fifo_err <= 0;
455
                        o_wb_ack  <= 0;
456
                        o_wb_err  <= 0;
457
                        fifo_tail <= 0;
458
                end else begin
459 8 dgisselq
                        if (axi_rd_ack)
460 2 dgisselq
                        begin
461 5 dgisselq
                                reorder_fifo_valid[i_axi_rid] <= 1'b1;
462 8 dgisselq
                                reorder_fifo_err[i_axi_rid] <= axi_rd_err;
463 2 dgisselq
                        end
464 8 dgisselq
                        if (axi_wr_ack)
465 2 dgisselq
                        begin
466 5 dgisselq
                                reorder_fifo_valid[i_axi_bid] <= 1'b1;
467 8 dgisselq
                                reorder_fifo_err[i_axi_bid] <= axi_wr_err;
468 2 dgisselq
                        end
469
 
470
                        if (reorder_fifo_valid[fifo_tail])
471
                        begin
472 8 dgisselq
                                o_wb_ack <= (!wb_abort)&&(!reorder_fifo_err[fifo_tail]);
473
                                o_wb_err <= (!wb_abort)&&( reorder_fifo_err[fifo_tail]);
474
                                fifo_tail <= fifo_tail + 1'b1;
475 2 dgisselq
                                reorder_fifo_valid[fifo_tail] <= 1'b0;
476
                                reorder_fifo_err[fifo_tail]   <= 1'b0;
477
                        end else begin
478
                                o_wb_ack <= 1'b0;
479
                                o_wb_err <= 1'b0;
480
                        end
481
 
482
                        if (!i_wb_cyc)
483
                        begin
484 8 dgisselq
                                // reorder_fifo_valid <= 0;
485
                                // reorder_fifo_err   <= 0;
486 2 dgisselq
                                o_wb_err <= 1'b0;
487
                                o_wb_ack <= 1'b0;
488
                        end
489
                end
490
 
491 3 dgisselq
                reg     r_fifo_full;
492 8 dgisselq
                initial r_fifo_full = 0;
493 2 dgisselq
                always @(posedge i_clk)
494 14 dgisselq
                if (i_reset)
495
                        r_fifo_full <= 0;
496
                else begin
497 8 dgisselq
                        if ((i_wb_stb)&&(!o_wb_stall)
498 2 dgisselq
                                        &&(reorder_fifo_valid[fifo_tail]))
499
                                r_fifo_full <= (fifo_tail==n_fifo_head);
500 8 dgisselq
                        else if ((i_wb_stb)&&(!o_wb_stall))
501 2 dgisselq
                                r_fifo_full <= (fifo_tail==nn_fifo_head);
502
                        else if (reorder_fifo_valid[fifo_tail])
503
                                r_fifo_full <= 1'b0;
504
                        else
505
                                r_fifo_full <= (fifo_tail==n_fifo_head);
506
                end
507
                assign w_fifo_full = r_fifo_full;
508
        end else begin
509 6 dgisselq
                //
510 8 dgisselq
                // Strict ordering
511 6 dgisselq
                //
512 8 dgisselq
                reg     reorder_fifo_valid;
513
                reg     reorder_fifo_err;
514
 
515
                initial reorder_fifo_valid = 1'b0;
516
                initial reorder_fifo_err   = 1'b0;
517 2 dgisselq
                always @(posedge i_clk)
518 14 dgisselq
                if (i_reset)
519
                begin
520
                        reorder_fifo_valid <= 0;
521
                        reorder_fifo_err   <= 0;
522
                end else begin
523 8 dgisselq
                        if (axi_rd_ack)
524
                        begin
525
                                reorder_fifo_valid <= 1'b1;
526
                                reorder_fifo_err   <= axi_rd_err;
527
                        end else if (axi_wr_ack)
528
                        begin
529
                                reorder_fifo_valid <= 1'b1;
530
                                reorder_fifo_err   <= axi_wr_err;
531
                        end else begin
532
                                reorder_fifo_valid <= 1'b0;
533
                                reorder_fifo_err   <= 1'b0;
534
                        end
535 14 dgisselq
                end
536 8 dgisselq
 
537
                initial fifo_tail = 0;
538 2 dgisselq
                always @(posedge i_clk)
539 14 dgisselq
                if (i_reset)
540
                        fifo_tail <= 0;
541
                else if (reorder_fifo_valid)
542
                        fifo_tail <= fifo_tail + 1'b1;
543 8 dgisselq
 
544
                initial o_wb_ack  = 0;
545 2 dgisselq
                always @(posedge i_clk)
546 14 dgisselq
                if (i_reset)
547
                        o_wb_ack <= 0;
548
                else
549 8 dgisselq
                        o_wb_ack <= (reorder_fifo_valid)&&(i_wb_cyc)&&(!wb_abort);
550
 
551
                initial o_wb_err  = 0;
552
                always @(posedge i_clk)
553 14 dgisselq
                if (i_reset)
554
                        o_wb_err <= 0;
555
                else
556 8 dgisselq
                        o_wb_err <= (reorder_fifo_err)&&(i_wb_cyc)&&(!wb_abort);
557
 
558
                reg     r_fifo_full;
559
                initial r_fifo_full = 0;
560
                always @(posedge i_clk)
561 14 dgisselq
                if (i_reset)
562
                        r_fifo_full <= 0;
563
                else begin
564 8 dgisselq
                        if ((i_wb_stb)&&(!o_wb_stall)
565
                                        &&(reorder_fifo_valid))
566
                                r_fifo_full <= (fifo_tail==n_fifo_head);
567
                        else if ((i_wb_stb)&&(!o_wb_stall))
568
                                r_fifo_full <= (fifo_tail==nn_fifo_head);
569 13 dgisselq
                        else if (reorder_fifo_valid)
570 8 dgisselq
                                r_fifo_full <= 1'b0;
571
                        else
572
                                r_fifo_full <= (fifo_tail==n_fifo_head);
573
                end
574
 
575
                assign w_fifo_full = r_fifo_full;
576 13 dgisselq
 
577
                // verilator lint_off UNUSED
578
                wire    [2*C_AXI_ID_WIDTH-1:0]   strict_unused;
579
                assign  strict_unused = { i_axi_bid, i_axi_rid };
580
                // verilator lint_on  UNUSED
581 3 dgisselq
        end endgenerate
582 2 dgisselq
 
583 8 dgisselq
        //
584
        // Wishbone abort logic
585
        //
586
 
587 14 dgisselq
        // Else, are we mid-cycle?
588 8 dgisselq
        initial wb_mid_cycle = 0;
589
        always @(posedge i_clk)
590 14 dgisselq
        if (i_reset)
591
                wb_mid_cycle <= 0;
592
        else if ((fifo_head != fifo_tail)
593
                        ||(o_axi_arvalid)||(o_axi_awvalid)
594
                        ||(o_axi_wvalid)
595
                        ||(i_wb_cyc)&&(i_wb_stb)&&(!o_wb_stall))
596
                wb_mid_cycle <= 1'b1;
597
        else
598
                wb_mid_cycle <= 1'b0;
599 8 dgisselq
 
600 14 dgisselq
        initial wb_mid_abort = 0;
601 8 dgisselq
        always @(posedge i_clk)
602 14 dgisselq
        if (i_reset)
603
                wb_mid_abort <= 0;
604
        else if (wb_mid_cycle)
605
                wb_mid_abort <= (wb_mid_abort)||(!i_wb_cyc);
606
        else
607
                wb_mid_abort <= 1'b0;
608 8 dgisselq
 
609
        assign  wb_abort = ((wb_mid_cycle)&&(!i_wb_cyc))||(wb_mid_abort);
610
 
611 2 dgisselq
        // Now, the difficult signal ... the stall signal
612
        // Let's build for a single cycle input ... and only stall if something
613
        // outgoing is valid and nothing is ready.
614
        assign  o_wb_stall = (i_wb_cyc)&&(
615 8 dgisselq
                                (w_fifo_full)||(wb_mid_abort)
616 5 dgisselq
                                ||((o_axi_awvalid)&&(!i_axi_awready))
617
                                ||((o_axi_wvalid )&&(!i_axi_wready ))
618
                                ||((o_axi_arvalid)&&(!i_axi_arready)));
619 8 dgisselq
 
620 15 dgisselq
        // Make Verilator happy
621
        // verilator lint_off UNUSED
622
        wire    [2:0]   unused;
623
        assign  unused = { i_axi_bresp[0], i_axi_rresp[0], i_axi_rlast };
624
        // verilator lint_on  UNUSED
625 8 dgisselq
 
626
/////////////////////////////////////////////////////////////////////////
627
//
628
//
629
//
630
// Formal methods section
631
//
632
// These are only relevant when *proving* that this translator works
633
//
634
//
635
//
636
/////////////////////////////////////////////////////////////////////////
637
//
638 13 dgisselq
// This section has been removed from this release.
639
//
640 2 dgisselq
endmodule

powered by: WebSVN 2.1.0

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