This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 19th, 2013  |  syntax: Python  |  size: 1.18 KB  |  views: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. 228ca258232fbf2c1745db5a39fd935e710685a5
  2.  migen/genlib/fsm.py | 11 +++++++++++
  3.  1 file changed, 11 insertions(+)
  4.  
  5. diff --git a/migen/genlib/fsm.py b/migen/genlib/fsm.py
  6. index 85f3a40..3d5bac4 100644
  7. --- a/migen/genlib/fsm.py
  8. +++ b/migen/genlib/fsm.py
  9. @@ -6,6 +6,7 @@ class FSM:
  10.                
  11.                 self._state = Signal(max=nstates)
  12.                 self._next_state = Signal(max=nstates)
  13. +               self._last_state = Signal(max=nstates)
  14.                 for n, state in enumerate(states):
  15.                         setattr(self, state, n)
  16.                 self.actions = [[] for i in range(len(states))]
  17. @@ -31,6 +32,15 @@ class FSM:
  18.         def act(self, state, *statements):
  19.                 self.actions[state] += statements
  20.        
  21. +       def entering(self, state):
  22. +               return (self._state == state) & (self._last_state != state)
  23. +      
  24. +       def ongoing(self, state):
  25. +               return self._state == state
  26. +              
  27. +       def exiting(self, state):
  28. +               return (self._state != state) & (self._last_state == state)
  29. +              
  30.         def get_fragment(self):
  31.                 cases = dict((s, a) for s, a in enumerate(self.actions) if a)
  32.                 comb = [
  33. @@ -38,4 +48,5 @@ class FSM:
  34.                         Case(self._state, cases)
  35.                 ]
  36.                 sync = [self._state.eq(self._next_state)]
  37. +               sync += [self._last_state.eq(self._state)]
  38.                 return Fragment(comb, sync)
clone this paste RAW Paste Data