From: Luke Kenneth Casson Leighton Date: Mon, 23 Jul 2018 06:25:11 +0000 (+0100) Subject: create new get/put interface pinmux declaration X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c3de1e8c6c5ef28c426ff8133734096acfd256ed;p=pinmux.git create new get/put interface pinmux declaration --- diff --git a/src/bsv/interface_decl.py b/src/bsv/interface_decl.py index f87bdd9..0ae52ab 100644 --- a/src/bsv/interface_decl.py +++ b/src/bsv/interface_decl.py @@ -82,13 +82,6 @@ class Pin(object): res += ";" return res - # sample bsv method definition : - """ - method Action cell0_mux(Bit#(2) in); - wrcell0_mux<=in; - endmethod - """ - def ifacedef(self, fmtoutfn, fmtinfn, fmtdecfn): res = ' method ' if self.action: @@ -102,6 +95,13 @@ class Pin(object): fmtname = fmtoutfn(self.name) res += "%s=%s;" % (self.name, fmtname) return res + # sample bsv method definition : + """ + method Action cell0_mux(Bit#(2) in); + wrcell0_mux<=in; + endmethod + """ + # sample bsv wire (wire definiton): """ Wire#(Bit#(2)) wrcell0_mux<-mkDWire(0); @@ -116,6 +116,26 @@ class Pin(object): res += "<-mkDWire(0);" return res + def ifacedef2(self, fmtoutfn, fmtinfn, fmtdecfn): + if self.action: + fmtname = fmtinfn(self.name) + res = " interface %s = interface Put\n" % self.name_ + res += ' method ' + res += "Action put" + #res += fmtdecfn(self.name) + res += '(%s in);\n' % self.bitspec + res += ' %s<=in;\n' % fmtname + res += ' endmethod\n' + res += ' endinterface;' + else: + fmtname = fmtoutfn(self.name) + res = " interface %s = interface Get\n" % self.name_ + res += ' method ActionValue#' + res += '(%s) get;\n' % self.bitspec + res += " return %s;\n" % (fmtname) + res += ' endmethod\n' + res += ' endinterface;' + return res class Interface(PeripheralIface): """ create an interface from a list of pinspecs. @@ -285,11 +305,26 @@ class Interface(PeripheralIface): return pin.ifacedef(outfn, self.ifacefmtinfn, decfn) + def ifacedef2pin(self, pin): + decfn = self.ifacefmtdecfn2 + outfn = self.ifacefmtoutfn + # print pin, pin.outenmode + if pin.outenmode: + decfn = self.ifacefmtdecfn3 + outfn = self.ifacefmtoutenfn + return pin.ifacedef2(outfn, self.ifacefmtinfn, + decfn) + def ifacedef(self, *args): res = '\n'.join(map(self.ifacefmtpin, self.pins)) res = res.format(*args) return '\n' + res + '\n' + def ifacedef2(self, *args): + res = '\n'.join(map(self.ifacedef2pin, self.pins)) + res = res.format(*args) + return '\n' + res + '\n' + class MuxInterface(Interface): @@ -326,6 +361,15 @@ class Interfaces(InterfacesBase, PeripheralInterfaces): for i in range(count): f.write(self.data[name].ifacedef(i)) + def ifacedef2(self, f, *args): + c = " interface {0} = interface PeripheralSide{1}" + for (name, count) in self.ifacecount: + for i in range(count): + iname = self.data[name].iname().format(i) + f.write(c.format(iname, name.upper())) + f.write(self.data[name].ifacedef2(i)) + f.write(" endinterface;\n\n") + def busfmt(self, f, *args): f.write("import BUtils::*;\n\n") for (name, count) in self.ifacecount: diff --git a/src/bsv/pinmux_generator.py b/src/bsv/pinmux_generator.py index 69a19c5..67e018c 100644 --- a/src/bsv/pinmux_generator.py +++ b/src/bsv/pinmux_generator.py @@ -256,7 +256,7 @@ def write_pmp(pmp, p, ifaces, iocells): interface peripheral_side = interface PeripheralSide ''') - ifaces.ifacedef(bsv_file) + ifaces.ifacedef2(bsv_file) bsv_file.write("\n endinterface;") bsv_file.write(footer) diff --git a/src/test_bsv/pinmux_experiment.bsv b/src/test_bsv/pinmux_experiment.bsv index 94c880f..975f86d 100644 --- a/src/test_bsv/pinmux_experiment.bsv +++ b/src/test_bsv/pinmux_experiment.bsv @@ -291,98 +291,95 @@ import GetPut::*; interface peripheral_side = interface PeripheralSide interface uart = interface PeripheralSideUART - // interface declaration between UART and pinmux interface tx = interface Put method Action put(Bit#(1) in); wruart_tx<=in; endmethod endinterface; - interface rx = interface Get + interface rx = interface Get method ActionValue#(Bit#(1)) get; return wruart_rx; endmethod endinterface; endinterface; - interface twi = interface PeripheralSideTWI - // interface declaration between TWI and pinmux - interface sda_out = interface Put + interface gpioa = interface PeripheralSideGPIOA + interface a0_out = interface Put method Action put(Bit#(1) in); - wrtwi_sda_out<=in; + wrgpioa_a0_out<=in; endmethod endinterface; - interface sda_outen = interface Put + interface a0_outen = interface Put method Action put(Bit#(1) in); - wrtwi_sda_outen<=in; + wrgpioa_a0_outen<=in; endmethod endinterface; - interface sda_in = interface Get + interface a0_in = interface Get method ActionValue#(Bit#(1)) get; - return wrtwi_sda_in; + return wrgpioa_a0_in; endmethod endinterface; - interface scl_out = interface Put + interface a1_out = interface Put method Action put(Bit#(1) in); - wrtwi_scl_out<=in; + wrgpioa_a1_out<=in; endmethod endinterface; - interface scl_outen = interface Put + interface a1_outen = interface Put method Action put(Bit#(1) in); - wrtwi_scl_outen<=in; + wrgpioa_a1_outen<=in; endmethod endinterface; - interface scl_in = interface Get + interface a1_in = interface Get method ActionValue#(Bit#(1)) get; - return wrtwi_scl_in; + return wrgpioa_a1_in; endmethod endinterface; - endinterface; - - interface gpioa = interface PeripheralSideGPIOA - - interface a0_out = interface Put + interface a2_out = interface Put method Action put(Bit#(1) in); - wrgpioa_a0_out<=in; + wrgpioa_a2_out<=in; endmethod endinterface; - interface a0_outen = interface Put + interface a2_outen = interface Put method Action put(Bit#(1) in); - wrgpioa_a0_outen<=in; + wrgpioa_a2_outen<=in; endmethod endinterface; - interface a0_in = interface Get + interface a2_in = interface Get method ActionValue#(Bit#(1)) get; - return wrgpioa_a0_in; + return wrgpioa_a2_in; endmethod endinterface; - interface a1_out = interface Put + endinterface; + + interface twi = interface PeripheralSideTWI + interface sda_out = interface Put method Action put(Bit#(1) in); - wrgpioa_a1_out<=in; + wrtwi_sda_out<=in; endmethod endinterface; - interface a1_outen = interface Put + interface sda_outen = interface Put method Action put(Bit#(1) in); - wrgpioa_a1_outen<=in; + wrtwi_sda_outen<=in; endmethod endinterface; - interface a1_in = interface Get + interface sda_in = interface Get method ActionValue#(Bit#(1)) get; - return wrgpioa_a1_in; + return wrtwi_sda_in; endmethod endinterface; - interface a2_out = interface Put + interface scl_out = interface Put method Action put(Bit#(1) in); - wrgpioa_a2_out<=in; + wrtwi_scl_out<=in; endmethod endinterface; - interface a2_outen = interface Put + interface scl_outen = interface Put method Action put(Bit#(1) in); - wrgpioa_a2_outen<=in; + wrtwi_scl_outen<=in; endmethod endinterface; - interface a2_in = interface Get + interface scl_in = interface Get method ActionValue#(Bit#(1)) get; - return wrgpioa_a2_in; + return wrtwi_scl_in; endmethod endinterface; endinterface;