corelogic: convert timeline to function and move to misc
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 15 Mar 2012 19:25:44 +0000 (20:25 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 15 Mar 2012 19:25:44 +0000 (20:25 +0100)
migen/bus/wishbone2csr.py
migen/corelogic/misc.py
migen/corelogic/timeline.py [deleted file]

index 21114b46cc95744e87df6f4ebb7ec632faa30d2a..342f1bf584a24d10700a61b4b6ceb2023ddaf245 100644 (file)
@@ -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)
index a6374c51780c940c5c53878843fa8a093eb9fa30..746433209f5be1a8f924ee2fb5c2cf9ead93e444 100644 (file)
@@ -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 (file)
index 0bbbdd1..0000000
+++ /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)