Skip to content

Commit 0ca42db

Browse files
committedMay 9, 2015
runtime/dds: send one FUD per command in a batch, compensate POW
1 parent ce4b573 commit 0ca42db

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed
 

Diff for: ‎soc/runtime/dds.c

+20-16
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include "dds.h"
77

88
#define DURATION_WRITE 5
9-
#define DURATION_INIT (8*DURATION_WRITE)
10-
#define DURATION_PROGRAM (8*DURATION_WRITE)
9+
#define DURATION_INIT (7*DURATION_WRITE) /* not counting FUD */
10+
#define DURATION_PROGRAM (8*DURATION_WRITE) /* not counting FUD */
1111

1212
#define DDS_WRITE(addr, data) do { \
1313
rtio_o_address_write(addr); \
@@ -25,7 +25,7 @@ void dds_init_all(void)
2525
now = rtio_get_counter() + 10000;
2626
for(i=0;i<DDS_CHANNEL_COUNT;i++) {
2727
dds_init(now, i);
28-
now += DURATION_INIT;
28+
now += DURATION_INIT + DURATION_WRITE; /* + FUD time */
2929
}
3030
while(rtio_get_counter() < now);
3131
}
@@ -50,7 +50,7 @@ void dds_init(long long int timestamp, int channel)
5050
DDS_WRITE(DDS_FUD, 0);
5151
}
5252

53-
static void dds_set_one(long long int now, long long int timestamp, int channel,
53+
static void dds_set_one(long long int now, long long int ref_time, int channel,
5454
unsigned int ftw, unsigned int pow, int phase_mode)
5555
{
5656
DDS_WRITE(DDS_GPIO, channel);
@@ -67,11 +67,19 @@ static void dds_set_one(long long int now, long long int timestamp, int channel,
6767
DDS_WRITE(DDS_FTW2, (ftw >> 16) & 0xff);
6868
DDS_WRITE(DDS_FTW3, (ftw >> 24) & 0xff);
6969

70+
/* We assume that the RTIO clock is DDS SYNCLK */
7071
if(phase_mode == PHASE_MODE_TRACKING)
71-
/* We assume that the RTIO clock is DDS SYNCLK */
72-
pow += (timestamp >> RTIO_FINE_TS_WIDTH)*ftw >> 18;
72+
pow += (ref_time >> RTIO_FINE_TS_WIDTH)*ftw >> 18;
73+
if(phase_mode != PHASE_MODE_CONTINUOUS) {
74+
long long int fud_time;
75+
76+
fud_time = now + 2*DURATION_WRITE;
77+
pow -= ((ref_time - fud_time) >> RTIO_FINE_TS_WIDTH)*ftw >> 18;
78+
}
79+
7380
DDS_WRITE(DDS_POW0, pow & 0xff);
7481
DDS_WRITE(DDS_POW1, (pow >> 8) & 0x3f);
82+
DDS_WRITE(DDS_FUD, 0);
7583
}
7684

7785
struct dds_set_params {
@@ -83,7 +91,7 @@ struct dds_set_params {
8391

8492
static int batch_mode;
8593
static int batch_count;
86-
static long long int batch_fud_time;
94+
static long long int batch_ref_time;
8795
static struct dds_set_params batch[DDS_MAX_BATCH];
8896

8997
void dds_batch_enter(long long int timestamp)
@@ -92,7 +100,7 @@ void dds_batch_enter(long long int timestamp)
92100
exception_raise(EID_DDS_BATCH_ERROR);
93101
batch_mode = 1;
94102
batch_count = 0;
95-
batch_fud_time = timestamp;
103+
batch_ref_time = timestamp;
96104
}
97105

98106
void dds_batch_exit(void)
@@ -103,13 +111,13 @@ void dds_batch_exit(void)
103111
if(!batch_mode)
104112
exception_raise(EID_DDS_BATCH_ERROR);
105113
rtio_chan_sel_write(RTIO_DDS_CHANNEL);
106-
now = batch_fud_time - batch_count*DURATION_PROGRAM;
114+
/* + FUD time */
115+
now = batch_ref_time - batch_count*(DURATION_PROGRAM + DURATION_WRITE);
107116
for(i=0;i<batch_count;i++) {
108-
dds_set_one(now, batch_fud_time,
117+
dds_set_one(now, batch_ref_time,
109118
batch[i].channel, batch[i].ftw, batch[i].pow, batch[i].phase_mode);
110-
now += DURATION_PROGRAM;
119+
now += DURATION_PROGRAM + DURATION_WRITE;
111120
}
112-
DDS_WRITE(DDS_FUD, 0);
113121
batch_mode = 0;
114122
}
115123

@@ -126,11 +134,7 @@ void dds_set(long long int timestamp, int channel,
126134
batch[batch_count].phase_mode = phase_mode;
127135
batch_count++;
128136
} else {
129-
long long int now;
130-
131137
rtio_chan_sel_write(RTIO_DDS_CHANNEL);
132138
dds_set_one(timestamp - DURATION_PROGRAM, timestamp, channel, ftw, pow, phase_mode);
133-
now = timestamp;
134-
DDS_WRITE(DDS_FUD, 0);
135139
}
136140
}

0 commit comments

Comments
 (0)
Please sign in to comment.