From 2700ec3ce515670a388e2a46a2b87a5b602cc9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Boczar?= Date: Wed, 15 Jul 2020 15:59:16 +0200 Subject: [PATCH] soc/integration: use AXILiteConverter (dummy implementation) in add_adapter() --- litex/soc/integration/soc.py | 54 +++++++++++++++++++++-------------- litex/soc/interconnect/axi.py | 19 ++++++++++++ 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/litex/soc/integration/soc.py b/litex/soc/integration/soc.py index 28ee0cc22..d52402c95 100644 --- a/litex/soc/integration/soc.py +++ b/litex/soc/integration/soc.py @@ -281,35 +281,45 @@ class SoCBusHandler(Module): def add_adapter(self, name, interface, direction="m2s"): assert direction in ["m2s", "s2m"] - if isinstance(interface, axi.AXILiteInterface): - self.logger.info("{} Bus {} from {} to {}.".format( - colorer(name), - colorer("converted", color="cyan"), - colorer("AXILite"), - colorer("Wishbone"))) - new_interface = wishbone.Interface(data_width=interface.data_width) - if direction == "m2s": - converter = axi.AXILite2Wishbone(axi_lite=interface, wishbone=new_interface) - elif direction == "s2m": - converter = axi.Wishbone2AXILite(wishbone=new_interface, axi_lite=interface) - self.submodules += converter - interface = new_interface - - if interface.data_width != self.data_width: - self.logger.info("{} Bus {} from {}-bit to {}-bit.".format( - colorer(name), - colorer("converted", color="cyan"), - colorer(interface.data_width), - colorer(self.data_width))) + if isinstance(interface, wishbone.Interface): new_interface = wishbone.Interface(data_width=self.data_width) if direction == "m2s": converter = wishbone.Converter(master=interface, slave=new_interface) if direction == "s2m": converter = wishbone.Converter(master=new_interface, slave=interface) self.submodules += converter - return new_interface + elif isinstance(interface, axi.AXILiteInterface): + # Data width conversion + intermediate = axi.AXILiteInterface(data_width=self.data_width) + if direction == "m2s": + converter = axi.AXILiteConverter(master=interface, slave=intermediate) + if direction == "s2m": + converter = axi.AXILiteConverter(master=intermediate, slave=interface) + self.submodules += converter + # Bus type conversion + new_interface = wishbone.Interface(data_width=self.data_width) + if direction == "m2s": + converter = axi.AXILite2Wishbone(axi_lite=intermediate, wishbone=new_interface) + elif direction == "s2m": + converter = axi.Wishbone2AXILite(wishbone=new_interface, axi_lite=intermediate) + self.submodules += converter else: - return interface + raise TypeError(interface) + + fmt = "{name} Bus {converted} from {frombus} {frombits}-bit to {tobus} {tobits}-bit." + frombus = "Wishbone" if isinstance(interface, wishbone.Interface) else "AXILite" + tobus = "Wishbone" if isinstance(new_interface, wishbone.Interface) else "AXILite" + frombits = interface.data_width + tobits = new_interface.data_width + if frombus != tobus or frombits != tobits: + self.logger.info(fmt.format( + name = colorer(name), + converted = colorer("converted", color="cyan"), + frombus = colorer("Wishbone" if isinstance(interface, wishbone.Interface) else "AXILite"), + frombits = colorer(interface.data_width), + tobus = colorer("Wishbone" if isinstance(new_interface, wishbone.Interface) else "AXILite"), + tobits = colorer(new_interface.data_width))) + return new_interface def add_master(self, name=None, master=None): if name is None: diff --git a/litex/soc/interconnect/axi.py b/litex/soc/interconnect/axi.py index cb9c9ad85..02002a58e 100644 --- a/litex/soc/interconnect/axi.py +++ b/litex/soc/interconnect/axi.py @@ -676,3 +676,22 @@ class AXILiteSRAM(Module): port_we=port.we if not read_only else None) self.submodules.fsm = fsm self.comb += comb + +# AXILite Data Width Converter --------------------------------------------------------------------- + +class AXILiteConverter(Module): + """AXILite data width converter""" + def __init__(self, master, slave): + self.master = master + self.slave = slave + + # # # + + dw_from = len(master.r.data) + dw_to = len(slave.r.data) + if dw_from > dw_to: + raise NotImplementedError + elif dw_from < dw_to: + raise NotImplementedError + else: + self.comb += master.connect(slave)