Skip to content

Commit ce4b573

Browse files
committedMay 9, 2015
runtime: reset all DDSes upon startup
1 parent 1ceb06f commit ce4b573

File tree

13 files changed

+208
-144
lines changed

13 files changed

+208
-144
lines changed
 

Diff for: ‎artiq/coredevice/dds.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def ftw_to_frequency(self, ftw):
7979

8080
@kernel
8181
def init(self):
82-
"""Resets and initializes the DDS channel."""
82+
"""Resets and initializes the DDS channel.
83+
84+
The runtime does this for all channels upon core device startup."""
8385
syscall("dds_init", time_to_cycles(now()), self.channel)
8486

8587
@kernel

Diff for: ‎soc/runtime/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include $(MSCDIR)/software/common.mak
22

3-
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
3+
OBJECTS := isr.o flash_storage.o clock.o elf_loader.o services.o session.o log.o test_mode.o kloader.o bridge_ctl.o mailbox.o ksupport_data.o kserver.o main.o
44
OBJECTS_KSUPPORT := ksupport.o exception_jmp.o exceptions.o mailbox.o bridge.o rtio.o ttl.o dds.o
55

66
CFLAGS += -Ilwip/src/include -Iliblwip

Diff for: ‎soc/runtime/bridge.c

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ void bridge_main(void)
5858
mailbox_acknowledge();
5959
break;
6060
}
61+
case MESSAGE_TYPE_BRG_DDS_INITALL:
62+
dds_init_all();
63+
mailbox_acknowledge();
64+
break;
6165
case MESSAGE_TYPE_BRG_DDS_SEL: {
6266
struct msg_brg_dds_sel *msg;
6367

Diff for: ‎soc/runtime/bridge_ctl.c

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#include <stdio.h>
2+
3+
#include "kloader.h"
4+
#include "mailbox.h"
5+
#include "messages.h"
6+
7+
void brg_start(void)
8+
{
9+
struct msg_base *umsg;
10+
11+
kloader_start_bridge();
12+
13+
while(1) {
14+
umsg = mailbox_wait_and_receive();
15+
if(umsg->type == MESSAGE_TYPE_BRG_READY) {
16+
mailbox_acknowledge();
17+
break;
18+
} else {
19+
printf("Warning: unexpected message %d from AMP bridge\n", umsg->type);
20+
mailbox_acknowledge();
21+
}
22+
}
23+
}
24+
25+
void brg_stop(void)
26+
{
27+
kloader_stop();
28+
}
29+
30+
void brg_ttloe(int n, int value)
31+
{
32+
struct msg_brg_ttl_out msg;
33+
34+
msg.type = MESSAGE_TYPE_BRG_TTL_OE;
35+
msg.channel = n;
36+
msg.value = value;
37+
mailbox_send_and_wait(&msg);
38+
}
39+
40+
void brg_ttlo(int n, int value)
41+
{
42+
struct msg_brg_ttl_out msg;
43+
44+
msg.type = MESSAGE_TYPE_BRG_TTL_O;
45+
msg.channel = n;
46+
msg.value = value;
47+
mailbox_send_and_wait(&msg);
48+
}
49+
50+
void brg_ddsinitall(void)
51+
{
52+
struct msg_base msg;
53+
54+
msg.type = MESSAGE_TYPE_BRG_DDS_INITALL;
55+
mailbox_send_and_wait(&msg);
56+
}
57+
58+
void brg_ddssel(int channel)
59+
{
60+
struct msg_brg_dds_sel msg;
61+
62+
msg.type = MESSAGE_TYPE_BRG_DDS_SEL;
63+
msg.channel = channel;
64+
mailbox_send_and_wait(&msg);
65+
}
66+
67+
void brg_ddsreset(void)
68+
{
69+
struct msg_base msg;
70+
71+
msg.type = MESSAGE_TYPE_BRG_DDS_RESET;
72+
mailbox_send_and_wait(&msg);
73+
}
74+
75+
unsigned int brg_ddsread(unsigned int address)
76+
{
77+
struct msg_brg_dds_read_request msg;
78+
struct msg_brg_dds_read_reply *rmsg;
79+
unsigned int r;
80+
81+
msg.type = MESSAGE_TYPE_BRG_DDS_READ_REQUEST;
82+
msg.address = address;
83+
mailbox_send(&msg);
84+
while(1) {
85+
rmsg = mailbox_wait_and_receive();
86+
if(rmsg->type == MESSAGE_TYPE_BRG_DDS_READ_REPLY) {
87+
r = rmsg->data;
88+
mailbox_acknowledge();
89+
return r;
90+
} else {
91+
printf("Warning: unexpected message %d from AMP bridge\n", rmsg->type);
92+
mailbox_acknowledge();
93+
}
94+
}
95+
}
96+
97+
void brg_ddswrite(unsigned int address, unsigned int data)
98+
{
99+
struct msg_brg_dds_write msg;
100+
101+
msg.type = MESSAGE_TYPE_BRG_DDS_WRITE;
102+
msg.address = address;
103+
msg.data = data;
104+
mailbox_send_and_wait(&msg);
105+
}
106+
107+
void brg_ddsfud(void)
108+
{
109+
struct msg_base msg;
110+
111+
msg.type = MESSAGE_TYPE_BRG_DDS_FUD;
112+
mailbox_send_and_wait(&msg);
113+
}

Diff for: ‎soc/runtime/bridge_ctl.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef __BRIDGE_CTL_H
2+
#define __BRIDGE_CTL_H
3+
4+
void brg_start(void);
5+
void brg_stop(void);
6+
7+
void brg_ttloe(int n, int value);
8+
void brg_ttlo(int n, int value);
9+
10+
void brg_ddsinitall(void);
11+
void brg_ddssel(int channel);
12+
void brg_ddsreset(void);
13+
unsigned int brg_ddsread(unsigned int address);
14+
void brg_ddswrite(unsigned int address, unsigned int data);
15+
void brg_ddsfud(void);
16+
17+
#endif /* __BRIDGE_CTL_H */

Diff for: ‎soc/runtime/dds.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "dds.h"
77

88
#define DURATION_WRITE 5
9+
#define DURATION_INIT (8*DURATION_WRITE)
910
#define DURATION_PROGRAM (8*DURATION_WRITE)
1011

1112
#define DDS_WRITE(addr, data) do { \
@@ -16,13 +17,26 @@
1617
now += DURATION_WRITE; \
1718
} while(0)
1819

