Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4c637b111d0daed332fefd651dbc0e02cb89f19d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
\section{HelloWorld for C}

\subsection{Scope}

In this tutorial you will learn how to create a model for C from scratch. There are some more steps to do 
in C compared to Java. The goal is to get familiar with the additional steps. The Java tutorial is a 
prerequisite for the following explanations. 
You will perform the following steps:

\begin{enumerate}
\item create a new model from scratch for C
\item create structure and behavior similar to Java
\item create a launch configuration for the C code generator
\item setup the C environment
\item generate the source code
\item run the model
\end{enumerate}

Make sure that you have set up the workspace as described in \textit{Setting up the Workspace for C 
Projects}.


\subsection{Create a new model from scratch}

Before you can create a new C-model, you have to create a new C project as described in \textit{Setting up 
the Workspace for C Projects}.
Remember:
\begin{itemize}
\item select the \textit{C/C++} perspective
\item From the main menue select \textit{File->New->C Project}
\item Name the project \textit{HelloWorldC}
\item Project type is \textit{Executable / Empty C Project}
\item Toolchain is \textit{MinGW}
\end{itemize}

The workspace should look like this:

\includegraphics{images/016-HelloWorldC01.png}
% !images/016-HelloWorldC01.png!

The next step is to add the model folder:
Right click on the new project. Select \textit{New->Folder} and name it \textit{model}.

\includegraphics{images/016-HelloWorldC02.png}
% !images/016-HelloWorldC02.png!

Add the model file to the folder. Right click on the new folder. Select \textit{New->file} and name it 
\textit{HelloWorldC.room}.

\includegraphics{images/016-HelloWorldC03.png}
% !images/016-HelloWorldC03.png!

Due to the file ending \textit{.room}, the tool will ask you to add the Xtext nature. Answer with 
\textit{Yes}. 

\includegraphics{images/016-HelloWorldC04.png}
% !images/016-HelloWorldC04.png!

The workspace should look like this:

\includegraphics{images/016-HelloWorldC05.png}
% !images/016-HelloWorldC05.png!



\subsection{Create the HelloWorld model}

Once the model file is created and the Xtext nature is added, you can create the model as you did it for 
Java.
Creating the model is not the focus of this tutorial. Therefore copy and paste the following code into 
your model file. Optionally you can open and layout the diagrams.  
Recognize the C specific parts:
\begin{itemize}
\item The action code contains C instead of Java. Later versions will contain a common action language, 
but for the moment the action language is target specific.
\item The application must be shutdown on model level (see also \textit{etRuntimeConfig.h}).  
\end{itemize}

\begin{verbatim} 
RoomModel HelloWorldCModel {
	import room.basic.types.* from "../../org.eclipse.etrice.modellib.c/model/Types.room"
	SubSystemClass HelloWorldCSubSysClass {
		ActorRef HelloETriceTopRef:AHelloWorldCTop 
	}
	ActorClass AHelloWorldCTop {
		Structure { }
		Behavior {
			StateMachine {
				Transition init: initial -> state0 { }
				State state0 {
					entry {
						"printf(\"HelloWorldC !\\n\");"
						"SubSysClass_shutdown();"
						"\t\t\t\t\t\t"
					}
				}
			}
		}
	}	
}
\end{verbatim}

\subsection{Create a launch configuration to start the C code generator}

Other than in Java a launch configuration for the C code generator must be created.

From the \textit{Run} menu select \textit{Run Configurations}

\includegraphics{images/016-HelloWorldC06.png}
% !images/016-HelloWorldC06.png!

Within the dialog select \textit{\eTrice{} C Generator} and click the \textit{New} button to create a new 
launch configuration.

\includegraphics{images/016-HelloWorldC07.png}
% !images/016-HelloWorldC07.png!

A new configuration should be created. Name it \textit{gen\_HelloWorldC} and add the model via one of the 
\textit{add} buttons.

\includegraphics{images/016-HelloWorldC08.png}
% !images/016-HelloWorldC08.png!

In the \textit{Refresh} tab select \textit{The entire workspace} 

\includegraphics{images/016-HelloWorldC09.png}
% !images/016-HelloWorldC09.png!

In the \textit{Common} tab select \textit{Shared file} and add the \textit{HelloWorldC} project via the 
\textit{Browse} button.

\includegraphics{images/016-HelloWorldC10.png}
% !images/016-HelloWorldC10.png!

Apply your changes. The new configuration should now exist in your workspace.

\includegraphics{images/016-HelloWorldC11.png}
% !images/016-HelloWorldC11.png!


\subsection{Generate the code}

Now you can generate the code as you know it from Java. Right click on the launch configuration and run it 
as \textit{gen\_HelloWorldC}.

\includegraphics{images/016-HelloWorldC12.png}
% !images/016-HelloWorldC12.png!

The code should be generated.

\includegraphics{images/016-HelloWorldC13.png}
% !images/016-HelloWorldC13.png!

\subsection{Setup the include path}

Before you can build the application you must setup the include path for the runtime system. Right click 
the project and select \textit{Properties}. Add the include path as described in \textit{setting up the 
workspace}.

\includegraphics{images/016-HelloWorldC14.png}
% !images/016-HelloWorldC14.png!

Add the runtime library.

\includegraphics{images/016-HelloWorldC15.png}
% !images/016-HelloWorldC15!

Recognize the name of the library ("org.eclipse.etrice.runtime.c"). The library file on your disk is 
"liborg.eclipse.etrice.runtime.c.a". 

\subsection{Build and run the model}

Now you can build the application. Click the build button to build the application.
Run the application as \textit{Local C/C++ Application}.
Verify the output.

\includegraphics{images/016-HelloWorldC16.png}
% !images/016-HelloWorldC16.png!

\subsection{Summary}

You are now familiar with all necessary steps to create, build and run an \eTrice{} C model from scratch. You 
are able to create a launch configuration to start the code generator and to perform all necessary 
settings to compile and link the application.  

The next tutorial provides an exercise to get more familiar with these working steps.

Back to the top