Skip to content

Commit

Permalink
runtime: break ttl-specific functions from rtio
Browse files Browse the repository at this point in the history
sbourdeauducq committed May 8, 2015
1 parent a36c51e commit 53c6339
Showing 10 changed files with 94 additions and 78 deletions.
8 changes: 4 additions & 4 deletions artiq/coredevice/runtime.py
Original file line number Diff line number Diff line change
@@ -16,11 +16,11 @@
"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",
}
14 changes: 7 additions & 7 deletions artiq/coredevice/ttl.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ def set_o(self, t, value):
: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 @@ def build(self):

@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 @@ def build(self):

@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 @@ def input(self):

@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 @@ def pulse(self, duration):

@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 @@ def count(self):
"""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 @@ def timestamp(self):
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))
2 changes: 1 addition & 1 deletion soc/runtime/Makefile
Original file line number Diff line number Diff line change
@@ -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

5 changes: 3 additions & 2 deletions soc/runtime/bridge.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "mailbox.h"
#include "messages.h"
#include "rtio.h"
#include "ttl.h"
#include "dds.h"
#include "bridge.h"

@@ -45,15 +46,15 @@ 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;
}
case MESSAGE_TYPE_BRG_TTL_O: {
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;
}
16 changes: 11 additions & 5 deletions soc/runtime/gen_service_table.py
Original file line number Diff line number Diff line change
@@ -9,17 +9,23 @@
("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"),
53 changes: 0 additions & 53 deletions soc/runtime/rtio.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <generated/csr.h>

#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;
}
5 changes: 0 additions & 5 deletions soc/runtime/rtio.h
Original file line number Diff line number Diff line change
@@ -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 */
2 changes: 1 addition & 1 deletion soc/runtime/services.c
Original file line number Diff line number Diff line change
@@ -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"
58 changes: 58 additions & 0 deletions soc/runtime/ttl.c
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions soc/runtime/ttl.h
Original file line number Diff line number Diff line change
@@ -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 */

0 comments on commit 53c6339

Please sign in to comment.