soc/integration: add axi-lite standard to SoCBusHandler

This commit is contained in:
Jędrzej Boczar 2020-07-17 09:59:30 +02:00
parent 2361abb12d
commit 69d8dd788d
1 changed files with 43 additions and 34 deletions

View File

@ -101,7 +101,7 @@ class SoCCSRRegion:
# SoCBusHandler ------------------------------------------------------------------------------------ # SoCBusHandler ------------------------------------------------------------------------------------
class SoCBusHandler(Module): class SoCBusHandler(Module):
supported_standard = ["wishbone"] supported_standard = ["wishbone", "axi-lite"]
supported_data_width = [32, 64] supported_data_width = [32, 64]
supported_address_width = [32] supported_address_width = [32]
@ -281,48 +281,57 @@ class SoCBusHandler(Module):
def add_adapter(self, name, interface, direction="m2s"): def add_adapter(self, name, interface, direction="m2s"):
assert direction in ["m2s", "s2m"] assert direction in ["m2s", "s2m"]
if isinstance(interface, wishbone.Interface): # Data width conversion
if interface.data_width != self.data_width: if interface.data_width != self.data_width:
new_interface = wishbone.Interface(data_width=self.data_width) interface_cls = type(interface)
if direction == "m2s": converter_cls = {
converter = wishbone.Converter(master=interface, slave=new_interface) wishbone.Interface: wishbone.Converter,
if direction == "s2m": axi.AXILiteInterface: axi.AXILiteConverter,
converter = wishbone.Converter(master=new_interface, slave=interface) }[interface_cls]
self.submodules += converter converted_interface = interface_cls(data_width=self.data_width)
else:
new_interface = interface
elif isinstance(interface, axi.AXILiteInterface):
# Data width conversion
intermediate = axi.AXILiteInterface(data_width=self.data_width)
if direction == "m2s": if direction == "m2s":
converter = axi.AXILiteConverter(master=interface, slave=intermediate) master, slave = interface, converted_interface
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": elif direction == "s2m":
converter = axi.Wishbone2AXILite(wishbone=new_interface, axi_lite=intermediate) master, slave = converted_interface, interface
converter = converter_cls(master=master, slave=slave)
self.submodules += converter self.submodules += converter
else: else:
raise TypeError(interface) converted_interface = interface
fmt = "{name} Bus {converted} from {frombus} {frombits}-bit to {tobus} {tobits}-bit." # Wishbone <-> AXILite bridging
frombus = "Wishbone" if isinstance(interface, wishbone.Interface) else "AXILite" main_bus_cls = {
tobus = "Wishbone" if isinstance(new_interface, wishbone.Interface) else "AXILite" "wishbone": wishbone.Interface,
frombits = interface.data_width "axi-lite": axi.AXILiteInterface,
tobits = new_interface.data_width }[self.standard]
if frombus != tobus or frombits != tobits: if isinstance(converted_interface, main_bus_cls):
bridged_interface = converted_interface
else:
bridged_interface = main_bus_cls(data_width=self.data_width)
if direction == "m2s":
master, slave = converted_interface, bridged_interface
elif direction == "s2m":
master, slave = bridged_interface, converted_interface
bridge_cls = {
(wishbone.Interface, axi.AXILiteInterface): axi.Wishbone2AXILite,
(axi.AXILiteInterface, wishbone.Interface): axi.AXILite2Wishbone,
}[type(master), type(slave)]
bridge = bridge_cls(master, slave)
self.submodules += bridge
if type(interface) != type(bridged_interface) or interface.data_width != bridged_interface.data_width:
fmt = "{name} Bus {converted} from {frombus} {frombits}-bit to {tobus} {tobits}-bit."
bus_names = {
wishbone.Interface: "Wishbone",
axi.AXILiteInterface: "AXI Lite",
}
self.logger.info(fmt.format( self.logger.info(fmt.format(
name = colorer(name), name = colorer(name),
converted = colorer("converted", color="cyan"), converted = colorer("converted", color="cyan"),
frombus = colorer("Wishbone" if isinstance(interface, wishbone.Interface) else "AXILite"), frombus = colorer(bus_names[type(interface)]),
frombits = colorer(interface.data_width), frombits = colorer(interface.data_width),
tobus = colorer("Wishbone" if isinstance(new_interface, wishbone.Interface) else "AXILite"), tobus = colorer(bus_names[type(bridged_interface)]),
tobits = colorer(new_interface.data_width))) tobits = colorer(bridged_interface.data_width)))
return new_interface return bridged_interface
def add_master(self, name=None, master=None): def add_master(self, name=None, master=None):
if name is None: if name is None: