2023-04-22 11:29:44 +02:00
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
2023-04-28 12:03:56 +02:00
|
|
|
<title>XSCHEM TUTORIAL: SYMBOL AND SCHEMATIC GENERATORS</title>
|
2023-04-22 11:29:44 +02:00
|
|
|
<link rel="stylesheet" type="text/css" href="xschem_man.css" />
|
|
|
|
|
<style type="text/css">
|
|
|
|
|
/* Local styling goes here */
|
|
|
|
|
p{padding: 15px 30px 10px;}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
|
|
<!-- start of slide -->
|
|
|
|
|
<div class="content">
|
|
|
|
|
<!-- navigation buttons -->
|
|
|
|
|
<a href="xschem_man.html" class="home">UP</a>
|
|
|
|
|
|
|
|
|
|
<!-- slide title -->
|
2023-04-28 12:03:56 +02:00
|
|
|
<h1> TUTORIAL: SYMBOL AND SCHEMATIC GENERATORS (aka PCELLS)</h1>
|
2023-04-23 11:06:08 +02:00
|
|
|
<p>
|
|
|
|
|
It is possible to insert a symbol by referencing a generator script instead of a <kbd>.sym</kbd> file.
|
|
|
|
|
When inserting the symbol select the <kbd>All</kbd> checkbox to see all files , select the generator script,
|
|
|
|
|
then in the File/Search textbox add two parenthesis <kbd>()</kbd> (or put required parameters in
|
|
|
|
|
between, like <kbd>(buf)</kbd>)
|
|
|
|
|
</p>
|
|
|
|
|
<img src="symbol_generators01.png">
|
|
|
|
|
<p>
|
|
|
|
|
The symbolgen generator in this example takes either a <kbd>(buf)</kbd> or a <kbd>(inv)</kbd> parameter
|
|
|
|
|
to generate a buffer or an inverter, respectively. If no parameters are given (empty parentheses) a buffer
|
|
|
|
|
is generated.<br>
|
2023-04-27 23:51:42 +02:00
|
|
|
In this example a tcl script is used, you can use any language you like. The script only needs to parse
|
|
|
|
|
the parameters (if any) and output on standard output a regular xschem symbol file.
|
2023-04-23 11:06:08 +02:00
|
|
|
</p>
|
|
|
|
|
<pre class="code">
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
# the next line restarts using wish \
|
|
|
|
|
exec tclsh "$0" "$@"
|
|
|
|
|
|
|
|
|
|
set arg1 [lindex $argv 0]
|
|
|
|
|
if { $arg1 eq {inv}} {
|
|
|
|
|
puts {v {xschem version=3.1.0 file_version=1.2}
|
|
|
|
|
K {type=subcircuit
|
2023-04-27 23:51:42 +02:00
|
|
|
xvhdl_primitive=true
|
|
|
|
|
xverilog_primitive=true
|
|
|
|
|
xvhdl_format="@@y < not @@a after 90 ps;"
|
|
|
|
|
xverilog_format="assign #90 @@y = ~@@a ;"
|
|
|
|
|
format="@name @pinlist @symname wn=@wn lln=@lln wp=@wp lp=@lp"
|
|
|
|
|
template="name=x1 wn=1u lln=2u wp=4u lp=2u"
|
|
|
|
|
schematic=schematicgen(inv)}
|
2023-04-23 11:06:08 +02:00
|
|
|
L 4 -40 0 -20 0 {}
|
|
|
|
|
L 4 -20 -20 20 0 {}
|
|
|
|
|
L 4 -20 -20 -20 20 {}
|
|
|
|
|
L 4 -20 20 20 0 {}
|
|
|
|
|
L 4 30 -0 40 -0 {}
|
2023-04-27 23:51:42 +02:00
|
|
|
B 5 37.5 -2.5 42.5 2.5 {name=y dir=out }
|
|
|
|
|
B 5 -42.5 -2.5 -37.5 2.5 {name=a dir=in }
|
2023-04-23 11:06:08 +02:00
|
|
|
A 4 25 -0 5 180 360 {}
|
|
|
|
|
T {@symname} -47.5 24 0 0 0.3 0.3 {}
|
|
|
|
|
T {@name} 25 -22 0 0 0.2 0.2 {}
|
2023-04-27 23:51:42 +02:00
|
|
|
T {y} 7.5 -6.5 0 1 0.2 0.2 {}
|
|
|
|
|
T {a} -17.5 -6.5 0 0 0.2 0.2 {}
|
2023-04-23 11:06:08 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
puts {v {xschem version=3.1.0 file_version=1.2}
|
|
|
|
|
K {type=subcircuit
|
2023-04-27 23:51:42 +02:00
|
|
|
xvhdl_primitive=true
|
|
|
|
|
xverilog_primitive=true
|
|
|
|
|
xvhdl_format="@@y < @@a after 90 ps;"
|
|
|
|
|
xverilog_format="assign #90 @@y = @@a ;"
|
|
|
|
|
format="@name @pinlist @symname wn=@wn lln=@lln wp=@wp lp=@lp"
|
|
|
|
|
template="name=x1 wn=1u lln=2u wp=4u lp=2u"
|
|
|
|
|
schematic=schematicgen(buf)}
|
2023-04-23 11:06:08 +02:00
|
|
|
L 4 20 0 40 0 {}
|
|
|
|
|
L 4 -40 0 -20 0 {}
|
|
|
|
|
L 4 -20 -20 20 0 {}
|
|
|
|
|
L 4 -20 -20 -20 20 {}
|
|
|
|
|
L 4 -20 20 20 0 {}
|
2023-04-27 23:51:42 +02:00
|
|
|
B 5 37.5 -2.5 42.5 2.5 {name=y dir=out }
|
|
|
|
|
B 5 -42.5 -2.5 -37.5 2.5 {name=a dir=in }
|
|
|
|
|
T {@symname} -47.5 24 0 0 0.3 0.3 {}
|
2023-04-23 11:06:08 +02:00
|
|
|
T {@name} 25 -22 0 0 0.2 0.2 {}
|
2023-04-27 23:51:42 +02:00
|
|
|
T {y} 7.5 -6.5 0 1 0.2 0.2 {}
|
|
|
|
|
T {a} -17.5 -6.5 0 0 0.2 0.2 {}
|
2023-04-23 11:06:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</pre>
|
|
|
|
|
<p>
|
|
|
|
|
The <kbd>generators/test_symbolgen.sch</kbd> is a test schematic that places two instancs of this
|
|
|
|
|
symbol generator, one as <kbd>symbolgen(buf)</kbd> and one as <kbd>symbolgen(inv)</kbd>.
|
|
|
|
|
The schematic implementations of these symbols are defined by the generator using a <kbd>schematic</kbd>
|
2023-04-27 23:51:42 +02:00
|
|
|
attribute. The buffer will use <kbd>schematicgen(buf)</kbd> and the inverter will
|
|
|
|
|
use <kbd>schematicgen(inv)</kbd>, these schematic names are referencing a schematic generator
|
|
|
|
|
script instead of regular schematic files. See next section about schematic generators.
|
2023-04-23 11:06:08 +02:00
|
|
|
</p>
|
|
|
|
|
<img src="symbol_generators02.png">
|
|
|
|
|
<p>
|
|
|
|
|
The following is the extracted netlist from this example:
|
|
|
|
|
</p>
|
|
|
|
|
<pre class="code">
|
2023-04-27 23:51:42 +02:00
|
|
|
|
2023-04-23 11:06:08 +02:00
|
|
|
** sch_path: /home/schippes/xschem-repo/trunk/xschem_library/generators/test_symbolgen.sch
|
|
|
|
|
**.subckt test_symbolgen
|
2023-04-27 23:51:42 +02:00
|
|
|
x1 IN_INV IN symbolgen_inv wn=1u lln=2u wp=4u lp=2u
|
|
|
|
|
x3 IN_BUF IN symbolgen_buf wn=1u lln=2u wp=4u lp=2u
|
2023-04-23 11:06:08 +02:00
|
|
|
C1 IN_BUF 0 100f m=1
|
|
|
|
|
C2 IN_INV 0 100f m=1
|
|
|
|
|
**** begin user architecture code
|
|
|
|
|
|
2023-04-27 23:51:42 +02:00
|
|
|
.include models_rom8k.txt
|
|
|
|
|
.param vcc=3
|
|
|
|
|
vvcc vcc 0 dc 3
|
|
|
|
|
Vin in 0 pwl 0 0 100n 0 100.1n 3 200n 3 200.1n 0
|
2023-04-23 11:06:08 +02:00
|
|
|
.control
|
|
|
|
|
save all
|
2023-04-27 23:51:42 +02:00
|
|
|
tran 1n 300n uic
|
2023-04-23 11:06:08 +02:00
|
|
|
write test_symbolgen.raw
|
|
|
|
|
.endc
|
|
|
|
|
**.ends
|
|
|
|
|
|
|
|
|
|
* expanding symbol: symbolgen(inv) # of pins=2
|
|
|
|
|
** sym_path: /home/schippes/xschem-repo/trunk/xschem_library/generators/symbolgen
|
2023-04-27 23:51:42 +02:00
|
|
|
** sch_path: /home/schippes/xschem-repo/trunk/xschem_library/generators/schematicgen
|
|
|
|
|
.subckt symbolgen_inv y a wn=1u lln=2u wp=4u lp=2u
|
|
|
|
|
*.opin y
|
|
|
|
|
*.ipin a
|
|
|
|
|
m2 y a VCC VCC cmosp w=wp l=lp ad='wp *4.6u' as='wp *4.6u' pd='wp *2+9.2u' ps='wp *2+9.2u' m=1
|
|
|
|
|
m1 y a 0 0 cmosn w=wn l=lln ad='wn *4.3u' as='wn *4.3u' pd='wn *2+8.6u' ps='wn *2+8.6u' m=1
|
2023-04-23 11:06:08 +02:00
|
|
|
.ends
|
|
|
|
|
|
|
|
|
|
* expanding symbol: symbolgen(buf) # of pins=2
|
|
|
|
|
** sym_path: /home/schippes/xschem-repo/trunk/xschem_library/generators/symbolgen
|
2023-04-27 23:51:42 +02:00
|
|
|
** sch_path: /home/schippes/xschem-repo/trunk/xschem_library/generators/schematicgen
|
|
|
|
|
.subckt symbolgen_buf y a wn=1u lln=2u wp=4u lp=2u
|
|
|
|
|
*.opin y
|
|
|
|
|
*.ipin a
|
|
|
|
|
m2 net1 a VCC VCC cmosp w=wp l=lp ad='wp *4.6u' as='wp *4.6u' pd='wp *2+9.2u' ps='wp *2+9.2u' m=1
|
|
|
|
|
m1 net1 a 0 0 cmosn w=wn l=lln ad='wn *4.3u' as='wn *4.3u' pd='wn *2+8.6u' ps='wn *2+8.6u' m=1
|
|
|
|
|
m3 y net1 VCC VCC cmosp w=wp l=lp ad='wp *4.6u' as='wp *4.6u' pd='wp *2+9.2u' ps='wp *2+9.2u' m=1
|
|
|
|
|
m4 y net1 0 0 cmosn w=wn l=lln ad='wn *4.3u' as='wn *4.3u' pd='wn *2+8.6u' ps='wn *2+8.6u' m=1
|
2023-04-23 11:06:08 +02:00
|
|
|
.ends
|
2023-04-27 23:51:42 +02:00
|
|
|
.GLOBAL VCC
|
2023-04-23 11:06:08 +02:00
|
|
|
.end
|
|
|
|
|
</pre>
|
|
|
|
|
<p>
|
|
|
|
|
This approach allows to create polymorphic symbols. Multiple parameters may be given to the generator script,
|
|
|
|
|
like <kbd>symbolgen(inv,hv,100)</kbd>. Xschem will call the symbolgen script with the following command:
|
|
|
|
|
<kbd>symbolgen inv hv 100</kbd> and take the standard output from the script as the symbol
|
|
|
|
|
file to load and display.
|
|
|
|
|
</p>
|
2023-04-28 12:03:56 +02:00
|
|
|
<h2> Schematic generators (pcells)</h2>
|
2023-04-27 23:51:42 +02:00
|
|
|
<p>
|
|
|
|
|
The same approach used for symbol generators can be used for schematic generators. If you add a
|
|
|
|
|
<kbd>schematic=schematicgen(buf,4)</kbd> attribute to an instance
|
|
|
|
|
xschem will look for a script named <kbd>schematicgen</kbd> in the search paths and call
|
|
|
|
|
it with the given parameters (that is, execute the command
|
|
|
|
|
<kbd>schematicgen buf 4</kbd>) and read the produced output as a schematic file.
|
|
|
|
|
</p>
|
|
|
|
|
<img src="symbol_generators03.png">
|
2023-04-23 11:06:08 +02:00
|
|
|
<br><br><br>
|
2023-04-22 11:29:44 +02:00
|
|
|
<!-- end of slide -->
|
|
|
|
|
<div class="filler"></div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- frame footer -->
|
|
|
|
|
<iframe seamless src="xschem_footer.html" class="footer_iframe" >
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
|