Skip to content

Enterprise Architect

  1. Create a new empty model and add a package to it.
    Project Browser
  2. Go to the package Properties and set the Stereotype to LL Embedded. This will add the needed Tagged Values as shown below.
    1. Set the GenerationLanguage Tagged Value to the language you would like to generate
    2. Set the GenSrcDir Tagged Value to the output path where you would like to generate the code to (relative paths will be relative to the current EAP file location)
      Stereotype
  3. Add the FSM structure to the newly-created package.
    FSM
    FSM
    FSM
  4. Now add a new Embedded Engineer diagram. This will be the diagram which displays your class and the dependencies of your class.
    Diagram
    Diagram
  5. The new diagram is opened automatically. Now add the FSM classes to your new diagram.
    FSM
  6. From the class toolbox, add a new class to the diagram.
    Toolbox
  7. From the Embedded Engineer toolbox, add a constructor to your class. You can put your initialization code in this method. This method will also contain initialization code for the state machines you define in your class.
    StateMachine Project Browser
  8. Now add a State Machine.
    StateMachine
  9. Your class now contains a state machine with a state machine diagram.
    StateMachine
  10. You can now add states and transitions to your state machine.
    Transition
  11. Add a Signal to the Transition of the state machine. Double-Click on the transition from State1 to itself, which brings up the transition properties. Here you can define a guard and triggers. Add a new trigger of type Signal, and also add a new Signal to your model in the same package where your class resides. For more information about signals and triggers, please consult the Enterprise Architect User Guide.
    You need to add a trigger as well as a signal. Please check if they're part of your model by using the Project Browser.
    Signal
    Signal
  12. Now you need an Enumeration for the signal. This enumeration will be filled with the signals from your model. You can also add other values here or alter the base value of your enumeration. From the toolbox, select Enumeration and add it to your diagram. Change the name to Signals, which is the name of the signals enumeration for Embedded Engineer.
    Signal
  13. Generate the signals. Right-click on the package, select Extensions LieberLieber Embedded Engineer Generate Signals. The signals enumeration will be updated accordingly.
    Signal
    Signal
    Signal
  14. The only thing missing now is the dependency between our class and the supporting definitions from FSM. Open the class diagram, and draw a Usage from the class to the FSM interface. This will instruct the code generator to include the FSM.h file (which is also generated) from MyClass.h.
    Using
  15. Depending on the toolchain you're using, and the availability of stdbool.h, you can now add a type definition for bool. Here we've added a type definition typedef int bool in a new static class called TypeDefinitions. Whenever you need the typedef, just add a 'use' relation to the TypeDefinitions class (see: How do I generate a define or a typedef?).
    Using
  16. Now we're ready to generate code. Right-click on the package, select Extensions LieberLieber Embedded Engineer Generate Code. Select an output directory for the generated files. The code will be generated and written to the specified directory.
    Generate
  17. The source code is now ready to be compiled and used in your project. Below is an example usage of the generated code.
  18. Using the generated code in your code

Example

This is just an example implementation to show you how to use the generated code.

// Include the main header file of the class
#include "MyClass.h"

int main(void)
{
    // Get an instance for this class (statically allocated, will always return the same instance!)
    MyClass* myClass = MyClass_new();

    // Example on how to call the constructor (if one was modelled)
    MyClass_MyConstructor(myClass);

    // Example on how to initialize a state machine (if one was modelled)
    MyClass_StateMachine_init(&myClass->StateMachine);

    // Example on how to run a state machine (if one was modelled)
    // The implementation on your target may differ
    while (true)
    {
        // Call the state machine with no signal
        MyClass_StateMachine(myClass, &myClass->StateMachine, NOSIG);
    }
}