def __init__(self):
self.ifacecount = []
- ifaces = {}
+ UserDict.__init__(self, {})
with open('interfaces.txt', 'r') as ifile:
for l in ifile.readlines():
l = l.strip()
print l
name = l[0]
count = int(l[1])
- self.ifacecount.append((name, count))
spec = self.read_spec(name)
- ifaces[name] = Interface(name, spec)
- UserDict.__init__(self, ifaces)
+ self.ifaceadd(name, count, Interface(name, spec))
+
+ def ifaceadd(self, name, count, iface):
+ self.ifacecount.append((name, count))
+ self[name] = iface
def read_spec(self, name):
spec = []
spec.append(d)
return spec
+ def ifacedef(self, f, *args):
+ for (name, count) in self.ifacecount:
+ for i in range(count):
+ f.write(self.data[name].ifacedef(i))
+
+ def ifacefmt(self, f, *args):
+ comment = '''
+ // interface declaration between %s-{0} and pinmux'''
+ for (name, count) in self.ifacecount:
+ for i in range(count):
+ c = comment % name.upper()
+ f.write(c.format(i))
+ f.write(self.data[name].ifacefmt(i))
+
+ def wirefmt(self, f, *args):
+ comment = '\n // following wires capture signals ' \
+ 'to IO CELL if %s-{0} is\n' \
+ ' // allotted to it'
+ for (name, count) in self.ifacecount:
+ for i in range(count):
+ c = comment % name
+ f.write(c.format(i))
+ f.write(self.data[name].wirefmt(i))
+
# ========= Interface declarations ================ #
# Outputs from the peripherals will be inputs to the pinmux
# module. Hence the change in direction for most pins
-uartinterface_decl = Interface('uart',
- [{'name': 'rx'},
- {'name': 'tx', 'action': True},
- ])
-
-spiinterface_decl = Interface('spi',
- [{'name': 'sclk', 'action': True},
- {'name': 'mosi', 'action': True},
- {'name': 'nss', 'action': True},
- {'name': 'miso'},
- ])
-
-twiinterface_decl = Interface('twi',
- [{'name': 'sda', 'outen': True},
- {'name': 'scl', 'outen': True},
- ])
-
-sdinterface_decl = Interface('sd',
- [{'name': 'clk', 'action': True},
- {'name': 'cmd', 'action': True},
- {'name': 'd0', 'outen': True},
- {'name': 'd1', 'outen': True},
- {'name': 'd2', 'outen': True},
- {'name': 'd3', 'outen': True}
- ])
-
-jtaginterface_decl = Interface('jtag',
- [{'name': 'tdi'},
- {'name': 'tms'},
- {'name': 'tclk'},
- {'name': 'trst'},
- {'name': 'tdo', 'action': True}
- ])
-
-pwminterface_decl = Interface('pwm',
- [{'name': "pwm", 'action': True}
- ])
-
ifaces = Interfaces()
# ======================================= #
# basic test
if __name__ == '__main__':
+ uartinterface_decl = Interface('uart',
+ [{'name': 'rx'},
+ {'name': 'tx', 'action': True},
+ ])
+
+ spiinterface_decl = Interface('spi',
+ [{'name': 'sclk', 'action': True},
+ {'name': 'mosi', 'action': True},
+ {'name': 'nss', 'action': True},
+ {'name': 'miso'},
+ ])
+
+ twiinterface_decl = Interface('twi',
+ [{'name': 'sda', 'outen': True},
+ {'name': 'scl', 'outen': True},
+ ])
+
+ sdinterface_decl = Interface('sd',
+ [{'name': 'clk', 'action': True},
+ {'name': 'cmd', 'action': True},
+ {'name': 'd0', 'outen': True},
+ {'name': 'd1', 'outen': True},
+ {'name': 'd2', 'outen': True},
+ {'name': 'd3', 'outen': True}
+ ])
+
+ jtaginterface_decl = Interface('jtag',
+ [{'name': 'tdi'},
+ {'name': 'tms'},
+ {'name': 'tclk'},
+ {'name': 'trst'},
+ {'name': 'tdo', 'action': True}
+ ])
+
+ pwminterface_decl = Interface('pwm',
+ [{'name': "pwm", 'action': True}
+ ])
+
def _pinmunge(p, sep, repl, dedupe=True):
""" munges the text so it's easier to compare.
splits by separator, strips out blanks, re-joins.
# ==============================================================
# == create method definitions for all peripheral interfaces ==#
- for i in range(0, N_UART):
- bsv_file.write('''
- // interface declaration between UART-{0} and pinmux'''.format(i))
- bsv_file.write(uartinterface_decl.ifacefmt(i))
-
- for i in range(0, N_SPI):
- bsv_file.write('''
- // interface declaration between SPI-{0} and pinmux'''.format(i))
- bsv_file.write(spiinterface_decl.ifacefmt(i))
+ ifaces.ifacefmt(bsv_file)
- for i in range(0, N_TWI):
- bsv_file.write('''
- // interface declaration between TWI-{0} and pinmux'''.format(i))
- bsv_file.write(twiinterface_decl.ifacefmt(i))
-
- for i in range(0, N_SD):
- bsv_file.write('''
- // interface declaration between SD-{0} and pinmux'''.format(i))
- bsv_file.write(sdinterface_decl.ifacefmt(i))
-
- for i in range(0, N_JTAG):
- bsv_file.write('''
- // interface declaration between JTAG-{0} and pinmux'''.format(i))
- bsv_file.write(jtaginterface_decl.ifacefmt(i))
-
- for i in range(0, N_PWM):
- bsv_file.write('''
- // interface declaration between PWM-{0} and pinmux'''.format(i))
- bsv_file.write(pwminterface_decl.ifacefmt(i))
# ==============================================================
# ===== finish interface definition and start module definition=======
for i in range(0, N_IO):
bsv_file.write(generic_io.format(i))
- for i in range(0, N_UART):
- bsv_file.write(
- '''\n // following wires capture signals to IO CELL if uart-{0} is
- // allotted to it'''.format(i))
- bsv_file.write(uartinterface_decl.wirefmt(i))
-
- for i in range(0, N_SPI):
- bsv_file.write(
- '''\n // following wires capture signals to IO CELL if spi-{0} is
- // allotted to it'''.format(i))
- bsv_file.write(spiinterface_decl.wirefmt(i))
-
- for i in range(0, N_TWI):
- bsv_file.write(
- '''\n // following wires capture signals to IO CELL if twi-{0} is
- // allotted to it'''.format(i))
- bsv_file.write(twiinterface_decl.wirefmt(i))
-
- for i in range(0, N_SD):
- bsv_file.write(
- '''\n // following wires capture signals to IO CELL if sd-{0} is
- // allotted to it'''.format(i))
- bsv_file.write(sdinterface_decl.wirefmt(i))
-
- for i in range(0, N_JTAG):
- bsv_file.write(
- '''\n // following wires capture signals to IO CELL if jtag-{0} is
- // allotted to it'''.format(i))
- bsv_file.write(jtaginterface_decl.wirefmt(i))
-
- for i in range(0, N_PWM):
- bsv_file.write(
- '''\n // following wires capture signals to IO CELL if pwm-{0} is
- // allotted to it'''.format(i))
- bsv_file.write(pwminterface_decl.wirefmt(i))
+ ifaces.wirefmt(bsv_file)
+
bsv_file.write("\n")
# ====================================================================
# ========================= Actual pinmuxing ========================#
''')
for i in range(0, N_IO):
bsv_file.write(io_interface.ifacedef(i))
- for i in range(0, N_UART):
- bsv_file.write(uartinterface_decl.ifacedef(i))
- for i in range(0, N_SPI):
- bsv_file.write(spiinterface_decl.ifacedef(i))
- for i in range(0, N_TWI):
- bsv_file.write(twiinterface_decl.ifacedef(i))
- for i in range(0, N_SD):
- bsv_file.write(sdinterface_decl.ifacedef(i))
- for i in range(0, N_JTAG):
- bsv_file.write(jtaginterface_decl.ifacedef(i))
- for i in range(0, N_PWM):
- bsv_file.write(pwminterface_decl.ifacedef(i))
+ ifaces.ifacedef(bsv_file)
bsv_file.write(footer)
print("BSV file successfully generated: bsv_src/pinmux.bsv")
# ======================================================================