AddingPeripherals.mdwn
[pinmux.git] / src / bsv / peripheral_gen / twi.py
1 from bsv.peripheral_gen.base import PBase
2
3
4 class twi(PBase):
5
6 def slowimport(self):
7 return "import I2C_top :: *;"
8
9 def irq_name(self):
10 return "twi{0}_isint"
11
12 def slowifdecl(self):
13 return "interface I2C_out twi{0}_out;\n" + \
14 "method Bit#(1) %s;" % self.irq_name()
15
16 def num_axi_regs32(self):
17 return 8
18
19 def mkslow_peripheral(self, size=0):
20 return "I2C_IFC twi{0} <- mkI2CController();"
21
22 def _mk_connection(self, name=None, count=0):
23 return "twi{0}.slave_i2c_axi"
24
25 def pinname_out(self, pname):
26 return {'sda': 'out.sda_out',
27 'scl': 'out.scl_out'}.get(pname, '')
28
29 def pinname_in(self, pname):
30 return {'sda': 'out.sda_in',
31 'scl': 'out.scl_in'}.get(pname, '')
32
33 def pinname_outen(self, pname):
34 return {'sda': 'out.sda_out_en',
35 'scl': 'out.scl_out_en'}.get(pname, '')
36
37 def num_irqs(self):
38 return 3
39
40 def plic_object(self, pname, idx):
41 return ["{0}.isint()",
42 "{0}.timerint()",
43 "{0}.isber()"
44 ][idx].format(pname)
45
46 def mk_ext_ifacedef(self, iname, inum):
47 name = self.get_iname(inum)
48 return "method {0}_isint = {0}.isint;".format(name)
49
50 def slowifdeclmux(self, name, inum):
51 sname = self.get_iname(inum)
52 return "method Bit#(1) %s_isint;" % sname