set parameters using python style (and auto-detection)
[soclayout.git] / experiments7 / doAlu16.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 from __future__ import print_function
4 import sys
5
6 import CRL
7 import Cfg
8 from Hurricane import Box
9 from coriolis2.settings import af
10 from utils import Module, SessionManager, Config
11
12 import symbolic.cmos # do not remove
13
14 BIT_WIDTH = 16
15
16
17 def coriolis_setup():
18 with Config(Cfg.Parameter.Priority.UserFile) as cfg:
19 cfg.misc_catchCore = False
20 cfg.misc_info = False
21 cfg.misc_paranoid = False
22 cfg.misc_bug = False
23 cfg.misc_logMode = True
24 cfg.misc_verboseLevel1 = True
25 cfg.misc_verboseLevel2 = True
26 cfg.etesian_effort = 2
27 cfg.etesian_spaceMargin = "20.0%"
28 cfg.etesian_aspectRatio = "100.0%"
29 cfg.etesian_uniformDensity = True
30 cfg.anabatic_edgeLenght = 24
31 cfg.anabatic_edgeWidth = 8
32 cfg.anabatic_topRoutingLayer = 'METAL5'
33 cfg.katana_searchHalo = 30
34 cfg.katana_eventsLimit = 1000000
35 cfg.katana_hTracksReservedLocal = 7
36 cfg.katana_vTracksReservedLocal = 6
37
38 env = af.getEnvironment()
39 env.setCLOCK('^clk$|m_clock')
40 env.setPOWER('vdd')
41 env.setGROUND('vss')
42
43
44 class AddSub(Module):
45
46 def build(self):
47 """ Main routine. """
48
49 with SessionManager():
50 self.init_abutment_box()
51 self.create_pins()
52
53 if self.editor:
54 self.editor.setCell(self.cell)
55
56 result = self.place_and_route()
57
58 with SessionManager():
59 self.create_pads()
60
61 self.save()
62 return result
63
64
65 class ALU16(Module):
66
67 def save(self):
68 self.name = self.name + '_r'
69 self.af.saveCell(self.cell, CRL.Catalog.State.Views)
70 super(ALU16, self).save()
71
72 def build(self):
73
74 if not self.build_submodules():
75 return False
76
77 with SessionManager():
78 self.init_abutment_box()
79 self.place_submodules()
80
81 # TODO: replace with some form of lazy evaluation?
82 y_north = self.from_dbu(self.cell.getAbutmentBox().getYMax())
83 for pin_conf in self.north_pins:
84 pin_conf['y'] = y_north
85
86 self.create_pins()
87
88 if self.editor:
89 self.editor.setCell(self.cell)
90
91 # place first (in middle, between two)
92 # this puts all the remaining cells (little ones)
93 # into this (small) space so that they do not go
94 # "all over the place" around the add and sub
95 self.ab = Box(self.to_dbu(400.0), self.to_dbu(50.0),
96 self.to_dbu(700.0), self.to_dbu(500.0))
97 self.place()
98
99 # then route (globally)
100 # this connects up not just in the remaining (little) cells,
101 # it connects *to add and sub and the outside world as well*
102 self.init_abutment_box()
103 result = self.place_and_route()
104
105 self.save()
106 return result
107
108
109 def ScriptMain(editor=None, **kwargs):
110 coriolis_setup()
111
112 add = AddSub(
113 'add', editor, width=350.0, height=400.0,
114 north_pins=[
115 {'net': 'a({})', 'x': 10.0, 'delta': 20.0, 'repeat': BIT_WIDTH},
116 {'net': 'b({})', 'x': 20.0, 'delta': 20.0, 'repeat': BIT_WIDTH},
117 ],
118 south_pins=[
119 {'net': 'o({})', 'x': 100.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
120 ],
121 pads={
122 'b({})'.format(BIT_WIDTH-1): (
123 'BLOCKAGE2', 'BLOCKAGE3', 'BLOCKAGE4',
124 ),
125 },
126 )
127 sub = AddSub(
128 'sub', editor, width=350.0, height=400.0,
129 north_pins=[
130 {'net': 'a({})', 'x': 10.0, 'delta': 20.0, 'repeat': BIT_WIDTH},
131 {'net': 'b({})', 'x': 20.0, 'delta': 20.0, 'repeat': BIT_WIDTH},
132 ],
133 south_pins=[
134 {'net': 'o({})', 'x': 100.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
135 ],
136 pads={
137 'b({})'.format(BIT_WIDTH-1): (
138 'BLOCKAGE2', 'BLOCKAGE3', 'BLOCKAGE4',
139 ),
140 },
141 )
142
143 alu16 = ALU16(
144 'alu16', editor, width=1100.0, height=570.0,
145 submodules=[(add, 25.0, 75.0), (sub, 725.0, 75.0)],
146 north_pins=[
147 {'net': 'o({})', 'x': 50.0, 'delta': 60.0, 'repeat': BIT_WIDTH},
148 {'net': 'op'},
149 ],
150 south_pins=[
151 {'net': 'a({})', 'x': 50.0, 'delta': 60.0, 'repeat': BIT_WIDTH},
152 {'net': 'b({})', 'x': 80.0, 'delta': 60.0, 'repeat': BIT_WIDTH},
153 ],
154 west_pins=[
155 {'net': 'rst', 'y': 140.0, 'layer': 'METAL2'},
156 ],
157 )
158 return alu16.build()
159
160
161 if __name__ == '__main__':
162 kwargs = {}
163 success = ScriptMain(**kwargs)
164 shellSuccess = 0
165 if not success:
166 shellSuccess = 1
167
168 sys.exit(shellSuccess)