From 608a144dd14cbde88f9a19cb54835775963bb00b Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Wed, 24 May 2023 08:43:05 +0200 Subject: [PATCH] fix tcl procedures using find_file to find a component: use find_file_first (return 1st match) , since find_file may return multiple matches; add njfet.sym, pjfet.sym and test_jfet.sch --- src/hilight.c | 2 +- src/xschem.tcl | 35 ++++++++--- xschem_library/devices/njfet.sym | 26 ++++++++ xschem_library/devices/pjfet.sym | 26 ++++++++ xschem_library/examples/0_examples_top.sch | 62 ++++++++++--------- xschem_library/examples/test_jfet.sch | 70 ++++++++++++++++++++++ xschem_library/examples/test_jfet.sym | 11 ++++ 7 files changed, 190 insertions(+), 42 deletions(-) create mode 100644 xschem_library/devices/njfet.sym create mode 100644 xschem_library/devices/pjfet.sym create mode 100644 xschem_library/examples/test_jfet.sch create mode 100644 xschem_library/examples/test_jfet.sym diff --git a/src/hilight.c b/src/hilight.c index 431dc91a..d6a5f9d2 100644 --- a/src/hilight.c +++ b/src/hilight.c @@ -132,7 +132,7 @@ Hilight_hashentry *inst_hilight_hash_lookup(int i, int value, int what) { const char *token = xctx->inst[i].instname; char *inst_tok = NULL; - size_t len = strlen(token) + 2; /* token plus one more character and \0 */ + size_t len = strlen(token) + 3; /* token plus two more character and \0 */ int label = 0; Hilight_hashentry *entry; if(IS_LABEL_SH_OR_PIN( (xctx->inst[i].ptr+xctx->sym)->type )) label = 1; diff --git a/src/xschem.tcl b/src/xschem.tcl index ff53987c..bf052882 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -1349,7 +1349,7 @@ proc select_inst {fullinst {redraw 1 } } { } proc pin_label {} { - return [rel_sym_path [find_file lab_pin.sym]] + return [rel_sym_path [find_file_first lab_pin.sym]] } ## given a hierarchical net name x1.xamp.netname go down in the hierarchy and @@ -3065,7 +3065,7 @@ proc create_pins {} { regsub -all {<} $retval {[} retval regsub -all {>} $retval {]} retval set lines [split $retval \n] - set dirprefix [file dirname [rel_sym_path [find_file ipin.sym]]] + set dirprefix [file dirname [rel_sym_path [find_file_first ipin.sym]]] if {$dirprefix == {.}} { set dirprefix {}} else {append dirprefix {/}} # viewdata $retval @@ -3169,7 +3169,7 @@ proc add_lab_no_prefix {} { global env retval USER_CONF_DIR global filetmp - set dirprefix [file dirname [rel_sym_path [find_file ipin.sym]]] + set dirprefix [file dirname [rel_sym_path [find_file_first ipin.sym]]] if {$dirprefix == {.}} { set dirprefix {}} else {append dirprefix {/}} set retval [ read_data_nonewline $filetmp ] regsub -all {<} $retval {[} retval @@ -3191,7 +3191,7 @@ proc add_lab_prefix {} { global env retval USER_CONF_DIR global filetmp - set dirprefix [file dirname [rel_sym_path [find_file ipin.sym]]] + set dirprefix [file dirname [rel_sym_path [find_file_first ipin.sym]]] if {$dirprefix == {.}} { set dirprefix {}} else {append dirprefix {/}} set retval [ read_data_nonewline $filetmp ] regsub -all {<} $retval {[} retval @@ -4558,7 +4558,7 @@ proc match_file { f {paths {}} } { return $res } -proc sub_find_file { f {paths {}} } { +proc sub_find_file { f {paths {}} {first 0} } { global pathlist match_file_dir_arr set res {} if {$paths eq {}} {set paths $pathlist} @@ -4570,13 +4570,17 @@ proc sub_find_file { f {paths {}} } { if {[array names match_file_dir_arr -exact $jj] == {}} { set match_file_dir_arr($jj) 1 # puts "********** directory $jj" - set sub_res [sub_find_file $f $j] ;# recursive call - if {$sub_res != {} } {set res [concat $res $sub_res]} + set sub_res [sub_find_file $f $j $first] ;# recursive call + if {$sub_res != {} } { + set res [concat $res $sub_res] + if {$first} {return $res} + } } } else { set fname [file tail $j] if {$fname == $f} { lappend res $j + if {$first} {return $res} } } } @@ -4590,11 +4594,24 @@ proc sub_find_file { f {paths {}} } { proc find_file { f {paths {}} } { global match_file_dir_arr catch {unset match_file_dir_arr} - set res [sub_find_file $f $paths] + set res [sub_find_file $f $paths 0] catch {unset match_file_dir_arr} return $res } +# find given file $f into $paths directories +# use $pathlist global search path if $paths empty +# recursively descend directories +# only return FIRST FOUND +proc find_file_first { f {paths {}} } { + global match_file_dir_arr + catch {unset match_file_dir_arr} + set res [sub_find_file $f $paths 1] + catch {unset match_file_dir_arr} + return $res +} + + # alternative implementation of "file dirname ... " # that does not mess with http:// (file dirname removes double slashes) proc get_directory {f} { @@ -6179,7 +6196,7 @@ proc build_widgets { {topwin {} } } { } $topwin.menubar.simulation.menu add command -label {Add waveform graph} -command {xschem add_graph} $topwin.menubar.simulation.menu add command -label {Add waveform reload launcher} -command { - xschem place_symbol [rel_sym_path [find_file launcher.sym]] "name=h5\ndescr=\"load waves\" + xschem place_symbol [rel_sym_path [find_file_first launcher.sym]] "name=h5\ndescr=\"load waves\" tclcommand=\"xschem raw_read \$netlist_dir/[file tail [file rootname [xschem get current_name]]].raw tran\" " } diff --git a/xschem_library/devices/njfet.sym b/xschem_library/devices/njfet.sym new file mode 100644 index 00000000..51517368 --- /dev/null +++ b/xschem_library/devices/njfet.sym @@ -0,0 +1,26 @@ +v {xschem version=3.4.0 file_version=1.2 +} +G {} +K {type=njfet +format="@spiceprefix@name @pinlist @model area=@area @extra m=@m" +template="name=J1 model=njfet area=1 m=1" +} +V {} +S {} +E {} +L 4 5 -30 5 30 {} +L 4 5 -20 20 -20 {} +L 4 20 -30 20 -20 {} +L 4 5 20 20 20 {} +L 4 20 20 20 30 {} +B 5 17.5 -32.5 22.5 -27.5 {name=d dir=inout} +B 5 -22.5 -2.5 -17.5 2.5 {name=g dir=in} +B 5 17.5 27.5 22.5 32.5 {name=s dir=inout} +P 4 7 -20 0 -5 0 -5 -5 5 -0 -5 5 -5 0 -20 0 {fill=true} +T {@spiceprefix@name} 7.5 7.5 0 0 0.2 0.2 {} +T {D} 25 -27.5 0 0 0.15 0.15 {} +T {@#0:net_name} 25 -42.5 0 0 0.15 0.15 {layer=15} +T {@#2:net_name} 25 32.5 0 0 0.15 0.15 {layer=15} +T {@#1:net_name} -25 -12.5 0 1 0.15 0.15 {layer=15} +T {@model} 7.5 -17.5 0 0 0.2 0.2 {} +T {area=@area} 7.5 -5 0 0 0.2 0.2 {} diff --git a/xschem_library/devices/pjfet.sym b/xschem_library/devices/pjfet.sym new file mode 100644 index 00000000..f34ba97c --- /dev/null +++ b/xschem_library/devices/pjfet.sym @@ -0,0 +1,26 @@ +v {xschem version=3.4.0 file_version=1.2 +} +G {} +K {type=pjfet +format="@spiceprefix@name @pinlist @model area=@area @extra m=@m" +template="name=J1 model=pjfet area=1 m=1" +} +V {} +S {} +E {} +L 4 5 -30 5 30 {} +L 4 5 -20 20 -20 {} +L 4 20 -30 20 -20 {} +L 4 5 20 20 20 {} +L 4 20 20 20 30 {} +B 5 17.5 -32.5 22.5 -27.5 {name=d dir=inout} +B 5 -22.5 -2.5 -17.5 2.5 {name=g dir=in} +B 5 17.5 27.5 22.5 32.5 {name=s dir=inout} +P 4 7 5 0 -7.5 0 -7.5 5 -17.5 0 -7.5 -5 -7.5 0 5 0 {fill=true} +T {@spiceprefix@name} 7.5 7.5 0 0 0.2 0.2 {} +T {D} 25 -27.5 0 0 0.15 0.15 {} +T {@#0:net_name} 25 -42.5 0 0 0.15 0.15 {layer=15} +T {@#2:net_name} 25 32.5 0 0 0.15 0.15 {layer=15} +T {@#1:net_name} -25 -12.5 0 1 0.15 0.15 {layer=15} +T {@model} 7.5 -17.5 0 0 0.2 0.2 {} +T {area=@area} 7.5 -5 0 0 0.2 0.2 {} diff --git a/xschem_library/examples/0_examples_top.sch b/xschem_library/examples/0_examples_top.sch index 6fbe2438..98b6bfaa 100644 --- a/xschem_library/examples/0_examples_top.sch +++ b/xschem_library/examples/0_examples_top.sch @@ -48,12 +48,9 @@ P 15 11 870 -520 880 -560 900 -530 910 -550 920 -520 940 -530 920 -490 890 -500 T {Welcome to XSCHEM!} 110 -1060 0 0 1 1 {layer=5} T {This is a test schematic window -On the left you see some sample circuits. You may descend into any -of these by selecting one with a left mouse button click and -pressing the 'e' key, or by menu 'Edit -> Push Schematic'. -You can return here after descending into a schematic by hitting -'-e' or by menu 'Edit -> Pop'. -} 60 -990 0 0 0.4 0.4 {} +On the left you see some sample circuits. You may descend into any of these by selecting one with a left mouse button click and +pressing the 'e' key, or by menu 'Edit -> Push Schematic'. You can return here after descending into a schematic by hitting +'-e' or by menu 'Edit -> Pop'.} 60 -990 0 0 0.4 0.4 {} T {Lines} 960 -680 0 0 0.6 0.6 {layer=4} T {Rectangles} 960 -620 0 0 0.6 0.6 {layer=4} T {Polygons} 960 -530 0 0 0.6 0.6 {layer=4} @@ -90,16 +87,16 @@ N 380 -310 640 -310 {lab=BUS[4:0]} N 510 -400 510 -320 {lab=BUS[1]} N 410 -350 410 -320 {lab=BUS[2]} N 460 -400 460 -320 {lab=BUS[2:1]} -C {poweramp.sym} 480 -690 0 0 {name=x1 +C {poweramp.sym} 480 -750 0 0 {name=x1 tclcommand="xschem descend"} -C {tesla.sym} 160 -570 0 0 {name=x2} -C {test_ne555.sym} 160 -530 0 0 {name=x3} -C {test_lm324.sym} 160 -490 0 0 {name=x4} -C {osc.sym} 160 -610 0 0 {name=x5} +C {tesla.sym} 160 -630 0 0 {name=x2} +C {test_ne555.sym} 160 -590 0 0 {name=x3} +C {test_lm324.sym} 160 -550 0 0 {name=x4} +C {osc.sym} 160 -670 0 0 {name=x5} C {title.sym} 160 -30 0 0 {name=l1 author="Stefan Schippers"} -C {cmos_example.sym} 160 -650 0 0 {name=x6} -C {greycnt.sym} 160 -690 0 0 {name=x8} -C {loading.sym} 160 -730 0 0 {name=x9} +C {cmos_example.sym} 160 -710 0 0 {name=x6} +C {greycnt.sym} 160 -750 0 0 {name=x8} +C {loading.sym} 160 -790 0 0 {name=x9} C {inv_bsource.sym} 880 -320 0 0 {name=B1 TABLE="1.4 3.0 1.6 0.0"} C {launcher.sym} 460 -140 0 0 {name=h1 descr="XSCHEM ON REPO.HU" @@ -116,17 +113,17 @@ url="$\{XSCHEM_SHAREDIR\}/../doc/xschem/index.html" program=x-www-browser } -C {rlc.sym} 160 -770 0 0 {name=x0} +C {rlc.sym} 160 -830 0 0 {name=x0} C {lab_pin.sym} 640 -310 0 1 {name=l2 sig_type=std_logic lab=BUS[4:0]} C {bus_connect.sym} 500 -310 0 0 {name=l3 lab=BUS[1]} C {bus_connect_nolab.sym} 400 -310 0 0 {name=r1} C {lab_pin.sym} 410 -350 3 1 {name=l4 sig_type=std_logic lab=BUS[2]} -C {LCC_instances.sym} 160 -450 0 0 {name=x7} -C {test_backannotated_subckt.sym} 160 -410 0 0 {name=x10} -C {plot_manipulation.sym} 160 -370 0 0 {name=x11} -C {logic_test.sym} 160 -330 0 0 {name=x12} -C {simulate_ff.sym} 160 -290 0 0 {name=x13} -C {test_mos_verilog.sym} 160 -250 0 0 {name=x14} +C {LCC_instances.sym} 160 -510 0 0 {name=x7} +C {test_backannotated_subckt.sym} 160 -470 0 0 {name=x10} +C {plot_manipulation.sym} 160 -430 0 0 {name=x11} +C {logic_test.sym} 160 -390 0 0 {name=x12} +C {simulate_ff.sym} 160 -350 0 0 {name=x13} +C {test_mos_verilog.sym} 160 -310 0 0 {name=x14} C {launcher.sym} 1265 -225 0 0 {name=h5 descr=" Ctrl-Left-Click to load/ unload waveforms" @@ -1459,17 +1456,18 @@ xwtAgA9ve8fHC0Dod8blIpQLQJBdgRgxavQ/AAAAgEslwD6d7SiMdxwqP41maeirFRxABH/Rb+tVM0DO cwtAyKwqggMC8z8AAABAXz/APixDHOviNio/cIyWTt0GHEAHmaX3NW0zQHJvU5F/bTNA3V5CW3kqoL85tJeeXUIJQIB/waNeQglAcFfF8JIdC0DY7tjwBPjxPwAAALCc UsA+" } -C {test_ac.sym} 160 -210 0 0 {name=x15} -C {rom8k.sym} 480 -730 0 0 {name=x17} -C {test_doublepin.sym} 160 -170 0 0 {name=x19} -C {classD_amp.sym} 480 -770 0 0 {name=x20} -C {delta_sigma.sym} 480 -610 0 0 {name=x21} -C {solar_panel.sym} 480 -570 0 0 {name=xsolar} -C {test_extracted_netlist.sym} 160 -130 0 0 {name=x23 +C {test_ac.sym} 160 -270 0 0 {name=x15} +C {rom8k.sym} 480 -790 0 0 {name=x17} +C {test_doublepin.sym} 160 -230 0 0 {name=x19} +C {classD_amp.sym} 480 -830 0 0 {name=x20} +C {delta_sigma.sym} 480 -670 0 0 {name=x21} +C {solar_panel.sym} 480 -630 0 0 {name=xsolar} +C {test_extracted_netlist.sym} 160 -190 0 0 {name=x23 tclcommand="xschem descend"} -C {poweramp_lcc.sym} 480 -650 0 0 {name=x16 +C {poweramp_lcc.sym} 480 -710 0 0 {name=x16 tclcommand="xschem descend"} -C {test_symbolgen.sym} 480 -530 0 0 {name=x18} -C {inst_sch_select.sym} 480 -490 0 0 {name=x24} -C {test_bus_tap.sym} 480 -450 0 0 {name=x22} +C {test_symbolgen.sym} 480 -590 0 0 {name=x18} +C {inst_sch_select.sym} 480 -550 0 0 {name=x24} +C {test_bus_tap.sym} 480 -510 0 0 {name=x22} C {bus_tap.sym} 450 -310 1 1 {name=l5 lab=[2:1]} +C {test_jfet.sym} 480 -470 0 0 {name=x25} diff --git a/xschem_library/examples/test_jfet.sch b/xschem_library/examples/test_jfet.sch new file mode 100644 index 00000000..bbbc8835 --- /dev/null +++ b/xschem_library/examples/test_jfet.sch @@ -0,0 +1,70 @@ +v {xschem version=3.4.0 file_version=1.2 +} +G {} +K {} +V {} +S {} +E {} +B 2 590 -730 1390 -330 {flags=graph,unlocked +y1=1.5e-42 +y2=0.0028 +ypos1=0 +ypos2=2 +divy=5 +subdivy=1 +unity=1 +x1=-0.308107 +x2=19.6819 +divx=5 +subdivx=1 +xlabmag=1.0 +ylabmag=1.0 +node=i(@j1[id]) +color=4 +dataset=-1 +unitx=1 +logx=0 +logy=0 +rainbow=0} +N 340 -300 340 -250 { +lab=#net1} +N 340 -190 340 -110 { +lab=GND} +N 260 -220 300 -220 { +lab=#net2} +N 150 -220 200 -220 { +lab=G} +N 340 -420 340 -360 { +lab=D} +C {title.sym} 160 -30 0 0 {name=l9 + +author="tcleval(Stefan Schippers[ + if \{$show_pin_net_names == 0\} \{ + set show_pin_net_names 1 + xschem update_all_sym_bboxes + \}] +)"} +C {njfet.sym} 320 -220 0 0 {name=J1 model=2N3459 area=1 m=1 +} +C {lab_pin.sym} 150 -220 0 0 {name=p1 sig_type=std_logic lab=G} +C {lab_pin.sym} 340 -420 0 0 {name=p2 sig_type=std_logic lab=D} +C {lab_pin.sym} 340 -110 0 0 {name=p3 sig_type=std_logic lab=GND} +C {code_shown.sym} 580 -280 0 0 {name=s1 only_toplevel=false value="VG G 0 dc 0 +VD D 0 dc 0 + +.options savecurrents +.control + save all + dc VD 0 20 0.01 VG 0 -1 -0.1 + write test_jfet.raw +.endc"} +C {code.sym} 70 -400 0 0 {name=MODEL only_toplevel=false value=".MODEL 2N3459 NJF(VTO=-1.4 BETA=1.265m BETATCE=-0.5 LAMBDA=4m RD=1 RS=1 CGS=2.916p CGD=2.8p PB=0.5 IS=114.5f XTI=3 AF=1 FC=0.5 N=1 NR=2)"} +C {noconn.sym} 340 -140 0 0 {name=l1} +C {noconn.sym} 340 -390 0 0 {name=l2} +C {noconn.sym} 180 -220 1 0 {name=l3} +C {launcher.sym} 980 -290 0 0 {name=h5 +descr="load waves" +tclcommand="xschem raw_read $netlist_dir/test_jfet.raw dc" +} +C {ammeter.sym} 230 -220 1 0 {name=Vgate} +C {ammeter.sym} 340 -330 0 0 {name=Vdrain} diff --git a/xschem_library/examples/test_jfet.sym b/xschem_library/examples/test_jfet.sym new file mode 100644 index 00000000..1c4d9bcd --- /dev/null +++ b/xschem_library/examples/test_jfet.sym @@ -0,0 +1,11 @@ +v {xschem version=3.4.0 file_version=1.2} +K {type=subcircuit +format="@name @pinlist @symname" +template="name=x1" +} +T {@symname} -72 -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 {}