From 0d8b6f8fbbedca5e3e2a84bfaf15684e825cca08 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Tue, 9 Mar 2021 13:55:43 +0100 Subject: [PATCH] csr_eventmanager/EventSourceProcess: Add Rising Edge support and Falling/Rising selection. --- litex/soc/interconnect/csr_eventmanager.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/litex/soc/interconnect/csr_eventmanager.py b/litex/soc/interconnect/csr_eventmanager.py index 2c445ca77..43da07ffb 100644 --- a/litex/soc/interconnect/csr_eventmanager.py +++ b/litex/soc/interconnect/csr_eventmanager.py @@ -78,20 +78,22 @@ class EventSourcePulse(Module, _EventSource): class EventSourceProcess(Module, _EventSource): - """EventSource which triggers on a falling edge. + """EventSource which triggers on a Falling or Rising edge. The purpose of this event source is to monitor the status of processes and generate an interrupt on their completion. """ - def __init__(self, name=None, description=None): + def __init__(self, name=None, description=None, edge="falling"): + assert edge in ["falling", "rising"] _EventSource.__init__(self, name, description) self.comb += self.status.eq(self.trigger) - old_trigger = Signal() - self.sync += [ - If(self.clear, self.pending.eq(0)), - old_trigger.eq(self.trigger), - If(~self.trigger & old_trigger, self.pending.eq(1)) - ] + trigger_d = Signal() + self.sync += If(self.clear, self.pending.eq(0)) + self.sync += trigger_d.eq(self.trigger) + if edge == "falling": + self.sync += If(~self.trigger & trigger_d, self.pending.eq(1)) + if edge == "rising": + self.sync += If(self.trigger & ~trigger_d, self.pending.eq(1)) class EventSourceLevel(Module, _EventSource):