Skip to content

Commit

Permalink
Merge pull request #270 from Readon/master
Browse files Browse the repository at this point in the history
add the explanation of stateReg usage in FSM.
  • Loading branch information
Dolu1990 authored Dec 20, 2024
2 parents 8b5f9b6 + 40c23a4 commit 39440ae
Showing 1 changed file with 14 additions and 0 deletions.
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.
}

0 comments on commit 39440ae

Please sign in to comment.