There is a very simple example which shows how to work with the Cuml tool.
For this example I was using the ArgoUML editor. The final diagram is shown on the picture below.
The diagram is exported into the XMI file you can find attached.
Open console and type in the following command line.
cuml -o . ./BlinkingLED.xmi
This produces the following files into the current folder (specified by -o parameter):
I have found a nice piece of the code implementing the timer for Win32 and Linux as well at https://www.teuniz.net/Timer_code/. We will use it as the timer BSP.
The main.c is the main entry, it has to initialise the HSM framework and timer. There are also implemented helper functions such as LedOn() and LedOff().
#include <stdio.h> #include <stdlib.h> #include "HSM_Framework.h" #include "blinkingLED_FSM.h" #include "timer.h" void LedOn(void) { printf("LED ON\n"); } void LedOff(void) { printf("LED OFF\n"); } void TimerHandler(void) { HSM_AddPendingEvent( &blinkingLED_FSM, eTimeout ); } void StartTimer(int ms) { if(start_timer(ms, &TimerHandler)) { printf("\n timer error\n"); exit(EXIT_FAILURE); } } int main(void) { //first of all we need to init state machine framework HSM_Init(); printf("\npress ctl-c to quit.\n"); //the main infinite loop while(1) { HSM_ProcessEvents(); } return EXIT_SUCCESS; }
The compiler needs to know prototypes of all functions we used in the diagram. The HSM_Setup.h is the right file where to define protopypes or to include header files. Simply add the declaration as follows:
// Include all files you need here #include <stdint.h> extern void LedOn(void); extern void LedOff(void); extern void StartTimer(int ms);
To be able to build the program on your computer a C-compiler is needed. You are free
to use whatever compiler you have installed. I used the GCC toolchain for MinGW.
The Makefile is easy to write.
CC = gcc CFLAGS = -I. LDFLAGS = %.o: %.c $(CC) $(CFLAGS) -o $@ -c $< blinkingLED: main.o blinkingLED_FSM.o HSM_Framework.o timer.o $(CC) -o $@ $^ $(LDFLAGS)
Type make in a console located into your folder. You should see something like this:
gcc -I. -o main.o -c main.c gcc -I. -o blinkingLED_FSM.o -c blinkingLED_FSM.c gcc -I. -o HSM_Framework.o -c HSM_Framework.c gcc -I. -o timer.o -c timer.c gcc -o blinkingLED main.o blinkingLED_FSM.o HSM_Framework.o timer.o
That's all. Try to run the executable file blinkingLED.exe.
You can download the source code and the diagram