Wiki source code of PLDI'14 Artifact on SCCharts

Version 32.1 by cmot on 2014/03/13 13:52

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
16
17 [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"]]
18
19
20
21 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:
22
23 [[~[~[image:attach:RTEmagicC_demo.png.png~]~]>>url:http://rtsys.informatik.uni-kiel.de/~~kieler/files/pldi14/sccharts.swf||shape="rect"]]
24
25 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"]]
26
27 = 1. Download & Start KIELER =
28
29 [[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.
30
31 [[~[~[image:attach:RTEmagicC_download.png.png~]~]>>url:http://rtsys.informatik.uni-kiel.de/~~kieler/files/pldi14/||shape="rect"]]
32
33 Download location: [[http:~~/~~/rtsys.informatik.uni-kiel.de/~~~~kieler/files/pldi14/>>url:http://rtsys.informatik.uni-kiel.de/~~kieler/files/pldi14/||shape="rect"]]
34
35 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).
36
37 [[image:attach:kieler1.png]]
38
39 If you selected a new workspace location, you will see a welcome screen like this:
40
41 [[image:attach:kieler02.png]]
42
43 Dismiss this "Welcome" tab. After that you'll be all set and KIELER should look like this:
44
45 [[image:attach:kieler03.png]]
46
47 In order to prepare modeling, we must create a project. Right-click in the Project Explorer to do so.
48
49 [[image:attach:kieler04.png]]
50
51 Select a General Project and click on next, then enter a project name, e.g. pldi14 and click on finish:
52
53 [[image:attach:kieler05.png]][[image:attach:kieler06.png]]
54
55 Now KIELER should look like this:
56
57 [[image:attach:kieler07.png]]
58
59 Now you can proceed in modeling an SCChart as explained below.
60
61 = 2. Model an SCChart =
62
63 Right-click on a project and create a (text) File:
64
65 [[image:attach:kieler08.png]]
66
67 Name it abo.sct:
68
69 [[image:attach:kieler09.png]]
70
71 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.
72
73 The textual SCCharts Xtext based editor (for *.sct files) will automatically be opened:
74
75 [[image:attach:kieler10.png]]
76
77 Now start modeling an SCChart. For example copy & paste the following sct code of abo, the hello world of SCCharts:
78
79 {{code title="abo.sct"}}
80 @VHLayout
81 scchart ABO {
82 input output bool A;
83 input output bool B;
84 output bool O1;
85 output bool O2;
86 region:
87
88 initial state Init
89 --> WaitAB immediate with / O1 = false; O2 = false;
90 state WaitAB {
91 region HandleA:
92 initial state WaitA
93 --> DoneA immediate with A / B = true; O1 = true;
94 final state DoneA;
95 region HandleB:
96 initial state WaitB
97 --> DoneB with B / O1 = true;
98 final state DoneB;
99 }
100 >-> GotAB with / O1 = false; O2 = true;
101 state GotAB;
102 }
103 {{/code}}
104
105 As you save (Ctrl+S), KIELER will automatically draw the graphical SCChart diagram in a new KLigD view:
106
107 [[image:attach:kieler11.png]]
108
109 You may want to re-arrange views. Just drag the KLighD view to the right side:
110
111 [[image:attach:kieler12.png]]
112
113 You will now see how to generate a C tick function.
114
115 = 3. Generate C Code =
116
117 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).
118
119 [[image:attach:kieler13.png]]
120
121 After performing a transformation the transformed SCChart will open (together with it's KLighD diagram visualization):
122
123 [[image:attach:kieler14.png]]
124
125 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).
126
127 [[image:attach:kieler15.png]][[image:attach:kieler16.png]]
128
129
130
131 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).
132
133 [[image:attach:kieler17.png]][[image:attach:kieler18.png]]
134
135
136
137 Now populate the SCG with basic block information (left side). The SCG with calculated basic blocks will look like this (right side).
138
139 [[image:attach:kieler19.png]][[image:attach:kieler20.png]]
140
141
142
143 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).
144
145 [[image:attach:kieler21.png]][[image:attach:kieler22.png]]
146
147
148
149 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).
150
151 [[image:attach:kieler23.png]][[image:attach:kieler24.png]]
152
153
154
155 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).
156
157 [[image:attach:kieler25.png]][[image:attach:kieler26.png]]
158
159
160
161 Selecting Generate SC will produce a C file:
162
163 [[image:attach:kieler27.png]][[image:attach:kieler28.png]]
164
165
166
167 = 4. Evaluated Examples =
168
169 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]].
170
171 |=(((
172 Example
173 )))|=(((
174
175 )))|=(((
176 SCChart  (Graphical)
177 )))|=(% colspan="1" %)(% colspan="1" %)
178 (((
179 SCChart (Textual SCT)
180 )))
181 |(% colspan="1" %)(% colspan="1" %)
182 (((
183 = shifter3 =
184 )))|(% colspan="1" %)(% colspan="1" %)
185 (((
186
187 )))|(% colspan="1" %)(% colspan="1" %)
188 (((
189 [[image:attach:shifter3.png]]
190 )))|(% colspan="1" %)(% colspan="1" %)
191 (((
192 {{code title="shifter3.sct"}}
193 scchart shifter3 {
194 input signal int I = 1;
195 signal int S0;
196 signal int S1;
197 output signal int O;
198 region R1:
199 initial state I2
200 --> I2 with pre(S0) / S1(pre(val(S0)));
201 region R0:
202 initial state I1
203 --> I1 with pre(I) / S0(pre(val(I)));
204 region R2:
205 initial state I3
206 --> I3 with pre(S1) / O(pre(val(S1)));
207 }
208 {{/code}}
209 )))
210 |(((
211 = reincarnation =
212 )))|(((
213
214 )))|(((
215 [[image:attach:reincarnation.png]]
216 )))|(% colspan="1" %)(% colspan="1" %)
217 (((
218 {{code title="reincarnation.sct"}}
219 scchart reincarnation {
220 input signal A;
221 output signal gotS;
222 region R0:
223 initial state Reincarnation {
224 signal S;
225 region R0:
226 initial state I
227 --> C1 immediate;
228 state p;
229 final state r;
230 state q
231 --> r with A / S;
232 state C1
233 --> p immediate with S / gotS
234 --> q immediate;
235 }
236 >-> Reincarnation;
237 }
238 {{/code}}
239 )))
240 |(((
241 = cabin =
242 )))|(((
243
244 )))|(((
245 [[image:attach:cabin.png]]
246 )))|(% colspan="1" %)(% colspan="1" %)
247 (((
248 {{code title="cabin.sct"}}
249 scchart Cabin {
250 input signal Stop;
251 input signal CabinStopped;
252 input signal DoorIsOpen;
253 input signal DoorOpen;
254 input signal DoorSensor;
255 input signal DoorIsClosed;
256 input signal DoorClose;
257 input signal TimerExpired;
258 output signal StartOK;
259 output signal OpenDoorMotorOff;
260 output signal OpenDoorMotorOn;
261 output signal StartTimer;
262 output signal CloseDoorMotorOn;
263 output signal CloseDoorMotorOff;
264 region R0:
265 initial state I
266 --> Open immediate with / OpenDoorMotorOn;
267 state Open
268 --> S0 with DoorIsOpen / OpenDoorMotorOff;
269 state S0 {
270 region R0:
271 initial state Initial
272 --> S0 immediate with / StartTimer;
273 state S0
274 --> S1 with TimerExpired | DoorClose / CloseDoorMotorOn;
275 state S1
276 --> S2 with DoorIsClosed / StartOK;
277 final state S2;
278 }
279 o-> I with DoorOpen | DoorSensor / CloseDoorMotorOff
280 >-> S1 with / CloseDoorMotorOff;
281 state S1
282 --> S2 with Stop;
283 state S2
284 --> I with CabinStopped;
285 }
286 {{/code}}
287 )))
288 |(((
289 = reactor control =
290 )))|(((
291
292 )))|(((
293 [[image:attach:reactor-control.png]]
294 )))|(% colspan="1" %)(% colspan="1" %)
295 (((
296 {{code title="reactor-control.sct"}}
297 scchart Module_ReactorControl {
298 output signal PullOutRods;
299 output signal PushInRods;
300 input signal Start;
301 input signal OverHeated;
302 input signal CooledDown;
303 signal unsafe;
304 region main:
305 initial state init0 "I"
306 --> ParallelStatementList40state immediate;
307 state ParallelStatementList40state {
308 region R0:
309 initial state init1 "I"
310 --> Await43state immediate;
311 state Await43state {
312 region R0:
313 initial state init2 "I"
314 --> S18 immediate;
315 state S18 "18"
316 --> S23 with Start / PullOutRods;
317 state S23 "23";
318 }
319 o-> Await43state with unsafe;
320 region R1:
321 initial state init3 "I"
322 --> S94 immediate;
323 state S94 "94"
324 --> S134 immediate with unsafe / PushInRods;
325 state S134 "134"
326 --> S94 with !unsafe;
327 region R2:
328 initial state init4 "I"
329 --> S193 immediate;
330 state S193 "193"
331 --> Sustain68state immediate with OverHeated;
332 state Sustain68state {
333 region R0:
334 initial state init5 "I"
335 --> S227 immediate with / unsafe;
336 state S227 "227"
337 --> S227 with / unsafe;
338 }
339 o-> S193 with CooledDown;
340 };
341 }
342 {{/code}}
343 )))