20+
void dds_init_all(void)
21+
{
22+
int i;
23+
long long int now;
24+
25+
now = rtio_get_counter() + 10000;
26+
for(i=0;i<DDS_CHANNEL_COUNT;i++) {
27+
dds_init(now, i);
28+
now += DURATION_INIT;
29+
}
30+
while(rtio_get_counter() < now);
31+
}
32+
1933
void dds_init(long long int timestamp, int channel)
2034
{
2135
long long int now;
2236

2337
rtio_chan_sel_write(RTIO_DDS_CHANNEL);
2438

25-
now = timestamp - 7*DURATION_WRITE;
39+
now = timestamp - DURATION_INIT;
2640

2741
DDS_WRITE(DDS_GPIO, channel);
2842
DDS_WRITE(DDS_GPIO, channel | (1 << 7));
@@ -32,6 +46,8 @@ void dds_init(long long int timestamp, int channel)
3246
DDS_WRITE(0x01, 0x00);
3347
DDS_WRITE(0x02, 0x00);
3448
DDS_WRITE(0x03, 0x00);
49+
50+
DDS_WRITE(DDS_FUD, 0);
3551
}
3652

3753
static void dds_set_one(long long int now, long long int timestamp, int channel,

Diff for: ‎soc/runtime/dds.h

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

7+
/* Number of DDS channels to initialize */
8+
#define DDS_CHANNEL_COUNT 8
9+
710
/* Maximum number of commands in a batch */
811
#define DDS_MAX_BATCH 16
912

@@ -23,6 +26,7 @@ enum {
2326
PHASE_MODE_TRACKING = 2
2427
};
2528

29+
void dds_init_all(void);
2630
void dds_init(long long int timestamp, int channel);
2731
void dds_batch_enter(long long int timestamp);
2832
void dds_batch_exit(void);

Diff for: ‎soc/runtime/kloader.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void kloader_start_idle_kernel(void)
117117
#endif
118118
}
119119

