2
<html lang="en" dir="ltr" class="no-js">
4
<meta charset="utf-8" />
5
<title>Workcraft - tutorial:stg:celement:start</title>
6
<script>(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement)</script>
7
<meta name="generator" content="DokuWiki"/>
8
<meta name="robots" content="noindex,nofollow"/>
9
<meta name="keywords" content="tutorial,stg,celement,start"/>
10
<link rel="search" type="application/opensearchdescription+xml" href="../../lib/exe/opensearch.html" title="Workcraft"/>
11
<link rel="start" href="start.html"/>
12
<link rel="contents" href="start.html" title="Sitemap"/>
13
<link rel="alternate" type="application/rss+xml" title="Changes" />
14
<link rel="alternate" type="application/rss+xml" title="Current namespace" />
15
<link rel="alternate" type="text/html" title="Plain HTML" href="../../_export/xhtml/tutorial/stg/celement/start.xhtml"/>
16
<link rel="alternate" type="text/plain" title="Wiki Markup" href="../../_export/raw/tutorial/stg/celement/start.raw"/>
17
<link rel="canonical" href="http://www.workcraft.org/tutorial/stg/celement/start"/>
18
<link rel="stylesheet" type="text/css" href="../../lib/exe/css.php.t.dokuwiki-light-export.css"/>
19
<script type="text/javascript">/*<![CDATA[*/var NS='tutorial:stg:celement';var JSINFO = {"id":"tutorial:stg:celement:start","namespace":"tutorial:stg:celement"};
21
<script type="text/javascript" charset="utf-8" src="../../lib/exe/js.php.t.dokuwiki-light-export.js"></script>
22
<meta name="viewport" content="width=device-width,initial-scale=1" />
23
<link rel="shortcut icon" href="../../favicon.ico" />
24
<link rel="apple-touch-icon" href="../../apple-touch-icon.png" />
28
<!--[if lte IE 7 ]><div id="IE7"><![endif]--><!--[if IE 8 ]><div id="IE8"><![endif]-->
29
<div id="dokuwiki__site"><div id="dokuwiki__top" class="site dokuwiki mode_show tpl_dokuwiki-light-export ">
32
<!-- ********** HEADER ********** -->
33
<div id="dokuwiki__header"><div class="pad group">
35
<h1><a href="../../start.html" title="Workcraft start page"><img src="../../logo.png" width="327" height="57" alt="" /></a></h1>
37
<div class="tools group">
39
<div id="dokuwiki__usertools">
40
<h3 class="a11y">User Tools</h3>
42
<li><a href="start.html" class="action login" rel="nofollow" title="Login">Login</a></li> </ul>
46
<div id="dokuwiki__searchtools">
47
<h3 class="a11y"></h3>
48
<form action="../../start.html" accept-charset="utf-8" class="search" id="dw__search" method="get" role="search"><div class="no"><input type="hidden" name="do" value="search" /><input type="text" id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" /><input type="submit" value="Search" class="button" title="Search" /><div id="qsearch__out" class="ajax_qsearch JSpopup"></div></div></form> </div>
51
<div id="dokuwiki__sitetools">
52
<h3 class="a11y">Site Tools</h3>
53
<div class="mobileTools">
54
<li><a href="start.html" class="action login" rel="nofollow" title="Login">Login</a></li> </div>
64
</div></div><!-- /header -->
66
<div class="wrapper group">
69
<!-- ********** CONTENT ********** -->
70
<div id="dokuwiki__content"><div class="pad group">
71
<div class="pageId"><span>tutorial:stg:celement:start</span></div>
72
<div class="page group">
73
<!-- wikipage start -->
76
<h3 class="toggle">Table of Contents</h3>
80
<li class="level1"><div class="li"><a href="#modelling">Modelling</a></div></li>
81
<li class="level1"><div class="li"><a href="#verification_of_specification">Verification of specification</a></div></li>
82
<li class="level1"><div class="li"><a href="#synthesis">Synthesis</a></div></li>
83
<li class="level1"><div class="li"><a href="#circuit_capturing">Circuit capturing</a></div></li>
84
<li class="level1"><div class="li"><a href="#verification_of_implementation">Verification of implementation</a></div></li>
85
<li class="level1"><div class="li"><a href="#solutions">Solutions</a></div></li>
91
<h1 class="sectionedit1" id="synthesis_and_verification_of_c-element">Synthesis and verification of C-element</h1>
95
<a href="http://en.wikipedia.org/wiki/C-element" class="interwiki iw_wp" title="http://en.wikipedia.org/wiki/C-element">C-element</a> is a gate that synchronises the phases of its inputs. A symbol for a 2-input C-element and its timing diagram are shown in the figures below. Initially all the signals are in the low state. When both inputs <code>in1</code> and <code>in2</code> go high, the output <code>out</code> also switches to logical 1. It stays in this state until both inputs go low, at which stage the output switches to logical 0.
97
<div class="plugin_wrap"><div class="wrap_column wrap_third plugin_wrap"><div class="table sectionedit6"><table class="inline">
99
<td class="col0"><img src="schematic-celement.png" class="mediacenter" alt="" /></td>
102
<td class="col0 centeralign"> Symbol </td>
105
</div><div class="wrap_column wrap_third plugin_wrap"><div class="table sectionedit9"><table class="inline">
107
<td class="col0"><img src="td-celement.png" class="mediacenter" alt="" /></td>
110
<td class="col0 centeralign"> Timing diagram </td>
116
<h2 class="sectionedit10" id="modelling">Modelling</h2>
120
Let us model the C-element behaviour using STG formalism. Create a new STG work called <em>stg-celement</em> and <em>translate</em> the sequence of events in the timing diagram into a sequence of STG transitions. Basically you need to create a signal transition for each event of the timing diagram and capture the causality between these events by means of directed arcs between signal transitions.
124
Start with the reset phase of the C-element where <code>out-</code> event is caused by <code>in1-</code> and <code>in2-</code> events:
127
<li class="level1"><div class="li">
128
Activate the <strong>signal transition generator</strong> <img src="../../../help/editor_tools-signal_transition.png" class="media" title="[T] Signal Transition" alt="[T] Signal Transition" />. Pay attention to the hint at the bottom of the screen: <em>Click to create a rising (or falling with Ctrl) transition of an output (or input with Shift) signal</em>.
130
<li class="level1"><div class="li">
131
Click the Editor panel in the location where you want the <code>out-</code> transition to appear.
133
<li class="level1"><div class="li">
134
Hold <kbd>Shift</kbd> and click in the desired location of <code>in1-</code> transition. The default name for the input signal is <code>in</code>, therefore you need to rename it. Go to the Property editor and change <em>in name</em> from <code>in</code> to <code>in1</code>.
136
<li class="level1"><div class="li">
137
Create <code>in2-</code> transition the same way as <code>in1-</code>.
139
<li class="level1"><div class="li">
140
Activate <strong>connection tool</strong> <img src="../../../help/editor_tools-connect.png" class="media" title="[C] Connect" alt="[C] Connect" />. Pay attention to the hints at the bottom of the screen. Initially the hint says <em>Click on the first component.</em> After the first component is chosen, the hint changes to <em>Click on the second component or create a node point. Hold Ctrl to connect continuously</em>.
142
<li class="level1"><div class="li">
143
Click <code>in1-</code>, move the mouse pointer to the <code>out-</code> transition and click again. A causality arc from <code>in1-</code> to <code>out-</code> will be created.
145
<li class="level1"><div class="li">
146
Repeat the connection procedure to capture causality between <code>in2-</code> and <code>out-</code> transitions.
152
<img src="stg-celement-step1.png" class="mediacenter" alt="" />
156
Similarly capture the set phase of the C-element:
159
<li class="level1"><div class="li">
160
Create transitions <code>in1+</code>, <code>in2+</code> and <code>out+</code>. As before, rename the default <code>in</code> signal to <code>in1</code> and <code>in2</code> respectively.
162
<li class="level1"><div class="li">
163
Create causality arcs from <code>in1+</code> to <code>out+</code> and from <code>in2+</code> to <code>out+</code>.
165
<li class="level1"><div class="li">
166
Use the <strong>selection tool</strong> <img src="../../../help/editor_tools-select.png" class="media" title="[S] Select" alt="[S] Select" /> to rearrange the STG nodes similar to the following figure.
172
<img src="stg-celement-step2.png" class="mediacenter" alt="" />
176
Now connect the set and reset portions of the specification:
179
<li class="level1"><div class="li">
180
The same as before, use <strong>connection tool</strong> <img src="../../../help/editor_tools-connect.png" class="media" title="[C] Connect" alt="[C] Connect" /> to introduce causality from <code>out+</code> to <code>in1-</code> and to <code>in2-</code>.
182
<li class="level1"><div class="li">
183
Create an arc from <code>out-</code> to <code>in1+</code>, but this time instead of a straight line connection use a polyline. After choosing the source of the connection (<code>out-</code> transition) click aside of the existing nodes - this will create a node point of a polyline. Continue forming the shape of the polyline by creating its node points, and finally choose the destination transition <code>in1+</code>.
185
<li class="level1"><div class="li">
186
Repeat the same procedure for creating a polyline connection from <code>out-</code> to <code>in2+</code>.
192
<img src="stg-celement-step3.png" class="mediacenter" alt="" />
196
Finally, specify the initial state of the C-element in accordance to the starting point of the timing diagram:
199
<li class="level1"><div class="li">
200
Activate the <strong>selection tool</strong> <img src="../../../help/editor_tools-select.png" class="media" title="[S] Select" alt="[S] Select" />.
202
<li class="level1"><div class="li">
203
Select the arc from <code>out-</code> to <code>in1+</code> and in the Property editor set the <em>Tokens</em> value to 1.
205
<li class="level1"><div class="li">
206
Similarly put a token on the arc from <code>out-</code> to <code>in2+</code>.
212
<img src="stg-celement.png" class="mediacenter" title="C-element STG model" alt="C-element STG model" />
217
<h2 class="sectionedit11" id="verification_of_specification">Verification of specification</h2>
221
Activate the <strong>simulation tool</strong> <img src="../../../help/editor_tools-simulate.png" class="media" title="[M] Simulate" alt="[M] Simulate" /> and exercise the obtained STG model. Click one of the enabled signal transitions (they are highlighted in orange) to <em>evaluate</em> the STG into the next state. Note that the sequence of fired transitions is recorded in the simulation trace that is somewhat similar to the original timing diagram. Check that the simulation traces resemble to the intended behaviour of a C-element.
225
Before proceeding to the synthesis of the C-element it is a good idea to verify that its specification meets essential requirements, e.g. that it is consistent and is free from deadlocks.
229
To verify the signal consistency (i.e. that the rising and falling phases of each signal alternate in all possible execution traces) select <em>Tools→Verification→Check for consistency [MPSat]</em> menu item. Similarly, for deadlock checking select <em>Tools→Verification→Check for deadlocks [MPSat]</em> menu item.
233
If the specification violates consistency or has a deadlock then a trace leading to the problematic state will be reported. This trace can be simulated for better understanding the reported issues and for correcting them in the specification.
238
<h2 class="sectionedit12" id="synthesis">Synthesis</h2>
242
The STG specification can now be synthesised into an asynchronous circuit implementation either with Petrify or MPSat backend tools via <em>Tools→Synthesis</em> menu.
246
A complex gate solution obtained with Petrify (<em>Tools→Synthesis→Complex gate synthesis [Petrify]</em> menu item) is as follows <span class="wrap_important ">Note that solution is not unique and you may get a slightly different equation.</span>:
248
<pre class="code">[out] = in2 (in1 + out) + in1 out;</pre>
251
By opening the parenthesis one can obtained the following equation:
253
<pre class="code">[out] = in1 in2 + in2 out + in1 out;</pre>
256
This equation can be directly mapped into an OR-AND complex gate whose function is <code>Z = A*B + C*D + E*F</code> ; let us call it <em>OA222</em> gate. The association of the C-element ports to the <em>OA222</em> gate pins is best described by the following Verilog module:
258
<pre class="code verilog"><span class="kw1">module</span> celement <span class="br0">(</span>in1<span class="sy0">,</span> in2<span class="sy0">,</span> out<span class="br0">)</span><span class="sy0">;</span>
259
<span class="kw1">input</span> in1<span class="sy0">;</span>
260
<span class="kw1">input</span> in2<span class="sy0">;</span>
261
<span class="kw1">output</span> out<span class="sy0">;</span>
262
OA222 inst_c <span class="br0">(</span>.A<span class="br0">(</span>in1<span class="br0">)</span><span class="sy0">,</span> .B<span class="br0">(</span>in2<span class="br0">)</span><span class="sy0">,</span> .C<span class="br0">(</span>in2<span class="br0">)</span><span class="sy0">,</span> .D<span class="br0">(</span>out<span class="br0">)</span><span class="sy0">,</span> .E<span class="br0">(</span>in1<span class="br0">)</span><span class="sy0">,</span> .F<span class="br0">(</span>out<span class="br0">)</span><span class="sy0">,</span> .Z<span class="br0">(</span>out<span class="br0">)</span><span class="br0">)</span><span class="sy0">;</span>
263
<span class="kw1">endmodule</span></pre>
267
<h2 class="sectionedit13" id="circuit_capturing">Circuit capturing</h2>
271
Create a new Digital Circuit work called <em>circuit-celement-cg</em> and capture the implementation suggested by Petrify in form of a gate-level netlist. <span class="wrap_info ">In the future versions of Workcraft the derivation of a circuit from the synthesis output will be automated, but for now please do it manually.</span>
274
<li class="level1"><div class="li">
275
Activate <strong>functional generator</strong> <img src="../../../help/editor_tools-function.png" class="media" title="[F] Function" alt="[F] Function" /> and click in the desired position of the OR-AND complex gate.
277
<li class="level1"><div class="li">
278
Activate <strong>selection tool</strong> <img src="../../../help/editor_tools-select.png" class="media" title="[S] Select" alt="[S] Select" />.
280
<li class="level1"><div class="li">
281
Select the only pin of the newly created function component.
283
<li class="level1"><div class="li">
284
In the Property editor change the <em>Name</em> of the pin to <code>Z</code> and modify its <em>Set function</em> to <code>A*B+C*D+E*F</code>.
290
<img src="circuit-celement-cg-step1.png" class="mediacenter" alt="" />
293
<li class="level1"><div class="li">
294
Select the function component and in the Property editor change its rendering type from <em>Box</em> to <em>Gate</em>.
300
<img src="circuit-celement-cg-step2.png" class="mediacenter" alt="" />
303
<li class="level1"><div class="li">
304
Activate <strong>port generator</strong> <img src="../../../help/editor_tools-port.png" class="media" title="[P] Input/output port" alt="[P] Input/output port" />. Pay attention to the hint at the bottom of the screen: <em>Click to create an output port (hold Shift for input port)</em>.
306
<li class="level1"><div class="li">
307
Click in intended location of the output port. Note that by default the port will be named <code>out1</code> - you can change this name to <code>out</code> later.
309
<li class="level1"><div class="li">
310
Hold <kbd>Shift</kbd> and click in the desired locations of the input ports – they will be automatically assigned <code>in0</code> and <code>in1</code> names.
312
<li class="level1"><div class="li">
313
Switch to the selection tool. Choose the output port, go to the property editor and change port <em>Name</em> to <code>out</code>. Similarly change the name of input port <code>in0</code> to <code>in2</code>.
319
<img src="circuit-celement-cg-step3.png" class="mediacenter" alt="" />
322
<li class="level1"><div class="li">
323
Activate <strong>connection tool</strong> <img src="../../../help/editor_tools-connect.png" class="media" title="[C] Connect" alt="[C] Connect" />.
325
<li class="level1"><div class="li">
326
Connect input ports <code>in1</code> to the 1<sup>st</sup> and 5<sup>th</sup> pins of the complex gate (<code>A</code> and <code>E</code> respectively).
328
<li class="level1"><div class="li">
329
Connect input ports <code>in2</code> to the 2<sup>nd</sup> and 3<sup>rd</sup> pins of the complex gate (<code>B</code> and <code>C</code> respectively).
331
<li class="level1"><div class="li">
332
Connect the output pin of the gate to the output port <code>out</code> and to the 4<sup>th</sup> and 6<sup>th</sup> inputs of the gate (<code>D</code> and <code>F</code> respectively).
338
<img src="circuit-celement-cg-step4.png" class="mediacenter" alt="" />
342
You may want to tidy up the circuit schematic and make it more readable by adding forks into the wires. This can be done with the <strong>joint generator</strong> <img src="../../../help/editor_tools-joint.png" class="media" title="[J] Joint" alt="[J] Joint" />. The resultant circuit should look similar to the following diagram.
346
<img src="circuit-celement-cg-step5.png" class="mediacenter" alt="" />
351
<h2 class="sectionedit14" id="verification_of_implementation">Verification of implementation</h2>
355
Activate the <strong>simulation tool</strong> <img src="../../../help/editor_tools-simulate.png" class="media" title="[M] Simulate" alt="[M] Simulate" /> and simulate the captured complex gate implementation of the C-element. Ports, pins and wires are colour-coded: blue means low level and red means high level of the signal. Excited pins and ports are highlighted in orange.
359
Click one of the exited pins to toggle its logical value. Similar to the STG simulation, the sequence of signal events is recorded in the simulation trace and can be subsequently replayed for analysing the circuit behaviour.
363
Note that in simulation the C-element inputs are not restricted in any way, i.e. they can change in an unexpected manner causing malfunction of the circuit. This can be confirmed by checking the circuit for hazards <em>Tools→Verification→Check for hazards only</em> – the circuit has a hazard after the following trace: <code>0: in2+, in1+</code>.
367
Play this trace to discover that indeed, by the end of the trace the output of the C-element is excited and ready to switch to logical 1, but an unexpected <code>in1-</code> or <code>in2-</code> transition would disable it, that does not fit the specification.
371
Restrict the environment behaviour in such a way that the circuit only receives those inputs that are expected according to the specification. For example, you can feed the inverted value of C-element output to its inputs.
374
<li class="level1"><div class="li">
375
Activate the <strong>selection tool</strong> <img src="../../../help/editor_tools-select.png" class="media" title="[S] Select" alt="[S] Select" />.
377
<li class="level1"><div class="li">
378
Select both input ports <code>in1</code> and <code>in2</code> (hold <kbd>Shift</kbd> and click each of them).
380
<li class="level1"><div class="li">
381
In the property editor assign the same <em>Set function</em> <code>!out</code> to both inputs (<code>!</code> means inversion – see <a href="..../../help/boolean_expression.html" class="wikilink1" title="help:boolean_expression">Boolean expressions</a> for details).
387
<img src="circuit-celement-cg-step6.png" class="mediacenter" alt="" />
391
Repeat the verification procedure to check if the circuit is free of hazards under the well behaved environment. Also check the circuit for deadlocks and verify if it conforms to the environment specification. All these verification steps can be run via <em>Tools→Verification→Check circuit for conformation, deadlocks and hazards (reuse unfolding)</em> menu.
395
Try to alter the circuit and verify if it still conforms to the environment, is deadlock-free and operates without hazards.
400
<h2 class="sectionedit15" id="solutions">Solutions</h2>
404
Download all the Workcraft models discussed in this tutorial here:
408
<span class="wrap_download "><a href="celement.tar.gz" class="media mediafile mf_gz" title="tutorial:stg:celement:celement.tar.gz (5.9 KB)">C-element models</a> (5.94 KiB, <acronym title="Modified: 2014-11-13 10:49.47">1d ago</acronym>)</span>
413
<!-- wikipage stop -->
416
</div></div><!-- /content -->
420
<!-- PAGE ACTIONS -->
421
<div id="dokuwiki__pagetools">
423
</div><!-- /wrapper -->
426
<!-- ********** FOOTER ********** -->
427
<div id="dokuwiki__footer"><div class="pad">
429
<div class="buttons">
430
<a href="http://www.dokuwiki.org/donate" title="Donate" ><img
431
src="../../lib/tpl/dokuwiki-light-export/images/button-donate.gif" width="80" height="15" alt="Donate" /></a>
432
<a href="http://www.php.net" title="Powered by PHP" ><img
433
src="../../lib/tpl/dokuwiki-light-export/images/button-php.gif" width="80" height="15" alt="Powered by PHP" /></a>
434
<a href="http://validator.w3.org/check/referer" title="Valid HTML5" ><img
435
src="../../lib/tpl/dokuwiki-light-export/images/button-html5.png" width="80" height="15" alt="Valid HTML5" /></a>
436
<a href="http://jigsaw.w3.org/css-validator/check/referer?profile=css3" title="Valid CSS" ><img
437
src="../../lib/tpl/dokuwiki-light-export/images/button-css.png" width="80" height="15" alt="Valid CSS" /></a>
438
<a href="http://dokuwiki.org/" title="Driven by DokuWiki" ><img
439
src="../../lib/tpl/dokuwiki-light-export/images/button-dw.png" width="80" height="15" alt="Driven by DokuWiki" /></a>
442
<div class="userInfo">
444
</div></div><!-- /footer -->
446
</div></div><!-- /site -->
448
<div class="no"><img width="2" height="1" alt="" /></div>
449
<div id="screen__mode" class="no"></div> <!--[if ( lte IE 7 | IE 8 ) ]></div><![endif]-->