2016-11-08 18:57:35 +01:00
|
|
|
import contact
|
2017-12-12 23:53:19 +01:00
|
|
|
import pgate
|
2016-11-08 18:57:35 +01:00
|
|
|
import debug
|
2017-11-30 01:11:15 +01:00
|
|
|
from tech import drc, parameter, spice, info
|
2016-11-08 18:57:35 +01:00
|
|
|
from ptx import ptx
|
|
|
|
|
from vector import vector
|
|
|
|
|
from math import ceil
|
|
|
|
|
from globals import OPTS
|
2017-11-30 21:15:20 +01:00
|
|
|
from utils import round_to_grid
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-12-12 23:53:19 +01:00
|
|
|
class pinv(pgate.pgate):
|
2016-11-08 18:57:35 +01:00
|
|
|
"""
|
2017-11-30 01:11:15 +01:00
|
|
|
Pinv generates gds of a parametrically sized inverter. The
|
|
|
|
|
size is specified as the drive size (relative to minimum NMOS) and
|
|
|
|
|
a beta value for choosing the pmos size. The inverter's cell
|
|
|
|
|
height is usually the same as the 6t library cell and is measured
|
|
|
|
|
from center of rail to rail.. The route_output will route the
|
|
|
|
|
output to the right side of the cell for easier access.
|
2016-11-08 18:57:35 +01:00
|
|
|
"""
|
2018-05-12 01:32:00 +02:00
|
|
|
from importlib import reload
|
2018-01-20 01:38:19 +01:00
|
|
|
c = reload(__import__(OPTS.bitcell))
|
|
|
|
|
bitcell = getattr(c, OPTS.bitcell)
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-06-02 20:11:57 +02:00
|
|
|
unique_id = 1
|
|
|
|
|
|
2017-12-01 17:31:16 +01:00
|
|
|
def __init__(self, size=1, beta=parameter["beta"], height=bitcell.height, route_output=True):
|
2017-11-29 21:31:00 +01:00
|
|
|
# We need to keep unique names because outputting to GDSII
|
|
|
|
|
# will use the last record with a given name. I.e., you will
|
|
|
|
|
# over-write a design in GDS if one has and the other doesn't
|
|
|
|
|
# have poly connected, for example.
|
2017-12-12 23:53:19 +01:00
|
|
|
name = "pinv_{}".format(pinv.unique_id)
|
2017-06-02 20:11:57 +02:00
|
|
|
pinv.unique_id += 1
|
2017-12-12 23:53:19 +01:00
|
|
|
pgate.pgate.__init__(self, name)
|
2017-11-29 21:31:00 +01:00
|
|
|
debug.info(2, "create pinv structure {0} with size of {1}".format(name, size))
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-11-29 21:31:00 +01:00
|
|
|
self.nmos_size = size
|
|
|
|
|
self.pmos_size = beta*size
|
2016-11-08 18:57:35 +01:00
|
|
|
self.beta = beta
|
2017-11-30 22:42:55 +01:00
|
|
|
self.height = height # Maybe minimize height if not defined in future?
|
2017-12-12 23:53:19 +01:00
|
|
|
self.route_output = False
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
self.add_pins()
|
|
|
|
|
self.create_layout()
|
2017-11-29 21:31:00 +01:00
|
|
|
|
|
|
|
|
# for run-time, we won't check every transitor DRC/LVS independently
|
|
|
|
|
# but this may be uncommented for debug purposes
|
2017-11-14 22:24:14 +01:00
|
|
|
#self.DRC_LVS()
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
def add_pins(self):
|
2017-12-01 17:31:16 +01:00
|
|
|
""" Adds pins for spice netlist """
|
2016-11-08 18:57:35 +01:00
|
|
|
self.add_pin_list(["A", "Z", "vdd", "gnd"])
|
|
|
|
|
|
|
|
|
|
def create_layout(self):
|
2017-12-01 17:31:16 +01:00
|
|
|
""" Calls all functions related to the generation of the layout """
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
self.determine_tx_mults()
|
|
|
|
|
self.create_ptx()
|
|
|
|
|
self.setup_layout_constants()
|
2017-11-30 01:11:15 +01:00
|
|
|
self.add_supply_rails()
|
2016-11-08 18:57:35 +01:00
|
|
|
self.add_ptx()
|
|
|
|
|
self.add_well_contacts()
|
2018-01-26 21:39:00 +01:00
|
|
|
self.extend_wells(self.well_pos)
|
2016-11-08 18:57:35 +01:00
|
|
|
self.connect_rails()
|
2017-12-12 23:53:19 +01:00
|
|
|
self.route_input_gate(self.pmos_inst, self.nmos_inst, self.output_pos.y, "A", rotate=0)
|
|
|
|
|
self.route_outputs()
|
2017-11-30 01:11:15 +01:00
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
def determine_tx_mults(self):
|
2017-11-29 21:31:00 +01:00
|
|
|
"""
|
|
|
|
|
Determines the number of fingers needed to achieve the size within
|
|
|
|
|
the height constraint. This may fail if the user has a tight height.
|
|
|
|
|
"""
|
|
|
|
|
# Do a quick sanity check and bail if unlikely feasible height
|
|
|
|
|
# Sanity check. can we make an inverter in the height with minimum tx sizes?
|
|
|
|
|
# Assume we need 3 metal 1 pitches (2 power rails, one between the tx for the drain)
|
|
|
|
|
# plus the tx height
|
|
|
|
|
nmos = ptx(tx_type="nmos")
|
2017-12-01 00:58:16 +01:00
|
|
|
pmos = ptx(width=drc["minwidth_tx"], tx_type="pmos")
|
|
|
|
|
tx_height = nmos.poly_height + pmos.poly_height
|
2017-11-30 22:42:55 +01:00
|
|
|
# rotated m1 pitch or poly to active spacing
|
2017-12-12 23:53:19 +01:00
|
|
|
min_channel = max(contact.poly.width + self.m1_space,
|
|
|
|
|
contact.poly.width + 2*drc["poly_to_active"])
|
|
|
|
|
# This is the extra space needed to ensure DRC rules to the active contacts
|
|
|
|
|
extra_contact_space = max(-nmos.get_pin("D").by(),0)
|
2017-12-01 00:58:16 +01:00
|
|
|
# This is a poly-to-poly of a flipped cell
|
2017-12-12 23:53:19 +01:00
|
|
|
self.top_bottom_space = max(0.5*self.m1_width + self.m1_space + extra_contact_space,
|
|
|
|
|
drc["poly_extend_active"], self.poly_space)
|
|
|
|
|
total_height = tx_height + min_channel + 2*self.top_bottom_space
|
2017-12-01 00:58:16 +01:00
|
|
|
debug.check(self.height> total_height,"Cell height {0} too small for simple min height {1}.".format(self.height,total_height))
|
2017-11-29 21:31:00 +01:00
|
|
|
|
|
|
|
|
# Determine the height left to the transistors to determine the number of fingers
|
2017-12-12 23:53:19 +01:00
|
|
|
tx_height_available = self.height - min_channel - 2*self.top_bottom_space
|
2017-11-30 01:11:15 +01:00
|
|
|
# Divide the height in half. Could divide proportional to beta, but this makes
|
|
|
|
|
# connecting wells of multiple cells easier.
|
2017-12-01 00:58:16 +01:00
|
|
|
# Subtract the poly space under the rail of the tx
|
|
|
|
|
nmos_height_available = 0.5 * tx_height_available - 0.5*drc["poly_to_poly"]
|
|
|
|
|
pmos_height_available = 0.5 * tx_height_available - 0.5*drc["poly_to_poly"]
|
|
|
|
|
|
2018-07-27 23:07:55 +02:00
|
|
|
debug.info(2,"Height avail {0:.4f} PMOS {1:.4f} NMOS {2:.4f}".format(tx_height_available,
|
|
|
|
|
nmos_height_available,
|
|
|
|
|
pmos_height_available))
|
2017-11-29 21:31:00 +01:00
|
|
|
|
|
|
|
|
# Determine the number of mults for each to fit width into available space
|
|
|
|
|
self.nmos_width = self.nmos_size*drc["minwidth_tx"]
|
|
|
|
|
self.pmos_width = self.pmos_size*drc["minwidth_tx"]
|
|
|
|
|
nmos_required_mults = max(int(ceil(self.nmos_width/nmos_height_available)),1)
|
|
|
|
|
pmos_required_mults = max(int(ceil(self.pmos_width/pmos_height_available)),1)
|
|
|
|
|
# The mults must be the same for easy connection of poly
|
|
|
|
|
self.tx_mults = max(nmos_required_mults, pmos_required_mults)
|
|
|
|
|
|
|
|
|
|
# Recompute each mult width and check it isn't too small
|
|
|
|
|
# This could happen if the height is narrow and the size is small
|
|
|
|
|
# User should pick a bigger size to fix it...
|
2017-11-30 21:15:20 +01:00
|
|
|
# We also need to round the width to the grid or we will end up with LVS property
|
|
|
|
|
# mismatch errors when fingers are not a grid length and get rounded in the offset geometry.
|
|
|
|
|
self.nmos_width = round_to_grid(self.nmos_width / self.tx_mults)
|
2017-11-29 21:31:00 +01:00
|
|
|
debug.check(self.nmos_width>=drc["minwidth_tx"],"Cannot finger NMOS transistors to fit cell height.")
|
2017-11-30 21:15:20 +01:00
|
|
|
self.pmos_width = round_to_grid(self.pmos_width / self.tx_mults)
|
|
|
|
|
debug.check(self.pmos_width>=drc["minwidth_tx"],"Cannot finger PMOS transistors to fit cell height.")
|
|
|
|
|
|
2017-11-30 01:11:15 +01:00
|
|
|
|
|
|
|
|
def setup_layout_constants(self):
|
|
|
|
|
"""
|
|
|
|
|
Pre-compute some handy layout parameters.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# the well width is determined the multi-finger PMOS device width plus
|
|
|
|
|
# the well contact width and half well enclosure on both sides
|
|
|
|
|
self.well_width = self.pmos.active_width + self.pmos.active_contact.width \
|
|
|
|
|
+ drc["active_to_body_active"] + 2*drc["well_enclosure_active"]
|
|
|
|
|
self.width = self.well_width
|
2017-11-30 22:42:55 +01:00
|
|
|
# Height is an input parameter, so it is not recomputed.
|
|
|
|
|
|
2017-11-30 01:11:15 +01:00
|
|
|
|
2017-11-29 21:31:00 +01:00
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
def create_ptx(self):
|
2017-11-30 01:11:15 +01:00
|
|
|
""" Create the PMOS and NMOS transistors. """
|
2017-11-29 21:31:00 +01:00
|
|
|
self.nmos = ptx(width=self.nmos_width,
|
2016-11-08 18:57:35 +01:00
|
|
|
mults=self.tx_mults,
|
2017-11-30 01:11:15 +01:00
|
|
|
tx_type="nmos",
|
|
|
|
|
connect_poly=True,
|
|
|
|
|
connect_active=True)
|
2016-11-08 18:57:35 +01:00
|
|
|
self.add_mod(self.nmos)
|
2017-11-30 20:56:40 +01:00
|
|
|
|
2017-11-29 21:31:00 +01:00
|
|
|
self.pmos = ptx(width=self.pmos_width,
|
2016-11-08 18:57:35 +01:00
|
|
|
mults=self.tx_mults,
|
2017-11-30 01:11:15 +01:00
|
|
|
tx_type="pmos",
|
|
|
|
|
connect_poly=True,
|
|
|
|
|
connect_active=True)
|
2016-11-08 18:57:35 +01:00
|
|
|
self.add_mod(self.pmos)
|
2017-11-30 01:11:15 +01:00
|
|
|
|
|
|
|
|
def add_supply_rails(self):
|
|
|
|
|
""" Add vdd/gnd rails to the top and bottom. """
|
2018-03-21 21:20:48 +01:00
|
|
|
self.add_layout_pin_rect_center(text="gnd",
|
2017-11-30 01:11:15 +01:00
|
|
|
layer="metal1",
|
|
|
|
|
offset=vector(0.5*self.width,0),
|
|
|
|
|
width=self.width)
|
|
|
|
|
|
2018-03-21 21:20:48 +01:00
|
|
|
self.add_layout_pin_rect_center(text="vdd",
|
2017-11-30 01:11:15 +01:00
|
|
|
layer="metal1",
|
|
|
|
|
offset=vector(0.5*self.width,self.height),
|
|
|
|
|
width=self.width)
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-11-30 01:11:15 +01:00
|
|
|
def add_ptx(self):
|
|
|
|
|
"""
|
|
|
|
|
Add PMOS and NMOS to the layout at the upper-most and lowest position
|
|
|
|
|
to provide maximum routing in channel
|
|
|
|
|
"""
|
2017-12-01 00:58:16 +01:00
|
|
|
|
2017-11-30 01:11:15 +01:00
|
|
|
# place PMOS so it is half a poly spacing down from the top
|
2017-12-01 17:31:16 +01:00
|
|
|
self.pmos_pos = self.pmos.active_offset.scale(1,0) \
|
2017-12-12 23:53:19 +01:00
|
|
|
+ vector(0, self.height-self.pmos.active_height-self.top_bottom_space)
|
2017-11-30 01:11:15 +01:00
|
|
|
self.pmos_inst=self.add_inst(name="pinv_pmos",
|
|
|
|
|
mod=self.pmos,
|
2017-12-01 00:58:16 +01:00
|
|
|
offset=self.pmos_pos)
|
2017-11-30 01:11:15 +01:00
|
|
|
self.connect_inst(["Z", "A", "vdd", "vdd"])
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-11-30 01:11:15 +01:00
|
|
|
# place NMOS so that it is half a poly spacing up from the bottom
|
2017-12-12 23:53:19 +01:00
|
|
|
self.nmos_pos = self.nmos.active_offset.scale(1,0) + vector(0,self.top_bottom_space)
|
2017-11-30 01:11:15 +01:00
|
|
|
self.nmos_inst=self.add_inst(name="pinv_nmos",
|
|
|
|
|
mod=self.nmos,
|
2017-12-01 17:31:16 +01:00
|
|
|
offset=self.nmos_pos)
|
2016-11-08 18:57:35 +01:00
|
|
|
self.connect_inst(["Z", "A", "gnd", "gnd"])
|
|
|
|
|
|
|
|
|
|
|
2018-01-26 21:39:00 +01:00
|
|
|
# Output position will be in between the PMOS and NMOS drains
|
|
|
|
|
pmos_drain_pos = self.pmos_inst.get_pin("D").ll()
|
|
|
|
|
nmos_drain_pos = self.nmos_inst.get_pin("D").ul()
|
|
|
|
|
self.output_pos = vector(0,0.5*(pmos_drain_pos.y+nmos_drain_pos.y))
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2018-01-26 21:39:00 +01:00
|
|
|
# This will help with the wells
|
|
|
|
|
self.well_pos = vector(0,self.nmos_inst.uy())
|
|
|
|
|
|
2017-12-12 23:53:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def route_outputs(self):
|
2017-11-30 01:11:15 +01:00
|
|
|
""" Route the output (drains) together. Optionally, routes output to edge. """
|
|
|
|
|
|
|
|
|
|
# Get the drain pins
|
|
|
|
|
nmos_drain_pin = self.nmos_inst.get_pin("D")
|
|
|
|
|
pmos_drain_pin = self.pmos_inst.get_pin("D")
|
|
|
|
|
|
2017-12-01 00:58:16 +01:00
|
|
|
# Pick point at right most of NMOS and connect down to PMOS
|
2018-01-26 21:39:00 +01:00
|
|
|
nmos_drain_pos = nmos_drain_pin.lr() - vector(0.5*self.m1_width,0)
|
|
|
|
|
pmos_drain_pos = vector(nmos_drain_pos.x, pmos_drain_pin.bc().y)
|
2017-11-30 01:11:15 +01:00
|
|
|
self.add_path("metal1",[nmos_drain_pos,pmos_drain_pos])
|
|
|
|
|
|
|
|
|
|
# Remember the mid for the output
|
2017-12-12 23:53:19 +01:00
|
|
|
mid_drain_offset = vector(nmos_drain_pos.x,self.output_pos.y)
|
|
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
if self.route_output == True:
|
2017-08-24 00:02:15 +02:00
|
|
|
# This extends the output to the edge of the cell
|
2017-11-30 01:11:15 +01:00
|
|
|
output_offset = mid_drain_offset.scale(0,1) + vector(self.width,0)
|
2018-03-21 21:20:48 +01:00
|
|
|
self.add_layout_pin_segment_center(text="Z",
|
2017-11-30 01:11:15 +01:00
|
|
|
layer="metal1",
|
|
|
|
|
start=mid_drain_offset,
|
|
|
|
|
end=output_offset)
|
2016-11-08 18:57:35 +01:00
|
|
|
else:
|
2017-08-24 00:02:15 +02:00
|
|
|
# This leaves the output as an internal pin (min sized)
|
2018-03-21 21:20:48 +01:00
|
|
|
self.add_layout_pin_rect_center(text="Z",
|
2017-12-12 23:53:19 +01:00
|
|
|
layer="metal1",
|
|
|
|
|
offset=mid_drain_offset + vector(0.5*self.m1_width,0))
|
2017-08-24 00:02:15 +02:00
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
def add_well_contacts(self):
|
2017-12-01 17:31:16 +01:00
|
|
|
""" Add n/p well taps to the layout and connect to supplies """
|
2017-11-30 01:11:15 +01:00
|
|
|
|
2018-01-11 19:24:44 +01:00
|
|
|
self.add_nwell_contact(self.pmos, self.pmos_pos)
|
2017-11-30 01:11:15 +01:00
|
|
|
|
2018-01-11 19:24:44 +01:00
|
|
|
self.add_pwell_contact(self.nmos, self.nmos_pos)
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
def connect_rails(self):
|
2017-11-30 01:11:15 +01:00
|
|
|
""" Connect the nmos and pmos to its respective power rails """
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-12-12 23:53:19 +01:00
|
|
|
self.connect_pin_to_rail(self.nmos_inst,"S","gnd")
|
|
|
|
|
|
|
|
|
|
self.connect_pin_to_rail(self.pmos_inst,"S","vdd")
|
|
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-05-30 21:50:07 +02:00
|
|
|
def input_load(self):
|
|
|
|
|
return ((self.nmos_size+self.pmos_size)/parameter["min_tx_size"])*spice["min_tx_gate_c"]
|
|
|
|
|
|
2017-11-09 20:13:44 +01:00
|
|
|
def analytical_delay(self, slew, load=0.0):
|
2017-05-30 21:50:07 +02:00
|
|
|
r = spice["min_tx_r"]/(self.nmos_size/parameter["min_tx_size"])
|
2017-07-06 17:42:25 +02:00
|
|
|
c_para = spice["min_tx_drain_c"]*(self.nmos_size/parameter["min_tx_size"])#ff
|
|
|
|
|
return self.cal_delay_with_rc(r = r, c = c_para+load, slew = slew)
|
2018-02-02 21:05:11 +01:00
|
|
|
|
2018-02-27 01:32:28 +01:00
|
|
|
def analytical_power(self, proc, vdd, temp, load):
|
2018-03-02 08:34:15 +01:00
|
|
|
"""Returns dynamic and leakage power. Results in nW"""
|
2018-02-22 04:51:21 +01:00
|
|
|
c_eff = self.calculate_effective_capacitance(load)
|
2018-02-28 21:32:54 +01:00
|
|
|
freq = spice["default_event_rate"]
|
|
|
|
|
power_dyn = c_eff*vdd*vdd*freq
|
2018-02-22 04:51:21 +01:00
|
|
|
power_leak = spice["inv_leakage"]
|
|
|
|
|
|
|
|
|
|
total_power = self.return_power(power_dyn, power_leak)
|
|
|
|
|
return total_power
|
|
|
|
|
|
|
|
|
|
def calculate_effective_capacitance(self, load):
|
2018-03-02 08:34:15 +01:00
|
|
|
"""Computes effective capacitance. Results in fF"""
|
2018-02-22 04:51:21 +01:00
|
|
|
c_load = load
|
|
|
|
|
c_para = spice["min_tx_drain_c"]*(self.nmos_size/parameter["min_tx_size"])#ff
|
|
|
|
|
transistion_prob = spice["inv_transisition_prob"]
|
2018-03-21 21:20:48 +01:00
|
|
|
return transistion_prob*(c_load + c_para)
|