120-
void kloader_stop_kernel(void)
120+
void kloader_stop(void)
121121
{
122122
kernel_cpu_reset_write(1);
123123
mailbox_acknowledge();

Diff for: ‎soc/runtime/kloader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ kernel_function kloader_find(const char *name);
1212
void kloader_start_bridge(void);
1313
void kloader_start_idle_kernel(void);
1414
void kloader_start_user_kernel(kernel_function k);
15-
void kloader_stop_kernel(void);
15+
void kloader_stop(void);
1616

1717
#endif /* __KLOADER_H */

Diff for: ‎soc/runtime/main.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,22 @@
2121
#include <lwip/timers.h>
2222
#endif
2323

24+
#include "bridge_ctl.h"
25+
#include "kloader.h"
2426
#include "flash_storage.h"
2527
#include "clock.h"
2628
#include "test_mode.h"
2729
#include "kserver.h"
2830
#include "session.h"
2931

32+
static void common_init(void)
33+
{
34+
clock_init();
35+
brg_start();
36+
brg_ddsinitall();
37+
kloader_stop();
38+
}
39+
3040
#ifdef CSR_ETHMAC_BASE
3141

3242
u32_t sys_now(void)
@@ -127,7 +137,6 @@ static void network_init(void)
127137
static void regular_main(void)
128138
{
129139
puts("Accepting sessions on Ethernet.");
130-
clock_init();
131140
network_init();
132141
kserver_init();
133142

@@ -186,7 +195,6 @@ static void serial_service(void)
186195
static void regular_main(void)
187196
{
188197
puts("Accepting sessions on serial link.");
189-
clock_init();
190198

191199
/* Open the session for the serial control. */
192200
session_start();
@@ -246,6 +254,7 @@ int main(void)
246254
test_main();
247255
} else {
248256
puts("Entering regular mode.");
257+
common_init();
249258
regular_main();
250259
}
251260
return 0;

Diff for: ‎soc/runtime/messages.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enum {
1919
MESSAGE_TYPE_BRG_READY,
2020
MESSAGE_TYPE_BRG_TTL_O,
2121
MESSAGE_TYPE_BRG_TTL_OE,
22+
MESSAGE_TYPE_BRG_DDS_INITALL,
2223
MESSAGE_TYPE_BRG_DDS_SEL,
2324
MESSAGE_TYPE_BRG_DDS_RESET,
2425
MESSAGE_TYPE_BRG_DDS_READ_REQUEST,

Diff for: ‎soc/runtime/session.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ void session_start(void)
6767
{
6868
buffer_in_index = 0;
6969
memset(&buffer_out[4], 0, 4);
70-
kloader_stop_kernel();
70+
kloader_stop();
7171
user_kernel_state = USER_KERNEL_NONE;
7272
}
7373

7474
void session_end(void)
7575
{
76-
kloader_stop_kernel();
76+
kloader_stop();
7777
kloader_start_idle_kernel();
7878
}
7979

@@ -417,7 +417,7 @@ static int process_kmsg(struct msg_base *umsg)
417417
buffer_out[8] = REMOTEMSG_TYPE_KERNEL_FINISHED;
418418
submit_output(9);
419419

420-
kloader_stop_kernel();
420+
kloader_stop();
421421
user_kernel_state = USER_KERNEL_LOADED;
422422
mailbox_acknowledge();
423423
break;
@@ -429,7 +429,7 @@ static int process_kmsg(struct msg_base *umsg)
429429
memcpy(&buffer_out[13], msg->eparams, 3*8);
430430
submit_output(9+4+3*8);
431431

432-
kloader_stop_kernel();
432+
kloader_stop();
433433
user_kernel_state = USER_KERNEL_LOADED;
434434
mailbox_acknowledge();
435435
break;

Diff for: ‎soc/runtime/test_mode.c

+31-133
Original file line numberDiff line numberDiff line change
@@ -7,113 +7,11 @@
77
#include <generated/csr.h>
88
#include <console.h>
99

10-
#include "kloader.h"
11-
#include "mailbox.h"
12-
#include "messages.h"
1310
#include "dds.h"
1411
#include "flash_storage.h"
12+
#include "bridge_ctl.h"
1513
#include "test_mode.h"
1614

17-
/* bridge access functions */
18-
19-
static void amp_bridge_init(void)
20-
{
21-
struct msg_base *umsg;
22-
23-
kloader_start_bridge();
24-
25-
while(1) {
26-
umsg = mailbox_wait_and_receive();
27-
if(umsg->type == MESSAGE_TYPE_BRG_READY) {
28-
printf("AMP bridge ready\n");
29-
mailbox_acknowledge();
30-
break;
31-
} else {
32-
printf("Warning: unexpected message %d from AMP bridge\n", umsg->type);
33-
mailbox_acknowledge();
34-
}
35-
}
36-
}
37-
38-
static void p_ttloe(int n, int value)
39-
{
40-
struct msg_brg_ttl_out msg;
41-
42-
msg.type = MESSAGE_TYPE_BRG_TTL_OE;
43-
msg.channel = n;
44-
msg.value = value;
45-
mailbox_send_and_wait(&msg);
46-
}
47-
48-
static void p_ttlo(int n, int value)
49-
{
50-
struct msg_brg_ttl_out msg;
51-
52-
msg.type = MESSAGE_TYPE_BRG_TTL_O;
53-
msg.channel = n;
54-
msg.value = value;
55-
mailbox_send_and_wait(&msg);
56-
}
57-
58-
static void p_ddssel(int channel)
59-
{
60-
struct msg_brg_dds_sel msg;
61-
62-
msg.type = MESSAGE_TYPE_BRG_DDS_SEL;
63-
msg.channel = channel;
64-
mailbox_send_and_wait(&msg);
65-
}
66-
67-
static void p_ddsreset(void)
68-
{
69-
struct msg_base msg;
70-
71-
msg.type = MESSAGE_TYPE_BRG_DDS_RESET;
72-
mailbox_send_and_wait(&msg);
73-
}
74-
75-
static unsigned int p_ddsread(unsigned int address)
76-
{
77-
struct msg_brg_dds_read_request msg;
78-
struct msg_brg_dds_read_reply *rmsg;
79-
unsigned int r;
80-
81-
msg.type = MESSAGE_TYPE_BRG_DDS_READ_REQUEST;
82-
msg.address = address;
83-
mailbox_send(&msg);
84-
while(1) {
85-
rmsg = mailbox_wait_and_receive();
86-
if(rmsg->type == MESSAGE_TYPE_BRG_DDS_READ_REPLY) {
87-
r = rmsg->data;
88-
mailbox_acknowledge();
89-
return r;
90-
} else {
91-
printf("Warning: unexpected message %d from AMP bridge\n", rmsg->type);
92-
mailbox_acknowledge();
93-
}
94-
}
95-
}
96-
97-
static void p_ddswrite(unsigned int address, unsigned int data)
98-
{
99-
struct msg_brg_dds_write msg;
100-
101-
msg.type = MESSAGE_TYPE_BRG_DDS_WRITE;
102-
msg.address = address;
103-
msg.data = data;
104-
mailbox_send_and_wait(&msg);
105-
}
106-
107-
static void p_ddsfud(void)
108-
{
109-
struct msg_base msg;
110-
111-
msg.type = MESSAGE_TYPE_BRG_DDS_FUD;
112-
mailbox_send_and_wait(&msg);
113-
}
114-
115-
/* */
116-
11715
static void leds(char *value)
11816
{
11917
char *c;
@@ -173,7 +71,7 @@ static void ttloe(char *n, char *value)
17371
return;
17472
}
17573

176-
p_ttloe(n2, value2);
74+
brg_ttloe(n2, value2);
17775
}
17876

17977
static void ttlo(char *n, char *value)
@@ -197,7 +95,7 @@ static void ttlo(char *n, char *value)
19795
return;
19896
}
19997

200-
p_ttlo(n2, value2);
98+
brg_ttlo(n2, value2);
20199
}
202100

