예제 #1
0
파일: csrgen.py 프로젝트: fallen/migen
 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:
                 mapaddr = self.address_map(name, memory)
                 if mapaddr is None:
                     continue
                 sram_bus = csr.Interface(*ifargs, **ifkwargs)
                 mmap = csr.SRAM(memory, mapaddr, 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 = csr.Interface(*ifargs, **ifkwargs)
             rmap = Bank(csrs, mapaddr, bus=bank_bus)
             self.submodules += rmap
             self.banks.append((name, csrs, mapaddr, rmap))
예제 #2
0
파일: actor.py 프로젝트: rohit91/migen
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
예제 #3
0
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
예제 #4
0
    def document_interrupt(self, soc, submodules, irq):
        managers = submodules["event_managers"]
        for m in managers:
            sources_u = [y for x, y in xdir(m, True) if isinstance(y, _EventSource)]
            sources = sorted(sources_u, key=lambda x: x.duid)

            def source_description(src):
                if hasattr(src, "name") and src.name is not None:
                    base_text = "`1` if a `{}` event occurred. ".format(src.name)
                else:
                    base_text = "`1` if a this particular event occurred. "
                if hasattr(src, "description") and src.description is not None:
                    return src.description
                elif isinstance(src, EventSourceLevel):
                    return base_text + "This Event is **level triggered** when the signal is **high**."
                elif isinstance(src, EventSourcePulse):
                    return base_text + "This Event is triggered on a **rising** edge."
                elif isinstance(src, EventSourceProcess):
                    return base_text + "This Event is triggered on a **falling** edge."
                else:
                    return base_text + "This Event uses an unknown method of triggering."

            # Patch the DocumentedCSR to add our own Description, if one doesn't exist.
            for dcsr in self.csrs:
                short_name = dcsr.short_name.upper()
                if short_name == m.status.name.upper():
                    if dcsr.fields is None or len(dcsr.fields) == 0:
                        fields = []
                        for i, source in enumerate(sources):
                            if hasattr(source, "name") and source.name is not None:
                                fields.append(DocumentedCSRField(CSRField(source.name, offset=i, description="Level of the `{}` event".format(source.name))))
                            else:
                                fields.append(DocumentedCSRField(CSRField("event{}".format(i), offset=i, description="Level of the `event{}` event".format(i))))
                        dcsr.fields = fields
                    if dcsr.description is None:
                        dcsr.description = "This register contains the current raw level of the Event trigger.  Writes to this register have no effect."
                elif short_name == m.pending.name.upper():
                    if dcsr.fields is None or len(dcsr.fields) == 0:
                        fields = []
                        for i, source in enumerate(sources):
                            if hasattr(source, "name") and source.name is not None:
                                fields.append(DocumentedCSRField(CSRField(source.name, offset=i, description=source_description(source))))
                            else:
                                fields.append(DocumentedCSRField(CSRField("event{}".format(i), offset=i, description=source_description(source))))
                        dcsr.fields = fields
                    if dcsr.description is None:
                        dcsr.description = "When an Event occurs, the corresponding bit will be set in this register.  To clear the Event, set the corresponding bit in this register."
                elif short_name == m.enable.name.upper():
                    if dcsr.fields is None or len(dcsr.fields) == 0:
                        fields = []
                        for i, source in enumerate(sources):
                            if hasattr(source, "name") and source.name is not None:
                                fields.append(DocumentedCSRField(CSRField(source.name, offset=i, description="Write a `1` to enable the `{}` Event".format(source.name))))
                            else:
                                fields.append(DocumentedCSRField(CSRField("event{}".format(i), offset=i, description="Write a `1` to enable the `{}` Event".format(i))))
                        dcsr.fields = fields
                    if dcsr.description is None:
                        dcsr.description = "This register enables the corresponding Events.  Write a `0` to this register to disable individual events."
예제 #5
0
파일: sim.py 프로젝트: tmbinc/migen
def _sim_multiread(sim, obj):
    if isinstance(obj, Signal):
        return sim.rd(obj)
    else:
        r = {}
        for k, v in xdir(obj, True):
            rd = _sim_multiread(sim, v)
            if isinstance(rd, int) or rd:
                r[k] = rd
        return r
예제 #6
0
파일: sim.py 프로젝트: fallen/migen
def _sim_multiread(sim, obj):
    if isinstance(obj, Signal):
        return sim.rd(obj)
    else:
        r = {}
        for k, v in xdir(obj, True):
            rd = _sim_multiread(sim, v)
            if isinstance(rd, int) or rd:
                r[k] = rd
        return r
예제 #7
0
파일: compiler.py 프로젝트: tmbinc/migen
	def do_finalize(self):
		UnifiedIOObject.do_finalize(self)
		if self.get_dataflow():
			self.busy.reset = 1
		self.memory_ports = dict()
		for key in xdir(self):
			mem = getattr(self, key)
			if isinstance(mem, Memory):
				port = mem.get_port(write_capable=True, we_granularity=8)
				self.specials += port
				self.memory_ports[mem] = port
		self._compile()
예제 #8
0
	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.huid)
		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(optree("|", irqs))
