import sys
if len(sys.argv) < 3:
- print(f'usage: {sys.argv[0]:s} channels.txt dot_dir')
+ print(f'usage: {sys.argv[0]:s} fets.txt dot_dir')
sys.exit(1)
-channels_txt = sys.argv[1]
+fets_txt = sys.argv[1]
dot_dir = sys.argv[2]
nets = {}
blocks = {}
-channels = []
-with open(channels_txt) as fin:
+fets = []
+with open(fets_txt) as fin:
line = fin.readline()
assert len(line)
fields = [int(i) for i in line.split()]
assert len(fields) >= 1
- n_channels = fields[0]
+ n_fets = fields[0]
n_gates = fields[1] if len(fields) >= 2 else 0
- for i in range(n_channels):
+ for i in range(n_fets):
line = fin.readline()
assert len(line)
fields = line.split()
for net in [poly_net] + diff_nets:
if net not in nets:
- nets[net] = set() # blocks (of channels/gates) that the net visits
+ nets[net] = set() # blocks (of fets/gates) that the net visits
nets[net].add(block)
if block not in blocks:
- blocks[block] = ([], []) # channels, gates
- blocks[block][0].append(len(channels))
- channels.append(
+ blocks[block] = ([], []) # fets, gates
+ blocks[block][0].append(len(fets))
+ fets.append(
(block, channel, poly_net, diff_nets, x, y, mass, r_matrix)
)
for product in expr:
for net in product:
if net not in nets:
- nets[net] = set() # blocks (of channels/gates) that the net visits
+ nets[net] = set() # blocks (of fets/gates) that the net visits
nets[net].add(block)
if block not in blocks:
- blocks[block] = ([], []) # channels, gates
+ blocks[block] = ([], []) # fets, gates
blocks[block][1].append(len(gates))
gates.append((block, output_net, expr))
-for block, (block_channels, block_gates) in sorted(blocks.items()):
+for block, (block_fets, block_gates) in sorted(blocks.items()):
with open(f'{dot_dir:s}/{block:s}.dot', 'w') as fout:
fout.write(f'digraph "{block:s}" {{\n')
fout.write(f' "{net_node:s}" [shape={shape:s}, label="{net:s}"]\n')
return net_node
- for i in block_channels:
- _, channel, poly_net, diff_nets, x, y, mass, r_matrix = channels[i]
+ for i in block_fets:
+ _, channel, poly_net, diff_nets, x, y, mass, r_matrix = fets[i]
- node = f'channel:{channel:s}'
+ node = f'fet:{channel:s}'
label = channel
if len(r_matrix) == 2:
label += f'\nR={r_matrix[1][0]:.3f}'
#print('R', 1. / sum_I2, 'squares')
return 1. / sum_I2
-print(len(channels))
+fets = []
image = numpy.zeros((ys, xs), numpy.uint8)
for (channel, (channel_items, channel_reports)) in sorted(channels.items()):
#adjacent_nodes = set([items[item1][0] for _, item1 in channel_reports])
r_matrix[-1].append(resistor_solver(image[min_y:max_y, min_x:max_x]))
image[min_y:max_y, min_x:max_x] = 0
+ fets.append((block, channel, poly_net, diff_nets, x, y, mass, r_matrix))
+
+print(len(fets))
+for block, channel, poly_net, diff_nets, x, y, mass, r_matrix in fets:
print(block, channel, poly_net, len(diff_nets), x, y, mass)
for i in range(len(diff_nets)):
print(' ' + diff_nets[i], ' '.join([str(j) for j in r_matrix[i]]))
import sys
if len(sys.argv) < 3:
- print(f'usage: {sys.argv[0]:s} channels.txt net_gnd,net_vcc')
+ print(f'usage: {sys.argv[0]:s} fets.txt net_gnd,net_vcc')
sys.exit(1)
-channels_txt = sys.argv[1]
+fets_txt = sys.argv[1]
[net_gnd, net_vcc] = sys.argv[2].split(',')
nets = {}
-channels = []
-with open(channels_txt) as fin:
+fets = []
+with open(fets_txt) as fin:
line = fin.readline()
assert len(line)
- [n_channels] = [int(i) for i in line.split()]
+ [n_fets] = [int(i) for i in line.split()]
- for i in range(n_channels):
+ for i in range(n_fets):
line = fin.readline()
assert len(line)
fields = line.split()
nets[net] = [False, 0, []] # visited, n_connections, switches
nets[net][1] += 1
- # make an index so we can quickly follow channels wired as switches
+ # make an index so we can quickly follow fets wired as switches
if len(diff_nets) == 2:
[diff_net0, diff_net1] = diff_nets
- nets[diff_net0][2].append((len(channels), diff_net1))
- nets[diff_net1][2].append((len(channels), diff_net0))
- channels.append(
+ nets[diff_net0][2].append((len(fets), diff_net1))
+ nets[diff_net1][2].append((len(fets), diff_net0))
+ fets.append(
[True, block, channel, poly_net, diff_nets, x, y, mass, r_matrix]
- ) # first element is valid flag, set to False to delete the channel
+ ) # first element is valid flag, set to False to delete the fet
# raised by follow() if pulled-up net doesn't appear to be a logic gate
class InvalidGate(Exception):
# inner list has nets to be ANDed together, outer list has products to
# be ORed together -- the OR of products, if true, pulls the output down
# note: expr of [] does not pull the output down, expr of [[]] does
-def follow(del_channels, net, parent_net):
+def follow(del_fets, net, parent_net):
if net == net_gnd:
return [[]]
if net == net_vcc:
try:
expr = []
- for channel1, net1 in nets[net][2]:
+ for fet1, net1 in nets[net][2]:
if net1 != parent_net:
- del_channels.append(channel1)
- valid1, _, _, poly_net1, _, _, _, _, _ = channels[channel1]
+ del_fets.append(fet1)
+ valid1, _, _, poly_net1, _, _, _, _, _ = fets[fet1]
if not valid1:
raise InvalidGate()
- expr1 = follow(del_channels, net1, net)
+ expr1 = follow(del_fets, net1, net)
expr.extend([i + [poly_net1] for i in expr1])
return expr
finally:
nets[net][0] = False
gates = []
-for i in range(len(channels)):
- valid, block, channel, poly_net, diff_nets, _, _, _, _ = channels[i]
+for i in range(len(fets)):
+ valid, block, _, poly_net, diff_nets, _, _, _, _ = fets[i]
if valid:
- # look for a channel wired as a pull-up to VCC (implied to be depletion)
+ # look for a fet wired as a pull-up to VCC (implied to be depletion)
if (
poly_net != net_gnd and
poly_net != net_vcc and
):
# the top level analysis ignores anything connected to the output that
# doesn't look like a pull-down (could be driving a transmission gate)
- del_channels = [i]
+ del_fets = [i]
expr = []
nets[poly_net][0] = True # set visited flag to avoid infinite recursion
- for channel1, net1 in nets[poly_net][2]:
- valid1, _, _, poly_net1, _, _, _, _, _ = channels[channel1]
+ for fet1, net1 in nets[poly_net][2]:
+ valid1, _, _, poly_net1, _, _, _, _, _ = fets[fet1]
if valid1:
- del_channels1 = [channel1]
+ del_fets1 = [fet1]
try:
- expr1 = follow(del_channels1, net1, poly_net)
- del_channels.extend(del_channels1)
+ expr1 = follow(del_fets1, net1, poly_net)
+ del_fets.extend(del_fets1)
expr.extend([i + [poly_net1] for i in expr1])
except InvalidGate:
pass
# don't allow constant expr (probably an error or analog circuit)
if expr != [] and expr != [[]]:
- for channel1 in del_channels:
- channels[channel1][0] = False
+ for fet1 in del_fets:
+ fets[fet1][0] = False
gates.append((block, poly_net, expr))
-n_channels = sum([int(valid) for valid, _, _, _, _, _, _, _, _ in channels])
-print(n_channels, len(gates))
+n_fets = sum([int(valid) for valid, _, _, _, _, _, _, _, _ in fets])
+print(n_fets, len(gates))
for [
valid,
block,
y,
mass,
r_matrix
-] in channels:
+] in fets:
if valid:
print(block, channel, poly_net, len(diff_nets), x, y, mass)
for i in range(len(diff_nets)):