Skip to content

Commit

Permalink
gateware/streamer: remove use of Counter/FlipFlop
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-digital committed Nov 15, 2015
1 parent 4f2aac2 commit 403c33e
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions gateware/streamer/__init__.py
Expand Up @@ -18,10 +18,19 @@ def __init__(self, ip_address, udp_port, fifo_depth=1024):
self.submodules.fifo = fifo = SyncFIFO([("data", 8)], fifo_depth)
self.comb += Record.connect(sink, fifo.sink)

self.submodules.level = level = FlipFlop(max=fifo_depth+1)
self.comb += level.d.eq(fifo.fifo.level)

self.submodules.counter = counter = Counter(max=fifo_depth)
level = Signal(max=fifo_depth + 1)
level_update = Signal()
self.sync += If(level_update, level.eq(fifo.fifo.level))

counter = Signal(max=fifo_depth)
counter_reset = Signal()
counter_ce = Signal()
self.sync += \
If(counter_reset,
counter.eq(0)
).Elif(counter_ce,
counter.eq(counter + 1)
)

self.submodules.flush_timer = WaitTimer(10000)
flush = Signal()
Expand All @@ -33,31 +42,31 @@ def __init__(self, ip_address, udp_port, fifo_depth=1024):
fsm.act("IDLE",
self.flush_timer.wait.eq(1),
If((fifo.fifo.level >= 256) | flush,
level.ce.eq(1),
counter.reset.eq(1),
level_update.eq(1),
counter_reset.eq(1),
NextState("SEND")
)
)
fsm.act("SEND",
source.stb.eq(fifo.source.stb),
source.sop.eq(counter.value == 0),
If(level.q == 0,
source.sop.eq(counter == 0),
If(level == 0,
source.eop.eq(1),
).Else(
source.eop.eq(counter.value == (level.q-1)),
source.eop.eq(counter == (level - 1)),
),
source.src_port.eq(udp_port),
source.dst_port.eq(udp_port),
source.ip_address.eq(ip_address),
If(level.q == 0,
If(level == 0,
source.length.eq(1),
).Else(
source.length.eq(level.q),
source.length.eq(level),
),
source.data.eq(fifo.source.data),
fifo.source.ack.eq(source.ack),
If(source.stb & source.ack,
counter.ce.eq(1),
counter_ce.eq(1),
If(source.eop,
NextState("IDLE")
)
Expand Down

0 comments on commit 403c33e

Please sign in to comment.