Skip to content

Commit

Permalink
rtio: raise RTIOSequenceError exceptions when events are not submitte…
Browse files Browse the repository at this point in the history
…d in-order
sbourdeauducq committed Sep 30, 2014
1 parent 73d0a84 commit 76fed11
Showing 6 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions artiq/devices/rtio_core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from artiq.language.core import *
from artiq.devices.runtime_exceptions import RTIOSequenceError


class _RTIOBase(AutoContext):
@@ -16,6 +17,8 @@ def _set_oe(self, oe):

@kernel
def _set_value(self, value):
if now() < self.previous_timestamp:
raise RTIOSequenceError
if self.previous_value != value:
if self.previous_timestamp == now():
syscall("rtio_replace", now(), self.channel, value)
15 changes: 15 additions & 0 deletions artiq/devices/runtime_exceptions.py
Original file line number Diff line number Diff line change
@@ -6,13 +6,28 @@
# Must be kept in sync with soc/runtime/exceptions.h

class OutOfMemory(RuntimeException):
"""Raised when the runtime fails to allocate memory.
"""
eid = 0


class RTIOUnderflow(RuntimeException):
"""Raised when the CPU fails to submit a RTIO event early enough (with respect to the event's timestamp).
"""
eid = 1


# Raised by RTIO driver for regular RTIO.
# Raised by runtime for DDS FUD.
class RTIOSequenceError(RuntimeException):
"""Raised when an event was not submitted with an increasing timestamp.
"""
eid = 2


exception_map = {e.eid: e for e in globals().values()
if inspect.isclass(e)
and issubclass(e, RuntimeException)
6 changes: 6 additions & 0 deletions doc/manual/drivers_reference.rst
Original file line number Diff line number Diff line change
@@ -12,3 +12,9 @@ Drivers reference

.. automodule:: artiq.devices.dds_core
:members:

:mod:`artiq.devices.runtime_exceptions` module
----------------------------------------------

.. automodule:: artiq.devices.runtime_exceptions
:members:
6 changes: 6 additions & 0 deletions soc/runtime/dds.c
Original file line number Diff line number Diff line change
@@ -28,15 +28,21 @@ static void fud_sync(void)
static void fud(long long int fud_time)
{
int r;
static int previous_fud_time;

r = rtio_reset_read();
if(r)
previous_fud_time = 0;
rtio_reset_write(0);

rtio_chan_sel_write(RTIO_FUD_CHANNEL);
if(fud_time < 0) {
rtio_counter_update_write(1);
fud_time = rtio_counter_read() + 3000;
}
if(fud_time < previous_fud_time)
exception_raise(EID_RTIO_SEQUENCE_ERROR);

rtio_o_timestamp_write(fud_time);
rtio_o_value_write(1);
rtio_o_we_write(1);
3 changes: 2 additions & 1 deletion soc/runtime/exceptions.h
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@

enum {
EID_OUT_OF_MEMORY = 0,
EID_RTIO_UNDERFLOW = 1
EID_RTIO_UNDERFLOW = 1,
EID_RTIO_SEQUENCE_ERROR = 2
};

int exception_setjmp(void *jb) __attribute__((returns_twice));
21 changes: 21 additions & 0 deletions test/full_stack.py
Original file line number Diff line number Diff line change
@@ -163,6 +163,17 @@ def run(self):
self.o.pulse(25*ns)


class _RTIOSequenceError(AutoContext):
parameters = "o"

@kernel
def run(self):
t = now()
self.o.pulse(25*us)
at(t)
self.o.pulse(25*us)


class RTIOCase(unittest.TestCase):
def test_loopback(self):
npulses = 4
@@ -186,3 +197,13 @@ def test_underflow(self):
)
with self.assertRaises(runtime_exceptions.RTIOUnderflow):
uut.run()

def test_sequence_error(self):
with corecom_serial.CoreCom() as com:
coredev = core.Core(com)
uut = _RTIOSequenceError(
core=coredev,
o=rtio_core.RTIOOut(core=coredev, channel=1)
)
with self.assertRaises(runtime_exceptions.RTIOSequenceError):
uut.run()

0 comments on commit 76fed11

Please sign in to comment.