1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283 | ###############################################################################
# Copyright (c) 2009-2024 by Altair Engineering, Inc.
# All rights reserved.
#
# Altair Engineering, Inc. makes this software available as part of the Vision
# tool platform. As long as you are a licensee of the Vision tool platform
# you may make copies of the software and modify it to be used within the
# Vision tool platform, but you must include all of this notice on any copy.
# Redistribution without written permission to any third party, with or
# without modification, is not permitted.
# Altair Engineering, Inc. does not warrant that this software is error free
# or fit for any purpose. Altair Engineering, Inc. disclaims any liability for
# all claims, expenses, losses, damages and costs any user may incur as a
# result of using, copying or modifying the software.
# =============================================================================
# @plugin
# Path to P/G
# @namespace
# PathToPG
# @section
# Miscellaneous Userware Examples
# @description
# Extend the Popup menu to extract a path from a S, D or G pin of a
# transistor to power and ground.
# Go through resistors, inductors and D->S or S->D of NMOS or PMOS
# transistors.
# @license
# permit spice
# @files
# pathToPG.tcl
# @example
# demo/spice/gl85.sp
# @cmdline
# -hspice @example[0]
# -userware @files[0]
# @tag
# spice gui
###############################################################################
# =============================================================================
# Init - Initialize the plugin.
# =============================================================================
#
proc PathToPG:Init {} {
##
# Customize the Popup Menu.
#
gui popup append "Path to PG" "PathToPG:Start"
}
# =============================================================================
# Finit - Finalize the plugin.
# =============================================================================
#
proc PathToPG:Finit {} {
gui popup remove "Path to PG"
}
# =============================================================================
# Start - This is the main procedure. Either called from the Popup menu or
# in batch mode.
# =============================================================================
#
proc PathToPG:Start {oidList} {
global PathToPG
##
# Only start if a database is available.
#
set db [gui database get]
if {$db == {}} {
return
}
##
# We expect exactly one object as a start point.
#
if {[llength $oidList] != 1} {
zmessage print WAR \
"Select exactly one start pin ([llength $oidList] given)"
return
}
##
# The given start object needs to be a pin.
#
set oid [lindex $oidList 0]
if {[$db oid type $oid] != "pin"} {
zmessage print WAR "Expect a pin but [$db oid type $oid] given."
return
}
##
# Set some path search limit.
#
set limitFactor 10
set PathToPG(limit) \
[expr {$limitFactor * [gui settings get "cone:devicePathMax"]}]
set PathToPG(limitReached) 0
##
# Initialize: clear PathToPG(resList) and 'black' flat flag.
#
set PathToPG(resList) {}
$db foreach top top {
$db flatflag $top clearall black
}
##
# Start the path extraction and load the result into the Cone window.
#
set PathToPG(startPin) $oid
PathToPG:_nextPin $db $PathToPG(startPin)
if {[PathToPG:_primFuncOK $db $oid] && (!$PathToPG(limitReached))} {
set PathToPG(startPin) [$db tdevice oppositePin $oid]
PathToPG:_nextPin $db $PathToPG(startPin)
}
if {$PathToPG(limitReached)} {
set message \
"Cannot determine full path to power/ground within iteration\
limits."
append message \
"\nMake sure power/ground nodes are specified correctly\
in 'Read Spice > Power / Ground' or activate the option\
'Read Spice > Options > Power > Guess Power and Ground Nets'."
append message \
"\nAlternatively, you may increase the iteration limit by\
increasing 'Preferences > Cone > Max path length to power/ground'."
zmessage print ERR $message
return
}
##
# Display the result in the Cone window without the hierarchy borders.
#
gui cone clear
gui settings set "cone:hierfilter" 1
gui settings changed
gui cone append $PathToPG(resList)
}
# -----------------------------------------------------------------------------
# _nextPin - recursive procedure to extract a path to P/G.
# -----------------------------------------------------------------------------
#
proc PathToPG:_nextPin {db pin} {
global PathToPG
if {$PathToPG(limitReached)} {
return
}
##
# If no net is connected to the given pin or the pin has been visited
# before (indicated flat flag 'black') then return from this procedure.
#
if {![$db isConnected $pin]} {
return
}
if {[$db flatflag $pin is black]} {
return
}
##
# Get the connected net and add the given pin to the result list.
#
set net [$db connectedNet $pin]
##
# If we hit a power or ground node then the target is reached.
# Add the pin to the result list and return from the procedure.
#
if {[$db isPgNet $net]} {
lappend PathToPG(resList) $pin
if {[llength $PathToPG(resList)] > $PathToPG(limit)} {
set PathToPG(limitReached) 1
}
return
}
##
# Mark the given pin as visited using the flat flag 'black'.
#
$db flatflag $pin set black
##
# Loop over all pins of this net in all levels of hierarchy.
#
$db flat foreach pin $net p {
##
# Skip the following:
# - already visited pins
# - top level ports
# - instances with the wrong function.
#
if {[$db flatflag $p is black]} {
continue
}
if {[$db oid type $p] == "port"} {
continue
}
if {![PathToPG:_primFuncOK $db $p]} {
continue
}
##
# Recursively call _nextPin with the pin connected to the net.
#
PathToPG:_nextPin $db $p
if {$PathToPG(limitReached)} {
return
}
}
##
# Add the currently processed pin to the result list.
#
lappend PathToPG(resList) $pin
if {[llength $PathToPG(resList)] > $PathToPG(limit)} {
set PathToPG(limitReached) 1
return
}
##
# Recursively call _nextPin with the opposite pin if the primitive
# function of the given pin allows this.
#
if {![PathToPG:_primFuncOK $db $pin]} {
return
}
if {[$db oid isequal $PathToPG(startPin) $pin]} {
return
}
PathToPG:_nextPin $db [$db tdevice oppositePin $pin]
}
# -----------------------------------------------------------------------------
# _primFuncOK - This procedure decides whether the path extraction goes
# through the instance of the given pin or not.
# -----------------------------------------------------------------------------
#
proc PathToPG:_primFuncOK {db pin} {
##
# Convert the given pin into an instance and decide based on the
# primitive function if the path extraction goes through the instance.
#
switch -- [$db primFuncOf [$db oid convertTo inst $pin]] {
"RES" -
"INDUCTOR" {
return true
}
"NMOS" -
"PMOS" {
##
# Do not follow the path through transistor gate or bulk pins.
#
if {[string equal -nocase [$db oid pname $pin] "g"]} {
return false
}
if {[string equal -nocase [$db oid pname $pin] "b"]} {
return false
}
return true
}
default {
return false
}
}
}
# =============================================================================
# Call the initialization procedure.
# =============================================================================
#
PathToPG:Init
|