From 140b4eb594dd3a7103e5d28ff81ade324a0bf8f8 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 15 Sep 2014 22:48:22 +0800 Subject: [PATCH] devices/rtio_core: set OE, implement gate/count --- artiq/devices/rtio_core.py | 39 +++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/artiq/devices/rtio_core.py b/artiq/devices/rtio_core.py index 694e2e2e2..a998629ce 100644 --- a/artiq/devices/rtio_core.py +++ b/artiq/devices/rtio_core.py @@ -1,7 +1,7 @@ from artiq.language.core import * -class RTIOOut(AutoContext): +class _RTIOBase(AutoContext): parameters = "channel" def build(self): @@ -10,6 +10,10 @@ class RTIOOut(AutoContext): kernel_attr = "previous_timestamp previous_value" + @kernel + def _set_oe(self, oe): + syscall("rtio_oe", self.channel, oe) + @kernel def _set_value(self, value): if self.previous_value != value: @@ -20,6 +24,12 @@ class RTIOOut(AutoContext): self.previous_timestamp = now() self.previous_value = value + +class RTIOOut(_RTIOBase): + def build(self): + _RTIOBase.build(self) + self._set_oe(1) + @kernel def sync(self): syscall("rtio_sync", self.channel) @@ -39,13 +49,32 @@ class RTIOOut(AutoContext): self.off() -class RTIOCounter(AutoContext): - parameters = "channel" +class RTIOCounter(_RTIOBase): + def build(self): + _RTIOBase.build(self) + self._set_oe(0) @kernel def count_rising(self, duration): - pass + self._set_value(1) + delay(duration) + self._set_value(0) + + @kernel + def count_falling(self, duration): + self._set_value(2) + delay(duration) + self._set_value(0) + + @kernel + def count_both_edges(self, duration): + self._set_value(3) + delay(duration) + self._set_value(0) @kernel def sync(self): - return 42 + count = 0 + while syscall("rtio_get", self.channel) >= 0: + count += 1 + return count