Skip to content
Browse files

corelogic: convert timeline to function and move to misc

  • Loading branch information...
1 parent 1665f29 commit e969b9afc3c31d3a5287c2a126af3e6cbc9617fd @sbourdeauducq sbourdeauducq committed
Showing with 34 additions and 38 deletions.
  1. +7 −6 migen/bus/wishbone2csr.py
  2. +27 −0 migen/corelogic/misc.py
  3. +0 −32 migen/corelogic/timeline.py
View
13 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 @@ def get_fragment(self):
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)
View
27 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
View
32 migen/corelogic/timeline.py
@@ -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)

0 comments on commit e969b9a

Please sign in to comment.
Something went wrong with that request. Please try again.