forked from GarvitK01/Sim2600
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwire.py
100 lines (88 loc) · 3.89 KB
/
wire.py
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
# Copyright (c) 2014 Greg James, Visual6502.org
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#------------------------------------------------------------------------------
#
# wire.py
# Wire is a piece of the circuit whose voltage is either high or low.
# It can drive the gates of transistors and it can be connected
# through transistors to other wires. A wire represents a group
# of physical parts in a chip where the parts might be metal
# interconnects, polysilicon wires, areas of diffusion, vias, i/o
# pads, or the gates of transistors.
# Certain wires have string names to describe their function, like
# 'VCC' to describe the network that supplies positive voltage, 'GND'
# or 'VSS' to describe the network connected to ground, 'CLK0' for
# the parts that carry the primary clock signal, etc.
#
class Wire:
PULLED_HIGH = 1 << 0
PULLED_LOW = 1 << 1
GROUNDED = 1 << 2
HIGH = 1 << 3
FLOATING_HIGH = 1 << 4
FLOATING_LOW = 1 << 5
FLOATING = 1 << 6
def __init__(self, idIndex, name, controlTransIndices, transGateIndices, pulled):
self.index = idIndex
self.name = name
# Transistors that switch other wires into connection with this wire
self.ctInds = controlTransIndices
# Transistors whos gate is driven by this wire
self.gateInds = transGateIndices
# pulled reflects whether or not the wire is connected to
# a pullup or pulldown.
self.pulled = pulled
# state reflects the logical state of the wire as the
# simulation progresses.
self.state = pulled
def __repr__(self):
rstr = 'Wire %d "%s": %d ct %s gates %s'%(self.idIndex, self.name,
self.state, str(self.ctInds), str(self.gateInds))
return rstr
def setHigh(self):
""" Used to pin a pad or external input high """
self.pulled = Wire.PULLED_HIGH
self.state = Wire.PULLED_HIGH
def setLow(self):
""" Used to pin a pad or external input low """
self.pulled = Wire.PULLED_LOW
self.state = Wire.PULLED_LOW
def setPulledHighOrLow(self, boolHigh):
""" Used to pin a pad or external input high or low """
if boolHigh == True:
self.pulled = Wire.PULLED_HIGH
self.state = Wire.PULLED_HIGH
elif boolHigh == False:
self.pulled = Wire.PULLED_LOW
self.state = Wire.PULLED_LOW
else:
raise Exception('Arg to setPulledHighOrLow is not True or False')
def isHigh(self):
if self.state == Wire.FLOATING_HIGH or \
self.state == Wire.PULLED_HIGH or \
self.state == Wire.HIGH:
return True
return False
def isLow(self):
if self.state == Wire.FLOATING_LOW or \
self.state == Wire.PULLED_LOW or \
self.state == Wire.GROUNDED:
return True
return False