def scan(self, ifargs, ifkwargs): self.banks = [] self.srams = [] for name, obj in xdir(self.source, True): if hasattr(obj, "get_csrs"): csrs = obj.get_csrs() else: csrs = [] if hasattr(obj, "get_memories"): memories = obj.get_memories() for memory in memories: if isinstance(memory, tuple): read_only, memory = memory else: read_only = False mapaddr = self.address_map(name, memory) if mapaddr is None: continue sram_bus = Interface(*ifargs, **ifkwargs) mmap = SRAM(memory, mapaddr, read_only=read_only, bus=sram_bus) self.submodules += mmap csrs += mmap.get_csrs() self.srams.append((name, memory, mapaddr, mmap)) if csrs: mapaddr = self.address_map(name, None) if mapaddr is None: continue bank_bus = Interface(*ifargs, **ifkwargs) rmap = CSRBank(csrs, mapaddr, bus=bank_bus) self.submodules += rmap self.banks.append((name, csrs, mapaddr, rmap))
def get_endpoints(obj, filt=Endpoint): if hasattr(obj, "get_endpoints") and callable(obj.get_endpoints): return obj.get_endpoints(filt) r = dict() for k, v in xdir(obj, True): if isinstance(v, filt): r[k] = v return r
def do_finalize(self): sources_u = [v for k, v in xdir(self, True) if isinstance(v, _EventSource)] sources = sorted(sources_u, key=lambda x: x.duid) n = len(sources) self.status = CSR(n) self.pending = CSR(n) self.enable = CSRStorage(n) for i, source in enumerate(sources): self.comb += [ self.status.w[i].eq(source.status), If(self.pending.re & self.pending.r[i], source.clear.eq(1)), self.pending.w[i].eq(source.pending) ] irqs = [self.pending.w[i] & self.enable.storage[i] for i in range(n)] self.comb += self.irq.eq(reduce(or_, irqs))
def gatherer(self): try: exclude = self.autocsr_exclude except AttributeError: exclude = {} try: prefixed = self.__prefixed except AttributeError: prefixed = self.__prefixed = set() r = [] for k, v in xdir(self, True): if k not in exclude: if isinstance(v, cls): r.append(v) elif hasattr(v, method) and callable(getattr(v, method)): items = getattr(v, method)() prefix_cb(k + "_", items, prefixed) r += items return sorted(r, key=lambda x: x.duid)