Wiki source code of PLDI'14 Artifact on SCCharts

Version 33.1 by cmot on 2014/03/13 13:54

Show last authors
1 [[image:attach:title7.png]]
2
3 = Modeling SCCharts with KIELER =
4
5 This tutorial should guide you if you like to model SCCharts with KIELER and use the circuit based software synthesis path as explained in our [1] [[PLDI'14 submission>>url:http://rtsys.informatik.uni-kiel.de/%7Ebiblio/downloads/papers/pldi14-submitted.pdf||shape="rect"]]. We will show you how to
6
7 ~1. Download & Start KIELER,
8
9 2. Model an SCChart, and
10
11 3. Generate C Code.
12
13 We will use a simple example here in order to illustrate the process. Please refer to the SCCharts superpage for the [[project status>>doc:SCCharts]] and [[known limitations>>doc:SCCharts]]. If you are interested in the source code you can find instruction how to download and compile it here: [[Getting Started>>url:http://rtsys.informatik.uni-kiel.de/confluence/display/KIELER/Getting+Started||shape="rect"]].
14
15 See a list of the evaluated examples at the end.
16
17
18
19 [1] PLDI submission: [[http:~~/~~/rtsys.informatik.uni-kiel.de/~~~~biblio/downloads/papers/pldi14-submitted.pdf>>url:http://rtsys.informatik.uni-kiel.de/%7Ebiblio/downloads/papers/pldi14-submitted.pdf||shape="rect"]]
20
21
22
23 In addition to the step-by-step tutorial below we also captured a [[video >>url:http://rtsys.informatik.uni-kiel.de/~~kieler/files/pldi14/sccharts.swf||shape="rect"]]that shows each of the explained steps:
24
25 [[~[~[image:attach:RTEmagicC_demo.png.png~]~]>>url:http://rtsys.informatik.uni-kiel.de/~~kieler/files/pldi14/sccharts.swf||shape="rect"]]
26
27 Download location: [[http:~~/~~/rtsys.informatik.uni-kiel.de/~~~~kieler/files/pldi14/sccharts.swf>>url:http://rtsys.informatik.uni-kiel.de/~~kieler/files/pldi14/sccharts.swf||shape="rect"]]
28
29 = 1. Download & Start KIELER =
30
31 [[Download>>url:http://rtsys.informatik.uni-kiel.de/~~kieler/files/pldi14/||shape="rect"]] a suitable KIELER version for your operation system. The zip bundles are fully compiled and ready-to-run, they do not need any further installation process. Just save and extract them to/at the location of your choice and start the KIELER executable.
32
33 [[~[~[image:attach:RTEmagicC_download.png.png~]~]>>url:http://rtsys.informatik.uni-kiel.de/~~kieler/files/pldi14/||shape="rect"]]
34
35 Download location: [[http:~~/~~/rtsys.informatik.uni-kiel.de/~~~~kieler/files/pldi14/>>url:http://rtsys.informatik.uni-kiel.de/~~kieler/files/pldi14/||shape="rect"]]
36
37 When you start the KIELER executable, you probably need to set a (new) workspace location of your choice. (Click on the images to enlarge them).
38
39 [[image:attach:kieler1.png]]
40
41 If you selected a new workspace location, you will see a welcome screen like this:
42
43 [[image:attach:kieler02.png]]
44
45 Dismiss this "Welcome" tab. After that you'll be all set and KIELER should look like this:
46
47 [[image:attach:kieler03.png]]
48
49 In order to prepare modeling, we must create a project. Right-click in the Project Explorer to do so.
50
51 [[image:attach:kieler04.png]]
52
53 Select a General Project and click on next, then enter a project name, e.g. pldi14 and click on finish:
54
55 [[image:attach:kieler05.png]][[image:attach:kieler06.png]]
56
57 Now KIELER should look like this:
58
59 [[image:attach:kieler07.png]]
60
61 Now you can proceed in modeling an SCChart as explained below.
62
63 = 2. Model an SCChart =
64
65 Right-click on a project and create a (text) File:
66
67 [[image:attach:kieler08.png]]
68
69 Name it abo.sct:
70
71 [[image:attach:kieler09.png]]
72
73 SCT is a textual description language for SCCharts. Due to space limitations SCT is not documented in the PLDI paper, but examples can be found [[here>>doc:SCT - Textual Description Language for SCCharts]]. Also the code completion functionality of the textual editor for SCT is very helpful. It can be invoked by pressing <Ctrl> + <Space>. It will list all syntactically possible input according to the SCT/SCCharts meta model.
74
75 The textual SCCharts Xtext based editor (for *.sct files) will automatically be opened:
76
77 [[image:attach:kieler10.png]]
78
79 Now start modeling an SCChart. For example copy & paste the following sct code of abo, the hello world of SCCharts:
80
81 {{code title="abo.sct"}}
82 @VHLayout
83 scchart ABO {
84 input output bool A;
85 input output bool B;
86 output bool O1;
87 output bool O2;
88 region:
89
90 initial state Init
91 --> WaitAB immediate with / O1 = false; O2 = false;
92 state WaitAB {
93 region HandleA:
94 initial state WaitA
95 --> DoneA immediate with A / B = true; O1 = true;
96 final state DoneA;
97 region HandleB:
98 initial state WaitB
99 --> DoneB with B / O1 = true;
100 final state DoneB;
101 }
102 >-> GotAB with / O1 = false; O2 = true;
103 state GotAB;
104 }
105 {{/code}}
106
107 As you save (Ctrl+S), KIELER will automatically draw the graphical SCChart diagram in a new KLigD view:
108
109 [[image:attach:kieler11.png]]
110
111 You may want to re-arrange views. Just drag the KLighD view to the right side:
112
113 [[image:attach:kieler12.png]]
114
115 You will now see how to generate a C tick function.
116
117 = 3. Generate C Code =
118
119 You can do several transformations on SCCharts (*.sct files). Just right click the file you want to transform in the project explorer and select the Transform SCChart sub menu. As abo is already a Core SCCart you do not need the core transformations. Click the All Normalize Transformations, this will do the Split Trigger and Effects and the Surface and Depth transformations together (in this order).
120
121 [[image:attach:kieler13.png]]
122
123 After performing a transformation the transformed SCChart will open (together with it's KLighD diagram visualization):
124
125 [[image:attach:kieler14.png]]
126
127 Now generate the Sequentially Constructive Graph (SCG) from the normalized form. You do this also in the context menu of the Project Explorer by selecting the *.normalized.sct and choosing Generate SCG. When selecting the abo.normalized.scg file the SCG diagram will be automatically synthesized (you may also want to re-arrange the KLigD view by dragging in to the right side again).
128
129 [[image:attach:kieler15.png]][[image:attach:kieler16.png]]
130
131
132
133 You can now populate the SCG automatically with dependency data. Choose Transform SCG -> SCG with Dependency Data from the context menu (left side). This will result in the following SCG (right side).
134
135 [[image:attach:kieler17.png]][[image:attach:kieler18.png]]
136
137
138
139 Now populate the SCG with basic block information (left side). The SCG with calculated basic blocks will look like this (right side).
140
141 [[image:attach:kieler19.png]][[image:attach:kieler20.png]]
142
143
144
145 The next step in compilation is the (more fine grained) calculate of scheduling blocks (left side). The populated SCG with scheduling information looks like this (right side).
146
147 [[image:attach:kieler21.png]][[image:attach:kieler22.png]]
148
149
150
151 The SCG is now ready to be sequentialized. A primitive scheduler currently is included in KIELER but more elaborate ones are already in the pipe line (left side). The sequentialized SCG looks like this (right side).
152
153 [[image:attach:kieler23.png]][[image:attach:kieler24.png]]
154
155
156
157 From here its only a short hop to C code. Transform the sequentialized SCG into an S Tick Function (left side). When opening the S file (abo.normalized.seq.s) this already is very c like code (right side).
158
159 [[image:attach:kieler25.png]][[image:attach:kieler26.png]]
160
161
162
163 Selecting Generate SC will produce a C file:
164
165 [[image:attach:kieler27.png]][[image:attach:kieler28.png]]
166
167
168
169 = 4. Evaluated Examples =
170
171 In the following, you find the examples used for evaluation. Be advised that there currently is no tool integrated evaluation possible. Please refer to the SCCharts superpage for the [[project status>>doc:SCCharts]] and [[known limitations>>doc:SCCharts]].
172
173 |=(((
174 Example
175 )))|=(((
176
177 )))|=(((
178 SCChart  (Graphical)
179 )))|=(% colspan="1" %)(% colspan="1" %)
180 (((
181 SCChart (Textual SCT)
182 )))
183 |(% colspan="1" %)(% colspan="1" %)
184 (((
185 = shifter3 =
186 )))|(% colspan="1" %)(% colspan="1" %)
187 (((
188
189 )))|(% colspan="1" %)(% colspan="1" %)
190 (((
191 [[image:attach:shifter3.png]]
192 )))|(% colspan="1" %)(% colspan="1" %)
193 (((
194 {{code title="shifter3.sct"}}
195 scchart shifter3 {
196 input signal int I = 1;
197 signal int S0;
198 signal int S1;
199 output signal int O;
200 region R1:
201 initial state I2
202 --> I2 with pre(S0) / S1(pre(val(S0)));
203 region R0:
204 initial state I1
205 --> I1 with pre(I) / S0(pre(val(I)));
206 region R2:
207 initial state I3
208 --> I3 with pre(S1) / O(pre(val(S1)));
209 }
210 {{/code}}
211 )))
212 |(((
213 = reincarnation =
214 )))|(((
215
216 )))|(((
217 [[image:attach:reincarnation.png]]
218 )))|(% colspan="1" %)(% colspan="1" %)
219 (((
220 {{code title="reincarnation.sct"}}
221 scchart reincarnation {
222 input signal A;
223 output signal gotS;
224 region R0:
225 initial state Reincarnation {
226 signal S;
227 region R0:
228 initial state I
229 --> C1 immediate;
230 state p;
231 final state r;
232 state q
233 --> r with A / S;
234 state C1
235 --> p immediate with S / gotS
236 --> q immediate;
237 }
238 >-> Reincarnation;
239 }
240 {{/code}}
241 )))
242 |(((
243 = cabin =
244 )))|(((
245
246 )))|(((
247 [[image:attach:cabin.png]]
248 )))|(% colspan="1" %)(% colspan="1" %)
249 (((
250 {{code title="cabin.sct"}}
251 scchart Cabin {
252 input signal Stop;
253 input signal CabinStopped;
254 input signal DoorIsOpen;
255 input signal DoorOpen;
256 input signal DoorSensor;
257 input signal DoorIsClosed;
258 input signal DoorClose;
259 input signal TimerExpired;
260 output signal StartOK;
261 output signal OpenDoorMotorOff;
262 output signal OpenDoorMotorOn;
263 output signal StartTimer;
264 output signal CloseDoorMotorOn;
265 output signal CloseDoorMotorOff;
266 region R0:
267 initial state I
268 --> Open immediate with / OpenDoorMotorOn;
269 state Open
270 --> S0 with DoorIsOpen / OpenDoorMotorOff;
271 state S0 {
272 region R0:
273 initial state Initial
274 --> S0 immediate with / StartTimer;
275 state S0
276 --> S1 with TimerExpired | DoorClose / CloseDoorMotorOn;
277 state S1
278 --> S2 with DoorIsClosed / StartOK;
279 final state S2;
280 }
281 o-> I with DoorOpen | DoorSensor / CloseDoorMotorOff
282 >-> S1 with / CloseDoorMotorOff;
283 state S1
284 --> S2 with Stop;
285 state S2
286 --> I with CabinStopped;
287 }
288 {{/code}}
289 )))
290 |(((
291 = reactor control =
292 )))|(((
293
294 )))|(((
295 [[image:attach:reactor-control.png]]
296 )))|(% colspan="1" %)(% colspan="1" %)
297 (((
298 {{code title="reactor-control.sct"}}
299 scchart Module_ReactorControl {
300 output signal PullOutRods;
301 output signal PushInRods;
302 input signal Start;
303 input signal OverHeated;
304 input signal CooledDown;
305 signal unsafe;
306 region main:
307 initial state init0 "I"
308 --> ParallelStatementList40state immediate;
309 state ParallelStatementList40state {
310 region R0:
311 initial state init1 "I"
312 --> Await43state immediate;
313 state Await43state {
314 region R0:
315 initial state init2 "I"
316 --> S18 immediate;
317 state S18 "18"
318 --> S23 with Start / PullOutRods;
319 state S23 "23";
320 }
321 o-> Await43state with unsafe;
322 region R1:
323 initial state init3 "I"
324 --> S94 immediate;
325 state S94 "94"
326 --> S134 immediate with unsafe / PushInRods;
327 state S134 "134"
328 --> S94 with !unsafe;
329 region R2:
330 initial state init4 "I"
331 --> S193 immediate;
332 state S193 "193"
333 --> Sustain68state immediate with OverHeated;
334 state Sustain68state {
335 region R0:
336 initial state init5 "I"
337 --> S227 immediate with / unsafe;
338 state S227 "227"
339 --> S227 with / unsafe;
340 }
341 o-> S193 with CooledDown;
342 };
343 }
344 {{/code}}
345 )))