OpenRAM/compiler/modules/dff_array.py

166 lines
6.5 KiB
Python
Raw Normal View History

# See LICENSE for licensing information.
#
2021-01-22 20:23:28 +01:00
# Copyright (c) 2016-2021 Regents of the University of California and The Board
2019-06-14 17:43:41 +02:00
# of Regents for the Oklahoma Agricultural and Mechanical College
# (acting for and on behalf of Oklahoma State University)
# All rights reserved.
#
import debug
import design
from vector import vector
2019-01-17 01:15:38 +01:00
from sram_factory import factory
from globals import OPTS
2020-06-30 22:26:38 +02:00
class dff_array(design.design):
"""
This is a simple row (or multiple rows) of flops.
Unlike the data flops, these are never spaced out.
"""
def __init__(self, rows, columns, name=""):
self.rows = rows
self.columns = columns
if name=="":
2018-02-15 01:03:29 +01:00
name = "dff_array_{0}x{1}".format(rows, columns)
2020-08-06 20:33:26 +02:00
super().__init__(name)
debug.info(1, "Creating {0} rows={1} cols={2}".format(self.name, self.rows, self.columns))
self.add_comment("rows: {0} cols: {1}".format(rows, columns))
2020-11-03 15:29:17 +01:00
self.create_netlist()
if not OPTS.netlist_only:
self.create_layout()
def create_netlist(self):
self.add_modules()
self.add_pins()
self.create_dff_array()
2020-11-03 15:29:17 +01:00
def create_layout(self):
self.width = self.columns * self.dff.width
self.height = self.rows * self.dff.height
2020-11-03 15:29:17 +01:00
self.place_dff_array()
self.route_supplies()
self.add_layout_pins()
self.add_boundary()
self.DRC_LVS()
def add_modules(self):
2019-01-17 01:15:38 +01:00
self.dff = factory.create(module_type="dff")
2020-11-03 15:29:17 +01:00
def add_pins(self):
2020-06-30 22:26:38 +02:00
for row in range(self.rows):
for col in range(self.columns):
2020-06-30 22:26:38 +02:00
self.add_pin(self.get_din_name(row, col), "INPUT")
for row in range(self.rows):
for col in range(self.columns):
2020-06-30 22:26:38 +02:00
self.add_pin(self.get_dout_name(row, col), "OUTPUT")
2019-08-06 23:14:09 +02:00
self.add_pin("clk", "INPUT")
self.add_pin("vdd", "POWER")
self.add_pin("gnd", "GROUND")
def create_dff_array(self):
2018-02-15 01:03:29 +01:00
self.dff_insts={}
2020-06-30 22:26:38 +02:00
for row in range(self.rows):
for col in range(self.columns):
2020-06-30 22:26:38 +02:00
name = "dff_r{0}_c{1}".format(row, col)
self.dff_insts[row, col]=self.add_inst(name=name,
mod=self.dff)
instance_ports = [self.get_din_name(row, col),
self.get_dout_name(row, col)]
2020-11-14 00:55:55 +01:00
for port in self.dff.pins:
if port != 'D' and port != 'Q':
instance_ports.append(port)
self.connect_inst(instance_ports)
def place_dff_array(self):
2020-06-30 22:26:38 +02:00
for row in range(self.rows):
for col in range(self.columns):
if (row % 2 == 0):
2020-06-30 22:26:38 +02:00
base = vector(col * self.dff.width, row * self.dff.height)
mirror = "R0"
else:
2020-06-30 22:26:38 +02:00
base = vector(col * self.dff.width, (row + 1) * self.dff.height)
mirror = "MX"
2020-06-30 22:26:38 +02:00
self.dff_insts[row, col].place(offset=base,
mirror=mirror)
2020-11-03 15:29:17 +01:00
def get_din_name(self, row, col):
if self.columns == 1:
din_name = "din_{0}".format(row)
elif self.rows == 1:
din_name = "din_{0}".format(col)
else:
2020-06-30 22:26:38 +02:00
din_name = "din_{0}_{1}".format(row, col)
return din_name
2020-11-03 15:29:17 +01:00
def get_dout_name(self, row, col):
if self.columns == 1:
dout_name = "dout_{0}".format(row)
elif self.rows == 1:
dout_name = "dout_{0}".format(col)
else:
2020-06-30 22:26:38 +02:00
dout_name = "dout_{0}_{1}".format(row, col)
return dout_name
2020-11-03 15:29:17 +01:00
def route_supplies(self):
if OPTS.experimental_power and self.rows > 1:
# Vertical straps on ends if multiple rows
left_dff_insts = [self.dff_insts[x, 0] for x in range(self.rows)]
right_dff_insts = [self.dff_insts[x, self.columns-1] for x in range(self.rows)]
self.route_vertical_pins("vdd", left_dff_insts, xside="lx", yside="cy")
self.route_vertical_pins("gnd", right_dff_insts, xside="rx", yside="cy")
else:
for row in range(self.rows):
for col in range(self.columns):
# Continous vdd rail along with label.
vdd_pin=self.dff_insts[row, col].get_pin("vdd")
self.copy_power_pin(vdd_pin)
2018-07-18 00:01:31 +02:00
# Continous gnd rail along with label.
gnd_pin=self.dff_insts[row, col].get_pin("gnd")
self.copy_power_pin(gnd_pin)
2020-11-03 15:29:17 +01:00
def add_layout_pins(self):
2020-06-30 22:26:38 +02:00
for row in range(self.rows):
for col in range(self.columns):
din_pin = self.dff_insts[row, col].get_pin("D")
debug.check(din_pin.layer == "m2", "DFF D pin not on metal2")
self.add_layout_pin(text=self.get_din_name(row, col),
2018-02-15 01:03:29 +01:00
layer=din_pin.layer,
offset=din_pin.ll(),
width=din_pin.width(),
height=din_pin.height())
2020-06-30 22:26:38 +02:00
dout_pin = self.dff_insts[row, col].get_pin("Q")
debug.check(dout_pin.layer == "m2", "DFF Q pin not on metal2")
self.add_layout_pin(text=self.get_dout_name(row, col),
layer=dout_pin.layer,
2018-02-15 01:03:29 +01:00
offset=dout_pin.ll(),
width=dout_pin.width(),
height=dout_pin.height())
# Create vertical spines to a single horizontal rail
2020-11-16 20:04:03 +01:00
clk_pin = self.dff_insts[0, 0].get_pin("clk")
2020-06-30 22:26:38 +02:00
clk_ypos = 2 * self.m3_pitch + self.m3_width
debug.check(clk_pin.layer == "m2", "DFF clk pin not on metal2")
self.add_layout_pin_segment_center(text="clk",
layer="m3",
2020-06-30 22:26:38 +02:00
start=vector(0, clk_ypos),
end=vector(self.width, clk_ypos))
for col in range(self.columns):
2020-11-16 20:04:03 +01:00
clk_pin = self.dff_insts[0, col].get_pin("clk")
# Make a vertical strip for each column
self.add_rect(layer="m2",
2020-06-30 22:26:38 +02:00
offset=clk_pin.ll().scale(1, 0),
width=self.m2_width,
height=self.height)
# Drop a via to the M3 pin
2020-06-30 22:26:38 +02:00
self.add_via_stack_center(from_layer=clk_pin.layer,
to_layer="m3",
offset=vector(clk_pin.cx(), clk_ypos))