Skip to content

Commit 80970b2

Browse files
author
Sebastien Bourdeauducq
committedMar 11, 2013
bus/asmibus: use implicit finalization
1 parent b042757 commit 80970b2

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed
 

‎migen/bus/asmibus.py

+11-17
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ def __init__(self, aw, time):
4343
]
4444

4545
class Port(Module):
46-
def __init__(self, hub, nslots):
46+
def __init__(self, hub, base, nslots):
4747
self.hub = hub
48+
self.base = base
4849
self.submodules.slots = [Slot(self.hub.aw, self.hub.time) for i in range(nslots)]
4950

5051
# request issuance
@@ -61,15 +62,11 @@ def __init__(self, hub, nslots):
6162
self.dat_w = Signal(self.hub.dw)
6263
self.dat_wm = Signal(self.hub.dw//8)
6364

64-
def set_position(self, tagbits, base):
65-
self.tagbits = tagbits
66-
self.base = base
67-
6865
def do_finalize(self):
6966
nslots = len(self.slots)
7067
if nslots > 1:
7168
self.tag_issue = Signal(max=nslots)
72-
self.tag_call = Signal(self.tagbits)
69+
self.tag_call = Signal(self.hub.tagbits)
7370

7471
# allocate
7572
for s in self.slots:
@@ -103,7 +100,10 @@ def __init__(self, aw, dw, time=0):
103100
self.aw = aw
104101
self.dw = dw
105102
self.time = time
103+
106104
self.ports = []
105+
self._next_base = 0
106+
self.tagbits = 0
107107

108108
self.call = Signal()
109109
# tag_call is created by do_finalize()
@@ -114,21 +114,15 @@ def __init__(self, aw, dw, time=0):
114114
def get_port(self, nslots=1):
115115
if self.finalized:
116116
raise FinalizeError
117-
new_port = Port(self, nslots)
117+
new_port = Port(self, self._next_base, nslots)
118+
self._next_base += nslots
119+
self.tagbits = bits_for(self._next_base-1)
118120
self.ports.append(new_port)
121+
self.submodules += new_port
119122
return new_port
120123

121124
def do_finalize(self):
122-
nslots = sum([len(port.slots) for port in self.ports])
123-
tagbits = bits_for(nslots-1)
124-
base = 0
125-
for port in self.ports:
126-
port.set_position(tagbits, base)
127-
port.finalize()
128-
base += len(port.slots)
129-
self.submodules += self.ports
130-
self.tag_call = Signal(tagbits)
131-
125+
self.tag_call = Signal(self.tagbits)
132126
for port in self.ports:
133127
self.comb += [
134128
port.call.eq(self.call),

0 commit comments

Comments
 (0)