Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/migen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7427eeed394a
Choose a base ref
...
head repository: m-labs/migen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9cd4900c70c6
Choose a head ref
  • 2 commits
  • 7 files changed
  • 1 contributor

Commits on Oct 17, 2016

  1. doc: use sphinx_rtd_theme.

    whitequark committed Oct 17, 2016
    Copy the full SHA
    33cf38d View commit details
  2. doc: add documentation for FSM module.

    whitequark committed Oct 17, 2016
    Copy the full SHA
    9cd4900 View commit details
Showing with 72 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +2 −0 conda/migen/meta.yaml
  3. +5 −3 doc/conf.py
  4. BIN doc/migen_logo_white.png
  5. +7 −0 doc/reference.rst
  6. +52 −1 migen/genlib/fsm.py
  7. +5 −0 setup.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -5,3 +5,4 @@ vpi/*.o
vpi/migensim.vpi
examples/*.vcd
doc/_build
/build/
2 changes: 2 additions & 0 deletions conda/migen/meta.yaml
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@ build:
requirements:
build:
- python 3.5.*
- sphinx
- sphinx_rtd_theme
run:
- python 3.5.*

8 changes: 5 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))

import sphinx_rtd_theme

# -- General configuration -----------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
@@ -96,15 +98,15 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}

# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
@@ -115,7 +117,7 @@

# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
html_logo = 'migen_logo_white.png'

# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
Binary file added doc/migen_logo_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions doc/reference.rst
Original file line number Diff line number Diff line change
@@ -35,3 +35,10 @@ API reference
.. automodule:: migen.genlib.sort
:members:
:show-inheritance:

:mod:`genlib.fsm` module
-------------------------

.. automodule:: migen.genlib.fsm
:members:
:show-inheritance:
53 changes: 52 additions & 1 deletion migen/genlib/fsm.py
Original file line number Diff line number Diff line change
@@ -82,8 +82,45 @@ def visit_unknown(self, node):
else:
return node


class FSM(Module):
"""
Finite state machine
Parameters
----------
reset_state : str
Reset state. Defaults to the first added state.
Examples
--------
>>> self.active = Signal()
>>> self.bitno = Signal(3)
>>>
>>> fsm = FSM(reset_state="START")
>>> self.submodules += fsm
>>>
>>> fsm.act("START",
... self.active.eq(1),
... If(strobe,
... NextState("DATA")
... )
... )
>>> fsm.act("DATA",
... self.active.eq(1),
... If(strobe,
... NextValue(self.bitno, self.bitno + 1)
... If(self.bitno == 7,
... NextState("END")
... )
... )
... )
>>> fsm.act("END",
... self.active.eq(0),
... NextState("STOP")
... )
"""
def __init__(self, reset_state=None):
self.actions = OrderedDict()
self.state_aliases = dict()
@@ -95,6 +132,16 @@ def __init__(self, reset_state=None):
self.after_leaving_signals = OrderedDict()

def act(self, state, *statements):
"""
Schedules `statements` to be executed in `state`. Statements may include:
* combinatorial statements of form `a.eq(b)`, equivalent to
`self.comb += a.eq(b)` when the FSM is in the given `state`;
* synchronous statements of form `NextValue(a, b)`, equivalent to
`self.sync += a.eq(b)` when the FSM is in the given `state`;
* a statement of form `NextState("STATE")`, selecting the next state;
* `If`, `Case`, etc.
"""
if self.finalized:
raise FinalizeError
if self.reset_state is None:
@@ -119,6 +166,10 @@ def delayed_enter(self, name, target, delay):
self.state_aliases[name] = target

def ongoing(self, state):
"""
Returns a signal that has the value 1 when the FSM is in the given `state`,
and 0 otherwise.
"""
is_ongoing = Signal()
self.act(state, is_ongoing.eq(1))
return is_ongoing
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,10 @@
raise SystemExit("You need Python 3.3+")


requirements = [
"sphinx", "sphinx_rtd_theme"
]

setup(
name="migen",
version="0.4",
@@ -19,6 +23,7 @@
url="https://m-labs.hk",
download_url="https://github.com/m-labs/migen",
packages=find_packages(),
install_requires=requirements,
test_suite="migen.test",
license="BSD",
platforms=["Any"],