From 861c4a9ae523927d51de498c8787ebd1ae60acf4 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 9 Mar 2016 19:03:05 +0800 Subject: [PATCH] fix more multi-DDS-bus problems --- artiq/runtime/dds.c | 13 +++++++++---- artiq/runtime/test_mode.c | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/artiq/runtime/dds.c b/artiq/runtime/dds.c index 18cb11cec..b9b07bde7 100644 --- a/artiq/runtime/dds.c +++ b/artiq/runtime/dds.c @@ -82,7 +82,7 @@ void dds_init(long long int timestamp, int bus_channel, int channel) /* Compensation to keep phase continuity when switching from absolute or tracking * to continuous phase mode. */ -static unsigned int continuous_phase_comp[CONFIG_DDS_CHANNEL_COUNT]; +static unsigned int continuous_phase_comp[CONFIG_RTIO_DDS_COUNT][CONFIG_DDS_CHANNELS_PER_BUS]; static void dds_set_one(long long int now, long long int ref_time, int bus_channel, int channel, @@ -90,10 +90,15 @@ static void dds_set_one(long long int now, long long int ref_time, { unsigned int channel_enc; - if(channel >= CONFIG_DDS_CHANNEL_COUNT) { + if((channel < 0) || (channel >= CONFIG_DDS_CHANNELS_PER_BUS)) { core_log("Attempted to set invalid DDS channel\n"); return; } + if((bus_channel < CONFIG_RTIO_FIRST_DDS_CHANNEL) + || (bus_channel >= (CONFIG_RTIO_FIRST_DDS_CHANNEL+CONFIG_RTIO_DDS_COUNT))) { + core_log("Attempted to use invalid DDS bus\n"); + return; + } #ifdef CONFIG_DDS_ONEHOT_SEL channel_enc = 1 << channel; #else @@ -125,7 +130,7 @@ static void dds_set_one(long long int now, long long int ref_time, /* Disable autoclear phase accumulator and enables OSK. */ DDS_WRITE(DDS_CFR1L, 0x0108); #endif - pow += continuous_phase_comp[channel]; + pow += continuous_phase_comp[bus_channel-CONFIG_RTIO_FIRST_DDS_CHANNEL][channel]; } else { long long int fud_time; @@ -141,7 +146,7 @@ static void dds_set_one(long long int now, long long int ref_time, pow -= (ref_time - fud_time)*CONFIG_DDS_RTIO_CLK_RATIO*ftw >> (32-DDS_POW_WIDTH); if(phase_mode == PHASE_MODE_TRACKING) pow += ref_time*CONFIG_DDS_RTIO_CLK_RATIO*ftw >> (32-DDS_POW_WIDTH); - continuous_phase_comp[channel] = pow; + continuous_phase_comp[bus_channel-CONFIG_RTIO_FIRST_DDS_CHANNEL][channel] = pow; } #ifdef CONFIG_DDS_AD9858 diff --git a/artiq/runtime/test_mode.c b/artiq/runtime/test_mode.c index d3b8f627f..3fcb8756b 100644 --- a/artiq/runtime/test_mode.c +++ b/artiq/runtime/test_mode.c @@ -305,7 +305,7 @@ static void do_ddstest_one(unsigned int i) brg_ddswrite(bus_channel, DDS_FTWL, f & 0xffff); brg_ddswrite(bus_channel, DDS_FTWH, (f >> 16) & 0xffff); #endif - brg_ddsfud(); + brg_ddsfud(bus_channel); #ifdef CONFIG_DDS_AD9858 g = brg_ddsread(bus_channel, DDS_FTW0); g |= brg_ddsread(bus_channel, DDS_FTW1) << 8;