Skip to content

Conversation

@FelipeMdeO
Copy link
Contributor

Fixed build issues

Added example to demonstate state machine framework

Removed unused file

Improve code quality | Fix thread termination issue

Note: Please adhere to Contributing Guidelines.

Summary

This change adds the State Machine Framework (SMF) to nuttx-apps as a
self-contained, reusable library.

The SMF provides a deterministic framework for implementing flat and
hierarchical state machines, based on explicit entry, run, and exit actions.
Event handling and scheduling remain fully under application control.

The implementation is a port of the SMF originally introduced in the Zephyr
RTOS, adapted to NuttX coding conventions and build infrastructure. The library
does not perform dynamic memory allocation and is intended to be used with
statically defined state tables.

An example application is included to demonstrate correct usage.

Impact

  • Adds a new optional library to nuttx-apps, enabled via Kconfig.
  • No impact on existing applications when the feature is disabled.
  • No changes to existing APIs or build configurations.
  • No dynamic memory usage introduced.
  • Architecture-independent and suitable for both hosted and embedded targets.

Testing

The change was validated using the provided SMF hierarchical state machine
(HSM) example application. Example available in:
| Prompt: State Machine Framework PSICC2 demo (HSM) │
│ Location:

│ -> Application Configuration │
│ -> Examples
| -> State Machine Framework PSICC2 demo

Testing was performed by enabling the SMF configuration options and building
the example for the simulator target. The example demonstrates:

  • Initialization of the state machine using smf_set_initial()
  • Execution of flat and hierarchical states
  • State transitions triggered from run actions
  • Entry and exit action sequencing
  • Graceful termination using smf_set_terminate()

The example was built and executed using the sim:nsh configuration. Runtime
output was manually verified to confirm correct state transitions and expected
execution order.

No regressions were observed, and existing applications build and run
unchanged when SMF is not enabled.

Copy link
Contributor

@linguini1 linguini1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really solid! Just some minor comments to pass the CI checks/adhere to the formatting rules. Thank you for porting this to NuttX!

By the way, the commit message's topic and the PR title should be formatted like: system/smf: Port SMF .c/.h files to NuttX

@FelipeMdeO FelipeMdeO force-pushed the feature/add-smf-squashed branch 8 times, most recently from 0c1804d to 33f79f2 Compare January 3, 2026 03:25
acassis
acassis previously approved these changes Jan 3, 2026
@FelipeMdeO
Copy link
Contributor Author

Hello All, I solved the issues as requested. Thanks for the review.

@linguini1 linguini1 changed the title Port SMF .c/.h files to NuttX system/smf: Port SMF .c/.h files to NuttX Jan 4, 2026
linguini1
linguini1 previously approved these changes Jan 4, 2026
Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @FelipeMdeO very useful features! :-)

Just please update select to depends on in the Kconfig as requsted by @xiaoxiang781216 :-)

Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm, sorry still some build errors + Kconfig updates todo :-)

@cederom
Copy link
Contributor

cederom commented Jan 4, 2026

Very cool, thanks @FelipeMdeO, lets just wait for the CI build verificaion :-)

@FelipeMdeO FelipeMdeO force-pushed the feature/add-smf-squashed branch from 4f33113 to 1f1cd96 Compare January 4, 2026 12:06
This commit add state machine framework lib to the NuttX project. Also an example is added to help users understand and use this feature.

Changes: Added some files. No impact in other features are expected.

Adjust SMF macro names

Fix issues requested during MR review

update kconfig

fix ci-cd issue

Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
@FelipeMdeO FelipeMdeO force-pushed the feature/add-smf-squashed branch from 1f1cd96 to 2172562 Compare January 4, 2026 12:25
Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @FelipeMdeO :-) Lets just wait for the CI to complete :-)

@linguini1 linguini1 merged commit ca11a7e into apache:master Jan 5, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants