From: Luke Kenneth Casson Leighton Date: Sun, 9 Aug 2020 18:44:09 +0000 (+0100) Subject: add rising edge function for generating pulse X-Git-Tag: 24jan2021_ls180~30 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=64b8a07b2c72e5fb870bafe9ef00f926d1bd0faf;p=nmutil.git add rising edge function for generating pulse --- diff --git a/src/nmutil/util.py b/src/nmutil/util.py index 3aae6ef..5e8660b 100644 --- a/src/nmutil/util.py +++ b/src/nmutil/util.py @@ -1,5 +1,5 @@ from collections.abc import Iterable -from nmigen import Mux +from nmigen import Mux, Signal # XXX this already exists in nmigen._utils # see https://bugs.libre-soc.org/show_bug.cgi?id=297 @@ -46,3 +46,15 @@ def wrap(process): yield from process return wrapper + +# a "rising edge" generator. can take signals of greater than width 1 + +def rising_edge(m, sig): + delay = Signal.like(sig) + rising = Signal.like(sig) + delay.name = "%s_dly" % sig.name + rising.name = "%s_rise" % sig.name + m.d.sync += delay.eq(sig) # 1 clock delay + m.d.comb += rising.eq(sig & ~delay) # sig is hi but delay-sig is lo + return rising +