From e969b9afc3c31d3a5287c2a126af3e6cbc9617fd Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 15 Mar 2012 20:25:44 +0100 Subject: [PATCH] corelogic: convert timeline to function and move to misc --- migen/bus/wishbone2csr.py | 13 +++++++------ migen/corelogic/misc.py | 27 +++++++++++++++++++++++++++ migen/corelogic/timeline.py | 32 -------------------------------- 3 files changed, 34 insertions(+), 38 deletions(-) delete mode 100644 migen/corelogic/timeline.py diff --git a/migen/bus/wishbone2csr.py b/migen/bus/wishbone2csr.py index 21114b46..342f1bf5 100644 --- a/migen/bus/wishbone2csr.py +++ b/migen/bus/wishbone2csr.py @@ -1,16 +1,12 @@ from migen.bus import wishbone from migen.bus import csr from migen.fhdl.structure import * -from migen.corelogic import timeline +from migen.corelogic.misc import timeline class WB2CSR: def __init__(self): self.wishbone = wishbone.Interface() self.csr = csr.Interface() - self.timeline = timeline.Timeline(self.wishbone.cyc & self.wishbone.stb, - [(1, [self.csr.we.eq(self.wishbone.we)]), - (2, [self.wishbone.ack.eq(1)]), - (3, [self.wishbone.ack.eq(0)])]) def get_fragment(self): sync = [ @@ -19,4 +15,9 @@ class WB2CSR: self.csr.adr.eq(self.wishbone.adr[:14]), self.wishbone.dat_r.eq(self.csr.dat_r) ] - return Fragment(sync=sync) + self.timeline.get_fragment() + sync += timeline(self.wishbone.cyc & self.wishbone.stb, [ + (1, [self.csr.we.eq(self.wishbone.we)]), + (2, [self.wishbone.ack.eq(1)]), + (3, [self.wishbone.ack.eq(0)]) + ]) + return Fragment(sync=sync) diff --git a/migen/corelogic/misc.py b/migen/corelogic/misc.py index a6374c51..74643320 100644 --- a/migen/corelogic/misc.py +++ b/migen/corelogic/misc.py @@ -64,3 +64,30 @@ def chooser(signal, shift, output, n=None, reverse=False): cases.append([Constant(i, shift.bv), output.eq(signal[s*w:(s+1)*w])]) cases[n-1][0] = Default() return Case(shift, *cases) + +def timeline(trigger, events): + lastevent = max([e[0] for e in events]) + counter = Signal(BV(bits_for(lastevent))) + + counterlogic = If(counter != Constant(0, counter.bv), + counter.eq(counter + Constant(1, counter.bv)) + ).Elif(trigger, + counter.eq(Constant(1, counter.bv)) + ) + # insert counter reset if it doesn't naturally overflow + # (test if lastevent+1 is a power of 2) + if (lastevent & (lastevent + 1)) != 0: + counterlogic = If(counter == lastevent, + counter.eq(Constant(0, counter.bv)) + ).Else( + counterlogic + ) + + def get_cond(e): + if e[0] == 0: + return trigger & (counter == Constant(0, counter.bv)) + else: + return counter == Constant(e[0], counter.bv) + sync = [If(get_cond(e), *e[1]) for e in events] + sync.append(counterlogic) + return sync diff --git a/migen/corelogic/timeline.py b/migen/corelogic/timeline.py deleted file mode 100644 index 0bbbdd1b..00000000 --- a/migen/corelogic/timeline.py +++ /dev/null @@ -1,32 +0,0 @@ -from migen.fhdl.structure import * - -class Timeline: - def __init__(self, trigger, events): - self.trigger = trigger - self.events = events - self.lastevent = max([e[0] for e in events]) - - def get_fragment(self): - counter = Signal(BV(bits_for(self.lastevent))) - - counterlogic = If(counter != Constant(0, counter.bv), - counter.eq(counter + Constant(1, counter.bv)) - ).Elif(self.trigger, - counter.eq(Constant(1, counter.bv)) - ) - # insert counter reset if it doesn't automatically overflow - # (test if self.lastevent+1 is a power of 2) - if (self.lastevent & (self.lastevent + 1)) != 0: - counterlogic = If(counter == self.lastevent, - counter.eq(Constant(0, counter.bv)) - ).Else( - counterlogic - ) - def get_cond(e): - if e[0] == 0: - return self.trigger & (counter == Constant(0, counter.bv)) - else: - return counter == Constant(e[0], counter.bv) - sync = [If(get_cond(e), *e[1]) for e in self.events] - sync.append(counterlogic) - return Fragment(sync=sync) -- 2.30.2