From 11e8c9d5f73e944207a816610c3ec929cc9ca928 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Mon, 23 Jul 2018 15:24:41 +0100 Subject: [PATCH] coredevice: Add Core.wait_until_mu() (This supersedes TTLOut.sync(), see see GitHub #1113.) --- artiq/coredevice/core.py | 11 +++++++++++ artiq/test/coredevice/test_rtio.py | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/artiq/coredevice/core.py b/artiq/coredevice/core.py index 9f84efe60..0caf31edb 100644 --- a/artiq/coredevice/core.py +++ b/artiq/coredevice/core.py @@ -153,6 +153,17 @@ class Core: def get_rtio_counter_mu(self): return rtio_get_counter() + @kernel + def wait_until_mu(self, cursor_mu): + """Block execution until the hardware RTIO counter reaches the given + value (see :meth:`get_rtio_counter_mu`). + + If the hardware counter has already passed the given time, the function + returns immediately. + """ + while self.get_rtio_counter_mu() < cursor_mu: + pass + @kernel def get_drtio_link_status(self, linkno): """Returns whether the specified DRTIO link is up. diff --git a/artiq/test/coredevice/test_rtio.py b/artiq/test/coredevice/test_rtio.py index 8fde4bcc4..9631cd38e 100644 --- a/artiq/test/coredevice/test_rtio.py +++ b/artiq/test/coredevice/test_rtio.py @@ -29,6 +29,23 @@ class RTIOCounter(EnvExperiment): self.set_dataset("dt", self.core.mu_to_seconds(t1 - t0)) +class InvalidCounter(Exception): + pass + + +class WaitForRTIOCounter(EnvExperiment): + def build(self): + self.setattr_device("core") + + @kernel + def run(self): + self.core.break_realtime() + target_mu = now_mu() + 10000 + self.core.wait_until_mu(target_mu) + if self.core.get_rtio_counter_mu() < target_mu: + raise InvalidCounter + + class PulseNotReceived(Exception): pass @@ -375,6 +392,9 @@ class CoredeviceTest(ExperimentCase): self.assertGreater(dt, 50*ns) self.assertLess(dt, 1*us) + def test_wait_for_rtio_counter(self): + self.execute(WaitForRTIOCounter) + def test_loopback(self): self.execute(Loopback) rtt = self.dataset_mgr.get("rtt")