2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 19:28:26 +08:00

ttl: use optimized rtio_output API

This commit is contained in:
Sebastien Bourdeauducq 2018-11-07 23:41:43 +08:00
parent 3d0c3cc1cf
commit fae95e73ad

View File

@ -29,11 +29,12 @@ class TTLOut:
:param channel: channel number :param channel: channel number
""" """
kernel_invariants = {"core", "channel"} kernel_invariants = {"core", "channel", "target_o"}
def __init__(self, dmgr, channel, core_device="core"): def __init__(self, dmgr, channel, core_device="core"):
self.core = dmgr.get(core_device) self.core = dmgr.get(core_device)
self.channel = channel self.channel = channel
self.target_o = channel << 8
@kernel @kernel
def output(self): def output(self):
@ -41,7 +42,7 @@ class TTLOut:
@kernel @kernel
def set_o(self, o): def set_o(self, o):
rtio_output(now_mu(), self.channel, 0, 1 if o else 0) rtio_output(now_mu(), self.target_o, 1 if o else 0)
@kernel @kernel
def on(self): def on(self):
@ -106,15 +107,20 @@ class TTLInOut:
:param channel: channel number :param channel: channel number
""" """
kernel_invariants = {"core", "channel"} kernel_invariants = {"core", "channel",
"target_o", "target_oe", "target_sens", "target_sample"}
def __init__(self, dmgr, channel, core_device="core"): def __init__(self, dmgr, channel, core_device="core"):
self.core = dmgr.get(core_device) self.core = dmgr.get(core_device)
self.channel = channel self.channel = channel
self.target_o = (channel << 8) + 0
self.target_oe = (channel << 8) + 1
self.target_sens = (channel << 8) + 2
self.target_sample = (channel << 8) + 3
@kernel @kernel
def set_oe(self, oe): def set_oe(self, oe):
rtio_output(now_mu(), self.channel, 1, 1 if oe else 0) rtio_output(now_mu(), self.target_oe, 1 if oe else 0)
@kernel @kernel
def output(self): def output(self):
@ -136,7 +142,7 @@ class TTLInOut:
@kernel @kernel
def set_o(self, o): def set_o(self, o):
rtio_output(now_mu(), self.channel, 0, 1 if o else 0) rtio_output(now_mu(), self.target_o, 1 if o else 0)
@kernel @kernel
def on(self): def on(self):
@ -181,7 +187,7 @@ class TTLInOut:
# Input API: gating # Input API: gating
@kernel @kernel
def _set_sensitivity(self, value): def _set_sensitivity(self, value):
rtio_output(now_mu(), self.channel, 2, value) rtio_output(now_mu(), self.target_sens, value)
@kernel @kernel
def gate_rising_mu(self, duration): def gate_rising_mu(self, duration):
@ -355,7 +361,7 @@ class TTLInOut:
position of the time cursor. position of the time cursor.
The time cursor is not modified by this function.""" The time cursor is not modified by this function."""
rtio_output(now_mu(), self.channel, 3, 0) rtio_output(now_mu(), self.target_sample, 0)
@kernel @kernel
def sample_get(self): def sample_get(self):
@ -392,13 +398,13 @@ class TTLInOut:
The time cursor is not modified by this function. The time cursor is not modified by this function.
""" """
rtio_output(now_mu(), self.channel, 3, 2) # gate falling rtio_output(now_mu(), self.target_sample, 2) # gate falling
return rtio_input_data(self.channel) == 1 return rtio_input_data(self.channel) == 1
@kernel @kernel
def watch_stay_off(self): def watch_stay_off(self):
"""Like :meth:`watch_stay_on`, but for low levels.""" """Like :meth:`watch_stay_on`, but for low levels."""
rtio_output(now_mu(), self.channel, 3, 1) # gate rising rtio_output(now_mu(), self.target_sample, 1) # gate rising
return rtio_input_data(self.channel) == 0 return rtio_input_data(self.channel) == 0
@kernel @kernel
@ -411,7 +417,7 @@ class TTLInOut:
The time cursor is not modified by this function. This function The time cursor is not modified by this function. This function
always makes the slack negative. always makes the slack negative.
""" """
rtio_output(now_mu(), self.channel, 2, 0) rtio_output(now_mu(), self.target_sens, 0)
success = True success = True
try: try:
while rtio_input_timestamp(now_mu(), self.channel) != -1: while rtio_input_timestamp(now_mu(), self.channel) != -1:
@ -432,11 +438,12 @@ class TTLClockGen:
:param channel: channel number :param channel: channel number
:param acc_width: accumulator width in bits :param acc_width: accumulator width in bits
""" """
kernel_invariants = {"core", "channel", "acc_width"} kernel_invariants = {"core", "channel", "target", "acc_width"}
def __init__(self, dmgr, channel, acc_width=24, core_device="core"): def __init__(self, dmgr, channel, acc_width=24, core_device="core"):
self.core = dmgr.get(core_device) self.core = dmgr.get(core_device)
self.channel = channel self.channel = channel
self.target = channel << 8
self.acc_width = numpy.int64(acc_width) self.acc_width = numpy.int64(acc_width)
@ -472,7 +479,7 @@ class TTLClockGen:
Due to the way the clock generator operates, frequency tuning words Due to the way the clock generator operates, frequency tuning words
that are not powers of two cause jitter of one RTIO clock cycle at the that are not powers of two cause jitter of one RTIO clock cycle at the
output.""" output."""
rtio_output(now_mu(), self.channel, 0, frequency) rtio_output(now_mu(), self.target, frequency)
@kernel @kernel
def set(self, frequency): def set(self, frequency):