forked from M-Labs/artiq
1
0
Fork 0

runtime: break ttl-specific functions from rtio

This commit is contained in:
Sebastien Bourdeauducq 2015-05-08 16:20:12 +08:00
parent a36c51eb83
commit 53c6339307
10 changed files with 94 additions and 78 deletions

View File

@ -16,11 +16,11 @@ _syscalls = {
"now_save": "I:n", "now_save": "I:n",
"watchdog_set": "i:i", "watchdog_set": "i:i",
"watchdog_clear": "i:n", "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_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_init": "Ii:n",
"dds_set": "Iiiii:n", "dds_set": "Iiiii:n",
} }

View File

@ -24,7 +24,7 @@ class LLTTLOut(AutoDB):
:param t: timestamp in RTIO cycles (64-bit integer). :param t: timestamp in RTIO cycles (64-bit integer).
:param value: value to set at the output. :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 @kernel
def on(self, t): def on(self, t):
@ -62,7 +62,7 @@ class TTLOut(AutoDB):
@kernel @kernel
def _set_o(self, o): 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()) self.o_previous_timestamp = time_to_cycles(now())
@kernel @kernel
@ -118,7 +118,7 @@ class TTLInOut(AutoDB):
@kernel @kernel
def _set_oe(self, oe): 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 @kernel
def output(self): def output(self):
@ -130,7 +130,7 @@ class TTLInOut(AutoDB):
@kernel @kernel
def _set_o(self, o): 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()) self.o_previous_timestamp = time_to_cycles(now())
@kernel @kernel
@ -158,7 +158,7 @@ class TTLInOut(AutoDB):
@kernel @kernel
def _set_sensitivity(self, value): 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()) self.i_previous_timestamp = time_to_cycles(now())
@kernel @kernel
@ -188,7 +188,7 @@ class TTLInOut(AutoDB):
"""Poll the RTIO input during all the previously programmed gate """Poll the RTIO input during all the previously programmed gate
openings, and returns the number of registered events.""" openings, and returns the number of registered events."""
count = 0 count = 0
while syscall("rtio_get", self.channel, while syscall("ttl_get", self.channel,
self.i_previous_timestamp) >= 0: self.i_previous_timestamp) >= 0:
count += 1 count += 1
return count return count
@ -200,5 +200,5 @@ class TTLInOut(AutoDB):
If the gate is permanently closed, returns a negative value. 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)) self.i_previous_timestamp))

View File

@ -1,7 +1,7 @@
include $(MSCDIR)/software/common.mak 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 := 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 CFLAGS += -Ilwip/src/include -Iliblwip

View File

@ -1,6 +1,7 @@
#include "mailbox.h" #include "mailbox.h"
#include "messages.h" #include "messages.h"
#include "rtio.h" #include "rtio.h"
#include "ttl.h"
#include "dds.h" #include "dds.h"
#include "bridge.h" #include "bridge.h"
@ -45,7 +46,7 @@ void bridge_main(void)
struct msg_brg_ttl_out *msg; struct msg_brg_ttl_out *msg;
msg = (struct msg_brg_ttl_out *)umsg; 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(); mailbox_acknowledge();
break; break;
} }
@ -53,7 +54,7 @@ void bridge_main(void)
struct msg_brg_ttl_out *msg; struct msg_brg_ttl_out *msg;
msg = (struct msg_brg_ttl_out *)umsg; 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(); mailbox_acknowledge();
break; break;
} }

View File

@ -9,17 +9,23 @@ services = [
("syscalls", [ ("syscalls", [
("now_init", "now_init"), ("now_init", "now_init"),
("now_save", "now_save"), ("now_save", "now_save"),
("rpc", "rpc"),
("watchdog_set", "watchdog_set"), ("watchdog_set", "watchdog_set"),
("watchdog_clear", "watchdog_clear"), ("watchdog_clear", "watchdog_clear"),
("rtio_set_o", "rtio_set_o"),
("rtio_set_oe", "rtio_set_oe"), ("rpc", "rpc"),
("rtio_set_sensitivity", "rtio_set_sensitivity"),
("rtio_get_counter", "rtio_get_counter"), ("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_init", "dds_init"),
("dds_set", "dds_set"), ("dds_set", "dds_set"),
]), ]),
("eh", [ ("eh", [
("setjmp", "exception_setjmp"), ("setjmp", "exception_setjmp"),
("push", "exception_push"), ("push", "exception_push"),

View File

@ -1,6 +1,5 @@
#include <generated/csr.h> #include <generated/csr.h>
#include "exceptions.h"
#include "rtio.h" #include "rtio.h"
void rtio_init(void) void rtio_init(void)
@ -16,55 +15,3 @@ long long int rtio_get_counter(void)
return rtio_counter_read(); 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;
}

View File

@ -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 */ #endif /* __RTIO_H */

View File

@ -3,7 +3,7 @@
#include "elf_loader.h" #include "elf_loader.h"
#include "session.h" #include "session.h"
#include "clock.h" #include "clock.h"
#include "rtio.h" #include "ttl.h"
#include "dds.h" #include "dds.h"
#include "exceptions.h" #include "exceptions.h"
#include "services.h" #include "services.h"

58
soc/runtime/ttl.c Normal file
View File

@ -0,0 +1,58 @@
#include <generated/csr.h>
#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;
}

9
soc/runtime/ttl.h Normal file
View File

@ -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 */