2013-05-22 11:11:09 -04:00
|
|
|
from migen.fhdl.std import *
|
2013-02-22 17:19:37 -05:00
|
|
|
from migen.genlib.record import *
|
|
|
|
from migen.genlib.fsm import *
|
2012-01-15 16:08:33 -05:00
|
|
|
from migen.flow.actor import *
|
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2012-01-15 16:08:33 -05:00
|
|
|
# Generates integers from start to maximum-1
|
2013-04-10 13:12:42 -04:00
|
|
|
class IntSequence(Module):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self, nbits, offsetbits=0, step=1):
|
|
|
|
parameters_layout = [("maximum", nbits)]
|
|
|
|
if offsetbits:
|
|
|
|
parameters_layout.append(("offset", offsetbits))
|
2014-10-17 05:08:37 -04:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
self.parameters = Sink(parameters_layout)
|
|
|
|
self.source = Source([("value", max(nbits, offsetbits))])
|
|
|
|
self.busy = Signal()
|
2014-10-17 05:08:37 -04:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
###
|
2014-10-17 05:08:37 -04:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
load = Signal()
|
|
|
|
ce = Signal()
|
|
|
|
last = Signal()
|
2014-10-17 05:08:37 -04:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
maximum = Signal(nbits)
|
|
|
|
if offsetbits:
|
|
|
|
offset = Signal(offsetbits)
|
|
|
|
counter = Signal(nbits)
|
2014-10-17 05:08:37 -04:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
if step > 1:
|
|
|
|
self.comb += last.eq(counter + step >= maximum)
|
|
|
|
else:
|
|
|
|
self.comb += last.eq(counter + 1 == maximum)
|
|
|
|
self.sync += [
|
|
|
|
If(load,
|
|
|
|
counter.eq(0),
|
|
|
|
maximum.eq(self.parameters.maximum),
|
|
|
|
offset.eq(self.parameters.offset) if offsetbits else None
|
|
|
|
).Elif(ce,
|
|
|
|
If(last,
|
|
|
|
counter.eq(0)
|
|
|
|
).Else(
|
|
|
|
counter.eq(counter + step)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
if offsetbits:
|
|
|
|
self.comb += self.source.value.eq(counter + offset)
|
|
|
|
else:
|
|
|
|
self.comb += self.source.value.eq(counter)
|
2014-10-17 05:08:37 -04:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
fsm = FSM()
|
|
|
|
self.submodules += fsm
|
|
|
|
fsm.act("IDLE",
|
|
|
|
load.eq(1),
|
|
|
|
self.parameters.ack.eq(1),
|
|
|
|
If(self.parameters.stb, NextState("ACTIVE"))
|
|
|
|
)
|
|
|
|
fsm.act("ACTIVE",
|
|
|
|
self.busy.eq(1),
|
|
|
|
self.source.stb.eq(1),
|
|
|
|
If(self.source.ack,
|
|
|
|
ce.eq(1),
|
|
|
|
If(last, NextState("IDLE"))
|
|
|
|
)
|
|
|
|
)
|