coredevice: Add Core.wait_until_mu()

(This supersedes TTLOut.sync(), see see GitHub #1113.)
pull/1191/head
David Nadlinger 2018-07-23 15:24:41 +01:00 committed by Sébastien Bourdeauducq
parent cbfbe24d7a
commit 11e8c9d5f7
2 changed files with 31 additions and 0 deletions

View File

@ -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.

View File

@ -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")