core/storage: split LiteScopeRecorder in LiteScopeRecorderUnit and LiteScopeRecorder
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 27 Jan 2015 10:34:59 +0000 (11:34 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 27 Jan 2015 10:34:59 +0000 (11:34 +0100)
litescope/core/storage.py

index 4c8d60a6184b877b2dc14e77685fada37c3c4610..e98ed5efb966a1ef2680568a7b62e8911b342712 100644 (file)
@@ -53,21 +53,20 @@ class LiteScopeRunLengthEncoder(LiteScopeRunLengthEncoderUnit, AutoCSR):
                ###
                self.comb += self.enable.eq(self_enable.storage)
 
-class LiteScopeRecorder(Module, AutoCSR):
+class LiteScopeRecorderUnit(Module):
        def __init__(self, dw, depth):
                self.dw = dw
+               self.depth = depth
 
                self.trigger_sink = trigger_sink = Sink(hit_layout())
                self.data_sink = data_sink = Sink(data_layout(dw))
 
-               self._trigger = CSR()
-               self._length = CSRStorage(bits_for(depth))
-               self._offset = CSRStorage(bits_for(depth))
-               self._done = CSRStatus()
+               self.trigger = Signal()
+               self.length = Signal(bits_for(depth))
+               self.offset = Signal(bits_for(depth))
+               self.done = Signal()
 
-               self._source_stb = CSRStatus()
-               self._source_ack = CSR()
-               self._source_data = CSRStatus(dw)
+               self.source = Source(data_layout(dw))
 
                ###
 
@@ -77,23 +76,23 @@ class LiteScopeRecorder(Module, AutoCSR):
                fsm = FSM(reset_state="IDLE")
                self.submodules += fsm
                self.comb += [
-                       self._source_stb.status.eq(fifo.source.stb),
-                       self._source_data.status.eq(fifo.source.data)
+                       self.source.stb.eq(fifo.source.stb),
+                       self.source.data.eq(fifo.source.data)
                ]
                fsm.act("IDLE",
-                       self._done.status.eq(1),
-                       If(self._trigger.re,
+                       self.done.eq(1),
+                       If(self.trigger,
                                NextState("PRE_HIT_RECORDING"),
                                fifo.reset.eq(1),
                        ),
-                       fifo.source.ack.eq(self._source_ack.re)
+                       fifo.source.ack.eq(self.source.ack)
                )
                fsm.act("PRE_HIT_RECORDING",
                        fifo.sink.stb.eq(data_sink.stb),
                        fifo.sink.data.eq(data_sink.data),
                        data_sink.ack.eq(fifo.sink.ack),
 
-                       fifo.source.ack.eq(fifo.fifo.level >= self._offset.storage),
+                       fifo.source.ack.eq(fifo.fifo.level >= self.offset),
                        If(trigger_sink.stb & trigger_sink.hit, NextState("POST_HIT_RECORDING"))
                )
                fsm.act("POST_HIT_RECORDING",
@@ -101,5 +100,31 @@ class LiteScopeRecorder(Module, AutoCSR):
                        fifo.sink.data.eq(data_sink.data),
                        data_sink.ack.eq(fifo.sink.ack),
 
-                       If(~fifo.sink.ack | (fifo.fifo.level >= self._length.storage), NextState("IDLE"))
+                       If(~fifo.sink.ack | (fifo.fifo.level >= self.length), NextState("IDLE"))
                )
+
+class LiteScopeRecorder(LiteScopeRecorderUnit, AutoCSR):
+       def __init__(self, dw, depth):
+               LiteScopeRecorderUnit.__init__(self, dw, depth)
+
+               self._trigger = CSR()
+               self._length = CSRStorage(bits_for(depth))
+               self._offset = CSRStorage(bits_for(depth))
+               self._done = CSRStatus()
+
+               self._source_stb = CSRStatus()
+               self._source_ack = CSR()
+               self._source_data = CSRStatus(dw)
+
+               ###
+
+               self.comb += [
+                       self.trigger.eq(self._trigger.re),
+                       self.length.eq(self._length.storage),
+                       self.offset.eq(self._offset.storage),
+                       self._done.status.eq(self.done),
+
+                       self._source_stb.status.eq(self.source.stb),
+                       self._source_data.status.eq(self.source.data),
+                       self.source.ack.eq(self._source_ack.re)
+               ]