203101
static void ddssel(char *n)
@@ -216,7 +114,7 @@ static void ddssel(char *n)
216114
return;
217115
}
218116

219-
p_ddssel(n2);
117+
brg_ddssel(n2);
220118
}
221119

222120
static void ddsw(char *addr, char *value)
@@ -240,7 +138,7 @@ static void ddsw(char *addr, char *value)
240138
return;
241139
}
242140

243-
p_ddswrite(addr2, value2);
141+
brg_ddswrite(addr2, value2);
244142
}
245143

246144
static void ddsr(char *addr)
@@ -259,12 +157,12 @@ static void ddsr(char *addr)
259157
return;
260158
}
261159

262-
printf("0x%02x\n", p_ddsread(addr2));
160+
printf("0x%02x\n", brg_ddsread(addr2));
263161
}
264162

265163
static void ddsfud(void)
266164
{
267-
p_ddsfud();
165+
brg_ddsfud();
268166
}
269167

270168
static void ddsftw(char *n, char *ftw)
@@ -288,27 +186,27 @@ static void ddsftw(char *n, char *ftw)
288186
return;
289187
}
290188

291-
p_ddssel(n2);
292-
p_ddswrite(DDS_FTW0, ftw2 & 0xff);
293-
p_ddswrite(DDS_FTW1, (ftw2 >> 8) & 0xff);
294-
p_ddswrite(DDS_FTW2, (ftw2 >> 16) & 0xff);
295-
p_ddswrite(DDS_FTW3, (ftw2 >> 24) & 0xff);
296-
p_ddsfud();
189+
brg_ddssel(n2);
190+
brg_ddswrite(DDS_FTW0, ftw2 & 0xff);
191+
brg_ddswrite(DDS_FTW1, (ftw2 >> 8) & 0xff);
192+
brg_ddswrite(DDS_FTW2, (ftw2 >> 16) & 0xff);
193+
brg_ddswrite(DDS_FTW3, (ftw2 >> 24) & 0xff);
194+
brg_ddsfud();
297195
}
298196

