diff --git a/orbtrace/glitch.py b/orbtrace/glitch.py new file mode 100644 index 0000000..c1037be --- /dev/null +++ b/orbtrace/glitch.py @@ -0,0 +1,43 @@ +from migen import * + +from litex.soc.interconnect.csr import AutoCSR, CSRStorage + +class Glitch(Module, AutoCSR): + def __init__(self, trigger, output): + self._delay = CSRStorage(32) + self._pulse = CSRStorage(32) + + cnt = Signal(32) + + self.submodules.fsm = fsm = FSM() + + fsm.act('IDLE', + If(trigger, + NextState('DELAY'), + NextValue(cnt, self._delay.storage), + ) + ) + + fsm.act('DELAY', + If(cnt, + NextValue(cnt, cnt - 1), + ).Else( + NextState('PULSE'), + NextValue(cnt, self._pulse.storage), + ) + ) + + fsm.act('PULSE', + output.eq(1), + If(cnt, + NextValue(cnt, cnt - 1), + ).Else( + NextState('DONE'), + ) + ) + + fsm.act('DONE', + If(~trigger, + NextState('IDLE'), + ) + ) diff --git a/orbtrace/soc.py b/orbtrace/soc.py index 3640ce6..e612b2c 100644 --- a/orbtrace/soc.py +++ b/orbtrace/soc.py @@ -31,6 +31,8 @@ from .reset import Reset +from .glitch import Glitch + from usb_protocol.types import USBTransferType, USBRequestType, USBStandardRequests, USBRequestRecipient, DescriptorTypes from usb_protocol.emitters.descriptors import cdc @@ -144,6 +146,7 @@ def __init__(self, platform, sys_clk_freq, with_debug, with_trace, with_target_p # Target power if with_target_power: self.add_target_power() + self.add_glitch() # Platform specific self.add_platform_specific() @@ -558,6 +561,14 @@ def add_test_io(self): self.submodules.test_io = TestIO(signals) + def add_glitch(self): + trigger = self.led_vtref.b + gpio = self.platform.request('gpio', 5) + + self.comb += gpio.dir.eq(1) + + self.submodules.glitch = Glitch(trigger, gpio.data) + def add_button_handler(self): # This is a workaround to ensure the button signal is not optimized out. # Optimizing out the button results in the internal pulldown being enabled,