From: Luke Kenneth Casson Leighton Date: Mon, 23 Jul 2018 05:32:21 +0000 (+0100) Subject: create new get/put interface pinmux declaration X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=48603ce2b71438af3d8fbba491e8046e56c60aaa;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 5d3182d..4e16fa1 100644 --- a/src/bsv/interface_decl.py +++ b/src/bsv/interface_decl.py @@ -20,6 +20,7 @@ class Pin(object): """ def __init__(self, name, + name_ = None, ready=True, enabled=True, io=False, @@ -27,6 +28,7 @@ class Pin(object): bitspec=None, outenmode=False): self.name = name + self.name_ = name_ self.ready = ready self.enabled = enabled self.io = io @@ -41,6 +43,18 @@ class Pin(object): Action io0_inputval (Bit#(1) in); """ + def ifacepfmt(self, fmtfn): + res = ' ' + status = [] + res += "interface " + name = fmtfn(self.name_) + if self.action: + res += "Put" + else: + res += "Get" + res += "#(%s) %s;" % (self.bitspec, name) + return res + def ifacefmt(self, fmtfn): res = ' ' status = [] @@ -134,6 +148,7 @@ class Interface(PeripheralIface): del _p['outen'] for psuffix in ['out', 'outen', 'in']: # changing the name (like sda) to (twi_sda_out) + _p['name_'] = "%s_%s" % (p['name'], psuffix) _p['name'] = "%s_%s" % (self.pname(p['name']), psuffix) _p['action'] = psuffix != 'in' self.pins.append(Pin(**_p)) @@ -142,6 +157,7 @@ class Interface(PeripheralIface): #{'name': 'twi_sda_in', 'action': False} # NOTice - outen key is removed else: + _p['name_'] = p['name'] _p['name'] = self.pname(p['name']) self.pins.append(Pin(**_p)) @@ -213,10 +229,17 @@ class Interface(PeripheralIface): res += '\n' return '\n' + res + def ifacepfmt(self, *args): + res = '\n'.join(map(self.ifacepfmtdecpin, self.pins)).format(*args) + return '\n' + res # pins is a list + def ifacefmt(self, *args): res = '\n'.join(map(self.ifacefmtdecpin, self.pins)).format(*args) return '\n' + res # pins is a list + def ifacepfmtdecfn(self, name): + return name + def ifacefmtdecfn(self, name): return name # like: uart @@ -237,6 +260,9 @@ class Interface(PeripheralIface): return pin.wirefmt(self.ifacefmtoutfn, self.ifacefmtinfn, self.ifacefmtdecfn2) + def ifacepfmtdecpin(self, pin): + return pin.ifacepfmt(self.ifacepfmtdecfn) + def ifacefmtdecpin(self, pin): return pin.ifacefmt(self.ifacefmtdecfn) @@ -298,6 +324,16 @@ class Interfaces(InterfacesBase, PeripheralInterfaces): bf = self.data[name].busfmt(i) f.write(bf) + def ifacepfmt(self, f, *args): + comment = ''' + // interface declaration between {0} and pinmux + (*always_ready,always_enabled*) + interface PeripheralSide{0};''' + for (name, count) in self.ifacecount: + f.write(comment.format(name.upper())) + f.write(self.data[name].ifacepfmt(0)) + f.write("\n endinterface\n") + def ifacefmt(self, f, *args): comment = ''' // interface declaration between %s-{0} and pinmux''' diff --git a/src/bsv/pinmux_generator.py b/src/bsv/pinmux_generator.py index 3a3fe25..a74eee1 100644 --- a/src/bsv/pinmux_generator.py +++ b/src/bsv/pinmux_generator.py @@ -39,6 +39,8 @@ copyright = ''' header = copyright + ''' package pinmux; +import GetPut::*; + ''' footer = ''' endmodule @@ -134,7 +136,8 @@ def write_pmp(pmp, p, ifaces, iocells): cell_bit_width = 'Bit#(%d)' % p.cell_bitwidth bsv_file.write('''\ - interface MuxSelectionLines; + (*always_ready,always_enabled*) + interface MuxSelectionLines; // declare the method which will capture the user pin-mux // selection values.The width of the input is dependent on the number @@ -159,9 +162,10 @@ def write_pmp(pmp, p, ifaces, iocells): # ===== finish interface definition and start module definition======= bsv_file.write("\n endinterface\n") + ifaces.ifacepfmt(bsv_file) # ===== io cell definition ======= bsv_file.write(''' - + (*always_ready,always_enabled*) interface PeripheralSide; // declare the interface to the peripherals // Each peripheral's function will be either an input, output diff --git a/src/test_bsv/pinmux_experiment.bsv b/src/test_bsv/pinmux_experiment.bsv index 6e3e5e0..49bee6f 100644 --- a/src/test_bsv/pinmux_experiment.bsv +++ b/src/test_bsv/pinmux_experiment.bsv @@ -12,7 +12,7 @@ package pinmux_experiment; import GetPut::*; (*always_ready,always_enabled*) - interface MuxSelectionLines; + interface MuxSelectionLines; // declare the method which will capture the user pin-mux // selection values.The width of the input is dependent on the number @@ -45,19 +45,16 @@ import GetPut::*; Action io2_cell_in (Bit#(1) in); endinterface - + // interface declaration between UART and pinmux (*always_ready,always_enabled*) interface PeripheralSideUART; - // interface declaration between UART and pinmux interface Put#(Bit#(1)) tx; interface Get#(Bit#(1)) rx; -// (*always_ready,always_enabled*) method Action tx (Bit#(1) in); -// (*always_ready,always_enabled*) method Bit#(1) rx; endinterface + // interface declaration between GPIOA and pinmux (*always_ready,always_enabled*) interface PeripheralSideGPIOA; - // interface declaration between GPIOA-0 and pinmux interface Put#(Bit#(1)) a0_out; interface Put#(Bit#(1)) a0_outen; interface Get#(Bit#(1)) a0_in; @@ -67,11 +64,11 @@ import GetPut::*; interface Put#(Bit#(1)) a2_out; interface Put#(Bit#(1)) a2_outen; interface Get#(Bit#(1)) a2_in; - endinterface + endinterface + // interface declaration between TWI and pinmux (*always_ready,always_enabled*) interface PeripheralSideTWI; - // interface declaration between TWI and pinmux interface Put#(Bit#(1)) sda_out; interface Put#(Bit#(1)) sda_outen; interface Get#(Bit#(1)) sda_in; @@ -392,12 +389,5 @@ import GetPut::*; endinterface; -// interface peripheral_side = interface PeripheralSide -// -// interface uart = peripherals.uart; -// interface gpioa = peripherals.gpioa; -// interface twi = peripherals.twi; -// -// endinterface; endmodule endpackage