self.add_csr_region(name + "_" + memory.name_override, (self.mem_map["csr"] + 0x800*mapaddr) | self.shadow_base, self.csr_data_width, memory)
# Interrupts
- for k, v in sorted(self.interrupt_map.items(), key=itemgetter(1)):
- if hasattr(self, k):
- self.comb += self.cpu_or_bridge.interrupt[v].eq(getattr(self, k).ev.irq)
+ if hasattr(self.cpu_or_bridge, "interrupt"):
+ for k, v in sorted(self.interrupt_map.items(), key=itemgetter(1)):
+ if hasattr(self, k):
+ self.comb += self.cpu_or_bridge.interrupt[v].eq(getattr(self, k).ev.irq)
def build(self, *args, **kwargs):
self.platform.build(self, *args, **kwargs)
self.source = Source(layout)
self.busy = Signal()
- ###
+ # # #
description = self.sink.description
fifo_layout = [("payload", description.payload_layout)]
from copy import copy
from litex.gen.util.misc import xdir
+def _rawbits_layout(l):
+ if isinstance(l, int):
+ return [("rawbits", l)]
+ else:
+ return l
+
def pack_layout(l, n):
return [("chunk"+str(i), l) for i in range(n)]
self.q.param.eq(self.d.param)
)
+
+class Cast(CombinatorialActor):
+ def __init__(self, layout_from, layout_to, reverse_from=False, reverse_to=False):
+ self.sink = Sink(_rawbits_layout(layout_from))
+ self.source = Source(_rawbits_layout(layout_to))
+ CombinatorialActor.__init__(self)
+
+ # # #
+
+ sigs_from = self.sink.payload.flatten()
+ if reverse_from:
+ sigs_from = list(reversed(sigs_from))
+ sigs_to = self.source.payload.flatten()
+ if reverse_to:
+ sigs_to = list(reversed(sigs_to))
+ if sum(len(s) for s in sigs_from) != sum(len(s) for s in sigs_to):
+ raise TypeError
+ self.comb += Cat(*sigs_to).eq(Cat(*sigs_from))
+
+
class Unpack(Module):
def __init__(self, n, layout_to, reverse=False):
self.source = source = Source(layout_to)
self.busy = Signal()
- ###
+ # # #
mux = Signal(max=n)
first = Signal()
self.source = source = Source(description_to)
self.busy = Signal()
- ###
+ # # #
demux = Signal(max=n)
self.source = Source(layout_to)
CombinatorialActor.__init__(self)
- ###
+ # # #
for i in range(n):
chunk = n-i-1 if reverse else i
self.source = Source(layout_to)
CombinatorialActor.__init__(self)
- ###
+ # # #
for i in range(n):
chunk = n-i-1 if reverse else i
self.source = Source(layout_to)
self.busy = Signal()
- ###
+ # # #
width_from = len(self.sink.payload.raw_bits())
width_to = len(self.source.payload.raw_bits())