fsm.py: set reset_state
authorRobert Jördens <jordens@gmail.com>
Mon, 22 Jul 2013 08:09:12 +0000 (02:09 -0600)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Mon, 22 Jul 2013 08:30:40 +0000 (10:30 +0200)
migen/genlib/fsm.py

index 7765f1521bfd6fa6cc6f9c663773315a0b0c7441..5fa577d9745f6092aa2c11bb92797ac230e056ca 100644 (file)
@@ -30,10 +30,10 @@ class _LowerNextState(NodeTransformer):
                        return node
 
 class FSM(Module):
-       def __init__(self):
+       def __init__(self, reset_state=None):
                self.actions = OrderedDict()
                self.state_aliases = dict()
-               self.reset_state = None
+               self.reset_state = reset_state
 
        def act(self, state, *statements):
                if self.finalized:
@@ -62,6 +62,8 @@ class FSM(Module):
 
                self.encoding = dict((s, n) for n, s in enumerate(self.actions.keys()))
                self.state = Signal(max=nstates)
+               if self.reset_state is not None:
+                       self.state.reset = self.encoding[self.reset_state]
                self.next_state = Signal(max=nstates)
 
                lns = _LowerNextState(self.next_state, self.encoding, self.state_aliases)