From 53c63393079dc26085fadda383576e2677f67a71 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 8 May 2015 16:20:12 +0800 Subject: [PATCH] runtime: break ttl-specific functions from rtio --- artiq/coredevice/runtime.py | 8 ++--- artiq/coredevice/ttl.py | 14 ++++---- soc/runtime/Makefile | 2 +- soc/runtime/bridge.c | 5 +-- soc/runtime/gen_service_table.py | 16 ++++++--- soc/runtime/rtio.c | 53 ----------------------------- soc/runtime/rtio.h | 5 --- soc/runtime/services.c | 2 +- soc/runtime/ttl.c | 58 ++++++++++++++++++++++++++++++++ soc/runtime/ttl.h | 9 +++++ 10 files changed, 94 insertions(+), 78 deletions(-) create mode 100644 soc/runtime/ttl.c create mode 100644 soc/runtime/ttl.h diff --git a/artiq/coredevice/runtime.py b/artiq/coredevice/runtime.py index fb6bf7f1d..395939329 100644 --- a/artiq/coredevice/runtime.py +++ b/artiq/coredevice/runtime.py @@ -16,11 +16,11 @@ _syscalls = { "now_save": "I:n", "watchdog_set": "i:i", "watchdog_clear": "i:n", - "rtio_set_o": "Iib:n", - "rtio_set_oe": "Iib:n", - "rtio_set_sensitivity": "Iii:n", "rtio_get_counter": "n:I", - "rtio_get": "iI:I", + "ttl_set_o": "Iib:n", + "ttl_set_oe": "Iib:n", + "ttl_set_sensitivity": "Iii:n", + "ttl_get": "iI:I", "dds_init": "Ii:n", "dds_set": "Iiiii:n", } diff --git a/artiq/coredevice/ttl.py b/artiq/coredevice/ttl.py index 05932979f..359b9b590 100644 --- a/artiq/coredevice/ttl.py +++ b/artiq/coredevice/ttl.py @@ -24,7 +24,7 @@ class LLTTLOut(AutoDB): :param t: timestamp in RTIO cycles (64-bit integer). :param value: value to set at the output. """ - syscall("rtio_set_o", t, self.channel, value) + syscall("ttl_set_o", t, self.channel, value) @kernel def on(self, t): @@ -62,7 +62,7 @@ class TTLOut(AutoDB): @kernel def _set_o(self, o): - syscall("rtio_set_o", time_to_cycles(now()), self.channel, o) + syscall("ttl_set_o", time_to_cycles(now()), self.channel, o) self.o_previous_timestamp = time_to_cycles(now()) @kernel @@ -118,7 +118,7 @@ class TTLInOut(AutoDB): @kernel def _set_oe(self, oe): - syscall("rtio_set_oe", time_to_cycles(now()), self.channel, oe) + syscall("ttl_set_oe", time_to_cycles(now()), self.channel, oe) @kernel def output(self): @@ -130,7 +130,7 @@ class TTLInOut(AutoDB): @kernel def _set_o(self, o): - syscall("rtio_set_o", time_to_cycles(now()), self.channel, o) + syscall("ttl_set_o", time_to_cycles(now()), self.channel, o) self.o_previous_timestamp = time_to_cycles(now()) @kernel @@ -158,7 +158,7 @@ class TTLInOut(AutoDB): @kernel def _set_sensitivity(self, value): - syscall("rtio_set_sensitivity", time_to_cycles(now()), self.channel, value) + syscall("ttl_set_sensitivity", time_to_cycles(now()), self.channel, value) self.i_previous_timestamp = time_to_cycles(now()) @kernel @@ -188,7 +188,7 @@ class TTLInOut(AutoDB): """Poll the RTIO input during all the previously programmed gate openings, and returns the number of registered events.""" count = 0 - while syscall("rtio_get", self.channel, + while syscall("ttl_get", self.channel, self.i_previous_timestamp) >= 0: count += 1 return count @@ -200,5 +200,5 @@ class TTLInOut(AutoDB): If the gate is permanently closed, returns a negative value. """ - return cycles_to_time(syscall("rtio_get", self.channel, + return cycles_to_time(syscall("ttl_get", self.channel, self.i_previous_timestamp)) diff --git a/soc/runtime/Makefile b/soc/runtime/Makefile index ba75870fc..1d93d6e63 100644 --- a/soc/runtime/Makefile +++ b/soc/runtime/Makefile @@ -1,7 +1,7 @@ include $(MSCDIR)/software/common.mak OBJECTS := isr.o flash_storage.o clock.o elf_loader.o services.o session.o log.o test_mode.o kloader.o mailbox.o ksupport_data.o kserver.o main.o -OBJECTS_KSUPPORT := ksupport.o exception_jmp.o exceptions.o mailbox.o bridge.o rtio.o dds.o +OBJECTS_KSUPPORT := ksupport.o exception_jmp.o exceptions.o mailbox.o bridge.o rtio.o ttl.o dds.o CFLAGS += -Ilwip/src/include -Iliblwip diff --git a/soc/runtime/bridge.c b/soc/runtime/bridge.c index d467a9a22..19cfd4b4e 100644 --- a/soc/runtime/bridge.c +++ b/soc/runtime/bridge.c @@ -1,6 +1,7 @@ #include "mailbox.h" #include "messages.h" #include "rtio.h" +#include "ttl.h" #include "dds.h" #include "bridge.h" @@ -45,7 +46,7 @@ void bridge_main(void) struct msg_brg_ttl_out *msg; msg = (struct msg_brg_ttl_out *)umsg; - rtio_set_oe(rtio_get_counter() + 8000, msg->channel, msg->value); + ttl_set_oe(rtio_get_counter() + 8000, msg->channel, msg->value); mailbox_acknowledge(); break; } @@ -53,7 +54,7 @@ void bridge_main(void) struct msg_brg_ttl_out *msg; msg = (struct msg_brg_ttl_out *)umsg; - rtio_set_o(rtio_get_counter() + 8000, msg->channel, msg->value); + ttl_set_o(rtio_get_counter() + 8000, msg->channel, msg->value); mailbox_acknowledge(); break; } diff --git a/soc/runtime/gen_service_table.py b/soc/runtime/gen_service_table.py index a58236207..f29d5307a 100755 --- a/soc/runtime/gen_service_table.py +++ b/soc/runtime/gen_service_table.py @@ -9,17 +9,23 @@ services = [ ("syscalls", [ ("now_init", "now_init"), ("now_save", "now_save"), - ("rpc", "rpc"), + ("watchdog_set", "watchdog_set"), ("watchdog_clear", "watchdog_clear"), - ("rtio_set_o", "rtio_set_o"), - ("rtio_set_oe", "rtio_set_oe"), - ("rtio_set_sensitivity", "rtio_set_sensitivity"), + + ("rpc", "rpc"), + ("rtio_get_counter", "rtio_get_counter"), - ("rtio_get", "rtio_get"), + + ("ttl_set_o", "ttl_set_o"), + ("ttl_set_oe", "ttl_set_oe"), + ("ttl_set_sensitivity", "ttl_set_sensitivity"), + ("ttl_get", "ttl_get"), + ("dds_init", "dds_init"), ("dds_set", "dds_set"), ]), + ("eh", [ ("setjmp", "exception_setjmp"), ("push", "exception_push"), diff --git a/soc/runtime/rtio.c b/soc/runtime/rtio.c index 8fdcd2759..0e5cdad10 100644 --- a/soc/runtime/rtio.c +++ b/soc/runtime/rtio.c @@ -1,6 +1,5 @@ #include -#include "exceptions.h" #include "rtio.h" void rtio_init(void) @@ -16,55 +15,3 @@ long long int rtio_get_counter(void) return rtio_counter_read(); } -void rtio_set_o(long long int timestamp, int channel, int value) -{ - rtio_chan_sel_write(channel); - rtio_o_timestamp_write(timestamp); - rtio_o_address_write(0); - rtio_o_data_write(value); - rtio_write_and_process_status(timestamp, channel); -} - -void rtio_set_oe(long long int timestamp, int channel, int oe) -{ - rtio_chan_sel_write(channel); - rtio_o_timestamp_write(timestamp); - rtio_o_address_write(1); - rtio_o_data_write(oe); - rtio_write_and_process_status(timestamp, channel); -} - -void rtio_set_sensitivity(long long int timestamp, int channel, int sensitivity) -{ - rtio_chan_sel_write(channel); - rtio_o_timestamp_write(timestamp); - rtio_o_address_write(2); - rtio_o_data_write(sensitivity); - rtio_write_and_process_status(timestamp, channel); -} - -long long int rtio_get(int channel, long long int time_limit) -{ - long long int r; - int status; - - rtio_chan_sel_write(channel); - while((status = rtio_i_status_read())) { - if(rtio_i_status_read() & RTIO_I_STATUS_OVERFLOW) { - rtio_i_overflow_reset_write(1); - exception_raise_params(EID_RTIO_OVERFLOW, - channel, 0, 0); - } - if(rtio_get_counter() >= time_limit) { - /* check empty flag again to prevent race condition. - * now we are sure that the time limit has been exceeded. - */ - if(rtio_i_status_read() & RTIO_I_STATUS_EMPTY) - return -1; - } - /* input FIFO is empty - keep waiting */ - } - r = rtio_i_timestamp_read(); - rtio_i_re_write(1); - return r; -} diff --git a/soc/runtime/rtio.h b/soc/runtime/rtio.h index 6c30cec12..be1591554 100644 --- a/soc/runtime/rtio.h +++ b/soc/runtime/rtio.h @@ -35,9 +35,4 @@ static inline void rtio_write_and_process_status(long long int timestamp, int ch } } -void rtio_set_o(long long int timestamp, int channel, int value); -void rtio_set_oe(long long int timestamp, int channel, int oe); -void rtio_set_sensitivity(long long int timestamp, int channel, int sensitivity); -long long int rtio_get(int channel, long long int time_limit); - #endif /* __RTIO_H */ diff --git a/soc/runtime/services.c b/soc/runtime/services.c index 35cbf3f57..4e5292506 100644 --- a/soc/runtime/services.c +++ b/soc/runtime/services.c @@ -3,7 +3,7 @@ #include "elf_loader.h" #include "session.h" #include "clock.h" -#include "rtio.h" +#include "ttl.h" #include "dds.h" #include "exceptions.h" #include "services.h" diff --git a/soc/runtime/ttl.c b/soc/runtime/ttl.c new file mode 100644 index 000000000..f28faadc7 --- /dev/null +++ b/soc/runtime/ttl.c @@ -0,0 +1,58 @@ +#include + +#include "exceptions.h" +#include "rtio.h" +#include "ttl.h" + +void ttl_set_o(long long int timestamp, int channel, int value) +{ + rtio_chan_sel_write(channel); + rtio_o_timestamp_write(timestamp); + rtio_o_address_write(0); + rtio_o_data_write(value); + rtio_write_and_process_status(timestamp, channel); +} + +void ttl_set_oe(long long int timestamp, int channel, int oe) +{ + rtio_chan_sel_write(channel); + rtio_o_timestamp_write(timestamp); + rtio_o_address_write(1); + rtio_o_data_write(oe); + rtio_write_and_process_status(timestamp, channel); +} + +void ttl_set_sensitivity(long long int timestamp, int channel, int sensitivity) +{ + rtio_chan_sel_write(channel); + rtio_o_timestamp_write(timestamp); + rtio_o_address_write(2); + rtio_o_data_write(sensitivity); + rtio_write_and_process_status(timestamp, channel); +} + +long long int ttl_get(int channel, long long int time_limit) +{ + long long int r; + int status; + + rtio_chan_sel_write(channel); + while((status = rtio_i_status_read())) { + if(rtio_i_status_read() & RTIO_I_STATUS_OVERFLOW) { + rtio_i_overflow_reset_write(1); + exception_raise_params(EID_RTIO_OVERFLOW, + channel, 0, 0); + } + if(rtio_get_counter() >= time_limit) { + /* check empty flag again to prevent race condition. + * now we are sure that the time limit has been exceeded. + */ + if(rtio_i_status_read() & RTIO_I_STATUS_EMPTY) + return -1; + } + /* input FIFO is empty - keep waiting */ + } + r = rtio_i_timestamp_read(); + rtio_i_re_write(1); + return r; +} diff --git a/soc/runtime/ttl.h b/soc/runtime/ttl.h new file mode 100644 index 000000000..a7d8cab49 --- /dev/null +++ b/soc/runtime/ttl.h @@ -0,0 +1,9 @@ +#ifndef __TTL_H +#define __TTL_H + +void ttl_set_o(long long int timestamp, int channel, int value); +void ttl_set_oe(long long int timestamp, int channel, int oe); +void ttl_set_sensitivity(long long int timestamp, int channel, int sensitivity); +long long int ttl_get(int channel, long long int time_limit); + +#endif /* __TTL_H */