From c83e22c11cf229ca20b26d41168249e13773d0ff Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 28 Aug 2018 15:41:24 +0800 Subject: [PATCH] test: add test for short RTIO input gate Based on https://github.com/m-labs/artiq/pull/1136 See also https://github.com/m-labs/artiq/issues/1137 --- artiq/test/coredevice/test_rtio.py | 58 ++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/artiq/test/coredevice/test_rtio.py b/artiq/test/coredevice/test_rtio.py index 67d54aea6..4f778f9fe 100644 --- a/artiq/test/coredevice/test_rtio.py +++ b/artiq/test/coredevice/test_rtio.py @@ -178,6 +178,61 @@ class LoopbackCount(EnvExperiment): self.set_dataset("count", self.loop_in.count()) +class IncorrectPulseTiming(Exception): + pass + + +class LoopbackGateTiming(EnvExperiment): + def build(self): + self.setattr_device("core") + self.setattr_device("loop_in") + self.setattr_device("loop_out") + + @kernel + def run(self): + # Make sure there are no leftover events. + self.core.reset() + + # Determine loop delay. + with parallel: + self.loop_in.gate_rising_mu(10000) + with sequential: + delay_mu(5000) + out_mu = now_mu() + self.loop_out.pulse_mu(1000) + in_mu = self.loop_in.timestamp_mu() + if in_mu < 0: + raise PulseNotReceived("Cannot determine loop delay") + loop_delay_mu = in_mu - out_mu + + # With the exact delay known, make sure tight gate timings work. + # In the most common configuration, 24 mu == 24 ns == 3 coarse periods, + # which should be plenty of slack. + delay_mu(10000) + + gate_start_mu = now_mu() + self.loop_in.gate_both_mu(24) + gate_end_mu = now_mu() + + # gateware latency offset between gate and input + lat_offset = 3*8 + out_mu = gate_start_mu - loop_delay_mu + lat_offset + at_mu(out_mu) + self.loop_out.pulse_mu(24) + + in_mu = self.loop_in.timestamp_mu() + if in_mu < 0: + raise PulseNotReceived() + if not (gate_start_mu <= (in_mu - lat_offset) <= gate_end_mu): + raise IncorrectPulseTiming("Input event should occur during gate") + if not (-2 < (in_mu - out_mu - loop_delay_mu) < 2): + raise IncorrectPulseTiming("Loop delay should not change") + + in_mu = self.loop_in.timestamp_mu() + if in_mu > 0: + raise IncorrectPulseTiming("Only one pulse should be received") + + class IncorrectLevel(Exception): pass @@ -387,6 +442,9 @@ class CoredeviceTest(ExperimentCase): count = self.dataset_mgr.get("count") self.assertEqual(count, npulses) + def test_loopback_gate_timing(self): + self.execute(LoopbackGateTiming) + def test_level(self): self.execute(Level)