has_included_subcircuit(): get symname from `schematic` attribute if set in instance or symbol, or use actual symbol name, add tb_symbol_include.sch example circuit

This commit is contained in:
stefan schippers 2024-01-08 17:19:12 +01:00
parent 8c55f3a99e
commit 6c163d5cb0
11 changed files with 154 additions and 15 deletions

View File

@ -1827,8 +1827,17 @@ static int has_included_subcircuit(int inst, int symbol, char **result)
my_strdup2(_ALLOC_ID_, &spice_sym_def, get_tok_value(xctx->sym[symbol].prop_ptr, "spice_sym_def", 0));
}
if(xctx->tok_size) {
tclvareval("has_included_subcircuit {", get_cell(xctx->sym[symbol].name, 0), "} {",
char *symname = NULL;
my_strdup2(_ALLOC_ID_, &symname, get_tok_value(xctx->inst[inst].prop_ptr, "schematic", 0));
if(!symname[0]) {
my_strdup2(_ALLOC_ID_, &symname, get_tok_value(xctx->sym[symbol].prop_ptr, "schematic", 0));
}
if(!symname[0]) {
my_strdup2(_ALLOC_ID_, &symname, xctx->sym[symbol].name);
}
tclvareval("has_included_subcircuit {", get_cell(symname, 0), "} {",
spice_sym_def, "}", NULL);
my_free(_ALLOC_ID_, &symname);
if(tclresult()[0]) {
char *pinlist = NULL;
char *pin, *save;

View File

@ -701,9 +701,9 @@ proc has_included_subcircuit {symname spice_sym_def} {
}
# return pinlist as found in the .subckt line or empty string if not found
if {!$include_found} {
puts "has_included_subcircuit: no matching .subckt found in spice_sym_def. Ignore"
puts "has_included_subcircuit: $symname: no matching .subckt found in spice_sym_def. Ignore"
if { [info exists has_x] } {
alert_ "has_included_subcircuit: no matching .subckt found in spice_sym_def. Ignore"
alert_ "has_included_subcircuit: $symname: no matching .subckt found in spice_sym_def. Ignore"
}
}
return $pinlist

View File

@ -15,6 +15,7 @@ install: FORCE
$(SCCBOX) install -f -d devices/*.sch "$(system_library_dir)"
$(SCCBOX) install -f -d examples/*.sym "$(XDOCDIR)"/examples
$(SCCBOX) install -f -d examples/*.sch "$(XDOCDIR)"/examples
$(SCCBOX) install -f -d examples/*.cir "$(XDOCDIR)"/examples
$(SCCBOX) install -f -d examples/stimuli.* "$(XDOCDIR)"/examples
$(SCCBOX) install -f -d binto7seg/*.sym "$(XDOCDIR)"/binto7seg
$(SCCBOX) install -f -d binto7seg/*.sch "$(XDOCDIR)"/binto7seg

View File

@ -108,7 +108,7 @@ N 410 -350 410 -320 {lab=BUS[2]}
N 460 -400 460 -320 {lab=BUS[2:1]}
N 860 -460 860 -390 {lab=#net2}
N 820 -420 910 -420 {lab=#net1}
C {poweramp.sym} 480 -900 0 0 {name=x1
C {poweramp.sym} 160 -140 0 0 {name=x1
tclcommand="xschem descend"}
C {tesla.sym} 160 -700 0 0 {name=x2}
C {test_ne555.sym} 160 -660 0 0 {name=x3}
@ -1481,18 +1481,19 @@ C {test_ac.sym} 160 -340 0 0 {name=x15}
C {rom8k.sym} 160 -180 0 0 {name=x17}
C {test_doublepin.sym} 160 -300 0 0 {name=x19}
C {classD_amp.sym} 160 -220 0 0 {name=x20}
C {delta_sigma.sym} 480 -820 0 0 {name=x21}
C {solar_panel.sym} 480 -780 0 0 {name=xsolar}
C {delta_sigma.sym} 480 -900 0 0 {name=x21}
C {solar_panel.sym} 480 -860 0 0 {name=xsolar}
C {test_extracted_netlist.sym} 160 -260 0 0 {name=x23
tclcommand="xschem descend"}
C {poweramp_lcc.sym} 480 -860 0 0 {name=x16
C {poweramp_lcc.sym} 160 -100 0 0 {name=x16
tclcommand="xschem descend"}
C {test_symbolgen.sym} 480 -740 0 0 {name=x18}
C {inst_sch_select.sym} 480 -700 0 0 {name=x24}
C {test_bus_tap.sym} 480 -660 0 0 {name=x22}
C {test_symbolgen.sym} 480 -820 0 0 {name=x18}
C {inst_sch_select.sym} 480 -740 0 0 {name=x24}
C {test_bus_tap.sym} 480 -700 0 0 {name=x22}
C {bus_tap.sym} 450 -310 1 1 {name=l5 lab=[2:1]}
C {test_jfet.sym} 480 -620 0 0 {name=x25}
C {test_short_option.sym} 480 -580 0 0 {name=x26}
C {test_lvs_ignore.sym} 480 -540 0 0 {name=x27}
C {test_generators.sym} 480 -500 0 0 {name=x28}
C {autozero_comp.sym} 480 -460 0 0 {name=x29}
C {test_jfet.sym} 480 -660 0 0 {name=x25}
C {test_short_option.sym} 480 -620 0 0 {name=x26}
C {test_lvs_ignore.sym} 480 -580 0 0 {name=x27}
C {test_generators.sym} 480 -540 0 0 {name=x28}
C {autozero_comp.sym} 480 -500 0 0 {name=x29}
C {tb_symbol_include.sym} 480 -780 0 0 {name=x30}

View File

@ -0,0 +1,7 @@
* example of a subcircuit contained in a file
.subckt symbol_include Z VCC VSS
+ A B C W=10 L=1
...
...
.ends

View File

@ -0,0 +1,11 @@
v {xschem version=3.4.5 file_version=1.2}
G {}
V {}
E {}
S {}
C {ipin.sym} -120 0 0 0 {name=g0 lab=A }
C {ipin.sym} -120 20 0 0 {name=g1 lab=B }
C {ipin.sym} -120 40 0 0 {name=g2 lab=C }
C {ipin.sym} -120 60 0 0 {name=g3 lab=VCC }
C {ipin.sym} -120 80 0 0 {name=g4 lab=VSS }
C {opin.sym} 120 0 0 0 {name=g5 lab=Z }

View File

@ -0,0 +1,52 @@
v {xschem version=3.4.5 file_version=1.2
}
G {}
K {type=subcircuit
format="@name @pinlist @symname"
template="name=x1"
comm="default_schematic=ignore will prevent netlisting the symbol definition,
only definitions contained in instance schematic=... will be used"
xdefault_schematic=ignore
comm="following spice_sym_def includes a file with the subckt definition"
spice_sym_def=".include symbol_include.cir"
comm="following spice_sym_def directly contains the definition of the subckt"
xxspice_sym_def="
.subckt symbol_include Z VCC VSS
+ A B C
...
...
.ends
"}
V {}
S {}
E {}
L 4 -130 -50 130 -50 {}
L 4 -130 50 130 50 {}
L 4 -130 -50 -130 50 {}
L 4 130 -50 130 50 {}
L 4 -150 -40 -130 -40 {}
L 4 -150 -20 -130 -20 {}
L 4 -150 0 -130 0 {}
L 4 130 -40 150 -40 {}
L 4 -150 20 -130 20 {}
L 4 -150 40 -130 40 {}
B 5 -152.5 -42.5 -147.5 -37.5 {name=A dir=in}
B 5 -152.5 -22.5 -147.5 -17.5 {name=B dir=in}
B 5 -152.5 -2.5 -147.5 2.5 {name=C dir=in}
B 5 147.5 -42.5 152.5 -37.5 {name=Z dir=out}
B 5 -152.5 17.5 -147.5 22.5 {name=VCC dir=in}
B 5 -152.5 37.5 -147.5 42.5 {name=VSS dir=in}
T {@symname} -81 -6 0 0 0.3 0.3 {}
T {@name} 135 -62 0 0 0.2 0.2 {}
T {A} -125 -44 0 0 0.2 0.2 {}
T {B} -125 -24 0 0 0.2 0.2 {}
T {C} -125 -4 0 0 0.2 0.2 {}
T {Z} 125 -44 0 1 0.2 0.2 {}
T {VCC} -125 16 0 0 0.2 0.2 {}
T {VSS} -125 36 0 0 0.2 0.2 {}
T {This symbol has attribute "spice_sym_def"
that references a .subckt file.
The port order of the symbol instance call
will match the order in the .subckt} -190 -210 0 0 0.4 0.4 {hide=instance layer=6}

View File

@ -0,0 +1,7 @@
* example of a subcircuit contained in a file
.subckt symbol_include Z VCC VSS
+ A B C W=10 L=1
...
...
.ends

View File

@ -0,0 +1,11 @@
v {xschem version=3.4.5 file_version=1.2}
G {}
V {}
E {}
S {}
C {ipin.sym} -120 0 0 0 {name=g0 lab=A }
C {ipin.sym} -120 20 0 0 {name=g1 lab=B }
C {ipin.sym} -120 40 0 0 {name=g2 lab=C }
C {ipin.sym} -120 60 0 0 {name=g3 lab=VCC }
C {ipin.sym} -120 80 0 0 {name=g4 lab=VSS }
C {opin.sym} 120 0 0 0 {name=g5 lab=Z }

View File

@ -0,0 +1,29 @@
v {xschem version=3.4.5 file_version=1.2
}
G {}
K {}
V {}
S {}
E {}
T {Control + left mouse button on
the symbol to see the
symbol_include.cir file} 290 -130 0 0 0.3 0.3 {}
C {symbol_include.sym} 410 -190 0 0 {name=x1
tclcommand="textwindow [xschem get current_dirname]/symbol_include.cir"
comm="following instance attributes (now 'x' commented) specify an alternate
symbol reference to use in netlist"
xspice_sym_def=".include symbol_include2.cir"
xschematic="symbol_include2.sch"}
C {lab_pin.sym} 260 -230 0 0 {name=p1 lab=XA}
C {lab_pin.sym} 260 -210 0 0 {name=p2 lab=XB}
C {lab_pin.sym} 260 -190 0 0 {name=p3 lab=XC}
C {lab_pin.sym} 560 -230 0 1 {name=p4 lab=XZ}
C {lab_pin.sym} 260 -170 0 0 {name=p5 lab=XVCC}
C {lab_pin.sym} 260 -150 0 0 {name=p6 lab=XVSS}
C {opin.sym} 120 -70 0 0 { name=p7 lab=XZ }
C {ipin.sym} 80 -70 0 0 { name=p8 lab=XVSS }
C {ipin.sym} 80 -90 0 0 { name=p9 lab=XVCC }
C {ipin.sym} 80 -110 0 0 { name=p10 lab=XC }
C {ipin.sym} 80 -130 0 0 { name=p11 lab=XB }
C {ipin.sym} 80 -150 0 0 { name=p12 lab=XA }

View File

@ -0,0 +1,11 @@
v {xschem version=3.4.5 file_version=1.2}
K {type=subcircuit
format="@name @pinlist @symname"
template="name=x1"
}
T {@symname} -94.5 -6 0 0 0.3 0.3 {}
T {@name} 135 -22 0 0 0.2 0.2 {}
L 4 -130 -10 130 -10 {}
L 4 -130 10 130 10 {}
L 4 -130 -10 -130 10 {}
L 4 130 -10 130 10 {}