From: Sebastien Bourdeauducq Date: Sat, 9 Mar 2013 23:45:16 +0000 (+0100) Subject: bank/csrgen: BankArray X-Git-Tag: 24jan2021_ls180~2099^2~667 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=68fe4c269c44e8aaf21c788a2cb2480a4aa372d4;p=litex.git bank/csrgen: BankArray --- diff --git a/migen/bank/csrgen.py b/migen/bank/csrgen.py index 4112e2b7..e345de3c 100644 --- a/migen/bank/csrgen.py +++ b/migen/bank/csrgen.py @@ -84,3 +84,47 @@ class Bank: sync.append(If(field.we, field.storage.eq(field.w))) return Fragment(comb, sync) + +# address_map(name, memory) returns the CSR offset at which to map +# the CSR object (register bank or memory). +# If memory=None, the object is the register bank of object source.name. +# Otherwise, it is a memory object belonging to source.name. +# address_map is called exactly once for each object at each call to +# scan(), so it can have side effects. +class BankArray: + def __init__(self, source, address_map): + self.source = source + self.address_map = address_map + self.scan() + + def scan(self): + self.banks = [] + self.srams = [] + for name, obj in self.source.__dict__.items(): + if hasattr(obj, "get_registers"): + registers = obj.get_registers() + else: + registers = [] + if hasattr(obj, "get_memories"): + memories = obj.get_memories() + for memory in memories: + mapaddr = self.address_map(name, memory) + mmap = csr.SRAM(memory, mapaddr) + registers += mmap.get_registers() + self.srams.append(mmap) + if registers: + mapaddr = self.address_map(name, None) + rmap = Bank(registers, mapaddr) + self.banks.append(rmap) + + def get_banks(self): + return self.banks + + def get_srams(self): + return self.srams + + def get_buses(self): + return [i.bus for i in self.banks + self.srams] + + def get_fragment(self): + return sum([i.get_fragment() for i in self.banks + self.srams], Fragment())