Skip to content

Commit 9dbfaed

Browse files
committed
with_enable is removed from SyncRAMManager
1 parent 2ad662a commit 9dbfaed

File tree

1 file changed

+42
-63
lines changed

1 file changed

+42
-63
lines changed

veriloggen/types/ram.py

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ class RAMInterface(object):
1313
_I = 'Reg'
1414
_O = 'Wire'
1515

16-
def __init__(self, m, name=None, datawidth=32, addrwidth=10, itype=None, otype=None,
17-
p_addr='addr', p_rdata='rdata', p_wdata='wdata', p_wenable='wenable',
18-
p_enable='enable', index=None, with_enable=False):
16+
def __init__(self, m, name=None, datawidth=32, addrwidth=10,
17+
itype=None, otype=None,
18+
p_addr='addr', p_rdata='rdata',
19+
p_wdata='wdata', p_wenable='wenable',
20+
p_enable='enable',
21+
with_enable=False, index=None):
1922

2023
if itype is None:
2124
itype = self._I
@@ -83,6 +86,7 @@ def mkRAMDefinition(name, datawidth=32, addrwidth=10, numports=2, sync=True, wit
8386
interface = RAMSlaveInterface(
8487
m, name + '_%d' % i, datawidth, addrwidth, with_enable=with_enable)
8588
interface.delay_addr = m.Reg(name + '_%d_daddr' % i, addrwidth)
89+
8690
interfaces.append(interface)
8791

8892
mem = m.Reg('mem', datawidth, length=2**addrwidth)
@@ -93,11 +97,14 @@ def mkRAMDefinition(name, datawidth=32, addrwidth=10, numports=2, sync=True, wit
9397
mem[interface.addr](interface.wdata)
9498
),
9599
interface.delay_addr(interface.addr)]
100+
96101
if with_enable:
97102
body = vtypes.If(interface.enable)(*body)
103+
98104
m.Always(vtypes.Posedge(clk))(
99105
body
100106
)
107+
101108
if sync:
102109
m.Assign(interface.rdata(mem[interface.delay_addr]))
103110
else:
@@ -114,6 +121,7 @@ def __init__(self, m, name, clk,
114121
self.m = m
115122
self.name = name
116123
self.clk = clk
124+
self.with_enable = with_enable
117125

118126
self.interfaces = [RAMInterface(m, name + '_%d' % i, datawidth, addrwidth,
119127
itype='Wire', otype='Wire', with_enable=with_enable)
@@ -125,10 +133,12 @@ def __init__(self, m, name, clk,
125133
self.m.Instance(ram_def, name,
126134
params=(), ports=m.connect_ports(ram_def))
127135

128-
def connect(self, port, addr, wdata, wenable):
136+
def connect(self, port, addr, wdata, wenable, enable=None):
129137
self.m.Assign(self.interfaces[port].addr(addr))
130138
self.m.Assign(self.interfaces[port].wdata(wdata))
131139
self.m.Assign(self.interfaces[port].wenable(wenable))
140+
if self.with_enable:
141+
self.m.Assign(self.interfaces[port].enable(enable))
132142

133143
def rdata(self, port):
134144
return self.interfaces[port].rdata
@@ -153,22 +163,22 @@ def __init__(self, m, name, clk,
153163
#-------------------------------------------------------------------------
154164
class SyncRAMManager (object):
155165

156-
def __init__(self, m, name, clk, rst, datawidth=32, addrwidth=10, numports=1,
157-
with_enable=False, nodataflow=False):
166+
def __init__(self, m, name, clk, rst,
167+
datawidth=32, addrwidth=10, numports=1,
168+
nodataflow=False):
158169

159170
self.m = m
160171
self.name = name
161172
self.clk = clk
162173
self.rst = rst
163174
self.datawidth = datawidth
164175
self.addrwidth = addrwidth
165-
self.with_enable = with_enable
166-
self.interfaces = [RAMInterface(m, name + '_%d' % i, datawidth, addrwidth,
167-
with_enable=with_enable)
176+
177+
self.interfaces = [RAMInterface(m, name + '_%d' % i, datawidth, addrwidth)
168178
for i in range(numports)]
169179

170-
self.definition = mkRAMDefinition(
171-
name, datawidth, addrwidth, numports, with_enable=with_enable)
180+
self.definition = mkRAMDefinition(name, datawidth, addrwidth, numports)
181+
172182
self.inst = self.m.Instance(self.definition, 'inst_' + name,
173183
ports=m.connect_ports(self.definition))
174184

@@ -202,24 +212,14 @@ def write(self, port, addr, wdata, cond=None):
202212
if cond is not None:
203213
self.seq.If(cond)
204214

205-
body = [self.interfaces[port].addr(addr),
206-
self.interfaces[port].wdata(wdata),
207-
self.interfaces[port].wenable(1)]
208-
209-
if self.with_enable:
210-
body.append(self.interfaces[port].enable(1))
211-
212215
self.seq(
213-
*body
216+
self.interfaces[port].addr(addr),
217+
self.interfaces[port].wdata(wdata),
218+
self.interfaces[port].wenable(1)
214219
)
215220

216-
body = [self.interfaces[port].wenable(0)]
217-
218-
if self.with_enable:
219-
body.append(self.interfaces[port].enable(0))
220-
221221
self.seq.Then().Delay(1)(
222-
*body
222+
self.interfaces[port].wenable(0)
223223
)
224224

225225
def write_dataflow(self, port, addr, data, length=1, cond=None, when=None):
@@ -247,33 +247,21 @@ def write_dataflow(self, port, addr, data, length=1, cond=None, when=None):
247247
counter(length),
248248
)
249249

250-
body = [self.interfaces[port].addr.inc(),
251-
self.interfaces[port].wdata(raw_data),
252-
self.interfaces[port].wenable(1)]
253-
254-
if self.with_enable:
255-
body.append(self.interfaces[port].enable(1))
256-
257-
body.append(counter.dec())
258-
259250
self.seq.If(make_condition(raw_valid, counter > 0))(
260-
*body
251+
self.interfaces[port].addr.inc(),
252+
self.interfaces[port].wdata(raw_data),
253+
self.interfaces[port].wenable(1),
254+
counter.dec()
261255
)
262256

263257
self.seq.If(make_condition(raw_valid, counter == 1))(
264258
last(1)
265259
)
266260

267261
# de-assert
268-
body = [self.interfaces[port].wenable(0)]
269-
270-
if self.with_enable:
271-
body.append(self.interfaces[port].enable(0))
272-
273-
body.append(last(0))
274-
275262
self.seq.Delay(1)(
276-
*body
263+
self.interfaces[port].wenable(0),
264+
last(0)
277265
)
278266

279267
done = last
@@ -288,26 +276,17 @@ def read(self, port, addr, cond=None):
288276
if cond is not None:
289277
self.seq.If(cond)
290278

291-
body = [self.interfaces[port].addr(addr)]
292-
293-
if self.with_enable:
294-
body.append(self.interfaces[port].enable(1))
295-
296279
self.seq(
297-
*body
280+
self.interfaces[port].addr(addr)
298281
)
299282

300283
rdata = self.interfaces[port].rdata
301284
rvalid = self.m.TmpReg(initval=0)
285+
302286
self.seq.Then().Delay(1)(
303287
rvalid(1)
304288
)
305289

306-
if self.with_enable:
307-
self.seq.Then().Delay(1)(
308-
self.interfaces[port].enable(0)
309-
)
310-
311290
self.seq.Then().Delay(2)(
312291
rvalid(0)
313292
)
@@ -331,18 +310,14 @@ def read_dataflow(self, port, addr, length=1, cond=None):
331310

332311
ext_cond = make_condition(cond)
333312
data_cond = make_condition(data_ack, last_ack)
334-
if not self.with_enable:
335-
prev_data_cond = self.seq.Prev(data_cond, 1)
313+
prev_data_cond = self.seq.Prev(data_cond, 1)
336314
all_cond = make_condition(data_cond, ext_cond)
337315

338316
data = self.m.TmpWireLike(self.interfaces[port].rdata)
339-
if not self.with_enable:
340-
prev_data = self.seq.Prev(data, 1)
341-
data.assign(vtypes.Mux(prev_data_cond,
342-
self.interfaces[port].rdata, prev_data))
343-
else:
344-
self.interfaces[port].rdata.assign(data_cond)
345-
data.assign(self.interfaces[port].rdata)
317+
318+
prev_data = self.seq.Prev(data, 1)
319+
data.assign(vtypes.Mux(prev_data_cond,
320+
self.interfaces[port].rdata, prev_data))
346321

347322
counter = self.m.TmpReg(length.bit_length() + 1, initval=0)
348323

@@ -358,6 +333,7 @@ def read_dataflow(self, port, addr, length=1, cond=None):
358333
last_valid(0),
359334
next_valid_off(0)
360335
)
336+
361337
self.seq.If(make_condition(data_cond, next_valid_on))(
362338
data_valid(1),
363339
last_valid(1),
@@ -366,18 +342,21 @@ def read_dataflow(self, port, addr, length=1, cond=None):
366342
next_valid_on(0),
367343
next_valid_off(1)
368344
)
345+
369346
self.seq.If(make_condition(ext_cond, counter == 0,
370347
vtypes.Not(next_last), vtypes.Not(last)))(
371348
self.interfaces[port].addr(addr),
372349
counter(length - 1),
373350
next_valid_on(1),
374351
)
352+
375353
self.seq.If(make_condition(data_cond, counter > 0))(
376354
self.interfaces[port].addr.inc(),
377355
counter.dec(),
378356
next_valid_on(1),
379357
next_last(0)
380358
)
359+
381360
self.seq.If(make_condition(data_cond, counter == 1))(
382361
next_last(1)
383362
)

0 commit comments

Comments
 (0)