gaf: Fix memory leak
[geda-gaf.git] / docs / wiki / geda-hierarchy.html
blob6d3770a658e31cd91aac45f827a4655f83e9dd0d
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html>
4 <head>
5 <link rel="stylesheet" media="screen" type="text/css" href="./style.css" />
6 <link rel="stylesheet" media="screen" type="text/css" href="./design.css" />
7 <link rel="stylesheet" media="print" type="text/css" href="./print.css" />
9 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10 </head>
11 <body>
13 <h1 id="hierarchicalschematics">Hierarchical schematics</h1>
14 <div class="level1">
16 <p>
17 Depending on what you want to achieve, there are several options how to use hierarchy. If you are unsure, ask yourself if you want to include a subcircuit multiple times in your design, or want to represent a subsheet as a symbol in another sheet. If you answer either with yes, go with full mangling. If not, you probably don&#039;t need hierarchy at all and can just use multiple schematic files.
18 </p>
19 <div class="noteclassic">The schematic hierarchy isn&#039;t limited to one level—subcircuits can in turn contain other subcircuits.
21 </div>
22 </div>
24 <h2 id="multipleschematicfiles">Multiple schematic files</h2>
25 <div class="level2">
27 <p>
28 If you just want to split your schematic to multiple pages, you don&#039;t need to use hierarchy at all. Just list the individual schematic files when invoking gnetlist:
29 </p>
30 <pre class="code">$ gnetlist -g geda page-one.sch page-two.sch</pre>
32 <p>
33 If you are using the same <code>netname=</code> attribute on different pages, the nets will automatically be connected.
34 </p>
36 </div>
38 <h2 id="hierarchyasaconveniencemethod">Hierarchy as a convenience method</h2>
39 <div class="level2">
41 <p>
42 Alternatively, you can create a top schematic which contains symbols for each subsheet and tell <code>gnetlist</code> to go look for the corresponding schematic files. You do so by adding a <code>source=</code> attribute to the symbol and adding the directory which contains the subsheets to the source library. Usually this will be the same directory as the schematic containing the subsheet symbol, so add the following line to <code>gnetlistrc</code> (either your global one in <code>~/.gEDA/</code>, or a project-specific one in the same directory):
43 </p>
44 <pre class="code">(source-library &quot;.&quot;)</pre>
46 <p>
47 You also need to tell gnetlist to disable component and net name mangling or you will end up with component names like <code>U?/R1</code>, and your nets will not connect. To do so, add the following lines to <code>gnetlistrc</code>:
48 </p>
49 <pre class="code">(hierarchy-netattrib-mangle &quot;disabled&quot;)
50 (hierarchy-netname-mangle &quot;disabled&quot;)
51 (hierarchy-uref-mangle &quot;disabled&quot;)</pre>
53 <p>
54 Now when invoking gnetlist, just specify the main schematic file:
55 </p>
56 <pre class="code">$ gnetlist -g geda main.sch</pre>
57 <div class="noteclassic">This will only work if the <a href="geda-gaf_utility.html#gaf_config" class="wikilink1" title="geda-gaf_utility.html">configuration</a> setting <code><a href="geda-gaf_utility.html#gnetlist_group" class="wikilink1" title="geda-gaf_utility.html">gnetlist.traverse-hierarchy</a></code> is set to <code>true</code>. This is the default but may have been overridden by your distribution or local administrator.
59 </div><div class="noteimportant"><code>gnetlist</code> will complain if the subsheet symbols don&#039;t contain a <code>refdes=</code> attribute, but with mangling disabled, it won&#039;t use it in any way.
61 </div>
62 <p>
63 In <code>gschem</code>, you can navigate the schematic hierarchy using the commands from the “Hierarchy” menu. To view the underlying schematic for a subcircuit component, select it and use <strong>Hierarchy→Down Schematic</strong>. Once finished editing, use <strong>Hierarchy→Up</strong> to return to the original schematic. (This works only if you accessed the subcircuit&#039;s schematic in that way.) Analogously, you can edit the subcircuit symbol itself using <strong>Hierarchy→Down Symbol</strong>.
64 </p>
66 <p>
67 As an alternative to using the same net name, you can add pins to a subsheet symbol to route nets to and from that schematic. See the section <em>Input/output pins</em> below for details.
68 </p>
70 </div>
72 <h2 id="hierarchyasagroupinginstantiationmechanism">Hierarchy as a grouping/instantiation mechanism</h2>
73 <div class="level2">
75 <p>
76 If you want to include a subcircuit multiple times in your schematic, you need a way to tell the components of one instantiation from those of another one (given that your subcircuit contains any components). This is where refdef mangling comes in. You enable it by specifying
77 </p>
78 <pre class="code">(hierarchy-uref-mangle &quot;enabled&quot;)</pre>
80 <p>
81 in <code>gnetlistrc</code>. Now, <code>gnetlist</code> constructs the name of an instantiated component by appending it to the subsheet symbol&#039;s <code>refdes=</code> attribute, separated by a slash. You can configure this in <code>gnetlistrc</code>. For example, to list the component <code>refdes=</code> first and use a colon as a separator, use
82 </p>
83 <pre class="code">(hierarchy-uref-order &quot;prepend&quot;)
84 (hierarchy-uref-separator &quot;:&quot;)</pre>
86 <p>
87 Named nets from one instantiation will connect to the same net of another one. This means you can&#039;t use net names to connect (non-power) pins across the hierarchy any more; you need I/O pins instead. Also, you will probably want to use separate net namespaces so you don&#039;t short-circuit nets between instantiations when using net names.
88 </p>
90 </div>
92 <h3 id="inputoutputpins">Input/output pins</h3>
93 <div class="level3">
95 <p>
96 In order to connect a net to a subcircuit, you need to add a pin to the subcircuit symbol and a corresponding footprint-less I/O component to the subcircuit whose <code>refdes=</code> matches the <code>pinlabel=</code> of the pin. During netlist generation, these two nets will be connected. (You can normally use the <code>in-1.sym</code> and <code>out-1.sym</code> symbols from the generic “Input/Output” symbol library for this.)
97 </p>
98 <div class="noteimportant">If you get an error about a “Missing I/O symbol”, make sure you set a <code>refdes=</code> for the subsheet symbols.
100 </div><div class="notewarning">Make sure not to add more than one I/O symbol for each pin as this will silently produce an incorrect netlist.
102 </div>
103 </div>
105 <h2 id="separatingnetnetnamenamespaces">Separating net=/netname= namespaces</h2>
106 <div class="level2">
109 The typical and cleanest way to use hierarchy is to enable both refdes and net=/netname= mangling. This means that the subcircuit lives in a namespace of its own, and the only way to connect nets between the instantiating and the instantiated schematic is through pins of the subsheet symbol and I/O ports in its schematic. If you want to include a subcircuit multiple times in your design, even though it&#039;s not strictly necessary, this is the recommended way to use hierarchy, as you would otherwise have to be very careful about avoiding naming nets in the subschematic which would cause them to be silently short-circuited between instantiations.
110 </p>
113 You enable net=/netname= mangling it by specifying
114 </p>
115 <pre class="code">(hierarchy-netattrib-mangle &quot;enabled&quot;)
116 (hierarchy-netname-mangle &quot;enabled&quot;)</pre>
119 in <code>gnetlistrc</code>. As with refdes mangling, you can also configure the way mangled net names are constructed.
120 </p>
122 </div>
124 <h3 id="netnamemanglingvsnetmangling">netname= mangling vs. net= mangling</h3>
125 <div class="level3">
128 There are two slightly different options which influence net namespaces: <code>netname=</code> mangling means that net names set via the <code>netname=</code> attribute on nets are prefixed or suffixed with the subsheet instance&#039;s hierarchy tag. <code>net=</code> attribute mangling means that net names which are set via the <code>net=</code> attribute on components (like, for example, <code>Vcc</code> and <code>GND</code> pins in some libraries) are prefixed or suffixed with the subsheet instance&#039;s hierarchy tag.
129 </p>
132 Usually, when using net namespaces, you would enable both <code>netname=</code> and <code>net=</code> mangling. Depending on how you use hierarchy in your design, there might be use cases where you might want to disable one of them, though: If you disable <code>netname=</code> mangling, you gain the ability to use global net names and connect nets across the hierarchy by setting the <code>netname=</code> attribute while still having implicit nets separate. If you disable <code>net=</code> mangling, all implicit pins (usually power and ground pins) across all of your schematic pages will be connected, so you don&#039;t have to use explicit power and ground pins on your subsheet symbols. Both approaches come at the cost of reduced readability, though: you can&#039;t tell any more how a subsheet is connected to the rest of the design by just looking at the schematic.
133 </p>
135 </div>
136 </body>
137 </html>