aboutsummaryrefslogtreecommitdiffstats
path: root/fpga/usrp3/lib/axi4_sv/AxiIf.sv
blob: 311387b5cec1c622554722eece891929be6a0054 (plain)
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
//
// Copyright 2021 Ettus Research, A National Instruments Brand
//
// SPDX-License-Identifier: LGPL-3.0-or-later
//
// Interface: AxiIf
// Description:
//  AXI4 is an ARM standard for bursting memory mapped transfers
//  For more information on the spec see
//    - https://developer.arm.com/docs/ihi0022/d
//
//  The interface contains methods for
//  (1) Writing an address
//  (2) Reading an address
//
// Parameters:
//  - DATA_WIDTH - Width of the data on AXI4 bus
//  - ADDR_WIDTH - Width of the address on AXI4 bus
//

//-----------------------------------------------------------------------------
// AXI4 interface
//-----------------------------------------------------------------------------

interface AxiIf #(
  int DATA_WIDTH = 64,
  int ADDR_WIDTH = 1
) (
  input logic clk,
  input logic rst = 1'b0
);

  import PkgAxi::*;

  localparam BYTES_PER_WORD = DATA_WIDTH/8;

  // local type defs
  typedef logic [DATA_WIDTH-1:0]     data_t;
  typedef logic [ADDR_WIDTH-1:0]     addr_t;
  typedef logic [BYTES_PER_WORD-1:0] strb_t;
  typedef logic [7:0]                len_t;
  typedef logic [2:0]                size_t;
  typedef logic [1:0]                burst_t;
  typedef logic [0:0]                lock_t;
  typedef logic [3:0]                cache_t;
  typedef logic [2:0]                prot_t;
  typedef logic [3:0]                qos_t;

  // Signals that make up an Axi interface
  // Write Address Channel
  addr_t  awaddr;
  len_t   awlen;
  size_t  awsize;
  burst_t awburst;
  lock_t  awlock;
  cache_t awcache;
  prot_t  awprot;
  qos_t   awqos;
  logic   awvalid;
  logic   awready;

  // Write Data Channel
  data_t wdata;
  strb_t wstrb = '1;
  logic  wlast;
  logic  wvalid;
  logic  wready;

  // Write Response Channel
  axi_resp_t bresp;
  logic  bvalid;
  logic  bready;

  // Read Address Channel
  addr_t  araddr;
  len_t   arlen;
  size_t  arsize;
  burst_t arburst;
  lock_t  arlock;
  cache_t arcache;
  prot_t  arprot;
  qos_t   arqos;
  logic   arvalid;
  logic   arready;

  // Read Data Channel
  data_t rdata;
  axi_resp_t rresp;
  logic  rlast;
  logic  rvalid;
  logic  rready;

  // Master Functions
  task automatic drive_aw(input addr_t  addr,
                          input len_t   len,
                          input size_t  size,
                          input burst_t burst,
                          input lock_t  lock,
                          input cache_t cache,
                          input prot_t  prot,
                          input qos_t   qos);
    awaddr  = addr;
    awlen   = len;
    awsize  = size;
    awburst = burst;
    awlock  = lock;
    awcache = cache;
    awprot  = prot;
    awqos   = qos;
    awvalid = 1;
  endtask

  task automatic drive_w(input data_t data,
                         input logic  last,
                         input strb_t strb = '1);
    wdata   = data;
    wstrb   = strb;
    wlast   = last;
    wvalid  = 1;
  endtask

  task automatic drive_aw_idle();
    awaddr  = 'X;
    awlen   = 'X;
    awsize  = 'X;
    awburst = 'X;
    awlock  = 'X;
    awcache = 'X;
    awprot  = 'X;
    awqos   = 'X;
    awvalid = 0;
  endtask

  task automatic drive_w_idle();
    wdata   = 'X;
    wstrb   = 'X;
    wlast   = 1'bX;
    wvalid  = 0;
  endtask

  task automatic drive_read(input addr_t  addr,
                            input len_t   len,
                            input size_t  size,
                            input burst_t burst,
                            input lock_t  lock,
                            input cache_t cache,
                            input prot_t  prot,
                            input qos_t   qos);
    araddr  = addr;
    arlen   = len;
    arsize  = size;
    arburst = burst;
    arlock  = lock;
    arcache = cache;
    arprot  = prot;
    arqos   = qos;
    arvalid = 1;
  endtask

  task automatic drive_read_idle();
    araddr  = 'X;
    araddr  = 'X;
    arlen   = 'X;
    arsize  = 'X;
    arburst = 'X;
    arlock  = 'X;
    arcache = 'X;
    arprot  = 'X;
    arqos   = 'X;
    arvalid = 0;
  endtask

  // Slave Functions
  task automatic drive_write_resp(input axi_resp_t resp=OKAY);
    bresp  = resp;
    bvalid = 1;
  endtask

  task automatic drive_write_resp_idle();
    bresp  = OKAY;
    bvalid = 0;
  endtask

  task automatic drive_read_resp(input data_t data,
                                 input logic  last,
                                 input axi_resp_t resp=OKAY);
    rdata  = data;
    rresp  = resp;
    rlast  = last;
    rvalid = 1;
  endtask

  task automatic drive_read_resp_idle();
    rdata  = 'X;
    rresp  = OKAY;
    rlast  = 1'bX;
    rvalid = 0;
  endtask

  // View from the master side
  modport master (
    input  clk, rst,
    output awaddr,awlen,awsize,awburst,awlock,awcache,awprot,awqos,awvalid,
           wdata,wstrb,wlast,wvalid,
           bready,
           araddr,arlen,arsize,arburst,arlock,arcache,arprot,arqos,arvalid,
           rready,
    input  awready,wready,bresp,bvalid,arready,rdata,rresp,rlast,rvalid,
    import drive_aw,
    import drive_w,
    import drive_w_idle,
    import drive_aw_idle,
    import drive_read,
    import drive_read_idle
  );

  // View from the slave side
  modport slave (
    input  clk, rst,
    input  awaddr,awlen,awsize,awburst,awlock,awcache,awprot,awqos,awvalid,
           wdata,wstrb,wlast,wvalid,
           bready,
           araddr,arlen,arsize,arburst,arlock,arcache,arprot,arqos,arvalid,
           rready,
    output awready,wready,bresp,bvalid,arready,rdata,rresp,rlast,rvalid,
    import drive_write_resp,
    import drive_write_resp_idle,
    import drive_read_resp,
    import drive_read_resp_idle
  );

endinterface : AxiIf

// The _v version of the interface does not assign any signals so it may be used
// in a continuous context.  The most common example is when associating members
// to a regular verilog output port.
interface AxiIf_v #(
  int DATA_WIDTH = 64,
  int ADDR_WIDTH = 1
) (
  input logic clk,
  input logic rst = 1'b0
);

  import PkgAxi::*;

  localparam BYTES_PER_WORD = DATA_WIDTH/8;

  // local type defs
  typedef logic [DATA_WIDTH-1:0]     data_t;
  typedef logic [ADDR_WIDTH-1:0]     addr_t;
  typedef logic [BYTES_PER_WORD-1:0] strb_t;
  typedef logic [7:0]                len_t;
  typedef logic [2:0]                size_t;
  typedef logic [1:0]                burst_t;
  typedef logic [0:0]                lock_t;
  typedef logic [3:0]                cache_t;
  typedef logic [2:0]                prot_t;
  typedef logic [3:0]                qos_t;

  // Signals that make up an Axi interface
  // Write Address Channel
  addr_t  awaddr;
  len_t   awlen;
  size_t  awsize;
  burst_t awburst;
  lock_t  awlock;
  cache_t awcache;
  prot_t  awprot;
  qos_t   awqos;
  logic   awvalid;
  logic   awready;

  // Write Data Channel
  data_t wdata;
  strb_t wstrb;
  logic  wlast;
  logic  wvalid;
  logic  wready;

  // Write Response Channel
  axi_resp_t bresp;
  logic  bvalid;
  logic  bready;

  // Read Address Channel
  addr_t  araddr;
  len_t   arlen;
  size_t  arsize;
  burst_t arburst;
  lock_t  arlock;
  cache_t arcache;
  prot_t  arprot;
  qos_t   arqos;
  logic   arvalid;
  logic   arready;

  // Read Data Channel
  data_t rdata;
  axi_resp_t rresp;
  logic  rlast;
  logic  rvalid;
  logic  rready;

  // View from the master side
  modport master (
    input  clk, rst,
    output awaddr,awlen,awsize,awburst,awlock,awcache,awprot,awqos,awvalid,
           wdata,wstrb,wlast,wvalid,
           bready,
           araddr,arlen,arsize,arburst,arlock,arcache,arprot,arqos,arvalid,
           rready,
    input  awready,wready,bresp,bvalid,arready,rdata,rresp,rlast,rvalid

  );

  // View from the slave side
  modport slave (
    input  clk, rst,
    input  awaddr,awlen,awsize,awburst,awlock,awcache,awprot,awqos,awvalid,
           wdata,wstrb,wlast,wvalid,
           bready,
           araddr,arlen,arsize,arburst,arlock,arcache,arprot,arqos,arvalid,
           rready,
    output awready,wready,bresp,bvalid,arready,rdata,rresp,rlast,rvalid

  );

endinterface : AxiIf_v