1 # -*- coding: utf-8 -*-
2 from __future__
import print_function
8 from Hurricane
import (
9 DbU
, DataBase
, UpdateSession
, Box
, Transformation
, Instance
, Pad
, Pin
,
10 NetExternalComponents
,
14 class SessionManager(object):
16 Context manager for a GO update session. See Hurricane reference manual
17 for an info on Hurricane::UpdateSession class.
23 def __exit__(self
, *args
):
32 def __init__(self
, cell
, editor
, width
=None, height
=None, submodules
=None,
33 pin_width
=2.0, pin_height
=2.0, pin_suffix
='.0',
34 pin_layer
=None, north_pins
=None, east_pins
=None,
35 south_pins
=None, west_pins
=None, pads
=None, **kwargs
):
39 :param cell: cell name or Hurricane.Cell object,
40 :param editor: editor object when executing from cgt (or None),
41 :param width: module width,
42 :param height: module height,
43 :param submodules: submodules (Module objects),
44 :param pin_width: default pin width,
45 :param pin_height: default pin height,
46 :param pin_suffix: default pin suffix,
47 :param pin_layer: default layer for placing pins,
48 :param north_pins: list of pin configuration dictionaries for placing
49 pins on the north side,
50 :param east_pins: ditto (for the east side),
51 :param south_pins: ditto (for the south side),
52 :param west_pins: ditto (for the west side),
53 :param pads: dictionary of {net: list of layers} for creating pads,
54 :param kwargs: extra parameters to be implemented in derived classes.
57 self
.af
= CRL
.AllianceFramework
.get()
58 self
.db
= DataBase
.getDB()
62 if isinstance(cell
, basestring
):
63 self
.cell
= self
.af
.getCell(cell
, CRL
.Catalog
.State
.Logical
)
67 self
.pin_width
= pin_width
68 self
.pin_height
= pin_height
69 self
.pin_suffix
= pin_suffix
71 self
.pin_layer
= self
.get_layer('METAL3')
72 elif isinstance(pin_layer
, basestring
):
73 self
.pin_layer
= self
.get_layer(pin_layer
)
75 self
.pin_layer
= pin_layer
76 self
.north_pins
= north_pins
or []
77 self
.east_pins
= east_pins
or []
78 self
.south_pins
= south_pins
or []
79 self
.west_pins
= west_pins
or []
81 self
.pads
= pads
or {}
83 self
.submodules
= submodules
or []
87 return self
.cell
.getName()
91 self
.cell
.setName(name
)
98 """ The real abutment box. """
99 return self
.cell
.getAbutmentBox()
103 self
.cell
.setAbutmentBox(ab
)
107 """ Cached instances. """
108 if self
._instances
is None:
109 self
._instances
= self
.cell
.getInstances()
111 return self
._instances
113 def get_layer(self
, name
):
114 """ Creates a new layer or returns it from cache. """
115 if name
in self
._layer
_cache
:
116 return self
._layer
_cache
[name
]
118 layer
= self
.db
.getTechnology().getLayer(name
)
119 self
._layer
_cache
[name
] = layer
125 Convert lambdas to database units. (See Hurricane+Python Manual 3.4.)
127 return DbU
.fromLambda(lmb
)
132 Convert lambdas to database units. (See Hurricane+Python Manual 3.4.)
134 return DbU
.toLambda(dbu
)
137 """ Places the current cell. """
138 etesian
= Etesian
.EtesianEngine
.create(self
.cell
)
142 """ Routes the current cell. """
143 katana
= Katana
.KatanaEngine
.create(self
.cell
)
145 katana
.runGlobalRouter(Katana
.Flags
.NoFlags
)
146 katana
.loadGlobalRouting(Anabatic
.EngineLoadGrByNet
)
147 katana
.layerAssign(Anabatic
.EngineNoNetLayerAssign
)
148 katana
.runNegociate(Katana
.Flags
.NoFlags
)
149 katana
.finalizeLayout()
150 result
= katana
.isDetailedRoutingSuccess()
154 def place_and_route(self
):
155 """ Places and routes. """
159 def create_pin_series(self
, net
, direction
, name
=None,
160 status
=Pin
.PlacementStatus
.FIXED
, layer
=None,
161 x
=None, y
=None, width
=2.0, height
=2.0,
162 repeat
=1, delta
=0.0, external
=True):
164 Creates a series of pins in a cell.
166 :param net: Hurricane.Net object name or name template, taking a pin
167 enumeration parameter, i. e. pin number,
168 :param name: pin name or name template taking a pin enumeration
169 parameter (net name or template + suffix),
170 :param direction: Pin.Direction value,
171 :param status: Pin.PlacementStatus value (default is FIXED),
172 :param layer: Hurricane.Layer object or name (METAL3),
173 :param x: starting pin position (left to right, 0.0),
174 :param y: starting pin position (bottom to top, 0.0),
175 :param width: pin width (2,0),
176 :param height: pin height (2.0),
177 :param repeat: a number of pins to be placed or an iterable containing
178 pin template parameters (i. e. pin number, 1),
179 :param delta: next pin position offset (0.0),
180 :param external: mark pin as external (yes),
181 :return: tuple of next pin coordinates, or just (x, y), if delta
185 layer
= self
.pin_layer
186 elif isinstance(layer
, basestring
):
187 layer
= self
.get_layer(layer
)
189 if isinstance(repeat
, int):
190 if repeat
> 1 and delta
== 0.0:
191 raise Warning('You are trying to place pins on each other.')
192 iterator
= range(repeat
)
197 name
= net
+ self
.pin_suffix
200 pin
= Pin
.create(self
.cell
.getNet(net
.format(i
)),
201 name
.format(i
), direction
, status
, layer
,
202 self
.to_dbu(x
), self
.to_dbu(y
),
203 self
.to_dbu(width
), self
.to_dbu(height
))
204 if direction
in (Pin
.Direction
.NORTH
, Pin
.Direction
.SOUTH
):
211 pin
.getNet().setExternal(True)
212 NetExternalComponents
.setExternal(pin
)
216 def init_abutment_box(self
):
217 """ Create the abutment box with object's initial values. """
219 self
.ab
= Box(0, 0, self
.to_dbu(self
.width
), self
.to_dbu(self
.height
))
221 def create_pins(self
):
222 """ Creates all pins set on Module object creation. """
225 if direction
== Pin
.Direction
.EAST
:
226 return self
.from_dbu(self
.ab
.getWidth())
227 if direction
== Pin
.Direction
.WEST
:
232 if direction
== Pin
.Direction
.NORTH
:
233 return self
.from_dbu(self
.ab
.getHeight())
234 if direction
== Pin
.Direction
.SOUTH
:
238 for pins
, direction
in (
239 (self
.north_pins
, Pin
.Direction
.NORTH
),
240 (self
.east_pins
, Pin
.Direction
.EAST
),
241 (self
.south_pins
, Pin
.Direction
.SOUTH
),
242 (self
.west_pins
, Pin
.Direction
.WEST
),
244 last_x
= last_y
= 0.0
245 for pin_config
in pins
:
246 net
= pin_config
.pop('net')
247 name
= pin_config
.pop('name', net
+ self
.pin_suffix
)
248 layer
= pin_config
.pop('layer', self
.pin_layer
)
249 x
= pin_config
.pop('x', default_x())
250 y
= pin_config
.pop('y', default_y())
251 last_x
, last_y
= self
.create_pin_series(
252 net
, direction
, name
=name
, layer
=layer
, x
=x
, y
=y
,
255 def create_pads_for_net(self
, net
, layers
):
257 Creates a series of pads for a given net.
259 :param net: net name or Hurricane.Net object to create pads for,
260 :param layers: list of layer names or Hurricane.Layer objects
264 temp_ab
.inflate(self
.to_dbu(-5.0))
265 if isinstance(net
, basestring
):
266 net
= self
.cell
.getNet(net
)
269 if isinstance(layer
, basestring
):
270 layer
= self
.get_layer(layer
)
271 Pad
.create(net
, layer
, temp_ab
)
273 def create_pads(self
):
274 """ Create all pads for a given Module object. """
276 for net
, layers
in self
.pads
.items():
277 self
.create_pads_for_net(net
, layers
)
279 def do_submodules(self
):
281 Execute submodules and gather their status.
283 :return: True if all submodules executed successfully, False otherwise.
286 for submodule
, x
, y
in self
.submodules
:
287 if not submodule
.do():
292 def place_submodules(self
):
293 """ Place submodules in the current module. """
295 for submodule
, x
, y
in self
.submodules
:
298 inst
for inst
in self
.instances
if inst
.getName().endswith(
304 instance
.setTransformation(Transformation(
305 self
.to_dbu(x
), self
.to_dbu(y
), Transformation
.Orientation
.ID
307 instance
.setPlacementStatus(Instance
.PlacementStatus
.FIXED
)
310 """ Main routine. """
312 raise NotImplementedError('You need to implement the `do` method.')