from migen.fhdl.structure import *
+from migen.corelogic.misc import optree
class SchedulingModel:
COMBINATORIAL, SEQUENTIAL, PIPELINE, DYNAMIC = range(4)
def __repr__(self):
return "<Source " + str(self.token) + ">"
-def _control_fragment_comb(stb_i, ack_o, stb_o, ack_i):
- return Fragment([stb_o.eq(stb_i), ack_o.eq(ack_i)])
+def _control_fragment_comb(stb_i, ack_o, stb_o, ack_i, busy):
+ return Fragment([stb_o.eq(stb_i), ack_o.eq(ack_i), busy.eq(0)])
-def _control_fragment_seq(latency, stb_i, ack_o, stb_o, ack_i, trigger):
+def _control_fragment_seq(latency, stb_i, ack_o, stb_o, ack_i, busy, trigger):
ready = Signal()
timer = Signal(BV(bits_for(latency)))
comb = [ready.eq(timer == 0)]
stb_o.eq(ready & mask),
trigger.eq(stb_i & (ack_i | ~mask) & ready),
ack_o.eq(trigger),
+ busy.eq(~ready)
]
sync += [
If(trigger, mask.eq(1)),
return Fragment(comb, sync)
-def _control_fragment_pipe(latency, stb_i, ack_o, stb_o, ack_i, pipe_ce):
+def _control_fragment_pipe(latency, stb_i, ack_o, stb_o, ack_i, busy, pipe_ce):
valid = Signal(BV(latency))
if latency > 1:
sync = [If(pipe_ce, valid.eq(Cat(stb_i, valid[:latency-1])))]
comb = [
pipe_ce.eq(ack_i | ~last_valid),
ack_o.eq(pipe_ce),
- stb_o.eq(last_valid)
+ stb_o.eq(last_valid),
+ busy.eq(optree('|', [valid[i] for i in range(latency)]))
]
return Fragment(comb, sync)
self.endpoints.append(Source(sources))
else:
self.endpoints = endpoints
+ self.busy = Signal()
if self.scheduling_model.model == SchedulingModel.SEQUENTIAL:
self.trigger = Signal()
elif self.scheduling_model.model == SchedulingModel.PIPELINE:
stb_o = source.stb
ack_i = source.ack
if self.scheduling_model.model == SchedulingModel.COMBINATORIAL:
- return _control_fragment_comb(stb_i, ack_o, stb_o, ack_i)
+ return _control_fragment_comb(stb_i, ack_o, stb_o, ack_i, self.busy)
elif self.scheduling_model.model == SchedulingModel.SEQUENTIAL:
- return _control_fragment_seq(self.scheduling_model.latency, stb_i, ack_o, stb_o, ack_i, self.trigger)
+ return _control_fragment_seq(self.scheduling_model.latency, stb_i, ack_o, stb_o, ack_i, self.busy, self.trigger)
elif self.scheduling_model.model == SchedulingModel.PIPELINE:
- return _control_fragment_pipe(self.scheduling_model.latency, stb_i, ack_o, stb_o, ack_i, self.pipe_ce)
+ return _control_fragment_pipe(self.scheduling_model.latency, stb_i, ack_o, stb_o, ack_i, self.busy, self.pipe_ce)
elif self.scheduling_model.model == SchedulingModel.DYNAMIC:
raise NotImplementedError("Actor classes with dynamic scheduling must overload get_control_fragment")
import networkx as nx
+from migen.fhdl.structure import *
from migen.flow.actor import *
+from migen.corelogic.misc import optree
class CompositeActor(Actor):
def __init__(self, dfg):
this = sum([get_conn_control_fragment(x[2]['source'], x[2]['sink'])
for x in self.dfg.edges(data=True)], Fragment())
others = sum([node.get_control_fragment() for node in self.dfg], Fragment())
- return this + others
+ busy = Fragment([self.busy.eq(optree('|', [node.busy for node in self.dfg]))])
+ return this + others + busy
def get_process_fragment(self):
this = sum([get_conn_process_fragment(x[2]['source'], x[2]['sink'])