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 = [
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)
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
+++ /dev/null
-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)