Skip to content

Commit 55f2fef

Browse files
committedMay 8, 2015
runtime: support DDS batches
1 parent 53c6339 commit 55f2fef

File tree

6 files changed

+74
-11
lines changed

6 files changed

+74
-11
lines changed
 

Diff for: ‎artiq/coredevice/runtime.py

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"ttl_set_sensitivity": "Iii:n",
2323
"ttl_get": "iI:I",
2424
"dds_init": "Ii:n",
25+
"dds_batch_enter": "I:n",
26+
"dds_batch_exit": "n:n",
2527
"dds_set": "Iiiii:n",
2628
}
2729

Diff for: ‎artiq/coredevice/runtime_exceptions.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
# Must be kept in sync with soc/runtime/exceptions.h
77

88
class InternalError(RuntimeException):
9-
"""Raised when the runtime encounters an internal error condition.
10-
11-
"""
9+
"""Raised when the runtime encounters an internal error condition."""
1210
eid = 1
1311

1412

@@ -21,7 +19,6 @@ class RTIOUnderflow(RuntimeException):
2119
(with respect to the event's timestamp).
2220
2321
The offending event is discarded and the RTIO core keeps operating.
24-
2522
"""
2623
eid = 3
2724

@@ -37,7 +34,6 @@ class RTIOSequenceError(RuntimeException):
3734
not larger than the previous one.
3835
3936
The offending event is discarded and the RTIO core keeps operating.
40-
4137
"""
4238
eid = 4
4339

@@ -53,14 +49,20 @@ class RTIOOverflow(RuntimeException):
5349
This does not interrupt operations further than cancelling the current
5450
read attempt and discarding some events. Reading can be reattempted after
5551
the exception is caught, and events will be partially retrieved.
56-
5752
"""
5853
eid = 5
5954

6055
def __str__(self):
6156
return "on channel {}".format(self.p0)
6257

6358

59+
class DDSBatchError(RuntimeException):
60+
"""Raised when attempting to start a DDS batch while already in a batch,
61+
or when too many commands are batched.
62+
"""
63+
eid = 6
64+
65+
6466
exception_map = {e.eid: e for e in globals().values()
6567
if inspect.isclass(e)
6668
and issubclass(e, RuntimeException)

Diff for: ‎soc/runtime/dds.c

+55-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <generated/csr.h>
22
#include <stdio.h>
33

4+
#include "exceptions.h"
45
#include "rtio.h"
56
#include "dds.h"
67

@@ -57,13 +58,62 @@ static void dds_set_one(long long int now, long long int timestamp, int channel,
5758
DDS_WRITE(DDS_POW1, (pow >> 8) & 0x3f);
5859
}
5960

60-
void dds_set(long long int timestamp, int channel,
61-
unsigned int ftw, unsigned int pow, int phase_mode)
61+
struct dds_set_params {
62+
int channel;
63+
unsigned int ftw;
64+
unsigned int pow;
65+
int phase_mode;
66+
};
67+
68+
static int batch_mode;
69+
static int batch_count;
70+
static long long int batch_fud_time;
71+
static struct dds_set_params batch[DDS_MAX_BATCH];
72+
73+
void dds_batch_enter(long long int timestamp)
74+
{
75+
if(batch_mode)
76+
exception_raise(EID_DDS_BATCH_ERROR);
77+
batch_mode = 1;
78+
batch_count = 0;
79+
batch_fud_time = timestamp;
80+
}
81+
82+
void dds_batch_exit(void)
6283
{
6384
long long int now;
85+
int i;
6486

65-
rtio_chan_sel_write(RTIO_DDS_CHANNEL);
66-
dds_set_one(timestamp - DURATION_PROGRAM, timestamp, channel, ftw, pow, phase_mode);
67-
now = timestamp;
87+
if(!batch_mode)
88+
exception_raise(EID_DDS_BATCH_ERROR);
89+
now = batch_fud_time - batch_count*DURATION_PROGRAM;
90+
for(i=0;i<batch_count;i++) {
91+
dds_set_one(now, batch_fud_time,
92+
batch[i].channel, batch[i].ftw, batch[i].pow, batch[i].phase_mode);
93+
now += DURATION_PROGRAM;
94+
}
6895
DDS_WRITE(DDS_FUD, 0);
96+
batch_mode = 0;
97+
}
98+
99+
void dds_set(long long int timestamp, int channel,
100+
unsigned int ftw, unsigned int pow, int phase_mode)
101+
{
102+
if(batch_mode) {
103+
if(batch_count >= DDS_MAX_BATCH)
104+
exception_raise(EID_DDS_BATCH_ERROR);
105+
/* timestamp parameter ignored (determined by batch) */
106+
batch[batch_count].channel = channel;
107+
batch[batch_count].ftw = ftw;
108+
batch[batch_count].pow = pow;
109+
batch[batch_count].phase_mode = phase_mode;
110+
batch_count++;
111+
} else {
112+
long long int now;
113+
114+
rtio_chan_sel_write(RTIO_DDS_CHANNEL);
115+
dds_set_one(timestamp - DURATION_PROGRAM, timestamp, channel, ftw, pow, phase_mode);
116+
now = timestamp;
117+
DDS_WRITE(DDS_FUD, 0);
118+
}
69119
}

Diff for: ‎soc/runtime/dds.h

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include <hw/common.h>
55
#include <generated/mem.h>
66

7+
/* Maximum number of commands in a batch */
8+
#define DDS_MAX_BATCH 16
9+
10+
/* DDS core registers */
711
#define DDS_FTW0 0x0a
812
#define DDS_FTW1 0x0b
913
#define DDS_FTW2 0x0c
@@ -20,6 +24,8 @@ enum {
2024
};
2125

2226
void dds_init(long long int timestamp, int channel);
27+
void dds_batch_enter(long long int timestamp);
28+
void dds_batch_exit(void);
2329
void dds_set(long long int timestamp, int channel,
2430
unsigned int ftw, unsigned int pow, int phase_mode);
2531

Diff for: ‎soc/runtime/exceptions.h

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum {
88
EID_RTIO_UNDERFLOW = 3,
99
EID_RTIO_SEQUENCE_ERROR = 4,
1010
EID_RTIO_OVERFLOW = 5,
11+
EID_DDS_BATCH_ERROR = 6,
1112
};
1213

1314
int exception_setjmp(void *jb) __attribute__((returns_twice));

Diff for: ‎soc/runtime/gen_service_table.py

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
("ttl_get", "ttl_get"),
2424

2525
("dds_init", "dds_init"),
26+
("dds_batch_enter", "dds_batch_enter"),
27+
("dds_batch_exit", "dds_batch_exit"),
2628
("dds_set", "dds_set"),
2729
]),
2830

0 commit comments

Comments
 (0)
Please sign in to comment.