299197
static void ddsreset(void)
300198
{
301-
p_ddsreset();
199+
brg_ddsreset();
302200
}
303201

304202
static void ddsinit(void)
305203
{
306-
p_ddsreset();
307-
p_ddswrite(0x00, 0x78);
308-
p_ddswrite(0x01, 0x00);
309-
p_ddswrite(0x02, 0x00);
310-
p_ddswrite(0x03, 0x00);
311-
p_ddsfud();
204+
brg_ddsreset();
205+
brg_ddswrite(0x00, 0x78);
206+
brg_ddswrite(0x01, 0x00);
207+
brg_ddswrite(0x02, 0x00);
208+
brg_ddswrite(0x03, 0x00);
209+
brg_ddsfud();
312210
}
313211

314212
static void ddstest_one(unsigned int i)
@@ -320,20 +218,20 @@ static void ddstest_one(unsigned int i)
320218
};
321219
unsigned int f, g, j;
322220

323-
p_ddssel(i);
221+
brg_ddssel(i);
324222
ddsinit();
325223

326224
for(j=0; j<12; j++) {
327225
f = v[j];
328-
p_ddswrite(0x0a, f & 0xff);
329-
p_ddswrite(0x0b, (f >> 8) & 0xff);
330-
p_ddswrite(0x0c, (f >> 16) & 0xff);
331-
p_ddswrite(0x0d, (f >> 24) & 0xff);
332-
p_ddsfud();
333-
g = p_ddsread(0x0a);
334-
g |= p_ddsread(0x0b) << 8;
335-
g |= p_ddsread(0x0c) << 16;
336-
g |= p_ddsread(0x0d) << 24;
226+
brg_ddswrite(0x0a, f & 0xff);
227+
brg_ddswrite(0x0b, (f >> 8) & 0xff);
228+
brg_ddswrite(0x0c, (f >> 16) & 0xff);
229+
brg_ddswrite(0x0d, (f >> 24) & 0xff);
230+
brg_ddsfud();
231+
g = brg_ddsread(0x0a);
232+
g |= brg_ddsread(0x0b) << 8;
233+
g |= brg_ddsread(0x0c) << 16;
234+
g |= brg_ddsread(0x0d) << 24;
337235
if(g != f)
338236
printf("readback fail on DDS %d, 0x%08x != 0x%08x\n", i, g, f);
339237
}
@@ -479,7 +377,7 @@ void test_main(void)
479377
{
480378
char buffer[64];
481379

482-
amp_bridge_init();
380+
brg_start();
483381

484382
while(1) {
485383
putsnonl("\e[1mtest>\e[0m ");

0 commit comments

Comments
 (0)
Please sign in to comment.