devices: new RTIO driver

This commit is contained in:
Sebastien Bourdeauducq 2014-09-12 15:28:02 +08:00
parent 813bc90194
commit b5f145d976
2 changed files with 39 additions and 11 deletions

View File

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

View File

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