5
5
from artiq .coredevice .rtio import rtio_output , rtio_input_timestamp
6
6
7
7
8
+ # RTIO TTL address map:
9
+ # 0 Output level
10
+ # 1 Output enable
11
+ # 2 Set input sensitivity
12
+ # 3 Set input sensitivity and sample
13
+
14
+
8
15
class TTLOut :
9
16
"""RTIO TTL output driver.
10
17
@@ -94,6 +101,10 @@ class TTLInOut:
94
101
the time in your setup, it is a good idea to call ``output`` in the
95
102
startup kernel.
96
103
104
+ There are three input APIs: gating, sampling and watching. When one
105
+ API is active (e.g. the gate is open, or the input events have not been
106
+ fully read out), another API must not be used simultaneously.
107
+
97
108
:param channel: channel number
98
109
"""
99
110
kernel_invariants = {"core" , "channel" }
@@ -105,6 +116,7 @@ def __init__(self, dmgr, channel, core_device="core"):
105
116
# in RTIO cycles
106
117
self .o_previous_timestamp = numpy .int64 (0 )
107
118
self .i_previous_timestamp = numpy .int64 (0 )
119
+ self .queued_samples = 0
108
120
109
121
@kernel
110
122
def set_oe (self , oe ):
@@ -180,6 +192,7 @@ def pulse(self, duration):
180
192
delay (duration )
181
193
self .off ()
182
194
195
+ # Input API: gating
183
196
@kernel
184
197
def _set_sensitivity (self , value ):
185
198
rtio_output (now_mu (), self .channel , 2 , value )
@@ -266,6 +279,78 @@ def timestamp_mu(self):
266
279
This function does not interact with the time cursor."""
267
280
return rtio_input_timestamp (self .i_previous_timestamp , self .channel )
268
281
282
+ # Input API: sampling
283
+ @kernel
284
+ def sample_input (self ):
285
+ """Instructs the RTIO core to read the value of the TTL input at the
286
+ position of the time cursor.
287
+
288
+ The time cursor is not modified by this function."""
289
+ rtio_output (now_mu (), self .channel , 3 , 0 )
290
+
291
+ @kernel
292
+ def sample_get (self ):
293
+ """Returns the value of a sample previously obtained with
294
+ ``sample_input``.
295
+
296
+ Multiple samples may be queued (using multiple calls to
297
+ ``sample_input``) into the RTIO FIFOs and subsequently read out using
298
+ multiple calls to this function.
299
+
300
+ This function does not interact with the time cursor."""
301
+ return rtio_input_data (self .channel )
302
+
303
+ @kernel
304
+ def sample_get_nonrt (self ):
305
+ """Convenience function that obtains the value of a sample
306
+ at the position of the time cursor, breaks realtime, and
307
+ returns the sample value."""
308
+ self .sample_input ()
309
+ r = self .sample_get ()
310
+ self .core .break_realtime ()
311
+ return r
312
+
313
+ # Input API: watching
314
+ @kernel
315
+ def watch_stay_on (self ):
316
+ """Checks that the input is at a high level at the position
317
+ of the time cursor and keep checking until ``watch_done``
318
+ is called.
319
+
320
+ Returns ``True`` if the input is high. A call to this function
321
+ must always be followed by an eventual call to ``watch_done``
322
+ (use e.g. a try/finally construct to ensure this).
323
+
324
+ The time cursor is not modified by this function.
325
+ """
326
+ rtio_output (now_mu (), self .channel , 3 , 2 ) # gate falling
327
+ return rtio_input_data (self .channel ) == 1
328
+
329
+ @kernel
330
+ def watch_stay_off (self ):
331
+ """Like ``watch_stay_on``, but for low levels."""
332
+ rtio_output (now_mu (), self .channel , 3 , 1 ) # gate rising
333
+ return rtio_input_data (self .channel ) == 0
334
+
335
+ @kernel
336
+ def watch_done (self ):
337
+ """Stop watching the input at the position of the time cursor.
338
+
339
+ Returns ``True`` if the input has not changed state while it
340
+ was being watched.
341
+
342
+ The time cursor is not modified by this function. This function
343
+ always makes the slack negative.
344
+ """
345
+ rtio_output (now_mu (), self .channel , 2 , 0 )
346
+ success = True
347
+ try :
348
+ while rtio_input_timestamp (now_mu (), self .channel ) != - 1 :
349
+ success = False
350
+ except RTIOOverflow :
351
+ success = False
352
+ return success
353
+
269
354
270
355
class TTLClockGen :
271
356
"""RTIO TTL clock generator driver.
0 commit comments