xiaoxiang781216 commented on code in PR #3296:
URL: https://github.com/apache/nuttx-apps/pull/3296#discussion_r2659002821


##########
system/smf/Kconfig:
##########
@@ -0,0 +1,28 @@
+# SMF (State Machine Framework) configuration options
+#
+# For syntax reference, see kconfig-language.txt in the NuttX tools repository.
+
+config APPS_SMF
+  bool "(SMF) support"
+  default n
+  ---help---
+    Enables the State Machine Framework (SMF) for implementing state machines
+
+if APPS_SMF
+
+config SMF_ANCESTOR_SUPPORT

Review Comment:
   use the same prefix APPS_SMF



##########
include/system/smf.h:
##########
@@ -0,0 +1,265 @@
+/****************************************************************************
+ * apps/include/system/smf.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __APPS_INCLUDE_SYSTEM_SMF_H
+#define __APPS_INCLUDE_SYSTEM_SMF_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef CONFIG_SMF_ANCESTOR_SUPPORT
+#  ifdef CONFIG_SMF_INITIAL_TRANSITION
+#    define SMF_CREATE_STATE(_entry, _run, _exit, _parent, _initial) \
+       { \
+         .entry = (_entry), \
+         .run = (_run), \
+         .exit = (_exit), \
+         .parent = (_parent), \
+         .initial = (_initial), \
+       }
+#  else
+#    define SMF_CREATE_STATE(_entry, _run, _exit, _parent, _initial) \
+       { \
+         .entry = (_entry), \
+         .run = (_run), \
+         .exit = (_exit), \
+         .parent = (_parent), \
+       }
+#  endif
+#else
+#  define SMF_CREATE_STATE(_entry, _run, _exit, _parent, _initial) \
+     { \
+       .entry = (_entry), \
+       .run = (_run), \
+       .exit = (_exit), \
+     }
+#endif
+
+#define SMF_CTX(o) ((struct smf_ctx *)(o))
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+enum smf_state_result
+{
+  SMF_EVENT_HANDLED,
+  SMF_EVENT_PROPAGATE
+};
+
+typedef void (*state_method)(void *obj);
+
+typedef enum smf_state_result (*state_execution)(void *obj);
+
+struct smf_state
+{
+  /* Optional method that will be run when this state is entered. */
+
+  state_method entry;
+
+  /* Optional method that will be run repeatedly during the state machine
+   * loop.
+   */
+
+  state_execution run;
+
+  /* Optional method that will be run when this state exits. */
+
+  state_method exit;
+
+#ifdef CONFIG_SMF_ANCESTOR_SUPPORT
+  /* Optional parent state that contains common entry/run/exit
+   * implementation among various child states.
+   * entry: Parent function executes BEFORE child function.
+   * run:   Parent function executes AFTER child function.
+   * exit:  Parent function executes AFTER child function.
+   * Note: When transitioning between two child states with a shared
+   * parent, that parent's exit and entry functions do not execute.
+   */
+
+  const struct smf_state *parent;
+
+#  ifdef CONFIG_SMF_INITIAL_TRANSITION
+  /* Optional initial transition state. NULL for leaf states. */
+
+  const struct smf_state *initial;
+#  endif /* CONFIG_SMF_INITIAL_TRANSITION */
+#endif /* CONFIG_SMF_ANCESTOR_SUPPORT */
+};
+
+struct smf_ctx
+{
+  /* Current state the state machine is executing. */
+
+  const struct smf_state *current;
+
+  /* Previous state the state machine executed. */
+
+  const struct smf_state *previous;
+
+#ifdef CONFIG_SMF_ANCESTOR_SUPPORT
+  /* Currently executing state (which may be a parent). */
+
+  const struct smf_state *executing;
+#endif /* CONFIG_SMF_ANCESTOR_SUPPORT */
+  /* This value is set by the set_terminate function and should */
+  /* terminate the state machine when its set to a value other than */

Review Comment:
   change to multiple line comment



##########
examples/smf/main.c:
##########
@@ -0,0 +1,127 @@
+/****************************************************************************
+ * apps/examples/smf/main.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Copyright (c) 2024 Glenn Andrews
+ * State Machine example copyright (c) Miro Samek
+ *
+ * Implementation of the statechart in Figure 2.11 of
+ * Practical UML Statecharts in C/C++, 2nd Edition by Miro Samek
+ * https://www.state-machine.com/psicc2
+ * Used with permission of the author.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "hsm_psicc2_thread.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: usage
+ ****************************************************************************/
+
+static void usage(void)
+{
+  printf("Usage:\n");
+  printf("  hsm_psicc2 start\n");
+  printf("  hsm_psicc2 event <A..I>\n");
+  printf("  hsm_psicc2 terminate\n");
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: hsm_psicc2_main
+ ****************************************************************************/
+
+int hsm_psicc2_main(int argc, char *argv[])

Review Comment:
   ```suggestion
   int main(int argc, char *argv[])
   ```



##########
examples/smf/Kconfig:
##########
@@ -0,0 +1,29 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config EXAMPLES_SMF
+  tristate "State Machine Framework PSICC2 demo (HSM)"
+  default n
+  select NSH_BUILTIN_APPS
+  select APPS_SMF
+  select SMF_ANCESTOR_SUPPORT

Review Comment:
   change to depends on



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to