-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
smf: support initial transition to nested states #55344
Comments
Noted |
Tagging maintainer @sambhurst and collaborator @keith-zephyr. |
I think the hierarchical model can support this today. In your case a button press in the
Note that if |
I agree that transitions to child states from parent siblings are supported today as you describe. But the current implementation leaks the implementation details of the parent state that I can definitely make this work, but initial transitions would be nice. |
I also agree with your example about transitioning between sibling states in |
@bdunlay This does seem like a useful feature. Will you be submitting an initial PR? I spoke to @keith-zephyr offline and he said we could add something like the following to
You might have an issue with the child entry being called twice, once from |
I'd need to spend some time digging in to understand how it can be changed to avoid improper entry/exit calls. But in the meantime, would you be open to changing the signature of the
|
I'd be reluctant to add another member to |
4 bytes per state for a pointer to support initial states on a 32 bit machine, yes. I gather that your flash requirements must be tight since you're probably using this in very constrained microcontrollers for managing usb-c devices. Would consuming another 132 or say 200 bytes severely impact those systems? I'm not sure how else initial states could be reasonably supported in first-class manner. I suppose one approach could be an optional feature, but seems a bit brutalist to have to turn that on in addition to the ancestor feature. Do you have any suggestions? And just to clarify, maybe I didn't understand @sambhurst when he commented that "this might be a useful feature." Was that in reference to first-class support for nested initial states? Or just fixing the issue that transitioning from parent to child (or any descendant) causes exit and reentry of that same parent? Obviously the latter will have to come in either way. |
Is a potential workaround here, that in the parent state's entry function, you issue The trick is that |
I spoke to @keith-zephyr offline and he said we could add something like the following to
A problem with this is that it only catches the issue if the target state is a direct, 1st-level child of the current state. If it's more than 1 level down, it'll still execute the exit function. There probably needs to be some |
I would argue that this is not just an "enhancement", this is a bug fix. This is in the way of being able to implement HSMs that follow the generally accepted behavior of HSMs (e.g., the behavior expounded in Miro Samek's book). |
@YaronShragai That was exactly my motivation behind this issue, Miro Samek's model, after having worked with his QP frameworks in the past. As an side note, unfortunately I am no longer employed by the company I was working for when I wrote this issue, so it's very unlikely I'll be able to commit any time to this going forward. I appreciate the renewed interested however, as I believe this would really be a useful change. |
Could we do it as a config option: |
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for RAM-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. 3. Adding a test case for `CONFIG_SMF_INITIAL_TRANSITION` and `smf_set_handled()` 4. Updating documentation for the new API (and fixing some references) There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for resource-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. 3. Adding a test case for `CONFIG_SMF_INITIAL_TRANSITION` and `smf_set_handled()` 4. Updating documentation for the new API (and fixing some references) There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for resource-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. 3. Adding a test case for `CONFIG_SMF_INITIAL_TRANSITION` and `smf_set_handled()` 4. Updating documentation for the new API (and fixing some references) There was discussion in #55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for resource-constrained devices. This does not fix #66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. 3. Adding a test case for `CONFIG_SMF_INITIAL_TRANSITION` and `smf_set_handled()` 4. Updating documentation for the new API (and fixing some references) There was discussion in zephyrproject-rtos/zephyr#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for resource-constrained devices. This does not fix zephyrproject-rtos/zephyr#66341 but documentation has been updated to warn users of the issue. (cherry picked from commit 0569809) Original-Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com> GitOrigin-RevId: 0569809 Change-Id: Ia2fdb5c57a2b108ff1827858138fb066410a186d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5344158 Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com> Reviewed-by: Tristan Honscheid <honscheid@google.com> Commit-Queue: Tristan Honscheid <honscheid@google.com> Tested-by: Tristan Honscheid <honscheid@google.com>
Brings SMF framework closer into alignment with accepted Hierarchical State Machine operation by: 1. Allowing 'programming by difference' by having some child states handle events and prevent propagation up to the parent run actions while others propagate events up to a common handler in a parent state. 2. Optionally allow initial transitions within a parent state to determine the most nested child state to transition to. 3. Adding a test case for `CONFIG_SMF_INITIAL_TRANSITION` and `smf_set_handled()` 4. Updating documentation for the new API (and fixing some references) There was discussion in zephyrproject-rtos#55344 about not making the initial transition a Kconfig option, but I'm not sure of any way else of doing it without permanently adding a pointer to each `smf_state` entry, which is a problem for resource-constrained devices. This does not fix zephyrproject-rtos#66341 but documentation has been updated to warn users of the issue. Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
#66753 should solve this issue. |
#71252 fixes all issues with initial transitions. This can be closed. |
Is your enhancement proposal related to a problem? Please describe.
SMF's hierarchical state machine doesn't support nested initial state transitions. This is a useful feature to have so that child states can remain abstracted from higher level states in the state machine.
Today, the only way to transition to a child state is to update the state machine to the sub-state directly. And this is problematic because setting the state always calls the exit action, even when an exit might not be occurring. For example, transitioning to a child state from a parent state is not an exit from the parent state.
Describe the solution you'd like
I would like to be able to define initial transitions so that I can set the current state to a parent state, which will then immediately transition to the designated initial child state, all without calling the exit action on the parent state.
Describe alternatives you've considered
I considered putting a
smf_set_state
call in the entry action of the parent state, but this appears to call the current state's exit function before transitioning to the child state.Additional context
Here's a visual of what I want to happen.
BUTTON_PRESS
fromOFF
state should transition toON
state, andON
state should transition immediately toSTART_MODIAL_INTERACTION
state.The text was updated successfully, but these errors were encountered: