1 |
2 |
sinclairrf |
################################################################################
|
2 |
|
|
#
|
3 |
6 |
sinclairrf |
# Copyright 2013-2014, Sinclair R.F., Inc.
|
4 |
2 |
sinclairrf |
#
|
5 |
|
|
################################################################################
|
6 |
|
|
|
7 |
|
|
import math
|
8 |
|
|
import re;
|
9 |
|
|
|
10 |
|
|
from ssbccPeripheral import SSBCCperipheral
|
11 |
|
|
from ssbccUtil import SSBCCException;
|
12 |
|
|
|
13 |
|
|
class AXI4_Lite_Master(SSBCCperipheral):
|
14 |
|
|
"""
|
15 |
|
|
AXI-Lite master for 32-bit reads and 8, 16, and 32-bit writes.\n
|
16 |
|
|
256 bytes addressable by a single 8-bit value. The data is stored in little
|
17 |
|
|
endian format (i.e., the LSB of the 32-bit word is stored in the lowest
|
18 |
|
|
numbered address).\n
|
19 |
|
|
Usage:
|
20 |
3 |
sinclairrf |
PERIPHERAL AXI4_Lite_Master \\
|
21 |
|
|
basePortName=<name> \\
|
22 |
|
|
address=<O_address> \\
|
23 |
|
|
data=<O_data> \\
|
24 |
|
|
command_read=<O_command_read> \\
|
25 |
|
|
command_write=<O_command_write> \\
|
26 |
|
|
busy=<I_busy> \\
|
27 |
|
|
error=<I_error> \\
|
28 |
|
|
read=<I_read> \\
|
29 |
|
|
address_width=<N> \\
|
30 |
|
|
synchronous={True|False} \\
|
31 |
|
|
write_enable=<O_write_enable>|noWSTRB\n
|
32 |
2 |
sinclairrf |
Where:
|
33 |
|
|
basePortName=<name>
|
34 |
|
|
specifies the name used to construct the multiple AXI4-Lite signals
|
35 |
|
|
address=<O_address>
|
36 |
|
|
specifies the symbol used to set the address used for read and write
|
37 |
|
|
operations from and to the dual-port memory
|
38 |
|
|
Note: If the address is 8 bits or less, a single write to this port will
|
39 |
|
|
set the address. If the address is 9 bits or longer, then multiple
|
40 |
|
|
writes to this address, starting with the MSB of the address, are
|
41 |
|
|
required to set all of the address bits. See the examples for
|
42 |
|
|
illustrations of how this works.
|
43 |
|
|
Note: The 2 lsb of the address are ignored. I.e., all addresses will be
|
44 |
|
|
treated as 32-bit aligned.
|
45 |
|
|
data=<O_data>
|
46 |
|
|
specifies the symbol used to set the 32-bit data for write operations
|
47 |
|
|
Note: Four outputs to this address are required, starting with the MSB of
|
48 |
|
|
the 32-bit value, See the examples for illustrations of how this
|
49 |
|
|
works.
|
50 |
|
|
command_read=<O_command_read>
|
51 |
|
|
specifies the symbol used to start the AXI4-Lite master core to issue a
|
52 |
|
|
read and store the received data
|
53 |
|
|
command_write=<O_command_write>
|
54 |
|
|
specifies the symbol used to start the AXI4-Lite master core to issue a
|
55 |
|
|
write
|
56 |
|
|
busy=<I_busy>
|
57 |
|
|
specifies the symbol used to read the busy/not-busy status of the core
|
58 |
|
|
Note: A non-zero value means the core is busy.
|
59 |
|
|
error=<I_error>
|
60 |
|
|
specified the symbol used to read the error status of the last write or
|
61 |
|
|
read transaction on the core
|
62 |
|
|
Note: A non-zero value means an error was encountered. Errors can be
|
63 |
|
|
reset by resetting the interface or by re-attempting the write or
|
64 |
|
|
read operation.
|
65 |
|
|
read=<I_read>
|
66 |
|
|
specifies the symbol used to read successive bytes of the received 32-bit
|
67 |
|
|
value starting with the LSB
|
68 |
|
|
address_width=<N>
|
69 |
|
|
specifies the width of the 8-bit aligned address\n
|
70 |
|
|
synchronous={True|False}
|
71 |
|
|
indicates whether or not he micro controller clock and the AXI4-Lite bus
|
72 |
|
|
are synchronous
|
73 |
3 |
sinclairrf |
write_enable=<O_write_enable>
|
74 |
|
|
optionally specify the symbol used to set the 4 write enable bits
|
75 |
|
|
Note: This must be used if one or more of the slaves includes the
|
76 |
6 |
sinclairrf |
optional WSTRB signals.
|
77 |
3 |
sinclairrf |
noWSTRB
|
78 |
|
|
indicates that the optional WSTRB signal should not be included
|
79 |
|
|
Note: This must be specified if write_enable is not specified.\n
|
80 |
|
|
Vivado Users:
|
81 |
|
|
The peripheral creates a TCL script to facilitate turning the micro
|
82 |
|
|
controller into an IP core. Look for a file with the name
|
83 |
|
|
"vivado_<basePortName>.tcl".\n
|
84 |
2 |
sinclairrf |
Example: Xilinx' AXI_DMA core has a 7-bit address range for its register
|
85 |
|
|
address map. The PERIPHERAL configuration statement to interface to this
|
86 |
|
|
core would be:\n
|
87 |
|
|
PERIPHERAL AXI4_Lite_Master \
|
88 |
|
|
basePortName=myAxiDmaDevice \
|
89 |
|
|
address=O_myAxiDmaDevice_address \
|
90 |
|
|
data=O_myAxiDmaDevice_data \
|
91 |
|
|
command_read=O_myAxiDmaDevice_cmd_read \
|
92 |
|
|
command_write=O_myAxiDmaDevice_cmd_write \
|
93 |
|
|
busy=I_myAxiDmaDevice_busy \
|
94 |
|
|
error=I_myAxiDmaDevice_error \
|
95 |
|
|
read=I_myAxiDmaDevice_read \
|
96 |
|
|
address_width=7 \
|
97 |
3 |
sinclairrf |
synchronous=True \\
|
98 |
|
|
write_enable=O_myAxiDmaDevice_wen\n
|
99 |
2 |
sinclairrf |
To write to the memory master to slave start address, use the
|
100 |
|
|
following, where "start_address" is a 4-byte variable set elsewhere in the
|
101 |
|
|
program:\n
|
102 |
|
|
; Set the 7-bit register address.
|
103 |
|
|
0x18 .outport(O_myAxiDmaDevice_address)
|
104 |
|
|
; Read the 4-byte start address from memory.
|
105 |
|
|
.fetchvector(start_address,4)
|
106 |
|
|
; write the address to the AXI4-Lite master
|
107 |
|
|
${4-1} :loop_data
|
108 |
|
|
swap .outport(O_myAxiDmaDevice_data)
|
109 |
|
|
.jumpc(loop_data,1-) drop
|
110 |
|
|
; Ensure all 4 bytes will be written.
|
111 |
|
|
0x0F .outport(O_myAxiDmaDevice_wen)
|
112 |
|
|
; Issue the write strobe.
|
113 |
|
|
.outstrobe(O_myAxiDmaDevice_cmd_write)
|
114 |
|
|
; Wait for the write operation to finish.
|
115 |
|
|
:loop_write_wait
|
116 |
|
|
.inport(I_myAxiDmaDevice_busy)
|
117 |
|
|
.jumpc(loop_write_wait)\n
|
118 |
|
|
Alternatively, a function could be defined as follows:\n
|
119 |
|
|
; Write the specified 32-bit value to the specified 7-bit address.
|
120 |
|
|
; ( u_LSB u u u_MSB u_addr - )
|
121 |
|
|
.function myAxiDmaDevice_write
|
122 |
|
|
; Write the 7-bit register address.
|
123 |
|
|
.outport(O_myAxiDmaDevice_address)
|
124 |
|
|
; Write the 32-bit value, starting with the MSB.
|
125 |
|
|
${4-1} :loop_data
|
126 |
|
|
swap .outport(O_myAxiDmaDevice_data)
|
127 |
|
|
.jumpc(loop_data,1-) drop
|
128 |
|
|
; Ensure all 4 bytes will be written.
|
129 |
|
|
0x0F .outport(O_myAxiDmaDevice_wen)
|
130 |
|
|
; Issue the write strobe.
|
131 |
|
|
.outstrobe(O_myAxiDmaDevice_cmd_write)
|
132 |
|
|
; Wait for the write operation to finish.
|
133 |
|
|
:loop_write_wait
|
134 |
|
|
.inport(I_myAxiDmaDevice_busy)
|
135 |
|
|
.jumpc(loop_write_wait)
|
136 |
|
|
; That's all
|
137 |
|
|
.return\n
|
138 |
|
|
And the write could then be performed using the following code:\n
|
139 |
|
|
.constant AXI_DMA_MM2S_Start_Address 0x18
|
140 |
|
|
...
|
141 |
|
|
; Write the start address to the AXI DMA.
|
142 |
|
|
.fetchvector(start_address,4)
|
143 |
|
|
.call(myAxiDmaDevice_write,AXI_DMA_MM2S_Start_Address)\n
|
144 |
|
|
Example: Suppose the AXI4-Lite Master peripheral is connected to a memory
|
145 |
|
|
with a 22-bit address width, i.e., a 4 MB address range. The PERIPHERAL
|
146 |
|
|
configuration command would be similar to the above except the string
|
147 |
|
|
"myAxiDmaDevice" would need to be changed to the new hardware peripheral and
|
148 |
|
|
the address width would be set using "address_width=22".\n
|
149 |
|
|
The 22-bit address would be set using 3 bytes. For example, the address
|
150 |
|
|
0x020100 would be set by:\n
|
151 |
|
|
0x00 .outport(O_myAxiMaster_address)
|
152 |
|
|
0x01 .outport(O_myAxiMaster_address)
|
153 |
|
|
0x02 .outport(O_myAxiMaster_address)\n
|
154 |
|
|
The 2 msb of the first, most-significant, address byte will be dropped by
|
155 |
|
|
the shift register receiving the address and the 2 lsb of the last, least
|
156 |
|
|
significant, address byte will be written as zeros to the AXI Lite
|
157 |
|
|
peripheral.\n
|
158 |
|
|
LEGAL NOTICE: ARM has restrictions on what kinds of applications can use
|
159 |
|
|
interfaces based on their AXI protocol. Ensure your application is in
|
160 |
|
|
compliance with their restrictions before using this peripheral for an AXI
|
161 |
|
|
interface.
|
162 |
|
|
"""
|
163 |
|
|
|
164 |
|
|
def __init__(self,peripheralFile,config,param_list,loc):
|
165 |
|
|
# Use the externally provided file name for the peripheral
|
166 |
|
|
self.peripheralFile = peripheralFile;
|
167 |
|
|
# Get the parameters.
|
168 |
|
|
allowables = (
|
169 |
|
|
('address', r'O_\w+$', None, ),
|
170 |
|
|
('address_width', r'[1-9]\d*$', int, ),
|
171 |
|
|
('basePortName', r'\w+$', None, ),
|
172 |
|
|
('command_read', r'O_\w+$', None, ),
|
173 |
|
|
('command_write', r'O_\w+$', None, ),
|
174 |
|
|
('data', r'O_\w+$', None, ),
|
175 |
|
|
('read', r'I_\w+$', None, ),
|
176 |
|
|
('busy', r'I_\w+$', None, ),
|
177 |
|
|
('error', r'I_\w+$', None, ),
|
178 |
3 |
sinclairrf |
('noWSTRB', None, None, ),
|
179 |
2 |
sinclairrf |
('synchronous', r'(True|False)$', bool, ),
|
180 |
|
|
('write_enable', r'O_\w+$', None, ),
|
181 |
|
|
);
|
182 |
|
|
names = [a[0] for a in allowables];
|
183 |
|
|
for param_tuple in param_list:
|
184 |
|
|
param = param_tuple[0];
|
185 |
|
|
if param not in names:
|
186 |
|
|
raise SSBCCException('Unrecognized parameter "%s" at %s' % (param,loc,));
|
187 |
|
|
param_test = allowables[names.index(param)];
|
188 |
|
|
self.AddAttr(config,param,param_tuple[1],param_test[1],loc,param_test[2]);
|
189 |
3 |
sinclairrf |
# Ensure the required parameters are provided.
|
190 |
|
|
for paramname in (
|
191 |
6 |
sinclairrf |
'address',
|
192 |
|
|
'address_width',
|
193 |
|
|
'basePortName',
|
194 |
|
|
'command_read',
|
195 |
|
|
'command_write',
|
196 |
|
|
'data',
|
197 |
|
|
'read',
|
198 |
|
|
'busy',
|
199 |
|
|
'error',
|
200 |
|
|
'synchronous',
|
201 |
|
|
):
|
202 |
2 |
sinclairrf |
if not hasattr(self,paramname):
|
203 |
|
|
raise SSBCCException('Required parameter "%s" is missing at %s' % (paramname,loc,));
|
204 |
6 |
sinclairrf |
# Ensure exclusive pair configurations are set and consistent.
|
205 |
|
|
for exclusivepair in (
|
206 |
|
|
('write_enable','noWSTRB',None,None,),
|
207 |
|
|
):
|
208 |
|
|
if hasattr(self,exclusivepair[0]) and hasattr(self,exclusivepair[1]):
|
209 |
|
|
raise SSBCCException('Only one of "%s" and "%s" can be specified at %s' % (exclusivepair[0],exclusivepair[1],loc,));
|
210 |
|
|
if not hasattr(self,exclusivepair[0]) and not hasattr(self,exclusivepair[1]) and exclusivepair[2]:
|
211 |
|
|
setattr(self,exclusivepair[2],exclusivepair[3]);
|
212 |
3 |
sinclairrf |
# Ensure one and only one of the complementary optional values are set.
|
213 |
|
|
if not hasattr(self,'write_enable') and not hasattr(self,'noWSTRB'):
|
214 |
|
|
raise SSBCCException('One of "write_enable" or "noWSTRB" must be set at %s' % loc);
|
215 |
2 |
sinclairrf |
# Temporary: Warning message
|
216 |
|
|
if not self.synchronous:
|
217 |
|
|
raise SSBCCException('synchronous=False has not been validated yet');
|
218 |
|
|
# Add the I/O port, internal signals, and the INPORT and OUTPORT symbols for this peripheral.
|
219 |
|
|
for signal in (
|
220 |
6 |
sinclairrf |
( '%s_aresetn', 1, 'input', ),
|
221 |
|
|
( '%s_aclk', 1, 'input', ),
|
222 |
|
|
( '%s_awvalid', 1, 'output', ),
|
223 |
|
|
( '%s_awready', 1, 'input', ),
|
224 |
|
|
( '%s_awaddr', self.address_width, 'output', ),
|
225 |
|
|
( '%s_wvalid', 1, 'output', ),
|
226 |
|
|
( '%s_wready', 1, 'input', ),
|
227 |
|
|
( '%s_wdata', 32, 'output', ),
|
228 |
|
|
( '%s_wstrb', 4, 'output', ) if hasattr(self,'write_enable') else None,
|
229 |
|
|
( '%s_bresp', 2, 'input', ),
|
230 |
|
|
( '%s_bvalid', 1, 'input', ),
|
231 |
|
|
( '%s_bready', 1, 'output', ),
|
232 |
|
|
( '%s_arvalid', 1, 'output', ),
|
233 |
|
|
( '%s_arready', 1, 'input', ),
|
234 |
|
|
( '%s_araddr', self.address_width, 'output', ),
|
235 |
|
|
( '%s_rvalid', 1, 'input', ),
|
236 |
|
|
( '%s_rready', 1, 'output', ),
|
237 |
|
|
( '%s_rdata', 32, 'input', ),
|
238 |
|
|
( '%s_rresp', 2, 'input', ),
|
239 |
2 |
sinclairrf |
):
|
240 |
3 |
sinclairrf |
if not signal:
|
241 |
|
|
continue
|
242 |
2 |
sinclairrf |
thisName = signal[0] % self.basePortName;
|
243 |
|
|
config.AddIO(thisName,signal[1],signal[2],loc);
|
244 |
|
|
config.AddSignal('s__%s__address' % self.basePortName, self.address_width, loc);
|
245 |
|
|
config.AddSignal('s__%s__rd' % self.basePortName, 1, loc);
|
246 |
|
|
config.AddSignal('s__%s__wr' % self.basePortName, 1, loc);
|
247 |
|
|
config.AddSignal('s__%s__busy' % self.basePortName, 5, loc);
|
248 |
|
|
config.AddSignal('s__%s__error' % self.basePortName, 2, loc);
|
249 |
|
|
config.AddSignal('s__%s__read' % self.basePortName, 32, loc);
|
250 |
|
|
self.ix_address = config.NOutports();
|
251 |
|
|
config.AddOutport((self.address,False,
|
252 |
|
|
# empty list -- disable normal output port signal generation
|
253 |
|
|
),loc);
|
254 |
|
|
self.ix_data = config.NOutports();
|
255 |
|
|
config.AddOutport((self.data,False,
|
256 |
|
|
# empty list -- disable normal output port signal generation
|
257 |
|
|
),loc);
|
258 |
6 |
sinclairrf |
if hasattr(self,'write_enable'):
|
259 |
3 |
sinclairrf |
config.AddOutport((self.write_enable,False,
|
260 |
6 |
sinclairrf |
('%s_wstrb' % self.basePortName, 4, 'data', ),
|
261 |
2 |
sinclairrf |
),loc);
|
262 |
|
|
config.AddOutport((self.command_read,True,
|
263 |
|
|
('s__%s__rd' % self.basePortName, 1, 'strobe', ),
|
264 |
|
|
),loc);
|
265 |
|
|
config.AddOutport((self.command_write,True,
|
266 |
|
|
('s__%s__wr' % self.basePortName, 1, 'strobe', ),
|
267 |
|
|
),loc);
|
268 |
|
|
config.AddInport((self.busy,
|
269 |
|
|
('s__%s__busy' % self.basePortName, 5, 'data', ),
|
270 |
|
|
),loc);
|
271 |
|
|
config.AddInport((self.error,
|
272 |
|
|
('s__%s__error' % self.basePortName, 2, 'data', ),
|
273 |
|
|
),loc);
|
274 |
|
|
self.ix_read = config.NInports();
|
275 |
|
|
config.AddInport((self.read,
|
276 |
|
|
('s__%s__read' % self.basePortName, 32, 'data', ),
|
277 |
|
|
),loc);
|
278 |
|
|
|
279 |
|
|
def GenVerilog(self,fp,config):
|
280 |
|
|
body = self.LoadCore(self.peripheralFile,'.v');
|
281 |
|
|
# avoid i_clk and i_rst
|
282 |
|
|
for subpair in (
|
283 |
6 |
sinclairrf |
( r'\bgen__', 'gen__@NAME@__', ),
|
284 |
|
|
( r'\bL__', 'L__@NAME@__', ),
|
285 |
|
|
( r'\bs__', 's__@NAME@__', ),
|
286 |
|
|
( r'\bi_a', '@NAME@_a', ),
|
287 |
|
|
( r'\bi_b', '@NAME@_b', ),
|
288 |
|
|
( r'\bi_rd', '@NAME@_rd', ),
|
289 |
|
|
( r'\bi_rr', '@NAME@_rr', ),
|
290 |
|
|
( r'\bi_rv', '@NAME@_rv', ),
|
291 |
|
|
( r'\bi_w', '@NAME@_w', ),
|
292 |
|
|
( r'\bo_', '@NAME@_', ),
|
293 |
|
|
( r'@ADDRESS_WIDTH@', str(self.address_width), ),
|
294 |
|
|
( r'@ISSYNC@', "1'b1" if self.synchronous else "1'b0", ),
|
295 |
|
|
( r'@IX_ADDRESS@', str(self.ix_address), ),
|
296 |
|
|
( r'@IX_DATA@', str(self.ix_data), ),
|
297 |
|
|
( r'@IX_READ@', str(self.ix_read), ),
|
298 |
|
|
( r'@NAME@', self.basePortName, ),
|
299 |
|
|
):
|
300 |
2 |
sinclairrf |
body = re.sub(subpair[0],subpair[1],body);
|
301 |
|
|
body = self.GenVerilogFinal(config,body);
|
302 |
|
|
fp.write(body);
|