Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 40 additions and 14 deletions.
  1. +40 −14 migen/actorlib/spi.py
View
54 migen/actorlib/spi.py
@@ -50,30 +50,51 @@ def _create_csrs_assign(layout, target, atomic, prefix=""):
(MODE_EXTERNAL, MODE_SINGLE_SHOT, MODE_CONTINUOUS) = range(3)
-class SingleGenerator(Module):
+class SingleGenerator(Module, AutoCSR):
def __init__(self, layout, mode):
self.source = Source(_convert_layout(layout))
self.busy = Signal()
- self._csrs, assigns = _create_csrs_assign(layout, self.source.payload, mode != MODE_SINGLE_SHOT)
+
+ self.comb += self.busy.eq(self.source.stb)
+
if mode == MODE_EXTERNAL:
self.trigger = Signal()
trigger = self.trigger
elif mode == MODE_SINGLE_SHOT:
- shoot = CSR()
- self._csrs.insert(0, shoot)
- trigger = shoot.re
+ self._r_shoot = CSR()
+ trigger = self._r_shoot.re
elif mode == MODE_CONTINUOUS:
- enable = CSRStorage()
- self._csrs.insert(0, enable)
- trigger = enable.storage
+ self._r_enable = CSRStorage()
+ trigger = self._r_enable.storage
else:
raise ValueError
- self.comb += self.busy.eq(self.source.stb)
- stmts = [self.source.stb.eq(trigger)] + assigns
- self.sync += If(self.source.ack | ~self.source.stb, *stmts)
-
- def get_csrs(self):
- return self._csrs
+ self.sync += If(self.source.ack | ~self.source.stb, self.source.stb.eq(trigger))
+
+ self._create_csrs(layout, self.source.payload, mode != MODE_SINGLE_SHOT)
+
+ def _create_csrs(self, layout, target, atomic, prefix=""):
+ for element in layout:
+ if isinstance(element[1], list):
+ self._create_csrs(element[1], atomic,
+ getattr(target, element[0]),
+ element[0] + "_")
+ else:
+ name = element[0]
+ nbits = element[1]
+ if len(element) > 2:
+ reset = element[2]
+ else:
+ reset = 0
+ if len(element) > 3:
+ alignment = element[3]
+ else:
+ alignment = 0
+ regname = prefix + name
+ reg = CSRStorage(nbits + alignment, reset=reset, atomic_write=atomic,
+ alignment_bits=alignment, name=regname)
+ setattr(self, "r_"+regname, reg)
+ self.sync += If(self.source.ack | ~self.source.stb,
+ getattr(target, name).eq(reg.storage))
class Collector(Module, AutoCSR):
def __init__(self, layout, depth=1024):
@@ -125,6 +146,11 @@ def __init__(self, bus_accessor, bus_aw, bus_dw, mode, base_reset=0, length_rese
self.generator = SingleGenerator(layout, mode)
self.r_busy = CSRStatus()
+ self.length = self.generator.r_length.storage
+ self.base = self.generator.r_base.storage
+ if hasattr(self.generator, "trigger"):
+ self.trigger = self.generator.trigger
+
def get_csrs(self):
return self.generator.get_csrs() + [self.r_busy]

No commit comments for this range

Something went wrong with that request. Please try again.