2015-09-12 07:34:07 -04:00
|
|
|
from migen import *
|
2012-01-09 10:28:48 -05:00
|
|
|
from migen.fhdl import verilog
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2013-03-12 11:45:28 -04:00
|
|
|
class Example(Module):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self):
|
|
|
|
self.s = Signal()
|
|
|
|
self.counter = Signal(8)
|
2014-11-25 04:16:21 -05:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
myfsm = FSM()
|
|
|
|
self.submodules += myfsm
|
2014-11-25 04:16:21 -05:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
myfsm.act("FOO",
|
|
|
|
self.s.eq(1),
|
|
|
|
NextState("BAR")
|
|
|
|
)
|
|
|
|
myfsm.act("BAR",
|
|
|
|
self.s.eq(0),
|
|
|
|
NextValue(self.counter, self.counter + 1),
|
|
|
|
NextState("FOO")
|
|
|
|
)
|
2014-11-25 04:16:21 -05:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
self.be = myfsm.before_entering("FOO")
|
|
|
|
self.ae = myfsm.after_entering("FOO")
|
|
|
|
self.bl = myfsm.before_leaving("FOO")
|
|
|
|
self.al = myfsm.after_leaving("FOO")
|
2013-03-12 11:45:28 -04:00
|
|
|
|
2015-09-12 07:34:07 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
example = Example()
|
|
|
|
print(verilog.convert(example, {example.s, example.counter, example.be, example.ae, example.bl, example.al}))
|