crossbar: Switch to LiteXModule.

This commit is contained in:
Florent Kermarrec 2023-07-10 09:53:45 +02:00
parent 1be13c2ece
commit 4bbb14a59c
1 changed files with 6 additions and 4 deletions

View File

@ -1,18 +1,20 @@
# #
# This file is part of LiteEth. # This file is part of LiteEth.
# #
# Copyright (c) 2015 Florent Kermarrec <florent@enjoy-digital.fr> # Copyright (c) 2015-2023 Florent Kermarrec <florent@enjoy-digital.fr>
# SPDX-License-Identifier: BSD-2-Clause # SPDX-License-Identifier: BSD-2-Clause
from collections import OrderedDict from collections import OrderedDict
from litex.gen import *
from liteeth.common import * from liteeth.common import *
from litex.soc.interconnect.packet import Arbiter, Dispatcher from litex.soc.interconnect.packet import Arbiter, Dispatcher
# Crossbar ----------------------------------------------------------------------------------------- # Crossbar -----------------------------------------------------------------------------------------
class LiteEthCrossbar(Module): class LiteEthCrossbar(LiteXModule):
def __init__(self, master_port, dispatch_param, dw=8): def __init__(self, master_port, dispatch_param, dw=8):
self.users = OrderedDict() self.users = OrderedDict()
self.master = master_port(dw) self.master = master_port(dw)
@ -25,11 +27,11 @@ class LiteEthCrossbar(Module):
def do_finalize(self): def do_finalize(self):
# TX arbitrate # TX arbitrate
sinks = [port.sink for port in self.users.values()] sinks = [port.sink for port in self.users.values()]
self.submodules.arbiter = Arbiter(sinks, self.master.source) self.arbiter = Arbiter(sinks, self.master.source)
# RX dispatch # RX dispatch
sources = [port.source for port in self.users.values()] sources = [port.source for port in self.users.values()]
self.submodules.dispatcher = Dispatcher(self.master.sink, sources, one_hot=True) self.dispatcher = Dispatcher(self.master.sink, sources, one_hot=True)
dispatch_sig = getattr(self.master.sink, self.dispatch_param) dispatch_sig = getattr(self.master.sink, self.dispatch_param)
for i, (k, v) in enumerate(self.users.items()): for i, (k, v) in enumerate(self.users.items()):
self.comb += If(dispatch_sig == k, self.dispatcher.sel.eq(2**i)) self.comb += If(dispatch_sig == k, self.dispatcher.sel.eq(2**i))