SURF  1.0
AxiPkg.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : AxiPkg.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2013-04-02
5 -- Last update: 2016-04-26
6 -------------------------------------------------------------------------------
7 -- Description: AXI4 Package File
8 -------------------------------------------------------------------------------
9 -- This file is part of 'SLAC Firmware Standard Library'.
10 -- It is subject to the license terms in the LICENSE.txt file found in the
11 -- top-level directory of this distribution and at:
12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
13 -- No part of 'SLAC Firmware Standard Library', including this file,
14 -- may be copied, modified, propagated, or distributed except according to
15 -- the terms contained in the LICENSE.txt file.
16 -------------------------------------------------------------------------------
17 
18 library ieee;
19 use ieee.std_logic_1164.all;
20 use ieee.std_logic_arith.all;
21 use ieee.std_logic_unsigned.all;
22 
23 use work.StdRtlPkg.all;
24 
25 package AxiPkg is
26 --! @file
27  --! @ingroup axi
28 
29  -------------------------------------
30  -- AXI bus, read master signal record
31  -------------------------------------
32  type AxiReadMasterType is record
33  -- Read Address channel
34  arvalid : sl; -- Address valid
35  araddr : slv(63 downto 0); -- Address
36  arid : slv(31 downto 0); -- Address ID
37  arlen : slv(7 downto 0); -- Transfer count
38  arsize : slv(2 downto 0); -- Bytes per transfer
39  arburst : slv(1 downto 0); -- Burst Type
40  arlock : slv(1 downto 0); -- Lock control
41  arprot : slv(2 downto 0); -- Protection control
42  arcache : slv(3 downto 0); -- Cache control
43  arqos : slv(3 downto 0); -- QoS value
44  arregion : slv(3 downto 0); -- Region identifier
45  -- Read data channel
46  rready : sl; -- Master is ready for data
47  end record;
48  type AxiReadMasterArray is array (natural range<>) of AxiReadMasterType;
50  arvalid => '0',
51  araddr => (others => '0'),
52  arid => (others => '0'),
53  arlen => (others => '0'),
54  arsize => (others => '0'),
55  arburst => (others => '0'),
56  arlock => (others => '0'),
57  arprot => (others => '0'),
58  arcache => (others => '0'),
59  arqos => (others => '0'),
60  arregion => (others => '0'),
61  rready => '0');
63  arvalid => '0',
64  araddr => (others => '0'),
65  arid => (others => '0'),
66  arlen => (others => '0'),
67  arsize => (others => '0'),
68  arburst => (others => '0'),
69  arlock => (others => '0'),
70  arprot => (others => '0'),
71  arcache => (others => '0'),
72  arqos => (others => '0'),
73  arregion => (others => '0'),
74  rready => '1');
75 
76  ------------------------------------
77  -- AXI bus, read slave signal record
78  ------------------------------------
79  type AxiReadSlaveType is record
80  -- Read Address channel
81  arready : sl; -- Slave is ready for address
82  -- Read data channel
83  rdata : slv(1023 downto 0); -- Read data from slave
84  rlast : sl; -- Read data last strobe
85  rvalid : sl; -- Read data is valid
86  rid : slv(31 downto 0); -- Read ID tag
87  rresp : slv(1 downto 0); -- Read data result
88  end record;
89  type AxiReadSlaveArray is array (natural range<>) of AxiReadSlaveType;
91  arready => '0',
92  rdata => (others => '0'),
93  rlast => '0',
94  rvalid => '0',
95  rid => (others => '0'),
96  rresp => (others => '0'));
98  arready => '1',
99  rdata => (others => '0'),
100  rlast => '0',
101  rvalid => '0',
102  rid => (others => '0'),
103  rresp => (others => '0'));
104 
105  --------------------------------------
106  -- AXI bus, write master signal record
107  --------------------------------------
108  type AxiWriteMasterType is record
109  -- Write address channel
110  awvalid : sl; -- Address valid
111  awaddr : slv(63 downto 0); -- Address
112  awid : slv(31 downto 0); -- Address ID
113  awlen : slv(7 downto 0); -- Transfer count (burst length)
114  awsize : slv(2 downto 0); -- Bytes per transfer
115  awburst : slv(1 downto 0); -- Burst Type
116  awlock : slv(1 downto 0); -- Lock control
117  awprot : slv(2 downto 0); -- Protection control
118  awcache : slv(3 downto 0); -- Cache control
119  awqos : slv(3 downto 0); -- QoS value
120  awregion : slv(3 downto 0); -- Region identifier
121  -- Write data channel
122  wdata : slv(1023 downto 0); -- Write data
123  wlast : sl; -- Write data is last
124  wvalid : sl; -- Write data is valid
125  wid : slv(31 downto 0); -- Write ID tag
126  wstrb : slv(127 downto 0); -- Write enable strobes, 1 per byte
127  -- Write ack channel
128  bready : sl; -- Write master is ready for status
129  end record;
130  type AxiWriteMasterArray is array (natural range<>) of AxiWriteMasterType;
132  awvalid => '0',
133  awaddr => (others => '0'),
134  awid => (others => '0'),
135  awlen => (others => '0'),
136  awsize => (others => '0'),
137  awburst => (others => '0'),
138  awlock => (others => '0'),
139  awprot => (others => '0'),
140  awcache => (others => '0'),
141  awqos => (others => '0'),
142  awregion => (others => '0'),
143  wdata => (others => '0'),
144  wlast => '0',
145  wvalid => '0',
146  wid => (others => '0'),
147  wstrb => (others => '0'),
148  bready => '0');
150  awvalid => '0',
151  awaddr => (others => '0'),
152  awid => (others => '0'),
153  awlen => (others => '0'),
154  awsize => (others => '0'),
155  awburst => (others => '0'),
156  awlock => (others => '0'),
157  awprot => (others => '0'),
158  awcache => (others => '0'),
159  awqos => (others => '0'),
160  awregion => (others => '0'),
161  wdata => (others => '0'),
162  wlast => '0',
163  wvalid => '0',
164  wid => (others => '0'),
165  wstrb => (others => '0'),
166  bready => '1');
167 
168  -------------------------------------
169  -- AXI bus, write slave signal record
170  -------------------------------------
171  type AxiWriteSlaveType is record
172  -- Write address channel
173  awready : sl; -- Write slave is ready for address
174  -- Write data channel
175  wready : sl; -- Write slave is ready for data
176  -- Write ack channel
177  bresp : slv(1 downto 0); -- Write access status
178  bvalid : sl; -- Write status valid
179  bid : slv(31 downto 0); -- Channel ID
180  end record;
181  type AxiWriteSlaveArray is array (natural range<>) of AxiWriteSlaveType;
183  awready => '0',
184  wready => '0',
185  bresp => (others => '0'),
186  bvalid => '0',
187  bid => (others => '0'));
189  awready => '1',
190  wready => '1',
191  bresp => (others => '0'),
192  bvalid => '0',
193  bid => (others => '0'));
194 
195  ------------------------
196  -- AXI bus, fifo control
197  ------------------------
198  type AxiCtrlType is record
201  end record AxiCtrlType;
202  type AxiCtrlArray is array (natural range<>) of AxiCtrlType;
203  constant AXI_CTRL_INIT_C : AxiCtrlType := (
204  pause => '1',
205  overflow => '0');
207  pause => '0',
208  overflow => '0');
209 
210  ------------------------
211  -- AXI bus configuration
212  ------------------------
213  type AxiConfigType is record
214  ADDR_WIDTH_C : positive range 12 to 64;
215  DATA_BYTES_C : positive range 1 to 128;
216  ID_BITS_C : positive range 1 to 32;
217  LEN_BITS_C : natural range 0 to 8;
218  end record AxiConfigType;
219 
220  function axiConfig (
221  constant ADDR_WIDTH_C : in positive range 12 to 64 := 32;
222  constant DATA_BYTES_C : in positive range 1 to 128 := 4;
223  constant ID_BITS_C : in positive range 1 to 32 := 12;
224  constant LEN_BITS_C : in natural range 0 to 8 := 4)
225  return AxiConfigType;
226 
227  constant AXI_CONFIG_INIT_C : AxiConfigType := axiConfig(
228  ADDR_WIDTH_C => 32,
229  DATA_BYTES_C => 4,
230  ID_BITS_C => 12,
231  LEN_BITS_C => 4);
232 
233 "01""1111" function axiWriteMasterInit (
234  constant AXI_CONFIG_C : in AxiConfigType;
235  bready : in sl := '0';
236  constant AXI_BURST_C : in slv(1 downto 0) := ;
237  constant AXI_CACHE_C : in slv(3 downto 0) := )
238 
239  return AxiWriteMasterType;
240 
241 "01""1111" function axiReadMasterInit (
242  constant AXI_CONFIG_C : in AxiConfigType;
243  constant AXI_BURST_C : in slv(1 downto 0) := ;
244  constant AXI_CACHE_C : in slv(3 downto 0) := )
245  return AxiReadMasterType;
246 
247  function ite(i : boolean; t : AxiConfigType; e : AxiConfigType) return AxiConfigType;
248 
249  -- Calculate number of txns in a burst based on number of bytes and bus configuration
250  -- Returned value is number of txns-1, so can be assigned to AWLEN/ARLEN
251  function getAxiLen (
252  axiConfig : AxiConfigType;
253  burstBytes : integer range 1 to 4096 := 4096)
254  return slv;
255 
256  -- Calculate number of txns in a burst based upon burst size, total remaining bytes,
257  -- current address and bus configuration.
258  -- Address is used to set a transaction size aligned to 4k boundaries
259  -- Returned value is number of txns-1, so can be assigned to AWLEN/ARLEN
260  function getAxiLen (
261  axiConfig : AxiConfigType;
262  burstBytes : integer range 1 to 4096 := 4096;
263  totalBytes : slv;
264  address : slv)
265  return slv;
266 
267  -- Caclulate the byte count for a read request
268  function getAxiReadBytes (
269  axiConfig : AxiConfigType;
270  axiRead : AxiReadMasterType)
271  return slv;
272 
273 end package AxiPkg;
274 
275 package body AxiPkg is
276 
277  function axiConfig (
278  constant ADDR_WIDTH_C : in positive range 12 to 64 := 32;
279  constant DATA_BYTES_C : in positive range 1 to 128 := 4;
280  constant ID_BITS_C : in positive range 1 to 32 := 12;
281  constant LEN_BITS_C : in natural range 0 to 8 := 4)
282  return AxiConfigType is
283  variable ret : AxiConfigType;
284  begin
285  ret := (
288  ID_BITS_C => ID_BITS_C,
290  return ret;
291  end function axiConfig;
292 
293 "01""1111" function axiWriteMasterInit (
294  constant AXI_CONFIG_C : in AxiConfigType;
295  bready : in sl := '0';
296  constant AXI_BURST_C : in slv(1 downto 0) := ;
297  constant AXI_CACHE_C : in slv(3 downto 0) := )
298  return AxiWriteMasterType is
299  variable ret : AxiWriteMasterType;
300  begin
302  ret.awsize := toSlv(log2(AXI_CONFIG_C.DATA_BYTES_C), 3);
303  ret.awlen := getAxiLen(AXI_CONFIG_C, 4096);
304  ret.bready := bready;
305  ret.awburst := AXI_BURST_C;
306  ret.awcache := AXI_CACHE_C;
307  return ret;
308  end function axiWriteMasterInit;
309 
310 "01""1111" function axiReadMasterInit (
311  constant AXI_CONFIG_C : in AxiConfigType;
312  constant AXI_BURST_C : in slv(1 downto 0) := ;
313  constant AXI_CACHE_C : in slv(3 downto 0) := )
314  return AxiReadMasterType is
315  variable ret : AxiReadMasterType;
316  begin
317  ret := AXI_READ_MASTER_INIT_C;
318  ret.arsize := toSlv(log2(AXI_CONFIG_C.DATA_BYTES_C), 3);
319  ret.arlen := getAxiLen(AXI_CONFIG_C, 4096);
320  ret.arburst := AXI_BURST_C;
321  ret.arcache := AXI_CACHE_C;
322  return ret;
323  end function axiReadMasterInit;
324 
325  function ite (i : boolean; t : AxiConfigType; e : AxiConfigType) return AxiConfigType is
326  begin
327  if (i) then return t; else return e; end if;
328  end function ite;
329 
330  function getAxiLen (
331  axiConfig : AxiConfigType;
332  burstBytes : integer range 1 to 4096 := 4096)
333  return slv is
334  begin
335  -- burstBytes / data bytes width is number of txns required.
336  -- Subtract by 1 for A*LEN value for even divides.
337  -- Convert to SLV and truncate to size of A*LEN port for this AXI bus
338  -- This limits number of txns approraiately based on size of len port
339  -- Then resize to 8 bits because our records define A*LEN as 8 bits always.
340  return resize(toSlv(wordCount(burstBytes,axiConfig.DATA_BYTES_C)-1, axiConfig.LEN_BITS_C), 8);
341  end function getAxiLen;
342 
343  -- Calculate number of txns in a burst based upon burst size, total remaining bytes,
344  -- current address and bus configuration.
345  -- Address is used to set a transaction size aligned to 4k boundaries
346  -- Returned value is number of txns-1, so can be assigned to AWLEN/ARLEN
347  function getAxiLen (
348  axiConfig : AxiConfigType;
349  burstBytes : integer range 1 to 4096 := 4096;
350  totalBytes : slv;
351  address : slv)
352  return slv is
353  variable max : natural;
354  variable req : natural;
355  variable maxLen : slv(7 downto 0);
356  begin
357 
358  max := 4096 - conv_integer(address(11 downto 0));
359  req := minimum(conv_integer(totalBytes),burstBytes);
360 
361  return getAxiLen(axiConfig,minimum(req,max));
362 
363  end function getAxiLen;
364 
365  -- Calculate the byte count for a read request
366  function getAxiReadBytes (
367  axiConfig : AxiConfigType;
368  axiRead : AxiReadMasterType)
369  return slv is
370  constant addrLsb : natural := bitSize(AxiConfig.DATA_BYTES_C-1);
371  variable tempSlv : slv(AxiConfig.LEN_BITS_C+addrLsb downto 0);
372  begin
373  tempSlv := (others=>'0');
374 
375  tempSlv(AxiConfig.LEN_BITS_C+addrLsb downto addrLsb)
376  := axiRead.arlen(AxiConfig.LEN_BITS_C-1 downto 0) + toSlv(1,AxiConfig.LEN_BITS_C+1);
377 
378  tempSlv := tempSlv - axiRead.araddr(addrLsb-1 downto 0);
379 
380  return(tempSlv);
381  end function getAxiReadBytes;
382 
383 end package body AxiPkg;
384 
AxiWriteSlaveType :=(awready => '0',wready => '0',bresp =>( others => '0'),bvalid => '0',bid =>( others => '0')) AXI_WRITE_SLAVE_INIT_C
Definition: AxiPkg.vhd:182
slv( 7 downto 0) arlen
Definition: AxiPkg.vhd:37
AxiReadMasterType :=(arvalid => '0',araddr =>( others => '0'),arid =>( others => '0'),arlen =>( others => '0'),arsize =>( others => '0'),arburst =>( others => '0'),arlock =>( others => '0'),arprot =>( others => '0'),arcache =>( others => '0'),arqos =>( others => '0'),arregion =>( others => '0'),rready => '0') AXI_READ_MASTER_INIT_C
Definition: AxiPkg.vhd:49
slv( 1023 downto 0) rdata
Definition: AxiPkg.vhd:83
sl rready
Definition: AxiPkg.vhd:46
AxiCtrlType
Definition: AxiPkg.vhd:198
slv( 31 downto 0) rid
Definition: AxiPkg.vhd:86
array(natural range <> ) of AxiReadSlaveType AxiReadSlaveArray
Definition: AxiPkg.vhd:89
slv( 2 downto 0) awprot
Definition: AxiPkg.vhd:117
slv( 1 downto 0) rresp
Definition: AxiPkg.vhd:87
sl wvalid
Definition: AxiPkg.vhd:124
_library_ ieeeieee
slv( 1 downto 0) awlock
Definition: AxiPkg.vhd:116
sl bvalid
Definition: AxiPkg.vhd:178
sl rvalid
Definition: AxiPkg.vhd:85
std_logic sl
Definition: StdRtlPkg.vhd:28
sl wlast
Definition: AxiPkg.vhd:123
slv( 1023 downto 0) wdata
Definition: AxiPkg.vhd:122
slv( 7 downto 0) awlen
Definition: AxiPkg.vhd:113
sl overflow
Definition: AxiPkg.vhd:200
slv( 2 downto 0) awsize
Definition: AxiPkg.vhd:114
sl awready
Definition: AxiPkg.vhd:173
sl bready
Definition: AxiPkg.vhd:128
slv( 3 downto 0) arcache
Definition: AxiPkg.vhd:42
sl arready
Definition: AxiPkg.vhd:81
AxiReadSlaveType :=(arready => '1',rdata =>( others => '0'),rlast => '0',rvalid => '0',rid =>( others => '0'),rresp =>( others => '0')) AXI_READ_SLAVE_FORCE_C
Definition: AxiPkg.vhd:97
slv( 127 downto 0) wstrb
Definition: AxiPkg.vhd:126
AxiCtrlType :=(pause => '0',overflow => '0') AXI_CTRL_UNUSED_C
Definition: AxiPkg.vhd:206
slv( 3 downto 0) awqos
Definition: AxiPkg.vhd:119
slv( 31 downto 0) bid
Definition: AxiPkg.vhd:179
AxiWriteMasterType axiWriteMasterInitAXI_CONFIG_C,bready,AXI_BURST_C,AXI_CACHE_C,
Definition: AxiPkg.vhd:233
positive range 12 to 64 ADDR_WIDTH_C
Definition: AxiPkg.vhd:214
AxiReadSlaveType
Definition: AxiPkg.vhd:79
AxiWriteMasterType
Definition: AxiPkg.vhd:108
slv( 3 downto 0) arqos
Definition: AxiPkg.vhd:43
AxiReadMasterType axiReadMasterInitAXI_CONFIG_C,AXI_BURST_C,AXI_CACHE_C,
Definition: AxiPkg.vhd:241
AxiConfigType axiConfigADDR_WIDTH_C,DATA_BYTES_C,ID_BITS_C,LEN_BITS_C,
Definition: AxiPkg.vhd:220
slv( 3 downto 0) awregion
Definition: AxiPkg.vhd:120
sl wready
Definition: AxiPkg.vhd:175
slv( 31 downto 0) arid
Definition: AxiPkg.vhd:36
sl awvalid
Definition: AxiPkg.vhd:110
slv( 3 downto 0) arregion
Definition: AxiPkg.vhd:44
slv( 63 downto 0) araddr
Definition: AxiPkg.vhd:35
sl pause
Definition: AxiPkg.vhd:199
AxiConfigType
Definition: AxiPkg.vhd:213
slv( 2 downto 0) arsize
Definition: AxiPkg.vhd:38
slv getAxiLenaxiConfig,burstBytes,
Definition: AxiPkg.vhd:251
AxiWriteSlaveType
Definition: AxiPkg.vhd:171
slv( 31 downto 0) wid
Definition: AxiPkg.vhd:125
slv( 1 downto 0) awburst
Definition: AxiPkg.vhd:115
slv( 1 downto 0) arburst
Definition: AxiPkg.vhd:39
AxiReadMasterType :=(arvalid => '0',araddr =>( others => '0'),arid =>( others => '0'),arlen =>( others => '0'),arsize =>( others => '0'),arburst =>( others => '0'),arlock =>( others => '0'),arprot =>( others => '0'),arcache =>( others => '0'),arqos =>( others => '0'),arregion =>( others => '0'),rready => '1') AXI_READ_MASTER_FORCE_C
Definition: AxiPkg.vhd:62
slv( 3 downto 0) awcache
Definition: AxiPkg.vhd:118
array(natural range <> ) of AxiReadMasterType AxiReadMasterArray
Definition: AxiPkg.vhd:48
array(natural range <> ) of AxiWriteMasterType AxiWriteMasterArray
Definition: AxiPkg.vhd:130
slv( 63 downto 0) awaddr
Definition: AxiPkg.vhd:111
positive range 1 to 128 DATA_BYTES_C
Definition: AxiPkg.vhd:215
AxiCtrlType :=(pause => '1',overflow => '0') AXI_CTRL_INIT_C
Definition: AxiPkg.vhd:203
sl rlast
Definition: AxiPkg.vhd:84
slv( 1 downto 0) arlock
Definition: AxiPkg.vhd:40
slv( 31 downto 0) awid
Definition: AxiPkg.vhd:112
AxiConfigType itei,t,e,
Definition: AxiPkg.vhd:247
slv getAxiReadBytesaxiConfig,axiRead,
Definition: AxiPkg.vhd:268
array(natural range <> ) of AxiWriteSlaveType AxiWriteSlaveArray
Definition: AxiPkg.vhd:181
slv( 1 downto 0) bresp
Definition: AxiPkg.vhd:177
AxiConfigType :=axiConfig(ADDR_WIDTH_C => 32,DATA_BYTES_C => 4,ID_BITS_C => 12,LEN_BITS_C => 4) AXI_CONFIG_INIT_C
Definition: AxiPkg.vhd:227
positive range 1 to 32 ID_BITS_C
Definition: AxiPkg.vhd:216
AxiWriteMasterType :=(awvalid => '0',awaddr =>( others => '0'),awid =>( others => '0'),awlen =>( others => '0'),awsize =>( others => '0'),awburst =>( others => '0'),awlock =>( others => '0'),awprot =>( others => '0'),awcache =>( others => '0'),awqos =>( others => '0'),awregion =>( others => '0'),wdata =>( others => '0'),wlast => '0',wvalid => '0',wid =>( others => '0'),wstrb =>( others => '0'),bready => '0') AXI_WRITE_MASTER_INIT_C
Definition: AxiPkg.vhd:131
array(natural range <> ) of AxiCtrlType AxiCtrlArray
Definition: AxiPkg.vhd:202
AxiReadMasterType
Definition: AxiPkg.vhd:32
slv( 2 downto 0) arprot
Definition: AxiPkg.vhd:41
AxiWriteMasterType :=(awvalid => '0',awaddr =>( others => '0'),awid =>( others => '0'),awlen =>( others => '0'),awsize =>( others => '0'),awburst =>( others => '0'),awlock =>( others => '0'),awprot =>( others => '0'),awcache =>( others => '0'),awqos =>( others => '0'),awregion =>( others => '0'),wdata =>( others => '0'),wlast => '0',wvalid => '0',wid =>( others => '0'),wstrb =>( others => '0'),bready => '1') AXI_WRITE_MASTER_FORCE_C
Definition: AxiPkg.vhd:149
AxiWriteSlaveType :=(awready => '1',wready => '1',bresp =>( others => '0'),bvalid => '0',bid =>( others => '0')) AXI_WRITE_SLAVE_FORCE_C
Definition: AxiPkg.vhd:188
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
sl arvalid
Definition: AxiPkg.vhd:34
natural range 0 to 8 LEN_BITS_C
Definition: AxiPkg.vhd:217
AxiReadSlaveType :=(arready => '0',rdata =>( others => '0'),rlast => '0',rvalid => '0',rid =>( others => '0'),rresp =>( others => '0')) AXI_READ_SLAVE_INIT_C
Definition: AxiPkg.vhd:90