Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the explanation of stateReg usage in FSM. #270

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions source/SpinalHDL/Libraries/fsm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,17 @@ Example:
STATE_B.whenIsActive(goto(STATE_C))
STATE_C.whenIsActive(goto(STATE_B))
}

Notes about using state value
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In cases that users want to retrieve the state value for purpose, where state value could be accessed by `stateReg`.
However, the `stateReg` is not initialized during elaboration of state machine, so any access of `stateReg` directly could cause error.
Use the `postBuild` method as below can solve this problem.

.. code-block:: scala

// After or inside the fsm's definition.
fsm.postBuild{
io.status := fsm.stateReg.asBits //io.status is the signal user want to assigned to.
}
Loading