forked from M-Labs/artiq
1
0
Fork 0

runtime/test: implement ttlout, clksel and dds functions

This commit is contained in:
Sebastien Bourdeauducq 2015-03-12 13:14:06 +01:00
parent 3122623c6f
commit 0416da8634
3 changed files with 90 additions and 79 deletions

View File

@ -1,24 +1,9 @@
#include <generated/csr.h> #include <generated/csr.h>
#include <hw/common.h>
#include <stdio.h> #include <stdio.h>
#include "rtio.h" #include "rtio.h"
#include "dds.h" #include "dds.h"
#define DDS_FTW0 0x0a
#define DDS_FTW1 0x0b
#define DDS_FTW2 0x0c
#define DDS_FTW3 0x0d
#define DDS_POW0 0x0e
#define DDS_POW1 0x0f
#define DDS_GPIO 0x41
#define DDS_READ(addr) \
MMPTR(0xb0000000 + (addr)*4)
#define DDS_WRITE(addr, data) \
MMPTR(0xb0000000 + (addr)*4) = data
void dds_init(void) void dds_init(void)
{ {
int i; int i;

View File

@ -1,6 +1,22 @@
#ifndef __DDS_H #ifndef __DDS_H
#define __DDS_H #define __DDS_H
#include <hw/common.h>
#define DDS_READ(addr) \
MMPTR(0xb0000000 + (addr)*4)
#define DDS_WRITE(addr, data) \
MMPTR(0xb0000000 + (addr)*4) = data
#define DDS_FTW0 0x0a
#define DDS_FTW1 0x0b
#define DDS_FTW2 0x0c
#define DDS_FTW3 0x0d
#define DDS_POW0 0x0e
#define DDS_POW1 0x0f
#define DDS_GPIO 0x41
void dds_init(void); void dds_init(void);
void dds_phase_clear_en(int channel, int phase_clear_en); void dds_phase_clear_en(int channel, int phase_clear_en);
void dds_program(long long int timestamp, int channel, void dds_program(long long int timestamp, int channel,

View File

@ -8,6 +8,8 @@
#include <console.h> #include <console.h>
#include "test_mode.h" #include "test_mode.h"
#include "rtio.h"
#include "dds.h"
static void leds(char *value) static void leds(char *value)
{ {
@ -28,22 +30,13 @@ static void leds(char *value)
leds_out_write(value2); leds_out_write(value2);
} }
#if 0 static void clksrc(char *value)
static void inputs(void)
{
int inp;
inp = test_inputs_in_read();
printf("0x%02x\n", inp);
}
static void ttlout(char *value)
{ {
char *c; char *c;
unsigned int value2; unsigned int value2;
if(*value == 0) { if(*value == 0) {
printf("ttlout <value>\n"); printf("clksrc <value>\n");
return; return;
} }
@ -53,19 +46,34 @@ static void ttlout(char *value)
return; return;
} }
test_ttl_oe_write(0x3); rtiocrg_clock_sel_write(value2);
test_ttl_o_write(value2);
} }
static void ttlin(void) static void ttlout(char *n, char *value)
{ {
test_ttl_oe_write(0x0); char *c;
printf("0x%04x\n", test_ttl_i_read()); unsigned int n2, value2;
}
#define DDS_REG(x) MMPTR(0xb0000000 + 4*(x)) if((*n == 0)||(*value == 0)) {
#define DDS_FUD DDS_REG(64) printf("ttlout <n> <value>\n");
#define DDS_GPIO DDS_REG(65) return;
}
n2 = strtoul(n, &c, 0);
if(*c != 0) {
printf("incorrect channel\n");
return;
}
value2 = strtoul(value, &c, 0);
if(*c != 0) {
printf("incorrect value\n");
return;
}
rtio_init();
rtio_oe(n2, 1);
rtio_set(rtio_get_counter() + 8000, n2, value2);
}
static void ddssel(char *n) static void ddssel(char *n)
{ {
@ -79,11 +87,11 @@ static void ddssel(char *n)
n2 = strtoul(n, &c, 0); n2 = strtoul(n, &c, 0);
if(*c != 0) { if(*c != 0) {
printf("incorrect number\n"); printf("incorrect channel\n");
return; return;
} }
DDS_GPIO = n2; DDS_WRITE(DDS_GPIO, n2);
} }
static void ddsw(char *addr, char *value) static void ddsw(char *addr, char *value)
@ -107,7 +115,7 @@ static void ddsw(char *addr, char *value)
return; return;
} }
DDS_REG(addr2) = value2; DDS_WRITE(addr2, value2);
} }
static void ddsr(char *addr) static void ddsr(char *addr)
@ -126,12 +134,13 @@ static void ddsr(char *addr)
return; return;
} }
printf("0x%02x\n", DDS_REG(addr2)); printf("0x%02x\n", DDS_READ(addr2));
} }
static void ddsfud(void) static void ddsfud(void)
{ {
DDS_FUD = 0; rtio_init();
rtio_fud(rtio_get_counter() + 8000);
} }
static void ddsftw(char *n, char *ftw) static void ddsftw(char *n, char *ftw)
@ -146,7 +155,7 @@ static void ddsftw(char *n, char *ftw)
n2 = strtoul(n, &c, 0); n2 = strtoul(n, &c, 0);
if(*c != 0) { if(*c != 0) {
printf("incorrect number\n"); printf("incorrect channel\n");
return; return;
} }
ftw2 = strtoul(ftw, &c, 0); ftw2 = strtoul(ftw, &c, 0);
@ -155,27 +164,30 @@ static void ddsftw(char *n, char *ftw)
return; return;
} }
DDS_GPIO = n2; DDS_WRITE(DDS_GPIO, n2);
DDS_REG(0x0a) = ftw2 & 0xff; DDS_WRITE(DDS_FTW0, ftw2 & 0xff);
DDS_REG(0x0b) = (ftw2 >> 8) & 0xff; DDS_WRITE(DDS_FTW1, (ftw2 >> 8) & 0xff);
DDS_REG(0x0c) = (ftw2 >> 16) & 0xff; DDS_WRITE(DDS_FTW2, (ftw2 >> 16) & 0xff);
DDS_REG(0x0d) = (ftw2 >> 24) & 0xff; DDS_WRITE(DDS_FTW3, (ftw2 >> 24) & 0xff);
DDS_FUD = 0; ddsfud();
} }
static void ddsreset(void) static void ddsreset(void)
{ {
DDS_GPIO |= 1 << 7; unsigned int g;
DDS_GPIO &= ~(1 << 7);
g = DDS_READ(DDS_GPIO);
DDS_WRITE(DDS_GPIO, g | (1 << 7));
DDS_WRITE(DDS_GPIO, g);
} }
static void ddsinit(void) static void ddsinit(void)
{ {
ddsreset(); ddsreset();
DDS_REG(0x00) = 0x78; DDS_WRITE(0x00, 0x78);
DDS_REG(0x01) = 0x00; DDS_WRITE(0x01, 0x00);
DDS_REG(0x02) = 0x00; DDS_WRITE(0x02, 0x00);
DDS_REG(0x03) = 0x00; DDS_WRITE(0x03, 0x00);
ddsfud(); ddsfud();
} }
@ -188,20 +200,20 @@ static void ddstest_one(unsigned int i)
}; };
unsigned int f, g, j; unsigned int f, g, j;
DDS_GPIO = i; DDS_WRITE(DDS_GPIO, i);
ddsinit(); ddsinit();
for(j=0; j<12; j++) { for(j=0; j<12; j++) {
f = v[j]; f = v[j];
DDS_REG(0x0a) = f & 0xff; DDS_WRITE(0x0a, f & 0xff);
DDS_REG(0x0b) = (f >> 8) & 0xff; DDS_WRITE(0x0b, (f >> 8) & 0xff);
DDS_REG(0x0c) = (f >> 16) & 0xff; DDS_WRITE(0x0c, (f >> 16) & 0xff);
DDS_REG(0x0d) = (f >> 24) & 0xff; DDS_WRITE(0x0d, (f >> 24) & 0xff);
DDS_FUD = 0; ddsfud();
g = DDS_REG(0x0a); g = DDS_READ(0x0a);
g |= DDS_REG(0x0b) << 8; g |= DDS_READ(0x0b) << 8;
g |= DDS_REG(0x0c) << 16; g |= DDS_READ(0x0c) << 16;
g |= DDS_REG(0x0d) << 24; g |= DDS_READ(0x0d) << 24;
if(g != f) if(g != f)
printf("readback fail on DDS %d, 0x%08x != 0x%08x\n", i, g, f); printf("readback fail on DDS %d, 0x%08x != 0x%08x\n", i, g, f);
} }
@ -225,25 +237,23 @@ static void ddstest(char *n)
} }
} }
} }
#endif
static void help(void) static void help(void)
{ {
puts("ARTIQ DDS/TTL Tester"); puts("ARTIQ DDS/TTL Tester");
puts("Available commands:"); puts("Available commands:");
puts("help - this message"); puts("help - this message");
puts("inputs - read inputs"); puts("clksrc <n> - select RTIO clock source");
puts("ttlout <n> - output ttl"); puts("ttlout <n> <v> - output TTL");
puts("ttlin - read ttl"); puts("ddssel <n> - select a DDS");
puts("ddssel <n> - select a dds"); puts("ddsinit - reset, config, FUD DDS");
puts("ddsinit - reset, cfr, fud dds"); puts("ddsreset - reset DDS");
puts("ddsreset - reset dds"); puts("ddsw <a> <d> - write to DDS register");
puts("ddsw <a> <d> - write to dds register"); puts("ddsr <a> - read DDS register");
puts("ddsr <a> - read dds register");
puts("ddsfud - pulse FUD"); puts("ddsfud - pulse FUD");
puts("ddsftw <n> <d> - write FTW"); puts("ddsftw <n> <d> - write FTW");
puts("ddstest <n> - perform test sequence on dds"); puts("ddstest <n> - perform test sequence on DDS");
puts("leds <n> - set leds"); puts("leds <n> - set LEDs");
} }
static void readstr(char *s, int size) static void readstr(char *s, int size)
@ -303,10 +313,10 @@ static void do_command(char *c)
if(strcmp(token, "help") == 0) help(); if(strcmp(token, "help") == 0) help();
else if(strcmp(token, "leds") == 0) leds(get_token(&c)); else if(strcmp(token, "leds") == 0) leds(get_token(&c));
/*
else if(strcmp(token, "inputs") == 0) inputs(); else if(strcmp(token, "clksrc") == 0) clksrc(get_token(&c));
else if(strcmp(token, "ttlout") == 0) ttlout(get_token(&c));
else if(strcmp(token, "ttlin") == 0) ttlin(); else if(strcmp(token, "ttlout") == 0) ttlout(get_token(&c), get_token(&c));
else if(strcmp(token, "ddssel") == 0) ddssel(get_token(&c)); else if(strcmp(token, "ddssel") == 0) ddssel(get_token(&c));
else if(strcmp(token, "ddsw") == 0) ddsw(get_token(&c), get_token(&c)); else if(strcmp(token, "ddsw") == 0) ddsw(get_token(&c), get_token(&c));
@ -315,7 +325,7 @@ static void do_command(char *c)
else if(strcmp(token, "ddsinit") == 0) ddsinit(); else if(strcmp(token, "ddsinit") == 0) ddsinit();
else if(strcmp(token, "ddsfud") == 0) ddsfud(); else if(strcmp(token, "ddsfud") == 0) ddsfud();
else if(strcmp(token, "ddsftw") == 0) ddsftw(get_token(&c), get_token(&c)); else if(strcmp(token, "ddsftw") == 0) ddsftw(get_token(&c), get_token(&c));
else if(strcmp(token, "ddstest") == 0) ddstest(get_token(&c));*/ else if(strcmp(token, "ddstest") == 0) ddstest(get_token(&c));
else if(strcmp(token, "") != 0) else if(strcmp(token, "") != 0)
printf("Command not found\n"); printf("Command not found\n");