litex/migen/flow/hooks.py

44 lines
945 B
Python
Raw Normal View History

2013-03-30 12:28:41 -04:00
from collections import defaultdict
2012-07-06 17:36:10 -04:00
from migen.fhdl.structure import *
from migen.fhdl.module import Module
2012-07-06 17:36:10 -04:00
from migen.flow.actor import *
class EndpointSimHook(Module):
2012-07-06 17:36:10 -04:00
def __init__(self, endpoint):
self.endpoint = endpoint
def on_ack(self):
pass
def on_nack(self):
pass
def on_inactive(self):
pass
def do_simulation(self, s):
if s.rd(self.endpoint.stb):
if s.rd(self.endpoint.ack):
self.on_ack()
else:
self.on_nack()
else:
self.on_inactive()
2013-03-30 12:28:41 -04:00
class DFGHook(Module):
2012-07-06 17:36:10 -04:00
def __init__(self, dfg, create):
assert(not dfg.is_abstract())
2013-03-30 12:28:41 -04:00
self.nodepair_to_ep = defaultdict(dict)
for hookn, (u, v, data) in dfg.edges_iter(data=True):
ep_to_hook = self.nodepair_to_ep[(u, v)]
2012-07-06 17:36:10 -04:00
ep = data["source"]
2013-03-30 12:28:41 -04:00
h = create(u, ep, v)
ep_to_hook[ep] = h
setattr(self.submodules, "hook"+str(hookn), h)
2012-07-06 17:36:10 -04:00
def hooks_iter(self):
2012-07-06 17:36:10 -04:00
for v1 in self.nodepair_to_ep.values():
for v2 in v1.values():
yield v2