예제 #9
0
    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))
예제 #10
0
파일: csr_bus.py 프로젝트: kazan-3d/litex
 def scan(self, ifargs, ifkwargs):
     self.banks = []
     self.srams = []
     self.constants = []
     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,
                             paging=self.paging)
                 self.submodules += mmap
                 csrs += mmap.get_csrs()
                 self.srams.append((name, memory, mapaddr, mmap))
         if hasattr(obj, "get_constants"):
             for constant in obj.get_constants():
                 self.constants.append((name, constant))
         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,
                            paging=self.paging,
                            ordering=self.ordering,
                            soc_bus_data_width=self.soc_bus_data_width)
             self.submodules += rmap
             self.banks.append((name, csrs, mapaddr, rmap))
예제 #11
0
 def get_csrs(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, _CSRBase):
                 r.append(v)
             elif hasattr(v, "get_csrs") and callable(v.get_csrs):
                 csrs = v.get_csrs()
                 csrprefix(k + "_", csrs, prefixed)
                 r += csrs
     return sorted(r, key=lambda x: x.huid)
예제 #12
0
파일: description.py 프로젝트: fallen/migen
 def get_memories(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, Memory):
                 r.append(v)
             elif hasattr(v, "get_memories") and callable(v.get_memories):
                 memories = v.get_memories()
                 memprefix(k + "_", memories, prefixed)
                 r += memories
     return sorted(r, key=lambda x: x.huid)
예제 #13
0
 def get_memories(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, Memory):
                 r.append(v)
             elif hasattr(v, "get_memories") and callable(v.get_memories):
                 memories = v.get_memories()
                 memprefix(k + "_", memories, prefixed)
                 r += memories
     return sorted(r, key=lambda x: x.huid)
예제 #14
0
파일: description.py 프로젝트: fallen/migen
 def get_csrs(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, _CSRBase):
                 r.append(v)
             elif hasattr(v, "get_csrs") and callable(v.get_csrs):
                 csrs = v.get_csrs()
                 csrprefix(k + "_", csrs, prefixed)
                 r += csrs
     return sorted(r, key=lambda x: x.huid)
예제 #15
0
파일: csr.py 프로젝트: peteut/misoc
 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=hash)
예제 #16
0
파일: doc.py 프로젝트: zsipos/litex
 def gatherer(self):
     try:
         exclude = self.autodoc_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)
예제 #17
0
파일: csrgen.py 프로젝트: tmbinc/migen
 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:
                 mapaddr = self.address_map(name, memory)
                 sram_bus = csr.Interface(*ifargs, **ifkwargs)
                 mmap = csr.SRAM(memory, mapaddr, 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)
             bank_bus = csr.Interface(*ifargs, **ifkwargs)
             rmap = Bank(csrs, mapaddr, bus=bank_bus)
             self.submodules += rmap
             self.banks.append((name, csrs, mapaddr, rmap))
예제 #18
0
파일: csr_bus.py 프로젝트: peteut/misoc
 def scan(self, ifargs, ifkwargs):
     self.banks = []
     self.srams = []
     self.constants = []
     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 hasattr(obj, "get_constants"):
             for constant in obj.get_constants():
                 self.constants.append((name, constant))
         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))
예제 #19
0
파일: ioo.py 프로젝트: tmbinc/migen
 def do_finalize(self):
     if self.get_dataflow():
         self.busy = Signal()
     self.specials += set(v for k, v in xdir(self, True)
                          if isinstance(v, Memory))
