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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [implement/] [rtl/] [axi_cmn/] [fm_axi_s.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 specular
//=======================================================================
2
// Project Monophony
3
//   Wire-Frame 3D Graphics Accelerator IP Core
4
//
5
// File:
6
//   fm_axi_s.v
7
//
8
// Abstract:
9
//   AXI Slave interface bridge
10
//
11
// Author:
12 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
13 5 specular
//
14
//======================================================================
15
//
16
// Copyright (c) 2016, Kenji Ishimaru
17
// All rights reserved.
18
//
19
// Redistribution and use in source and binary forms, with or without
20
// modification, are permitted provided that the following conditions are met:
21
//
22
//  -Redistributions of source code must retain the above copyright notice,
23
//   this list of conditions and the following disclaimer.
24
//  -Redistributions in binary form must reproduce the above copyright notice,
25
//   this list of conditions and the following disclaimer in the documentation
26
//   and/or other materials provided with the distribution.
27
//
28
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
35
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
37
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
//
40
// Revision History
41
 
42
module fm_axi_s (
43
  // system
44
  clk_core,
45
  rst_x,
46
  // AXI write port
47
  i_awid_s,
48
  i_awaddr_s,
49
  i_awlen_s,
50
  i_awsize_s,
51
  i_awburst_s,
52
  i_awlock_s,
53
  i_awcache_s,
54
  i_awprot_s,
55
  i_awvalid_s,
56
  o_awready_s,
57
  i_wid_s,
58
  i_wdata_s,
59
  i_wstrb_s,
60
  i_wlast_s,
61
  i_wvalid_s,
62
  o_wready_s,
63
  o_bid_s,
64
  o_bresp_s,
65
  o_bvalid_s,
66
  i_bready_s,
67
  // AXI read port
68
  i_arid_s,
69
  i_araddr_s,
70
  i_arlen_s,
71
  i_arsize_s,
72
  i_arburst_s,
73
  i_arlock_s,
74
  i_arcache_s,
75
  i_arprot_s,
76
  i_arvalid_s,
77
  o_arready_s,
78
  o_rid_s,
79
  o_rdata_s,
80
  o_rresp_s,
81
  o_rlast_s,
82
  o_rvalid_s,
83
  i_rready_s,
84
  // internal bus
85
  o_req,
86
  o_wr,
87
  o_adrs,
88
  i_ack,
89
  o_be,
90
  o_wd,
91
  i_rstr,
92
  i_rd
93
);
94
`include "polyphony_axi_def.v"
95
//////////////////////////////////
96
// I/O port definition
97
//////////////////////////////////
98
  // system
99
  input clk_core;
100
  input rst_x;
101
  // AXI Slave
102
  //   write port
103
  input [P_AXI_S_AWID-1:0] i_awid_s;
104
  input [P_AXI_S_AWADDR-1:0] i_awaddr_s;
105
  input [P_AXI_S_AWLEN-1:0] i_awlen_s;
106
  input [P_AXI_S_AWSIZE-1:0] i_awsize_s;
107
  input [P_AXI_S_AWBURST-1:0] i_awburst_s;
108
  input [P_AXI_S_AWLOCK-1:0] i_awlock_s;
109
  input [P_AXI_S_AWCACHE-1:0] i_awcache_s;
110
  input [P_AXI_S_AWPROT-1:0] i_awprot_s;
111
  input i_awvalid_s;
112
  output o_awready_s;
113
  input [P_AXI_S_WID-1:0] i_wid_s;
114
  input [P_AXI_S_WDATA-1:0] i_wdata_s;
115
  input [P_AXI_S_WSTRB-1:0] i_wstrb_s;
116
  input i_wlast_s;
117
  input i_wvalid_s;
118
  output o_wready_s;
119
  output [P_AXI_S_BID-1:0] o_bid_s;
120
  output [P_AXI_S_BRESP-1:0] o_bresp_s;
121
  output o_bvalid_s;
122
  input i_bready_s;
123
  //   read port
124
  input [P_AXI_S_ARID-1:0] i_arid_s;
125
  input [P_AXI_S_ARADDR-1:0] i_araddr_s;
126
  input [P_AXI_S_ARLEN-1:0] i_arlen_s;
127
  input [P_AXI_S_ARSIZE-1:0] i_arsize_s;
128
  input [P_AXI_S_ARBURST-1:0] i_arburst_s;
129
  input [P_AXI_S_ARLOCK-1:0] i_arlock_s;
130
  input [P_AXI_S_ARCACHE-1:0] i_arcache_s;
131
  input [P_AXI_S_ARPROT-1:0] i_arprot_s;
132
  input i_arvalid_s;
133
  output o_arready_s;
134
  // read response
135
  output [P_AXI_S_RID-1:0] o_rid_s;
136
  output [P_AXI_S_RDATA-1:0] o_rdata_s;
137
  output [P_AXI_S_RRESP-1:0] o_rresp_s;
138
  output o_rlast_s;
139
  output o_rvalid_s;
140
  input i_rready_s;
141
  // internal side
142
  output          o_req;
143
  output          o_wr;
144
  output [23:0]   o_adrs;
145
  input           i_ack;
146
  output [3:0]    o_be;
147
  output [31:0]   o_wd;
148
  input           i_rstr;
149
  input  [31:0]   i_rd;
150
//////////////////////////////////
151
// parameter definition
152
//////////////////////////////////
153
  localparam P_IDLE = 'd0;
154
  localparam P_WRITE_CMD = 'd1;
155
  localparam P_READ_CMD = 'd2;
156
  localparam P_READ_DT  = 'd3;
157
 
158
  localparam P_WC_FIFO_W = P_AXI_S_AWID +
159
                           P_AXI_S_AWADDR +
160
                           P_AXI_S_AWLEN +
161
                           P_AXI_S_AWSIZE +
162
                           P_AXI_S_AWBURST +
163
                           P_AXI_S_AWLOCK +
164
                           P_AXI_S_AWCACHE +
165
                           P_AXI_S_AWPROT;
166
 
167
  localparam P_WD_FIFO_W = P_AXI_S_WID +
168
                           P_AXI_S_WDATA +
169
                           P_AXI_S_WSTRB + 1;
170
 
171
  localparam P_WR_FIFO_W = P_AXI_S_BID +
172
                           P_AXI_S_BRESP;
173
 
174
  localparam P_RC_FIFO_W = P_AXI_S_ARID +
175
                           P_AXI_S_ARADDR +
176
                           P_AXI_S_ARLEN +
177
                           P_AXI_S_ARSIZE +
178
                           P_AXI_S_ARBURST +
179
                           P_AXI_S_ARLOCK +
180
                           P_AXI_S_ARCACHE +
181
                           P_AXI_S_ARPROT;
182
 
183
  localparam P_RR_FIFO_W =  P_AXI_S_RID +
184
                            P_AXI_S_RDATA +
185
                            P_AXI_S_RRESP + 1;
186
 
187
//////////////////////////////////
188
// reg
189
//////////////////////////////////
190
  reg [1:0] r_state;
191
  reg [P_AXI_S_ARID-1:0] r_arid_s;
192
//////////////////////////////////
193
// wire
194
//////////////////////////////////
195
  wire w_w_access;
196
  wire w_r_access;
197
 
198
  // write command
199
  wire [P_AXI_S_AWID-1:0] w_awid_s;
200
  wire [P_AXI_S_AWADDR-1:0] w_awaddr_s;
201
  wire [P_AXI_S_AWLEN-1:0] w_awlen_s;
202
  wire [P_AXI_S_AWSIZE-1:0] w_awsize_s;
203
  wire [P_AXI_S_AWBURST-1:0] w_awburst_s;
204
  wire [P_AXI_S_AWLOCK-1:0] w_awlock_s;
205
  wire [P_AXI_S_AWCACHE-1:0] w_awcache_s;
206
  wire [P_AXI_S_AWPROT-1:0] w_awprot_s;
207
  wire [P_WC_FIFO_W-1:0] w_wc_fifo_in;
208
  wire [P_WC_FIFO_W-1:0] w_wc_fifo_out;
209
  wire w_wc_full;
210
  wire w_wc_empty;
211
  wire w_wc_ren;
212
  // write data
213
  wire [P_AXI_S_WID-1:0] w_wid_s;
214
  wire [P_AXI_S_WDATA-1:0] w_wdata_s;
215
  wire [P_AXI_S_WSTRB-1:0] w_wstrb_s;
216
  wire w_wlast_s;
217
  wire [P_WD_FIFO_W-1:0] w_wd_fifo_in;
218
  wire [P_WD_FIFO_W-1:0] w_wd_fifo_out;
219
  wire w_wd_full;
220
  wire w_wd_empty;
221
  wire w_wd_ren;
222
  // write response
223
  wire [P_AXI_S_BID-1:0] w_bid_s;
224
  wire [P_AXI_S_BRESP-1:0] w_bresp_s;
225
  wire [P_WR_FIFO_W-1:0] w_wr_fifo_in;
226
  wire [P_WR_FIFO_W-1:0] w_wr_fifo_out;
227
  wire w_wr_full;
228
  wire w_wr_empty;
229
  wire w_wr_ren;
230
  // read command
231
  wire [P_AXI_S_ARID-1:0] w_arid_s;
232
  wire [P_AXI_S_ARADDR-1:0] w_araddr_s;
233
  wire [P_AXI_S_ARLEN-1:0] w_arlen_s;
234
  wire [P_AXI_S_ARSIZE-1:0] w_arsize_s;
235
  wire [P_AXI_S_ARBURST-1:0] w_arburst_s;
236
  wire [P_AXI_S_ARLOCK-1:0] w_arlock_s;
237
  wire [P_AXI_S_ARCACHE-1:0] w_arcache_s;
238
  wire [P_AXI_S_ARPROT-1:0] w_arprot_s;
239
  wire [P_RC_FIFO_W-1:0] w_rc_fifo_in;
240
  wire [P_RC_FIFO_W-1:0] w_rc_fifo_out;
241
  wire w_rc_full;
242
  wire w_rc_empty;
243
  wire w_rc_ren;
244
  // read response
245
  wire [P_AXI_S_RID-1:0] w_rid_s;
246
  wire [P_AXI_S_RDATA-1:0] w_rdata_s;
247
  wire [P_AXI_S_RRESP-1:0] w_rresp_s;
248
  wire w_rlast_s;
249
  wire [P_RR_FIFO_W-1:0] w_rr_fifo_in;
250
  wire [P_RR_FIFO_W-1:0] w_rr_fifo_out;
251
  wire w_rr_full;
252
  wire w_rr_empty;
253
  wire w_rr_ren;
254
//////////////////////////////////
255
// assign
256
//////////////////////////////////
257
  assign o_awready_s = ~w_wc_full;
258
  assign w_wc_fifo_in = {
259
    i_awid_s,
260
    i_awaddr_s,
261
    i_awlen_s,
262
    i_awsize_s,
263
    i_awburst_s,
264
    i_awlock_s,
265
    i_awcache_s,
266
    i_awprot_s
267
  };
268
 
269
  assign {
270
    w_awid_s,
271
    w_awaddr_s,
272
    w_awlen_s,
273
    w_awsize_s,
274
    w_awburst_s,
275
    w_awlock_s,
276
    w_awcache_s,
277
    w_awprot_s
278
  } = w_wc_fifo_out;
279
 
280
  assign o_wready_s = ~w_wd_full;
281
  assign w_wd_fifo_in = {
282
    i_wid_s,
283
    i_wdata_s,
284
    i_wstrb_s,
285
    i_wlast_s};
286
 
287
  assign {
288
    w_wid_s,
289
    w_wdata_s,
290
    w_wstrb_s,
291
    w_wlast_s} = w_wd_fifo_out;
292
 
293
  assign w_bid_s = w_awid_s;
294
  assign w_bresp_s = {P_AXI_S_BRESP{1'b0}};
295
  assign w_wr_fifo_in = {
296
    w_bid_s,
297
    w_bresp_s};
298
 
299
  assign {
300
    o_bid_s,
301
    o_bresp_s} = w_wr_fifo_out;
302
 
303
  assign o_bvalid_s = !w_wr_empty;
304
  assign w_rc_fifo_in = {
305
    i_arid_s,
306
    i_araddr_s,
307
    i_arlen_s,
308
    i_arsize_s,
309
    i_arburst_s,
310
    i_arlock_s,
311
    i_arcache_s,
312
    i_arprot_s};
313
 
314
  assign o_arready_s = ~w_rc_full;
315
  assign {
316
    w_arid_s,
317
    w_araddr_s,
318
    w_arlen_s,
319
    w_arsize_s,
320
    w_arburst_s,
321
    w_arlock_s,
322
    w_arcache_s,
323
    w_arprot_s} = w_rc_fifo_out;
324
 
325
  assign {
326
    o_rid_s,
327
    o_rdata_s,
328
    o_rresp_s,
329
    o_rlast_s} = w_rr_fifo_out;
330
 
331
  assign w_rresp_s = {P_AXI_S_RRESP{1'b0}};
332
  assign w_rlast_s = 1'b1;
333
  assign w_rr_fifo_in = {
334
    r_arid_s,
335
    i_rd,
336
    w_rresp_s,
337
    w_rlast_s};
338
 
339
  assign o_rvalid_s = !w_rr_empty;
340
  assign w_w_access = !w_wc_empty & !w_wd_empty;
341
  assign w_r_access = !w_rc_empty;
342
  assign w_wc_ren = (r_state == P_WRITE_CMD) & i_ack;
343
  assign w_wd_ren = (r_state == P_WRITE_CMD) & i_ack;
344
  assign w_rc_ren = (r_state == P_READ_CMD) & i_ack;
345
  assign o_req = (r_state == P_WRITE_CMD) | (r_state == P_READ_CMD);
346
  assign o_wr = (r_state == P_WRITE_CMD);
347
  assign o_adrs = (r_state == P_WRITE_CMD) ? w_awaddr_s[23:0] : w_araddr_s[23:0];
348
  assign o_be = w_wstrb_s;
349
  assign o_wd = w_wdata_s;
350
//////////////////////////////////
351
// always
352
//////////////////////////////////
353
  always @(posedge clk_core) begin
354
    if ((r_state == P_IDLE) & w_r_access) r_arid_s <= w_arid_s;
355
  end
356
 
357
  always @(posedge clk_core or negedge rst_x) begin
358
    if (~rst_x) begin
359
      r_state <= P_IDLE;
360
    end else begin
361
      case (r_state)
362
        P_IDLE : begin
363
          if (w_w_access) r_state <= P_WRITE_CMD;
364
          else if (w_r_access) r_state <= P_READ_CMD;
365
        end
366
        P_WRITE_CMD : begin
367
          if (i_ack) r_state <= P_IDLE;
368
        end
369
        P_READ_CMD : begin
370
          if (i_ack) begin
371
            if (i_rstr) r_state <= P_IDLE;
372
            else r_state <= P_READ_DT;
373
          end
374
        end
375
        P_READ_DT : begin
376
          if (i_rstr) r_state <= P_IDLE;
377
        end
378
 
379
      endcase
380
    end
381
  end
382
 
383
 
384
//////////////////////////////////
385
// module instance
386
//////////////////////////////////
387
// AXI write command
388
  fm_fifo #(P_WC_FIFO_W) u_wc_fifo (
389
    .clk_core(clk_core),
390
    .rst_x(rst_x),
391
    .i_wstrobe(i_awvalid_s),
392
    .i_dt(w_wc_fifo_in),
393
    .o_full(w_wc_full),
394
    .i_renable(w_wc_ren),
395
    .o_dt(w_wc_fifo_out),
396
    .o_empty(w_wc_empty),
397
    .o_dnum()
398
  );
399
// AXI write data
400
  fm_fifo #(P_WD_FIFO_W) u_wd_fifo (
401
    .clk_core(clk_core),
402
    .rst_x(rst_x),
403
    .i_wstrobe(i_wvalid_s),
404
    .i_dt(w_wd_fifo_in),
405
    .o_full(w_wd_full),
406
    .i_renable(w_wd_ren),
407
    .o_dt(w_wd_fifo_out),
408
    .o_empty(w_wd_empty),
409
    .o_dnum()
410
  );
411
// AXI write response
412
  fm_fifo #(P_WR_FIFO_W) u_wr_fifo (
413
    .clk_core(clk_core),
414
    .rst_x(rst_x),
415
    .i_wstrobe(w_wd_ren),
416
    .i_dt(w_wr_fifo_in),
417
    .o_full(w_wr_full),
418
    .i_renable(i_bready_s),
419
    .o_dt(w_wr_fifo_out),
420
    .o_empty(w_wr_empty),
421
    .o_dnum()
422
  );
423
// AXI read command
424
  fm_fifo #(P_RC_FIFO_W) u_rc_fifo (
425
    .clk_core(clk_core),
426
    .rst_x(rst_x),
427
    .i_wstrobe(i_arvalid_s),
428
    .i_dt(w_rc_fifo_in),
429
    .o_full(w_rc_full),
430
    .i_renable(w_rc_ren),
431
    .o_dt(w_rc_fifo_out),
432
    .o_empty(w_rc_empty),
433
    .o_dnum()
434
  );
435
// AXI read data
436
  fm_fifo #(P_RR_FIFO_W) u_rr_fifo (
437
    .clk_core(clk_core),
438
    .rst_x(rst_x),
439
    .i_wstrobe(i_rstr),
440
    .i_dt(w_rr_fifo_in),
441
    .o_full(w_rr_full),
442
    .i_renable(i_rready_s),
443
    .o_dt(w_rr_fifo_out),
444
    .o_empty(w_rr_empty),
445
    .o_dnum()
446
  );
447
 
448
endmodule
449
 

powered by: WebSVN 2.1.0

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