622feb0bf6e2fd8eb9992ea20cfea25fdf908500
2 from copy
import deepcopy
6 def __init__(self
, name
):
9 def slowifdeclmux(self
):
12 def slowifinstance(self
):
18 def num_axi_regs32(self
):
24 def axibase(self
, name
, ifacenum
):
26 return "%(name)s%(ifacenum)dBase" % locals()
28 def axiend(self
, name
, ifacenum
):
30 return "%(name)s%(ifacenum)dEnd" % locals()
32 def axi_reg_def(self
, start
, name
, ifacenum
):
34 offs
= self
.num_axi_regs32() * 4 * 16
37 end
= start
+ offs
- 1
38 bname
= self
.axibase(name
, ifacenum
)
39 bend
= self
.axiend(name
, ifacenum
)
40 comment
= "%d 32-bit regs" % self
.num_axi_regs32()
41 return (" `define %(bname)s 'h%(start)08X\n"
42 " `define %(bend)s 'h%(end)08X // %(comment)s" % locals(),
45 def axi_slave_name(self
, name
, ifacenum
):
47 return "{0}{1}_slave_num".format(name
, ifacenum
)
49 def axi_slave_idx(self
, idx
, name
, ifacenum
):
50 name
= self
.axi_slave_name(name
, ifacenum
)
51 return ("typedef {0} {1};".format(idx
, name
), 1)
53 def axi_addr_map(self
, name
, ifacenum
):
54 bname
= self
.axibase(name
, ifacenum
)
55 bend
= self
.axiend(name
, ifacenum
)
56 name
= self
.axi_slave_name(name
, ifacenum
)
58 if(addr>=`{0} && addr<=`{1})
59 return tuple2(True,fromInteger(valueOf({2})));
60 else""".format(bname
, bend
, name
)
62 def mk_pincon(self
, name
, count
):
63 # TODO: really should be using bsv.interface_decl.Interfaces
64 # pin-naming rules.... logic here is hard-coded to duplicate
65 # it (see Interface.__init__ outen)
67 for p
in self
.peripheral
.pinspecs
:
70 #n = "{0}{1}".format(self.name, self.mksuffix(name, count))
71 n
= name
# "{0}{1}".format(self.name, self.mksuffix(name, count))
72 ret
.append(" //%s %s" % (n
, str(p
)))
73 sname
= self
.peripheral
.pname(pname
).format(count
)
74 ps
= "pinmux.peripheral_side.%s" % sname
75 if typ
== 'out' or typ
== 'inout':
76 ret
.append(" rule con_%s%d_%s_out;" % (name
, count
, pname
))
77 fname
= self
.pinname_out(pname
)
78 if not n
.startswith('gpio'): # XXX EURGH! horrible hack
79 n_
= "{0}{1}".format(n
, count
)
87 ret
.append(" {0}({1}.{2});".format(ps_
, n_
, fname
))
90 fname
= self
.pinname_outen(pname
)
92 if isinstance(fname
, str):
93 fname
= "{0}.{1}".format(n_
, fname
)
94 fname
= self
.pinname_tweak(pname
, 'outen', fname
)
95 ret
.append(" {0}_outen({1});".format(ps
, fname
))
96 ret
.append(" endrule")
97 if typ
== 'in' or typ
== 'inout':
98 fname
= self
.pinname_in(pname
)
105 " rule con_%s%d_%s_in;" %
106 (name
, count
, pname
))
107 n_
= "{0}{1}".format(n
, count
)
108 n_
= '{0}.{1}'.format(n_
, fname
)
109 n_
= self
.ifname_tweak(pname
, 'in', n_
)
110 ret
.append(" {1}({0});".format(ps_
, n_
))
111 ret
.append(" endrule")
112 return '\n'.join(ret
)
114 def mk_cellconn(self
, *args
):
117 def mkslow_peripheral(self
, size
=0):
120 def mksuffix(self
, name
, i
):
123 def __mk_connection(self
, con
, aname
):
124 txt
= " mkConnection (slow_fabric.v_to_slaves\n" + \
125 " [fromInteger(valueOf({1}))],\n" + \
128 print "PBase __mk_connection", self
.name
, aname
131 return txt
.format(con
, aname
)
133 def mk_connection(self
, count
, name
=None):
136 print "PBase mk_conn", self
.name
, count
137 aname
= self
.axi_slave_name(name
, count
)
138 #dname = self.mksuffix(name, count)
139 #dname = "{0}{1}".format(name, dname)
140 con
= self
._mk
_connection
(name
, count
).format(count
, aname
)
141 return self
.__mk
_connection
(con
, aname
)
143 def _mk_connection(self
, name
=None, count
=0):
146 def pinname_out(self
, pname
):
149 def pinname_in(self
, pname
):
152 def pinname_outen(self
, pname
):
155 def ifname_tweak(self
, pname
, typ
, txt
):
158 def pinname_tweak(self
, pname
, typ
, txt
):
164 def mk_plic(self
, inum
, irq_offs
):
166 print "mk_plic", self
.name
, inum
, irq_offs
167 niq
= self
.num_irqs()
169 return ('', irq_offs
)
170 for idx
in range(niq
):
171 name
= "{0}{1}".format(self
.name
, self
.mksuffix(self
.name
, inum
))
172 plic_obj
= self
.plic_object(name
, idx
)
173 print "plic_obj", name
, idx
, plic_obj
174 plic
= mkplic_rule
.format(self
.name
, plic_obj
, irq_offs
)
176 irq_offs
+= 1 # increment to next irq
177 return ('\n'.join(res
), irq_offs
)
181 rule rl_connect_{0}_to_plic_{2};
182 if({1} == 1'b1) begin
183 ff_gateway_queue[{2}].enq(1);
184 plic.ifc_external_irq[{2}].irq_frm_gateway(True);
191 def slowimport(self
):
192 return " import Uart_bs :: *;\n" + \
193 " import RS232_modified::*;"
195 def slowifdecl(self
):
196 return " interface RS232 uart{0}_coe;\n" + \
197 " method Bit#(1) uart{0}_intr;"
199 def num_axi_regs32(self
):
202 def mkslow_peripheral(self
, size
=0):
203 return " Ifc_Uart_bs uart{0} <- \n" + \
204 " mkUart_bs(clocked_by sp_clock,\n" + \
205 " reset_by uart_reset, sp_clock, sp_reset);"
207 def _mk_connection(self
, name
=None, count
=0):
208 return "uart{0}.slave_axi_uart"
210 def pinname_out(self
, pname
):
211 return {'tx': 'coe_rs232.sout'}.get(pname
, '')
213 def pinname_in(self
, pname
):
214 return {'rx': 'coe_rs232.sin'}.get(pname
, '')
219 def slowimport(self
):
220 return " import Uart16550 :: *;"
222 def slowifdecl(self
):
223 return " interface RS232_PHY_Ifc quart{0}_coe;\n" + \
224 " method Bit#(1) quart{0}_intr;"
226 def num_axi_regs32(self
):
229 def mkslow_peripheral(self
, size
=0):
230 return " Uart16550_AXI4_Lite_Ifc quart{0} <- \n" + \
231 " mkUart16550(clocked_by sp_clock,\n" + \
232 " reset_by uart_reset, sp_clock, sp_reset);"
234 def _mk_connection(self
, name
=None, count
=0):
235 return "quart{0}.slave_axi_uart"
237 def pinname_out(self
, pname
):
238 return {'tx' : 'coe_rs232.modem_output_stx',
239 'rts': 'coe_rs232.modem_output_rts',
242 def _pinname_in(self
, pname
):
243 return {'rx': 'coe_rs232.modem_input.srx',
244 'cts': 'coe_rs232.modem_input.cts'
247 def mk_pincon(self
, name
, count
):
248 ret
= [PBase
.mk_pincon(self
, name
, count
)]
249 size
= len(self
.peripheral
.pinspecs
)
250 ret
.append(eint_pincon_template
.format(size
))
251 ret
.append(" rule con_%s%d_io_in;" % (name
, count
))
252 ret
.append(" {0}{1}.coe_rs232.modem_input(".format(name
, count
))
253 for idx
, pname
in enumerate(['rx', 'cts']):
254 sname
= self
.peripheral
.pname(pname
).format(count
)
255 ps
= "pinmux.peripheral_side.%s" % sname
256 ret
.append(" {0},".format(ps
))
257 ret
.append(" 1'b1,1'b0,1'b1")
259 ret
.append(" endrule")
261 return '\n'.join(ret
)
266 def slowimport(self
):
267 return " import Uart_bs::*;\n" + \
268 " import RS232_modified::*;"
270 def slowifdecl(self
):
271 return " interface RS232 uart{0}_coe;"
273 def num_axi_regs32(self
):
276 def mkslow_peripheral(self
, size
=0):
277 return " //Ifc_Uart_bs uart{0} <-" + \
278 " // mkUart_bs(clocked_by uart_clock,\n" + \
279 " // reset_by uart_reset,sp_clock, sp_reset);" +\
280 " Ifc_Uart_bs uart{0} <-" + \
281 " mkUart_bs(clocked_by sp_clock,\n" + \
282 " reset_by sp_reset, sp_clock, sp_reset);"
284 def _mk_connection(self
, name
=None, count
=0):
285 return "uart{0}.slave_axi_uart"
287 def pinname_out(self
, pname
):
288 return {'tx': 'coe_rs232.sout'}.get(pname
, '')
290 def pinname_in(self
, pname
):
291 return {'rx': 'coe_rs232.sin'}.get(pname
, '')
296 def slowimport(self
):
297 return " import I2C_top :: *;"
299 def slowifdecl(self
):
300 return " interface I2C_out twi{0}_out;\n" + \
301 " method Bit#(1) twi{0}_isint;"
306 def num_axi_regs32(self
):
309 def mkslow_peripheral(self
, size
=0):
310 return " I2C_IFC twi{0} <- mkI2CController();"
312 def _mk_connection(self
, name
=None, count
=0):
313 return "twi{0}.slave_i2c_axi"
315 def pinname_out(self
, pname
):
316 return {'sda': 'out.sda_out',
317 'scl': 'out.scl_out'}.get(pname
, '')
319 def pinname_in(self
, pname
):
320 return {'sda': 'out.sda_in',
321 'scl': 'out.scl_in'}.get(pname
, '')
323 def pinname_outen(self
, pname
):
324 return {'sda': 'out.sda_out_en',
325 'scl': 'out.scl_out_en'}.get(pname
, '')
327 def pinname_tweak(self
, pname
, typ
, txt
):
329 return "pack({0})".format(txt
)
332 def plic_object(self
, pname
, idx
):
333 return ["{0}.isint()",
341 def slowimport(self
):
342 size
= len(self
.peripheral
.pinspecs
)
343 return " `define NUM_EINTS %d" % size
345 def mkslow_peripheral(self
, size
=0):
346 size
= len(self
.peripheral
.pinspecs
)
347 return " Wire#(Bit#(%d)) wr_interrupt <- mkWire();" % size
349 def axi_slave_name(self
, name
, ifacenum
):
352 def axi_slave_idx(self
, idx
, name
, ifacenum
):
355 def axi_addr_map(self
, name
, ifacenum
):
358 def ifname_tweak(self
, pname
, typ
, txt
):
361 print "ifnameweak", pname
, typ
, txt
362 return "wr_interrupt[{0}] <= ".format(pname
)
364 def mk_pincon(self
, name
, count
):
365 ret
= [PBase
.mk_pincon(self
, name
, count
)]
366 size
= len(self
.peripheral
.pinspecs
)
367 ret
.append(eint_pincon_template
.format(size
))
368 ret
.append(" rule con_%s%d_io_in;" % (name
, count
))
369 ret
.append(" wr_interrupt <= ({")
370 for idx
, p
in enumerate(self
.peripheral
.pinspecs
):
372 sname
= self
.peripheral
.pname(pname
).format(count
)
373 ps
= "pinmux.peripheral_side.%s" % sname
374 comma
= '' if idx
== size
- 1 else ','
375 ret
.append(" {0}{1}".format(ps
, comma
))
377 ret
.append(" endrule")
379 return '\n'.join(ret
)
382 eint_pincon_template
= '''\
383 // TODO: offset i by the number of eints already used
384 for(Integer i=0;i<{0};i=i+ 1)begin
385 rule connect_int_to_plic(wr_interrupt[i]==1);
386 ff_gateway_queue[i].enq(1);
387 plic.ifc_external_irq[i].irq_frm_gateway(True);
395 def axi_slave_name(self
, name
, ifacenum
):
398 def axi_slave_idx(self
, idx
, name
, ifacenum
):
401 def axi_addr_map(self
, name
, ifacenum
):
404 def slowifdeclmux(self
):
405 return " method Action jtag_ms (Bit#(1) in);\n" + \
406 " method Bit#(1) jtag_di;\n" + \
407 " method Action jtag_do (Bit#(1) in);\n" + \
408 " method Action jtag_ck (Bit#(1) in);"
410 def slowifinstance(self
):
411 return jtag_method_template
# bit of a lazy hack this...
413 jtag_method_template
= """\
414 method Action jtag_ms (Bit#(1) in);
415 pinmux.peripheral_side.jtag_ms(in);
417 method Bit#(1) jtag_di=pinmux.peripheral_side.jtag_di;
418 method Action jtag_do (Bit#(1) in);
419 pinmux.peripheral_side.jtag_do(in);
421 method Action jtag_ck (Bit#(1) in);
422 pinmux.peripheral_side.jtag_ck(in);
428 def slowimport(self
):
429 return " import sdcard_dummy :: *;"
431 def slowifdecl(self
):
432 return " interface QSPI_out sd{0}_out;\n" + \
433 " method Bit#(1) sd{0}_isint;"
435 def num_axi_regs32(self
):
438 def mkslow_peripheral(self
):
439 return " Ifc_sdcard_dummy sd{0} <- mksdcard_dummy();"
441 def _mk_connection(self
, name
=None, count
=0):
444 def pinname_in(self
, pname
):
445 return "%s_in" % pname
447 def pinname_out(self
, pname
):
448 if pname
.startswith('d'):
449 return "%s_out" % pname
452 def pinname_outen(self
, pname
):
453 if pname
.startswith('d'):
454 return "%s_outen" % pname
459 def slowimport(self
):
460 return " import qspi :: *;"
462 def slowifdecl(self
):
463 return " interface QSPI_out spi{0}_out;\n" + \
464 " method Bit#(1) spi{0}_isint;"
466 def num_axi_regs32(self
):
469 def mkslow_peripheral(self
):
470 return " Ifc_qspi spi{0} <- mkqspi();"
472 def _mk_connection(self
, name
=None, count
=0):
473 return "spi{0}.slave"
475 def pinname_out(self
, pname
):
476 return {'clk': 'out.clk_o',
478 'mosi': 'out.io_o[0]',
479 'miso': 'out.io_o[1]',
482 def pinname_outen(self
, pname
):
485 'mosi': 'out.io_enable[0]',
486 'miso': 'out.io_enable[1]',
489 def mk_pincon(self
, name
, count
):
490 ret
= [PBase
.mk_pincon(self
, name
, count
)]
491 # special-case for gpio in, store in a temporary vector
492 plen
= len(self
.peripheral
.pinspecs
)
493 ret
.append(" // XXX NSS and CLK are hard-coded master")
494 ret
.append(" // TODO: must add spi slave-mode")
495 ret
.append(" // all ins done in one rule from 4-bitfield")
496 ret
.append(" rule con_%s%d_io_in;" % (name
, count
))
497 ret
.append(" {0}{1}.out.io_i({{".format(name
, count
))
498 for idx
, pname
in enumerate(['mosi', 'miso']):
499 sname
= self
.peripheral
.pname(pname
).format(count
)
500 ps
= "pinmux.peripheral_side.%s_in" % sname
501 ret
.append(" {0},".format(ps
))
502 ret
.append(" 1'b0,1'b0")
504 ret
.append(" endrule")
505 return '\n'.join(ret
)
510 def slowimport(self
):
511 return " import qspi :: *;"
513 def slowifdecl(self
):
514 return " interface QSPI_out qspi{0}_out;\n" + \
515 " method Bit#(1) qspi{0}_isint;"
517 def num_axi_regs32(self
):
520 def mkslow_peripheral(self
, size
=0):
521 return " Ifc_qspi qspi{0} <- mkqspi();"
523 def _mk_connection(self
, name
=None, count
=0):
524 return "qspi{0}.slave"
526 def pinname_out(self
, pname
):
527 return {'ck': 'out.clk_o',
529 'io0': 'out.io_o[0]',
530 'io1': 'out.io_o[1]',
531 'io2': 'out.io_o[2]',
532 'io3': 'out.io_o[3]',
535 def pinname_outen(self
, pname
):
538 'io0': 'out.io_enable[0]',
539 'io1': 'out.io_enable[1]',
540 'io2': 'out.io_enable[2]',
541 'io3': 'out.io_enable[3]',
544 def mk_pincon(self
, name
, count
):
545 ret
= [PBase
.mk_pincon(self
, name
, count
)]
546 # special-case for gpio in, store in a temporary vector
547 plen
= len(self
.peripheral
.pinspecs
)
548 ret
.append(" // XXX NSS and CLK are hard-coded master")
549 ret
.append(" // TODO: must add qspi slave-mode")
550 ret
.append(" // all ins done in one rule from 4-bitfield")
551 ret
.append(" rule con_%s%d_io_in;" % (name
, count
))
552 ret
.append(" {0}{1}.out.io_i({{".format(name
, count
))
553 for i
, p
in enumerate(self
.peripheral
.pinspecs
):
556 if not pname
.startswith('io'):
560 sname
= self
.peripheral
.pname(pname
).format(count
)
561 ps
= "pinmux.peripheral_side.%s_in" % sname
562 comma
= '' if i
== 5 else ','
563 ret
.append(" {0}{1}".format(ps
, comma
))
565 ret
.append(" endrule")
566 return '\n'.join(ret
)
571 def slowimport(self
):
572 return " import pwm::*;"
574 def slowifdecl(self
):
575 return " interface PWMIO pwm{0}_io;"
577 def num_axi_regs32(self
):
580 def mkslow_peripheral(self
, size
=0):
581 return " Ifc_PWM_bus pwm{0} <- mkPWM_bus(sp_clock);"
583 def _mk_connection(self
, name
=None, count
=0):
584 return "pwm{0}.axi4_slave"
586 def pinname_out(self
, pname
):
587 return {'out': 'pwm_io.pwm_o'}.get(pname
, '')
592 def slowimport(self
):
593 return " import pinmux::*;\n" + \
594 " import mux::*;\n" + \
597 def slowifdeclmux(self
):
598 size
= len(self
.peripheral
.pinspecs
)
599 return " interface GPIO_config#(%d) pad_config{0};" % size
601 def num_axi_regs32(self
):
604 def axi_slave_idx(self
, idx
, name
, ifacenum
):
605 """ generates AXI slave number definition, except
606 GPIO also has a muxer per bank
609 mname
= 'mux' + name
[4:]
610 mname
= mname
.upper()
611 print "AXIslavenum", name
, mname
612 (ret
, x
) = PBase
.axi_slave_idx(self
, idx
, name
, ifacenum
)
613 (ret2
, x
) = PBase
.axi_slave_idx(self
, idx
+ 1, mname
, ifacenum
)
614 return ("%s\n%s" % (ret
, ret2
), 2)
616 def mkslow_peripheral(self
, size
=0):
617 print "gpioslow", self
.peripheral
, dir(self
.peripheral
)
618 size
= len(self
.peripheral
.pinspecs
)
619 return " MUX#(%d) mux{0} <- mkmux();\n" % size
+ \
620 " GPIO#(%d) gpio{0} <- mkgpio();" % size
622 def mk_connection(self
, count
):
623 print "GPIO mk_conn", self
.name
, count
625 dname
= self
.mksuffix(self
.name
, count
)
626 for i
, n
in enumerate(['gpio' + dname
, 'mux' + dname
]):
627 res
.append(PBase
.mk_connection(self
, count
, n
))
628 return '\n'.join(res
)
630 def _mk_connection(self
, name
=None, count
=0):
631 n
= self
.mksuffix(name
, count
)
632 if name
.startswith('gpio'):
633 return "gpio{0}.axi_slave".format(n
)
634 if name
.startswith('mux'):
635 return "mux{0}.axi_slave".format(n
)
637 def mksuffix(self
, name
, i
):
638 if name
.startswith('mux'):
642 def mk_cellconn(self
, cellnum
, name
, count
):
644 bank
= self
.mksuffix(name
, count
)
645 txt
= " pinmux.mux_lines.cell{0}_mux(mux{1}.mux_config.mux[{2}]);"
646 for p
in self
.peripheral
.pinspecs
:
647 ret
.append(txt
.format(cellnum
, bank
, p
['name'][1:]))
649 return ("\n".join(ret
), cellnum
)
651 def pinname_out(self
, pname
):
652 return "func.gpio_out[{0}]".format(pname
[1:])
654 def pinname_outen(self
, pname
):
655 return "func.gpio_out_en[{0}]".format(pname
[1:])
657 def mk_pincon(self
, name
, count
):
658 ret
= [PBase
.mk_pincon(self
, name
, count
)]
659 # special-case for gpio in, store in a temporary vector
660 plen
= len(self
.peripheral
.pinspecs
)
661 ret
.append(" rule con_%s%d_in;" % (name
, count
))
662 ret
.append(" Vector#({0},Bit#(1)) temp;".format(plen
))
663 for p
in self
.peripheral
.pinspecs
:
668 sname
= self
.peripheral
.pname(pname
).format(count
)
669 ps
= "pinmux.peripheral_side.%s_in" % sname
670 ret
.append(" temp[{0}]={1};".format(idx
, ps
))
671 ret
.append(" {0}.func.gpio_in(temp);".format(name
))
672 ret
.append(" endrule")
673 return '\n'.join(ret
)
676 axi_slave_declarations
= """\
677 typedef 0 SlowMaster;
679 typedef TAdd#(LastGen_slave_num,`ifdef CLINT 1 `else 0 `endif )
681 typedef TAdd#(CLINT_slave_num ,`ifdef PLIC 1 `else 0 `endif )
683 typedef TAdd#(Plic_slave_num ,`ifdef AXIEXP 1 `else 0 `endif )
685 typedef TAdd#(AxiExp1_slave_num,1) Num_Slow_Slaves;
688 pinmux_cellrule
= """\
689 rule connect_select_lines_pinmux;
695 class CallFn(object):
696 def __init__(self
, peripheral
, name
):
697 self
.peripheral
= peripheral
700 def __call__(self
, *args
):
701 #print "__call__", self.name, self.peripheral.slow, args
702 if not self
.peripheral
.slow
:
704 return getattr(self
.peripheral
.slow
, self
.name
)(*args
[1:])
707 class PeripheralIface(object):
708 def __init__(self
, ifacename
):
710 slow
= slowfactory
.getcls(ifacename
)
711 print "Iface", ifacename
, slow
713 self
.slow
= slow(ifacename
)
714 self
.slow
.peripheral
= self
715 for fname
in ['slowimport',
716 'slowifinstance', 'slowifdecl', 'slowifdeclmux',
717 'mkslow_peripheral', 'mk_plic',
718 'mk_connection', 'mk_cellconn', 'mk_pincon']:
719 fn
= CallFn(self
, fname
)
720 setattr(self
, fname
, types
.MethodType(fn
, self
))
722 #print "PeripheralIface"
725 def mksuffix(self
, name
, i
):
726 if self
.slow
is None:
728 return self
.slow
.mksuffix(name
, i
)
730 def axi_reg_def(self
, start
, count
):
733 return self
.slow
.axi_reg_def(start
, self
.ifacename
, count
)
735 def axi_slave_idx(self
, start
, count
):
738 return self
.slow
.axi_slave_idx(start
, self
.ifacename
, count
)
740 def axi_addr_map(self
, count
):
743 return self
.slow
.axi_addr_map(self
.ifacename
, count
)
746 class PeripheralInterfaces(object):
750 def slowimport(self
, *args
):
752 for (name
, count
) in self
.ifacecount
:
753 #print "slowimport", name, self.data[name].slowimport
754 ret
.append(self
.data
[name
].slowimport())
755 return '\n'.join(list(filter(None, ret
)))
757 def slowifinstance(self
, *args
):
759 for (name
, count
) in self
.ifacecount
:
760 #print "slowimport", name, self.data[name].slowimport
761 ret
.append(self
.data
[name
].slowifinstance())
762 return '\n'.join(list(filter(None, ret
)))
764 def slowifdeclmux(self
, *args
):
766 for (name
, count
) in self
.ifacecount
:
767 for i
in range(count
):
768 ret
.append(self
.data
[name
].slowifdeclmux().format(i
, name
))
769 return '\n'.join(list(filter(None, ret
)))
771 def slowifdecl(self
, *args
):
773 for (name
, count
) in self
.ifacecount
:
774 for i
in range(count
):
775 ret
.append(self
.data
[name
].slowifdecl().format(i
, name
))
776 return '\n'.join(list(filter(None, ret
)))
778 def axi_reg_def(self
, *args
):
780 start
= 0x00011100 # start of AXI peripherals address
781 for (name
, count
) in self
.ifacecount
:
782 for i
in range(count
):
783 x
= self
.data
[name
].axi_reg_def(start
, i
)
784 #print ("ifc", name, x)
788 return '\n'.join(list(filter(None, ret
)))
790 def axi_slave_idx(self
, *args
):
793 for (name
, count
) in self
.ifacecount
:
794 for i
in range(count
):
795 (rdef
, offs
) = self
.data
[name
].axi_slave_idx(start
, i
)
796 #print ("ifc", name, rdef, offs)
799 ret
.append("typedef %d LastGen_slave_num;" % (start
- 1))
800 decls
= '\n'.join(list(filter(None, ret
)))
801 return axi_slave_declarations
.format(decls
)
803 def axi_addr_map(self
, *args
):
805 for (name
, count
) in self
.ifacecount
:
806 for i
in range(count
):
807 ret
.append(self
.data
[name
].axi_addr_map(i
))
808 return '\n'.join(list(filter(None, ret
)))
810 def mkslow_peripheral(self
, *args
):
812 for (name
, count
) in self
.ifacecount
:
813 for i
in range(count
):
814 print "mkslow", name
, count
815 x
= self
.data
[name
].mkslow_peripheral()
817 suffix
= self
.data
[name
].mksuffix(name
, i
)
818 ret
.append(x
.format(suffix
))
819 return '\n'.join(list(filter(None, ret
)))
821 def mk_connection(self
, *args
):
823 for (name
, count
) in self
.ifacecount
:
824 for i
in range(count
):
825 print "mk_conn", name
, i
826 txt
= self
.data
[name
].mk_connection(i
)
829 print self
.data
[name
].mk_connection
831 return '\n'.join(list(filter(None, ret
)))
833 def mk_cellconn(self
):
836 for (name
, count
) in self
.ifacecount
:
837 for i
in range(count
):
838 res
= self
.data
[name
].mk_cellconn(cellcount
, name
, i
)
841 (txt
, cellcount
) = res
843 ret
= '\n'.join(list(filter(None, ret
)))
844 return pinmux_cellrule
.format(ret
)
848 for (name
, count
) in self
.ifacecount
:
849 for i
in range(count
):
850 txt
= self
.data
[name
].mk_pincon(name
, i
)
852 return '\n'.join(list(filter(None, ret
)))
857 irq_offs
= 8 # XXX: DMA scovers 0-7?
858 for (name
, count
) in self
.ifacecount
:
859 for i
in range(count
):
860 res
= self
.data
[name
].mk_plic(i
, irq_offs
)
863 (txt
, irq_offs
) = res
865 return '\n'.join(list(filter(None, ret
)))
868 class PFactory(object):
869 def getcls(self
, name
):
870 for k
, v
in {'uart': uart
,
882 if name
.startswith(k
):
887 slowfactory
= PFactory()
889 if __name__
== '__main__':
893 i
= PeripheralIface('uart')
895 i
= PeripheralIface('gpioa')