mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
corelogic: convert timeline to function and move to misc
This commit is contained in:
parent
1665f293a6
commit
e969b9afc3
3 changed files with 34 additions and 38 deletions
|
@ -1,16 +1,12 @@
|
||||||
from migen.bus import wishbone
|
from migen.bus import wishbone
|
||||||
from migen.bus import csr
|
from migen.bus import csr
|
||||||
from migen.fhdl.structure import *
|
from migen.fhdl.structure import *
|
||||||
from migen.corelogic import timeline
|
from migen.corelogic.misc import timeline
|
||||||
|
|
||||||
class WB2CSR:
|
class WB2CSR:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.wishbone = wishbone.Interface()
|
self.wishbone = wishbone.Interface()
|
||||||
self.csr = csr.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):
|
def get_fragment(self):
|
||||||
sync = [
|
sync = [
|
||||||
|
@ -19,4 +15,9 @@ class WB2CSR:
|
||||||
self.csr.adr.eq(self.wishbone.adr[:14]),
|
self.csr.adr.eq(self.wishbone.adr[:14]),
|
||||||
self.wishbone.dat_r.eq(self.csr.dat_r)
|
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)
|
||||||
|
|
|
@ -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.append([Constant(i, shift.bv), output.eq(signal[s*w:(s+1)*w])])
|
||||||
cases[n-1][0] = Default()
|
cases[n-1][0] = Default()
|
||||||
return Case(shift, *cases)
|
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
|
||||||
|
|
|
@ -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)
|
|
Loading…
Reference in a new issue