From b5f145d976a432944e8b4f557150e6988a241596 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 12 Sep 2014 15:28:02 +0800 Subject: [PATCH] devices: new RTIO driver --- artiq/devices/rtio_core.py | 39 ++++++++++++++++++++++++++++++++++++++ artiq/devices/ttl_core.py | 11 ----------- 2 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 artiq/devices/rtio_core.py delete mode 100644 artiq/devices/ttl_core.py diff --git a/artiq/devices/rtio_core.py b/artiq/devices/rtio_core.py new file mode 100644 index 000000000..2c0b1988f --- /dev/null +++ b/artiq/devices/rtio_core.py @@ -0,0 +1,39 @@ +from artiq.language.core import * + + +class RTIOOut(AutoContext): + parameters = "channel" + + def build(self): + self.previous_timestamp = int64(0) + self.previous_value = 0 + + kernel_attr = "previous_timestamp previous_value" + + @kernel + def _set_value(self, value): + if self.previous_value != value: + if self.previous_timestamp == now(): + syscall("rtio_replace", now(), self.channel, value) + else: + syscall("rtio_set", now(), self.channel, value) + self.previous_timestamp = now() + self.previous_value = value + + @kernel + def sync(self): + syscall("rtio_sync", self.channel) + + @kernel + def on(self): + self._set_value(1) + + @kernel + def off(self): + self._set_value(0) + + @kernel + def pulse(self, duration): + self.on() + delay(duration) + self.off() diff --git a/artiq/devices/ttl_core.py b/artiq/devices/ttl_core.py deleted file mode 100644 index 4320e6a9c..000000000 --- a/artiq/devices/ttl_core.py +++ /dev/null @@ -1,11 +0,0 @@ -from artiq.language.core import * - - -class TTLOut(AutoContext): - parameters = "channel" - - @kernel - def pulse(self, duration): - syscall("rtio_set", now(), self.channel, 1) - delay(duration) - syscall("rtio_set", now(), self.channel, 0)