An Introduction to FsmPro

FsmPro
FsmPro
Jul 13 · 7 min read

This is an introduction to FsmPro, An ultimate tool to design State Machines and generate code from State Diagrams.

If you have an project built with the C language and depend on State Machines to handle time-critical business logic, FsmPro can help you design State Machines and integrate generated code files seamlessly into your project. There is no limit on the number of State Machines that can be designed and the interaction between State Machines and Software Modules can be graphically mapped for better understanding and maintenance.

FsmPro saves development time and helps in the maintenance of projects. In this article, We would take a tour of the tool by creating a project and walking through the features FsmPro has to offer for designing complex systems.

Creating a Project

To create a project, go to the file menu from the menu bar, click new and give a name to your project in the window. In this example, the name of the project is MyApp. A file with .rfsm extension would be created in the selected location. This is the only file you would need to work with FsmPro.

Project Hierarchy

In the project browser, the hierarchy can be expanded to view the content at each level. By default, A project has a Hardware Module at level 2 which has a Microcontroller(level 3) that houses Software Modules(level 4) which in turn houses the State Machines(level 5).

Each item in the project hierarchy has an associated process item. You can change the label of any item in the project hierarchy by making changes to the associated process item(Shown in detail below).

Project Elements

To design State Machines, FsmPro provides several project elements at different levels of project hierarchy as shown below. Note that State Diagrams can be designed only at level 6.

Process Item

A process item is an abstract project element that is used to denote an entry in the project hierarchy. For example, In the image shown below, MyApp has two software modules: Main Module and Engine Control. Both modules can contain one or more State Machines and have a dependency on each other for data and signals. Also, Main Module gets the Rpm value from Engine Control by using its get_Rpm() API and sets the engine speed using set_speed(int).

A typical Engine Control module could be of vital importance to a project and shall be changed only by a select few and can be shown in red colour. To add a process, simply select process item(rounded rectangle) from the toolbar and add it to the canvas with a simple click. A real-world project could have several software modules and state machines denoted by process items with bi-directional dependency.

Link Item

Links represent dependencies between two process items. In the image above, Main Module is dependent on Engine control for RPM. It uses a link item to access Engine Control API getRpm() that returns an integer.

To draw a Link, select Link Item from the toolbar that would change the cursor to the shape of a link, click on the source process item and drag the mouse to the destination process item. A Link can only connect two process items.

It is possible to change the background colour of a Link Item by using its properties window. For all graphical items, the properties window can be invoked either by double-clicking on the item or by selecting properties from the context menu.

Memory Item

A Memory Item is used to denote global variables in FsmPro. A System might use global variables as a part of its design. Globals could be of any type: Integer, Struct, Enum, Float, etc.

In the image below, Main Module has two State Machines: Primary (primary_sm) and Auxiliary (aux_sm). The two State Machines could use a global integer variable for their individual purpose. In this example, a boolean global variable, app_status is shared between the two State Machines.

A project could have several memory items to represent variables of different types. To draw a memory Item, select the memory item option from the toolbar and click on the canvas to add it to the project.

Dataflow Item

Dataflow item denotes the relationship between a Memory item and a Process item. Dataflow item inherits its label from the connected memory item.

To draw a Dataflow, select the Dataflow option from the toolbar, click and drag from a source memory item to a destination process item or vice versa.

Initial State Item

Initial State is the entry to the State Machine and displayed in red. There can only be one initial state in a State Machine. Only in the initial state, an optional initial condition can be inserted. When the initial condition is true, the initial state action(shown below) is executed. The initial condition can be used to block the execution of a State Machine.

Initial condition and initial action can be inserted in the Initial tab of the Properties window of a State Item.

State Item

A state can be inserted in a State Machine by selecting insert state from the toolbar and clicking on the canvas. There is no limit on the number of states that can be inserted in a State Machine.

A State Item has the following properties:

  • Label: This is shown on the top of the State Item and would be represented as a function name when code is generated.
  • Action: This is the code for a given state and is shown in the body of the state. It is reflected as-is in the generated code. It is recommended to paste code in the action text field of the state properties window. Action code is executed as long as the condition for a given state is true while the control is in a given State.
  • Description: It is a textual description of a given state which can be used for documentation purpose. It is available for all graphical items.

Also, like all graphical items, the visual appearance of a state can be changed in the properties window. Any state can be converted to an initial state by checking the Set Initial State checkbox on the properties window.

Transition Item

Transition Item represents a transition from one state to other. A transition is executed when its condition(shown in blue) is true. The action code of a transition is executed once before making the transition to the destination state. To insert a transition, select insert transition from the toolbar, click on the source state and drag the mouse to the destination state.

A Transition item has the following properties:

  • Label: This is shown on the top of the Transition Item and would be represented as a comment in the generated code.
  • Condition: This represents the logical condition for the transition to execute and is shown in blue. Note that brackets shall be maintained for the condition but there is no need to mention the if keyword,
  • Action: This is the action code for a given transition and is executed once the transition condition is true before the control goes to the destination state. It is recommended to paste code in the action text field in the transition properties window.

Text Item

A Text item is a multipurpose graphics element. An instance of Text item can be present in one of the following modes:

  • Macros: In this mode, a text item is used to define a macro which would be represented in the global section of the generated code file.
  • Includes: This mode is used to include external files.
  • Default: In this mode, global comments or compilable code snippets can be inserted which would reflect as-is in the global section of the generated source file.

Mode for a text item can be selected at the bottom of the properties window and respective text can be provided in the action box.

How to Design Bluetooth Earphones by Pairing Logic with State Machines — Part 2 | by Faisal Khan | codeburst

Code generation

To generate code from State Diagrams, select generate code option from the Run Menu. Enter details in the dialog and click on generate. A header and source file is generated for each State Machine.

In addition, you can also take an In-app tour which can be invoked from the help menu. FsmPro is available to download for Windows and Linux distributions. If you any queries getting started with FsmPro, reach out to us at info@fsmpro.io. We’ll be glad to help.

FsmPro

Design robust embedded systems fast