Enterprise Architect
-
- Create a new empty model and add a package to it.
- Go to the package Properties and set the Stereotype to
LL Embedded
. This will add the needed Tagged Values as shown below.- Set the
GenerationLanguage
Tagged Value to the language you would like to generate -
- 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)
- Set the
- Set the
-
- Add the FSM structure to the newly-created package.
-
- Now add a new Embedded Engineer diagram. This will be the diagram which displays your class and the dependencies of your class.
-
- The new diagram is opened automatically. Now add the FSM classes to your new diagram.
-
- From the class toolbox, add a new class to the diagram.
-
- 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.
-
- Now add a State Machine.
-
- Your class now contains a state machine with a state machine diagram.
-
- You can now add states and transitions to your state machine.
-
- 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.
- Add a Signal to the Transition of the state machine. Double-Click on the transition from
-
- 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.
-
- Generate the signals. Right-click on the package, select
Extensions
LieberLieber Embedded Engineer
Generate Signals
. The signals enumeration will be updated accordingly.
- Generate the signals. Right-click on the package, select
-
- 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) fromMyClass.h
.
- 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
-
- Depending on the toolchain you're using, and the availability of
stdbool.h
, you can now add a type definition forbool
. 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?).
- Depending on the toolchain you're using, and the availability of
-
- 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.
- The source code is now ready to be compiled and used in your project. Below is an example usage of the generated code.
- 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);
}
}