From 16b2d9f1776d619ced486d7f181de7d12dde14e4 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 12 Sep 2014 15:34:11 +0800 Subject: [PATCH] runtime: support real-time FUD --- artiq/devices/runtime.py | 2 +- soc/runtime/dds.c | 35 +++++++++++++++++++++++++++++++---- soc/runtime/dds.h | 2 +- soc/runtime/main.c | 2 +- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/artiq/devices/runtime.py b/artiq/devices/runtime.py index 5f84fc52e..9e55002de 100644 --- a/artiq/devices/runtime.py +++ b/artiq/devices/runtime.py @@ -12,7 +12,7 @@ _syscalls = { "rtio_set": "Iii:n", "rtio_replace": "Iii:n", "rtio_sync": "i:n", - "dds_program": "ii:n", + "dds_program": "iiI:n", } _chr_to_type = { diff --git a/soc/runtime/dds.c b/soc/runtime/dds.c index 8cfeb08ce..08aae424d 100644 --- a/soc/runtime/dds.c +++ b/soc/runtime/dds.c @@ -1,4 +1,6 @@ +#include #include +#include #include "dds.h" @@ -6,7 +8,6 @@ #define DDS_FTW1 0x0b #define DDS_FTW2 0x0c #define DDS_FTW3 0x0d -#define DDS_FUD 0x40 #define DDS_GPIO 0x41 #define DDS_READ(addr) \ @@ -15,6 +16,30 @@ #define DDS_WRITE(addr, data) \ MMPTR(0xb0000000 + (addr)*4) = data +#define RTIO_FUD_CHANNEL 4 + +static void fud(long long int fud_time) +{ + 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; + } + rtio_o_timestamp_write(fud_time); + rtio_o_value_write(1); + rtio_o_we_write(1); + rtio_o_timestamp_write(fud_time+3*8); + rtio_o_value_write(0); + rtio_o_we_write(1); +} + +static void fud_sync(void) +{ + rtio_chan_sel_write(RTIO_FUD_CHANNEL); + while(rtio_o_level_read() != 0); +} + void dds_init(void) { int i; @@ -26,16 +51,18 @@ void dds_init(void) DDS_WRITE(0x01, 0x00); DDS_WRITE(0x02, 0x00); DDS_WRITE(0x03, 0x00); - DDS_WRITE(DDS_FUD, 0); + fud(-1); + fud_sync(); } } -void dds_program(int channel, int ftw) +void dds_program(int channel, int ftw, long long int fud_time) { + fud_sync(); DDS_WRITE(DDS_GPIO, channel); DDS_WRITE(DDS_FTW0, ftw & 0xff); DDS_WRITE(DDS_FTW1, (ftw >> 8) & 0xff); DDS_WRITE(DDS_FTW2, (ftw >> 16) & 0xff); DDS_WRITE(DDS_FTW3, (ftw >> 24) & 0xff); - DDS_WRITE(DDS_FUD, 0); + fud(fud_time); } diff --git a/soc/runtime/dds.h b/soc/runtime/dds.h index 91093b03b..78fa4e307 100644 --- a/soc/runtime/dds.h +++ b/soc/runtime/dds.h @@ -2,6 +2,6 @@ #define __DDS_H void dds_init(void); -void dds_program(int channel, int ftw); +void dds_program(int channel, int ftw, long long int fud_time); #endif /* __DDS_H */ diff --git a/soc/runtime/main.c b/soc/runtime/main.c index 49ba853d2..8250bfcd4 100644 --- a/soc/runtime/main.c +++ b/soc/runtime/main.c @@ -29,8 +29,8 @@ int main(void) if(length > 0) { k = load_elf(resolve_symbol, "run", kbuf, length, kcode, sizeof(kcode)); if(k != NULL) { - rtio_init(); dds_init(); + rtio_init(); flush_cpu_icache(); k(); kernel_finished();