예제 #20
0
파일: ioo.py 프로젝트: tmbinc/migen
 def get_buses(self):
     return dict((k, v) for k, v in xdir(self, True)
                 if isinstance(v, (wishbone.Interface, Memory)))
예제 #21
0
    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)

        # Common
        def get_source_name(src, i):
            r = getattr(src, "name", None)
            if r is None:
                r = f"event{i}"
            return r

        def get_pending_source_description(src):
            r = ""
            if getattr(src, "name", None) is not None:
                r += "`1` if a `{}` event occurred. ".format(src.name)
            else:
                r += "`1` if a this particular event occurred. "
            if getattr(src, "description", None) is not None:
                return src.description
            elif isinstance(src, EventSourceLevel):
                return r + "This Event is **level triggered** when the signal is **high**."
            elif isinstance(src, EventSourcePulse):
                return r + "This Event is triggered on a **rising** edge."
            elif isinstance(src, EventSourceProcess):
                return r + "This Event is triggered on a **falling** edge."
            else:
                return r + "This Event uses an unknown method of triggering."

        # Status register
        fields = []
        for i, source in enumerate(sources):
            # Get source name and use default if None.
            name = get_source_name(source, i)
            # Get description and use default description if None.
            desc = getattr(source, "description", None)
            if desc is None:
                desc = "This register contains the current raw level of the {} event trigger.  Writes to this register have no effect.".format(
                    str(name))
            # Add CSRField
            fields.append(
                CSRField(name=name,
                         size=1,
                         description=f"Level of the ``{name}`` event"))
        self.status = CSRStatus(n, description=desc, fields=fields)

        # Pending Register
        fields = []
        for i, source in enumerate(sources):
            # Get source name and use default if None.
            name = get_source_name(source, i)
            # Get description and use default description if None.
            desc = getattr(source, "description", None)
            if desc is None:
                desc = "When a  {} event occurs, the corresponding bit will be set in this register.  To clear the Event, set the corresponding bit in this register.".format(
                    str(name))
            # Add CSRField
            fields.append(
                CSRField(name=name,
                         size=1,
                         description=get_pending_source_description(source)))
        self.pending = CSRStatus(n,
                                 description=desc,
                                 fields=fields,
                                 read_only=False)

        # Enable Register
        fields = []
        for i, source in enumerate(sources):
            # Get source name and use default if None.
            name = get_source_name(source, i)
            # Get description and use default description if None.
            desc = getattr(source, "description", None)
            if desc is None:
                desc = "This register enables the corresponding {} events.  Write a ``0`` to this register to disable individual events.".format(
                    str(name))
            # Add CSRField
            fields.append(
                CSRField(
                    name=name,
                    offset=i,
                    description=f"Write a ``1`` to enable the ``{name}`` Event"
                ))
        self.enable = CSRStorage(n, description=desc, fields=fields)

        # Connect Events/Fields
        for i, source in enumerate(sources):
            # Get source name and use default if None.
            name = get_source_name(source, i)
            self.comb += [
                getattr(self.status.fields, name).eq(source.status),
                getattr(self.pending.fields, name).eq(source.pending),
                If(self.pending.re & self.pending.r[i], source.clear.eq(1)),
            ]
            irqs = [
                self.pending.status[i] & self.enable.storage[i]
                for i in range(n)
            ]
        self.comb += self.irq.eq(reduce(or_, irqs))
예제 #22
0
파일: ioo.py 프로젝트: RP7/migen
	def get_buses(self):
		return dict((k, v) for k, v in xdir(self, True) if isinstance(v, (wishbone.Interface, Memory)))
예제 #23
0
파일: ioo.py 프로젝트: RP7/migen
	def get_dataflow(self):
		return dict((k, v) for k, v in xdir(self, True) if isinstance(v, _Endpoint))
예제 #24
0
파일: ioo.py 프로젝트: RP7/migen
	def do_finalize(self):
		if self.get_dataflow():
			self.busy = Signal()
		self.specials += set(v for k, v in xdir(self, True) if isinstance(v, Memory))
예제 #25
0
파일: ioo.py 프로젝트: tmbinc/migen
 def get_dataflow(self):
     return dict(
         (k, v) for k, v in xdir(self, True) if isinstance(v, _Endpoint))