mirror of https://github.com/m-labs/artiq.git
runtime: remove "test mode" functionality.
This commit is contained in:
parent
3263def5c8
commit
1e392cca64
|
@ -4,10 +4,10 @@ include $(MISOC_DIRECTORY)/software/common.mak
|
|||
PYTHON ?= python3.5
|
||||
|
||||
OBJECTS := isr.o clock.o rtiocrg.o flash_storage.o mailbox.o \
|
||||
session.o log.o analyzer.o moninj.o net_server.o bridge_ctl.o \
|
||||
ksupport_data.o kloader.o test_mode.o main.o
|
||||
session.o log.o analyzer.o moninj.o net_server.o \
|
||||
ksupport_data.o kloader.o main.o
|
||||
OBJECTS_KSUPPORT := ksupport.o artiq_personality.o mailbox.o \
|
||||
bridge.o rtio.o dds.o i2c.o
|
||||
rtio.o dds.o i2c.o
|
||||
|
||||
CFLAGS += -I$(LIBALLOC_DIRECTORY) \
|
||||
-I$(MISOC_DIRECTORY)/software/include/dyld \
|
||||
|
|
|
@ -1,131 +0,0 @@
|
|||
#include "mailbox.h"
|
||||
#include "messages.h"
|
||||
#include "rtio.h"
|
||||
#include "ttl.h"
|
||||
#include "dds.h"
|
||||
#include "bridge.h"
|
||||
|
||||
#define TIME_BUFFER (8000 << CONFIG_RTIO_FINE_TS_WIDTH)
|
||||
|
||||
static void rtio_output_blind(int channel, int addr, int data)
|
||||
{
|
||||
rtio_chan_sel_write(channel);
|
||||
#ifdef CSR_RTIO_O_ADDRESS_ADDR
|
||||
rtio_o_address_write(addr);
|
||||
#endif
|
||||
rtio_o_data_write(data);
|
||||
rtio_o_timestamp_write(rtio_get_counter() + TIME_BUFFER);
|
||||
rtio_o_we_write(1);
|
||||
}
|
||||
|
||||
#if ((defined CONFIG_RTIO_DDS_COUNT) && (CONFIG_RTIO_DDS_COUNT > 0))
|
||||
static void dds_write(int bus_channel, int addr, int data)
|
||||
{
|
||||
rtio_output_blind(bus_channel, addr, data);
|
||||
}
|
||||
|
||||
static int dds_read(int bus_channel, int addr)
|
||||
{
|
||||
int r;
|
||||
|
||||
#ifdef CONFIG_DDS_AD9858
|
||||
#define DDS_READ_FLAG 128
|
||||
#endif
|
||||
#ifdef CONFIG_DDS_AD9914
|
||||
#define DDS_READ_FLAG 256
|
||||
#endif
|
||||
dds_write(bus_channel, addr | DDS_READ_FLAG, 0);
|
||||
while(rtio_i_status_read() & RTIO_I_STATUS_EMPTY);
|
||||
r = rtio_i_data_read();
|
||||
rtio_i_re_write(1);
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void send_ready(void)
|
||||
{
|
||||
struct msg_base msg;
|
||||
|
||||
msg.type = MESSAGE_TYPE_BRG_READY;
|
||||
mailbox_send_and_wait(&msg);
|
||||
}
|
||||
|
||||
void bridge_main(void)
|
||||
{
|
||||
struct msg_base *umsg;
|
||||
|
||||
rtio_init();
|
||||
send_ready();
|
||||
while(1) {
|
||||
umsg = mailbox_wait_and_receive();
|
||||
switch(umsg->type) {
|
||||
case MESSAGE_TYPE_BRG_TTL_OE: {
|
||||
struct msg_brg_ttl_out *msg;
|
||||
|
||||
msg = (struct msg_brg_ttl_out *)umsg;
|
||||
rtio_output_blind(msg->channel, TTL_OE_ADDR, msg->value);
|
||||
mailbox_acknowledge();
|
||||
break;
|
||||
}
|
||||
case MESSAGE_TYPE_BRG_TTL_O: {
|
||||
struct msg_brg_ttl_out *msg;
|
||||
|
||||
msg = (struct msg_brg_ttl_out *)umsg;
|
||||
rtio_output_blind(msg->channel, TTL_O_ADDR, msg->value);
|
||||
mailbox_acknowledge();
|
||||
break;
|
||||
}
|
||||
#if ((defined CONFIG_RTIO_DDS_COUNT) && (CONFIG_RTIO_DDS_COUNT > 0))
|
||||
case MESSAGE_TYPE_BRG_DDS_SEL: {
|
||||
struct msg_brg_dds_sel *msg;
|
||||
|
||||
msg = (struct msg_brg_dds_sel *)umsg;
|
||||
dds_write(msg->bus_channel, DDS_GPIO, msg->channel << 1);
|
||||
mailbox_acknowledge();
|
||||
break;
|
||||
}
|
||||
case MESSAGE_TYPE_BRG_DDS_RESET: {
|
||||
unsigned int g;
|
||||
struct msg_brg_dds_reset *msg;
|
||||
|
||||
msg = (struct msg_brg_dds_reset *)umsg;
|
||||
g = dds_read(msg->bus_channel, DDS_GPIO);
|
||||
dds_write(msg->bus_channel, DDS_GPIO, g | 1);
|
||||
dds_write(msg->bus_channel, DDS_GPIO, g);
|
||||
|
||||
mailbox_acknowledge();
|
||||
break;
|
||||
}
|
||||
case MESSAGE_TYPE_BRG_DDS_READ_REQUEST: {
|
||||
struct msg_brg_dds_read_request *msg;
|
||||
struct msg_brg_dds_read_reply rmsg;
|
||||
|
||||
msg = (struct msg_brg_dds_read_request *)umsg;
|
||||
rmsg.type = MESSAGE_TYPE_BRG_DDS_READ_REPLY;
|
||||
rmsg.data = dds_read(msg->bus_channel, msg->address);
|
||||
mailbox_send_and_wait(&rmsg);
|
||||
break;
|
||||
}
|
||||
case MESSAGE_TYPE_BRG_DDS_WRITE: {
|
||||
struct msg_brg_dds_write *msg;
|
||||
|
||||
msg = (struct msg_brg_dds_write *)umsg;
|
||||
dds_write(msg->bus_channel, msg->address, msg->data);
|
||||
mailbox_acknowledge();
|
||||
break;
|
||||
}
|
||||
case MESSAGE_TYPE_BRG_DDS_FUD: {
|
||||
struct msg_brg_dds_fud *msg;
|
||||
|
||||
msg = (struct msg_brg_dds_fud *)umsg;
|
||||
dds_write(msg->bus_channel, DDS_FUD, 0);
|
||||
mailbox_acknowledge();
|
||||
break;
|
||||
}
|
||||
#endif /* CONFIG_RTIO_DDS_COUNT */
|
||||
default:
|
||||
mailbox_acknowledge();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef __BRIDGE_H
|
||||
#define __BRIDGE_H
|
||||
|
||||
void bridge_main(void);
|
||||
|
||||
#endif /* __BRIDGE_H */
|
|
@ -1,106 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "kloader.h"
|
||||
#include "mailbox.h"
|
||||
#include "messages.h"
|
||||
#include "bridge_ctl.h"
|
||||
|
||||
void brg_start(void)
|
||||
{
|
||||
struct msg_base *umsg;
|
||||
|
||||
kloader_start_bridge();
|
||||
|
||||
while(1) {
|
||||
umsg = mailbox_wait_and_receive();
|
||||
if(umsg->type == MESSAGE_TYPE_BRG_READY) {
|
||||
mailbox_acknowledge();
|
||||
break;
|
||||
} else {
|
||||
printf("Warning: unexpected message %d from AMP bridge\n", umsg->type);
|
||||
mailbox_acknowledge();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void brg_ttloe(int n, int value)
|
||||
{
|
||||
struct msg_brg_ttl_out msg;
|
||||
|
||||
msg.type = MESSAGE_TYPE_BRG_TTL_OE;
|
||||
msg.channel = n;
|
||||
msg.value = value;
|
||||
mailbox_send_and_wait(&msg);
|
||||
}
|
||||
|
||||
void brg_ttlo(int n, int value)
|
||||
{
|
||||
struct msg_brg_ttl_out msg;
|
||||
|
||||
msg.type = MESSAGE_TYPE_BRG_TTL_O;
|
||||
msg.channel = n;
|
||||
msg.value = value;
|
||||
mailbox_send_and_wait(&msg);
|
||||
}
|
||||
|
||||
void brg_ddssel(int bus_channel, int channel)
|
||||
{
|
||||
struct msg_brg_dds_sel msg;
|
||||
|
||||
msg.type = MESSAGE_TYPE_BRG_DDS_SEL;
|
||||
msg.bus_channel = bus_channel;
|
||||
msg.channel = channel;
|
||||
mailbox_send_and_wait(&msg);
|
||||
}
|
||||
|
||||
void brg_ddsreset(int bus_channel)
|
||||
{
|
||||
struct msg_brg_dds_reset msg;
|
||||
|
||||
msg.type = MESSAGE_TYPE_BRG_DDS_RESET;
|
||||
msg.bus_channel = bus_channel;
|
||||
mailbox_send_and_wait(&msg);
|
||||
}
|
||||
|
||||
unsigned int brg_ddsread(int bus_channel, unsigned int address)
|
||||
{
|
||||
struct msg_brg_dds_read_request msg;
|
||||
struct msg_brg_dds_read_reply *rmsg;
|
||||
unsigned int r;
|
||||
|
||||
msg.type = MESSAGE_TYPE_BRG_DDS_READ_REQUEST;
|
||||
msg.bus_channel = bus_channel;
|
||||
msg.address = address;
|
||||
mailbox_send(&msg);
|
||||
while(1) {
|
||||
rmsg = mailbox_wait_and_receive();
|
||||
if(rmsg->type == MESSAGE_TYPE_BRG_DDS_READ_REPLY) {
|
||||
r = rmsg->data;
|
||||
mailbox_acknowledge();
|
||||
return r;
|
||||
} else {
|
||||
printf("Warning: unexpected message %d from AMP bridge\n", rmsg->type);
|
||||
mailbox_acknowledge();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void brg_ddswrite(int bus_channel, unsigned int address, unsigned int data)
|
||||
{
|
||||
struct msg_brg_dds_write msg;
|
||||
|
||||
msg.type = MESSAGE_TYPE_BRG_DDS_WRITE;
|
||||
msg.bus_channel = bus_channel;
|
||||
msg.address = address;
|
||||
msg.data = data;
|
||||
mailbox_send_and_wait(&msg);
|
||||
}
|
||||
|
||||
void brg_ddsfud(int bus_channel)
|
||||
{
|
||||
struct msg_brg_dds_fud msg;
|
||||
|
||||
msg.type = MESSAGE_TYPE_BRG_DDS_FUD;
|
||||
msg.bus_channel = bus_channel;
|
||||
mailbox_send_and_wait(&msg);
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
#ifndef __BRIDGE_CTL_H
|
||||
#define __BRIDGE_CTL_H
|
||||
|
||||
void brg_start(void);
|
||||
|
||||
void brg_ttloe(int n, int value);
|
||||
void brg_ttlo(int n, int value);
|
||||
|
||||
void brg_ddssel(int bus_channel, int channel);
|
||||
void brg_ddsreset(int bus_channel);
|
||||
unsigned int brg_ddsread(int bus_channel, unsigned int address);
|
||||
void brg_ddswrite(int bus_channel, unsigned int address, unsigned int data);
|
||||
void brg_ddsfud(int bus_channel);
|
||||
|
||||
#endif /* __BRIDGE_CTL_H */
|
|
@ -26,11 +26,6 @@ static void start_kernel_cpu(struct msg_load_request *msg)
|
|||
kernel_cpu_reset_write(0);
|
||||
}
|
||||
|
||||
void kloader_start_bridge()
|
||||
{
|
||||
start_kernel_cpu(NULL);
|
||||
}
|
||||
|
||||
static int load_or_start_kernel(const void *library, int run_kernel)
|
||||
{
|
||||
static struct dyld_info library_info;
|
||||
|
|
|
@ -12,7 +12,6 @@ int kloader_load_library(const void *code);
|
|||
void kloader_filter_backtrace(struct artiq_backtrace_item *backtrace,
|
||||
size_t *backtrace_size);
|
||||
|
||||
void kloader_start_bridge(void);
|
||||
int kloader_start_startup_kernel(void);
|
||||
int kloader_start_idle_kernel(void);
|
||||
void kloader_start_kernel(void);
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "kloader.h"
|
||||
#include "mailbox.h"
|
||||
#include "messages.h"
|
||||
#include "bridge.h"
|
||||
#include "artiq_personality.h"
|
||||
#include "rtio.h"
|
||||
#include "dds.h"
|
||||
|
@ -377,11 +376,6 @@ int main(void)
|
|||
.error = NULL
|
||||
};
|
||||
|
||||
if(request == NULL) {
|
||||
bridge_main();
|
||||
while(1);
|
||||
}
|
||||
|
||||
if(request->library != NULL) {
|
||||
if(!dyld_load(request->library, KERNELCPU_PAYLOAD_ADDRESS,
|
||||
resolve_runtime_export, request->library_info,
|
||||
|
|
|
@ -24,12 +24,10 @@
|
|||
#include <netif/ppp/pppos.h>
|
||||
#endif
|
||||
|
||||
#include "bridge_ctl.h"
|
||||
#include "kloader.h"
|
||||
#include "flash_storage.h"
|
||||
#include "clock.h"
|
||||
#include "rtiocrg.h"
|
||||
#include "test_mode.h"
|
||||
#include "net_server.h"
|
||||
#include "session.h"
|
||||
#include "analyzer.h"
|
||||
|
@ -208,6 +206,8 @@ static struct net_server_instance analyzer_inst = {
|
|||
|
||||
static void regular_main(void)
|
||||
{
|
||||
session_startup_kernel();
|
||||
|
||||
puts("Accepting network sessions.");
|
||||
network_init();
|
||||
net_server_init(&session_inst);
|
||||
|
@ -225,41 +225,6 @@ static void regular_main(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void blink_led(void)
|
||||
{
|
||||
int i;
|
||||
long long int t;
|
||||
|
||||
for(i=0;i<3;i++) {
|
||||
#ifdef CSR_LEDS_BASE
|
||||
leds_out_write(1);
|
||||
#endif
|
||||
t = clock_get_ms();
|
||||
while(clock_get_ms() < t + 250);
|
||||
#ifdef CSR_LEDS_BASE
|
||||
leds_out_write(0);
|
||||
#endif
|
||||
t = clock_get_ms();
|
||||
while(clock_get_ms() < t + 250);
|
||||
}
|
||||
}
|
||||
|
||||
static int check_test_mode(void)
|
||||
{
|
||||
char c;
|
||||
long long int t;
|
||||
|
||||
t = clock_get_ms();
|
||||
while(clock_get_ms() < t + 1000) {
|
||||
if(readchar_nonblock()) {
|
||||
c = readchar();
|
||||
if((c == 't')||(c == 'T'))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern void _fheap, _eheap;
|
||||
|
||||
extern void rust_main();
|
||||
|
@ -279,17 +244,9 @@ int main(void)
|
|||
alloc_give(&_fheap, &_eheap - &_fheap);
|
||||
clock_init();
|
||||
rtiocrg_init();
|
||||
puts("Press 't' to enter test mode...");
|
||||
blink_led();
|
||||
|
||||
if(check_test_mode()) {
|
||||
puts("Entering test mode.");
|
||||
test_main();
|
||||
} else {
|
||||
puts("Entering regular mode.");
|
||||
// rust_main();
|
||||
session_startup_kernel();
|
||||
regular_main();
|
||||
}
|
||||
// rust_main();
|
||||
regular_main();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -24,16 +24,6 @@ enum {
|
|||
MESSAGE_TYPE_CACHE_PUT_REQUEST,
|
||||
MESSAGE_TYPE_CACHE_PUT_REPLY,
|
||||
MESSAGE_TYPE_LOG,
|
||||
|
||||
MESSAGE_TYPE_BRG_READY,
|
||||
MESSAGE_TYPE_BRG_TTL_O,
|
||||
MESSAGE_TYPE_BRG_TTL_OE,
|
||||
MESSAGE_TYPE_BRG_DDS_SEL,
|
||||
MESSAGE_TYPE_BRG_DDS_RESET,
|
||||
MESSAGE_TYPE_BRG_DDS_READ_REQUEST,
|
||||
MESSAGE_TYPE_BRG_DDS_READ_REPLY,
|
||||
MESSAGE_TYPE_BRG_DDS_WRITE,
|
||||
MESSAGE_TYPE_BRG_DDS_FUD,
|
||||
};
|
||||
|
||||
struct msg_base {
|
||||
|
@ -132,48 +122,4 @@ struct msg_log {
|
|||
va_list args;
|
||||
};
|
||||
|
||||
/* bridge messages */
|
||||
|
||||
struct msg_brg_ttl_out {
|
||||
/* used for OE and O */
|
||||
int type;
|
||||
int channel;
|
||||
int value;
|
||||
};
|
||||
|
||||
struct msg_brg_dds_sel {
|
||||
int type;
|
||||
int bus_channel;
|
||||
int channel;
|
||||
};
|
||||
|
||||
struct msg_brg_dds_reset {
|
||||
int type;
|
||||
int bus_channel;
|
||||
};
|
||||
|
||||
struct msg_brg_dds_read_request {
|
||||
int type;
|
||||
int bus_channel;
|
||||
unsigned int address;
|
||||
};
|
||||
|
||||
struct msg_brg_dds_read_reply {
|
||||
int type;
|
||||
int bus_channel;
|
||||
unsigned int data;
|
||||
};
|
||||
|
||||
struct msg_brg_dds_write {
|
||||
int type;
|
||||
int bus_channel;
|
||||
unsigned int address;
|
||||
unsigned int data;
|
||||
};
|
||||
|
||||
struct msg_brg_dds_fud {
|
||||
int type;
|
||||
int bus_channel;
|
||||
};
|
||||
|
||||
#endif /* __MESSAGES_H */
|
||||
|
|
|
@ -1,700 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2014, 2015 M-Labs Limited
|
||||
* Copyright (C) 2014, 2015 Robert Jordens <jordens@gmail.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <irq.h>
|
||||
#include <uart.h>
|
||||
#include <generated/csr.h>
|
||||
#include <console.h>
|
||||
|
||||
#include "dds.h"
|
||||
#include "flash_storage.h"
|
||||
#include "bridge_ctl.h"
|
||||
#include "clock.h"
|
||||
#include "test_mode.h"
|
||||
|
||||
#ifdef CSR_LEDS_BASE
|
||||
static void leds(char *value)
|
||||
{
|
||||
char *c;
|
||||
unsigned int value2;
|
||||
|
||||
if(*value == 0) {
|
||||
printf("leds <value>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
value2 = strtoul(value, &c, 0);
|
||||
if(*c != 0) {
|
||||
printf("incorrect value\n");
|
||||
return;
|
||||
}
|
||||
|
||||
leds_out_write(value2);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CSR_RTIO_CRG_BASE
|
||||
static void clksrc(char *value)
|
||||
{
|
||||
char *c;
|
||||
unsigned int value2;
|
||||
|
||||
if(*value == 0) {
|
||||
printf("clksrc <value>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
value2 = strtoul(value, &c, 0);
|
||||
if(*c != 0) {
|
||||
printf("incorrect value\n");
|
||||
return;
|
||||
}
|
||||
|
||||
rtio_crg_clock_sel_write(value2);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void ttloe(char *n, char *value)
|
||||
{
|
||||
char *c;
|
||||
unsigned int n2, value2;
|
||||
|
||||
if((*n == 0)||(*value == 0)) {
|
||||
printf("ttloe <n> <value>\n");
|
||||
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;
|
||||
}
|
||||
|
||||
brg_ttloe(n2, value2);
|
||||
}
|
||||
|
||||
static void ttlo(char *n, char *value)
|
||||
{
|
||||
char *c;
|
||||
unsigned int n2, value2;
|
||||
|
||||
if((*n == 0)||(*value == 0)) {
|
||||
printf("ttlo <n> <value>\n");
|
||||
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;
|
||||
}
|
||||
|
||||
brg_ttlo(n2, value2);
|
||||
}
|
||||
|
||||
#if ((defined CONFIG_RTIO_DDS_COUNT) && (CONFIG_RTIO_DDS_COUNT > 0))
|
||||
|
||||
static int bus_channel = CONFIG_RTIO_FIRST_DDS_CHANNEL;
|
||||
|
||||
static void ddsbus(char *n)
|
||||
{
|
||||
char *c;
|
||||
unsigned int n2;
|
||||
|
||||
if(*n == 0) {
|
||||
printf("ddsbus <n>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
n2 = strtoul(n, &c, 0);
|
||||
if(*c != 0) {
|
||||
printf("incorrect bus channel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
bus_channel = n2;
|
||||
}
|
||||
|
||||
|
||||
static void ddssel(char *n)
|
||||
{
|
||||
char *c;
|
||||
unsigned int n2;
|
||||
|
||||
if(*n == 0) {
|
||||
printf("ddssel <n>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
n2 = strtoul(n, &c, 0);
|
||||
if(*c != 0) {
|
||||
printf("incorrect channel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DDS_ONEHOT_SEL
|
||||
n2 = 1 << n2;
|
||||
#endif
|
||||
brg_ddssel(bus_channel, n2);
|
||||
}
|
||||
|
||||
static void ddsw(char *addr, char *value)
|
||||
{
|
||||
char *c;
|
||||
unsigned int addr2, value2;
|
||||
|
||||
if((*addr == 0) || (*value == 0)) {
|
||||
printf("ddsr <addr> <value>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
addr2 = strtoul(addr, &c, 0);
|
||||
if(*c != 0) {
|
||||
printf("incorrect address\n");
|
||||
return;
|
||||
}
|
||||
value2 = strtoul(value, &c, 0);
|
||||
if(*c != 0) {
|
||||
printf("incorrect value\n");
|
||||
return;
|
||||
}
|
||||
|
||||
brg_ddswrite(bus_channel, addr2, value2);
|
||||
}
|
||||
|
||||
static void ddsr(char *addr)
|
||||
{
|
||||
char *c;
|
||||
unsigned int addr2;
|
||||
|
||||
if(*addr == 0) {
|
||||
printf("ddsr <addr>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
addr2 = strtoul(addr, &c, 0);
|
||||
if(*c != 0) {
|
||||
printf("incorrect address\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DDS_AD9858
|
||||
printf("0x%02x\n", brg_ddsread(bus_channel, addr2));
|
||||
#endif
|
||||
#ifdef CONFIG_DDS_AD9914
|
||||
printf("0x%04x\n", brg_ddsread(bus_channel, addr2));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void ddsfud(void)
|
||||
{
|
||||
brg_ddsfud(bus_channel);
|
||||
}
|
||||
|
||||
static void ddsftw(char *n, char *ftw)
|
||||
{
|
||||
char *c;
|
||||
unsigned int n2, ftw2;
|
||||
|
||||
if((*n == 0) || (*ftw == 0)) {
|
||||
printf("ddsftw <n> <ftw>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
n2 = strtoul(n, &c, 0);
|
||||
if(*c != 0) {
|
||||
printf("incorrect channel\n");
|
||||
return;
|
||||
}
|
||||
ftw2 = strtoul(ftw, &c, 0);
|
||||
if(*c != 0) {
|
||||
printf("incorrect value\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DDS_ONEHOT_SEL
|
||||
n2 = 1 << n2;
|
||||
#endif
|
||||
brg_ddssel(bus_channel, n2);
|
||||
|
||||
#ifdef CONFIG_DDS_AD9858
|
||||
brg_ddswrite(bus_channel, DDS_FTW0, ftw2 & 0xff);
|
||||
brg_ddswrite(bus_channel, DDS_FTW1, (ftw2 >> 8) & 0xff);
|
||||
brg_ddswrite(bus_channel, DDS_FTW2, (ftw2 >> 16) & 0xff);
|
||||
brg_ddswrite(bus_channel, DDS_FTW3, (ftw2 >> 24) & 0xff);
|
||||
#endif
|
||||
#ifdef CONFIG_DDS_AD9914
|
||||
brg_ddswrite(bus_channel, DDS_FTWL, ftw2 & 0xffff);
|
||||
brg_ddswrite(bus_channel, DDS_FTWH, (ftw2 >> 16) & 0xffff);
|
||||
#endif
|
||||
|
||||
brg_ddsfud(bus_channel);
|
||||
}
|
||||
|
||||
static void ddsreset(void)
|
||||
{
|
||||
brg_ddsreset(bus_channel);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DDS_AD9858
|
||||
static void ddsinit(void)
|
||||
{
|
||||
brg_ddsreset(bus_channel);
|
||||
brg_ddswrite(bus_channel, DDS_CFR0, 0x78);
|
||||
brg_ddswrite(bus_channel, DDS_CFR1, 0x00);
|
||||
brg_ddswrite(bus_channel, DDS_CFR2, 0x00);
|
||||
brg_ddswrite(bus_channel, DDS_CFR3, 0x00);
|
||||
brg_ddsfud(bus_channel);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DDS_AD9914
|
||||
static void ddsinit(void)
|
||||
{
|
||||
long long int t;
|
||||
|
||||
brg_ddsreset(bus_channel);
|
||||
brg_ddswrite(bus_channel, DDS_CFR1H, 0x0000); /* Enable cosine output */
|
||||
brg_ddswrite(bus_channel, DDS_CFR2L, 0x8900); /* Enable matched latency */
|
||||
brg_ddswrite(bus_channel, DDS_CFR2H, 0x0080); /* Enable profile mode */
|
||||
brg_ddswrite(bus_channel, DDS_ASF, 0x0fff); /* Set amplitude to maximum */
|
||||
brg_ddswrite(bus_channel, DDS_CFR4H, 0x0105); /* Enable DAC calibration */
|
||||
brg_ddswrite(bus_channel, DDS_FUD, 0);
|
||||
t = clock_get_ms();
|
||||
while(clock_get_ms() < t + 2);
|
||||
brg_ddswrite(bus_channel, DDS_CFR4H, 0x0005); /* Disable DAC calibration */
|
||||
brg_ddsfud(bus_channel);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void do_ddstest_one(unsigned int i)
|
||||
{
|
||||
unsigned int v[12] = {
|
||||
0xaaaaaaaa, 0x55555555, 0xa5a5a5a5, 0x5a5a5a5a,
|
||||
0x00000000, 0xffffffff, 0x12345678, 0x87654321,
|
||||
0x0000ffff, 0xffff0000, 0x00ff00ff, 0xff00ff00,
|
||||
};
|
||||
unsigned int f, g, j;
|
||||
|
||||
#ifdef CONFIG_DDS_ONEHOT_SEL
|
||||
brg_ddssel(bus_channel, 1 << i);
|
||||
#else
|
||||
brg_ddssel(bus_channel, i);
|
||||
#endif
|
||||
ddsinit();
|
||||
|
||||
for(j=0; j<12; j++) {
|
||||
f = v[j];
|
||||
#ifdef CONFIG_DDS_AD9858
|
||||
brg_ddswrite(bus_channel, DDS_FTW0, f & 0xff);
|
||||
brg_ddswrite(bus_channel, DDS_FTW1, (f >> 8) & 0xff);
|
||||
brg_ddswrite(bus_channel, DDS_FTW2, (f >> 16) & 0xff);
|
||||
brg_ddswrite(bus_channel, DDS_FTW3, (f >> 24) & 0xff);
|
||||
#endif
|
||||
#ifdef CONFIG_DDS_AD9914
|
||||
brg_ddswrite(bus_channel, DDS_FTWL, f & 0xffff);
|
||||
brg_ddswrite(bus_channel, DDS_FTWH, (f >> 16) & 0xffff);
|
||||
#endif
|
||||
brg_ddsfud(bus_channel);
|
||||
#ifdef CONFIG_DDS_AD9858
|
||||
g = brg_ddsread(bus_channel, DDS_FTW0);
|
||||
g |= brg_ddsread(bus_channel, DDS_FTW1) << 8;
|
||||
g |= brg_ddsread(bus_channel, DDS_FTW2) << 16;
|
||||
g |= brg_ddsread(bus_channel, DDS_FTW3) << 24;
|
||||
#endif
|
||||
#ifdef CONFIG_DDS_AD9914
|
||||
g = brg_ddsread(bus_channel, DDS_FTWL);
|
||||
g |= brg_ddsread(bus_channel, DDS_FTWH) << 16;
|
||||
#endif
|
||||
if(g != f)
|
||||
printf("readback fail on DDS %d, 0x%08x != 0x%08x\n", i, g, f);
|
||||
}
|
||||
}
|
||||
|
||||
static void ddstest(char *n, char *channel)
|
||||
{
|
||||
int i, j;
|
||||
char *c;
|
||||
unsigned int n2;
|
||||
int channel2;
|
||||
|
||||
if((*n == 0) || (*channel == 0)) {
|
||||
printf("ddstest <cycles> <channel/'all'>\n");
|
||||
return;
|
||||
}
|
||||
n2 = strtoul(n, &c, 0);
|
||||
if(*c != 0) {
|
||||
printf("incorrect cycles\n");
|
||||
return;
|
||||
}
|
||||
if(strcmp(channel, "all") == 0)
|
||||
channel2 = -1;
|
||||
else {
|
||||
channel2 = strtoul(channel, &c, 0);
|
||||
if(*c != 0) {
|
||||
printf("incorrect channel\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(channel2 >= 0) {
|
||||
for(i=0;i<n2;i++)
|
||||
do_ddstest_one(channel2);
|
||||
} else {
|
||||
for(i=0;i<n2;i++)
|
||||
for(j=0;j<CONFIG_DDS_CHANNELS_PER_BUS;j++)
|
||||
do_ddstest_one(j);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_RTIO_DDS_COUNT */
|
||||
|
||||
#if (defined CSR_SPIFLASH_BASE && defined CONFIG_SPIFLASH_PAGE_SIZE)
|
||||
static void fsread(char *key)
|
||||
{
|
||||
char readbuf[CONFIG_SPIFLASH_SECTOR_SIZE];
|
||||
int r;
|
||||
|
||||
r = fs_read(key, readbuf, sizeof(readbuf)-1, NULL);
|
||||
readbuf[r] = 0;
|
||||
if(r == 0)
|
||||
printf("key %s does not exist\n", key);
|
||||
else
|
||||
puts(readbuf);
|
||||
}
|
||||
|
||||
static void fswrite(char *key, void *buffer, unsigned int length)
|
||||
{
|
||||
if(!fs_write(key, buffer, length))
|
||||
printf("cannot write key %s because flash storage is full\n", key);
|
||||
}
|
||||
|
||||
static void fsfull(void)
|
||||
{
|
||||
int i;
|
||||
char value[4096];
|
||||
memset(value, '@', sizeof(value));
|
||||
|
||||
for(i = 0; i < CONFIG_SPIFLASH_SECTOR_SIZE/sizeof(value); i++)
|
||||
fs_write("plip", value, sizeof(value));
|
||||
}
|
||||
|
||||
static void check_read(char *key, char *expected, unsigned int length, unsigned int testnum)
|
||||
{
|
||||
char readbuf[CONFIG_SPIFLASH_SECTOR_SIZE];
|
||||
unsigned int remain, readlength;
|
||||
|
||||
memset(readbuf, '\0', sizeof(readbuf));
|
||||
|
||||
readlength = fs_read(key, readbuf, sizeof(readbuf), &remain);
|
||||
if(remain > 0)
|
||||
printf("KO[%u] remain == %u, expected 0\n", testnum, remain);
|
||||
if(readlength != length)
|
||||
printf("KO[%u] read length == %u, expected %u\n", testnum, readlength, length);
|
||||
if(remain == 0 && readlength == length)
|
||||
printf(".");
|
||||
|
||||
readbuf[readlength] = 0;
|
||||
if(memcmp(expected, readbuf, readlength) == 0)
|
||||
printf(".\n");
|
||||
else
|
||||
printf("KO[%u] read %s instead of %s\n", testnum, readbuf, expected);
|
||||
}
|
||||
|
||||
static void check_doesnt_exist(char *key, unsigned int testnum)
|
||||
{
|
||||
char readbuf;
|
||||
unsigned int remain, readlength;
|
||||
|
||||
readlength = fs_read(key, &readbuf, sizeof(readbuf), &remain);
|
||||
if(remain > 0)
|
||||
printf("KO[%u] remain == %u, expected 0\n", testnum, remain);
|
||||
if(readlength > 0)
|
||||
printf("KO[%u] readlength == %d, expected 0\n", testnum, readlength);
|
||||
if(remain == 0 && readlength == 0)
|
||||
printf(".\n");
|
||||
}
|
||||
|
||||
static void check_write(unsigned int ret)
|
||||
{
|
||||
if(!ret)
|
||||
printf("KO");
|
||||
else
|
||||
printf(".");
|
||||
}
|
||||
|
||||
static inline void test_sector_is_full(void)
|
||||
{
|
||||
char c;
|
||||
char value[4096];
|
||||
char key[2] = {0, 0};
|
||||
|
||||
fs_erase();
|
||||
memset(value, '@', sizeof(value));
|
||||
for(c = 1; c <= CONFIG_SPIFLASH_SECTOR_SIZE/sizeof(value); c++) {
|
||||
key[0] = c;
|
||||
check_write(fs_write(key, value, sizeof(value) - 6));
|
||||
}
|
||||
check_write(!fs_write("this_should_fail", "fail", 5));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void test_one_big_record(int testnum)
|
||||
{
|
||||
char value[CONFIG_SPIFLASH_SECTOR_SIZE];
|
||||
memset(value, '@', sizeof(value));
|
||||
|
||||
fs_erase();
|
||||
check_write(fs_write("a", value, sizeof(value) - 6));
|
||||
check_read("a", value, sizeof(value) - 6, testnum);
|
||||
check_write(fs_write("a", value, sizeof(value) - 6));
|
||||
check_read("a", value, sizeof(value) - 6, testnum);
|
||||
check_write(!fs_write("b", value, sizeof(value) - 6));
|
||||
check_read("a", value, sizeof(value) - 6, testnum);
|
||||
fs_remove("a");
|
||||
check_doesnt_exist("a", testnum);
|
||||
check_write(fs_write("a", value, sizeof(value) - 6));
|
||||
check_read("a", value, sizeof(value) - 6, testnum);
|
||||
fs_remove("a");
|
||||
check_doesnt_exist("a", testnum);
|
||||
value[0] = '!';
|
||||
check_write(fs_write("b", value, sizeof(value) - 6));
|
||||
check_read("b", value, sizeof(value) - 6, testnum);
|
||||
}
|
||||
|
||||
static void test_flush_duplicate_rollback(int testnum)
|
||||
{
|
||||
char value[CONFIG_SPIFLASH_SECTOR_SIZE];
|
||||
memset(value, '@', sizeof(value));
|
||||
|
||||
fs_erase();
|
||||
/* This makes the flash storage full with one big record */
|
||||
check_write(fs_write("a", value, CONFIG_SPIFLASH_SECTOR_SIZE - 6));
|
||||
/* This should trigger the try_to_flush_duplicate code which
|
||||
* at first will not keep the old "a" record value because we are
|
||||
* overwriting it. But then it should roll back to the old value
|
||||
* because the new record is too large.
|
||||
*/
|
||||
value[0] = '!';
|
||||
check_write(!fs_write("a", value, sizeof(value)));
|
||||
/* check we still have the old record value */
|
||||
value[0] = '@';
|
||||
check_read("a", value, CONFIG_SPIFLASH_SECTOR_SIZE - 6, testnum);
|
||||
}
|
||||
|
||||
static void test_too_big_fails(int testnum)
|
||||
{
|
||||
char value[CONFIG_SPIFLASH_SECTOR_SIZE];
|
||||
memset(value, '@', sizeof(value));
|
||||
|
||||
fs_erase();
|
||||
check_write(!fs_write("a", value, sizeof(value) - 6 + /* TOO BIG */ 1));
|
||||
check_doesnt_exist("a", testnum);
|
||||
}
|
||||
|
||||
static void fs_test(void)
|
||||
{
|
||||
int i;
|
||||
char writebuf[] = "abcdefghijklmnopqrst";
|
||||
char read_check[4096];
|
||||
int vect_length = sizeof(writebuf);
|
||||
|
||||
memset(read_check, '@', sizeof(read_check));
|
||||
printf("testing...\n");
|
||||
for(i = 0; i < vect_length; i++) {
|
||||
printf("%u.0:", i);
|
||||
fs_erase();
|
||||
check_write(fs_write("a", writebuf, i));
|
||||
check_read("a", writebuf, i, i);
|
||||
|
||||
printf("%u.1:", i);
|
||||
fsfull();
|
||||
check_read("a", writebuf, i, i);
|
||||
|
||||
printf("%u.2:", i);
|
||||
check_read("plip", read_check, sizeof(read_check), i);
|
||||
|
||||
printf("%u.3:", i);
|
||||
check_write(fs_write("a", "b", 2));
|
||||
check_read("a", "b", 2, i);
|
||||
|
||||
printf("%u.4:", i);
|
||||
fsfull();
|
||||
check_read("a", "b", 2, i);
|
||||
|
||||
printf("%u.5:", i);
|
||||
check_doesnt_exist("notfound", i);
|
||||
|
||||
printf("%u.6:", i);
|
||||
fs_remove("a");
|
||||
check_doesnt_exist("a", i);
|
||||
|
||||
printf("%u.7:", i);
|
||||
fsfull();
|
||||
check_doesnt_exist("a", i);
|
||||
}
|
||||
|
||||
printf("%u:", vect_length);
|
||||
test_sector_is_full();
|
||||
|
||||
printf("%u:", vect_length+1);
|
||||
test_one_big_record(vect_length+1);
|
||||
|
||||
printf("%u:", vect_length+2);
|
||||
test_flush_duplicate_rollback(vect_length+2);
|
||||
|
||||
printf("%u:", vect_length+3);
|
||||
test_too_big_fails(vect_length+3);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void help(void)
|
||||
{
|
||||
puts("Available commands:");
|
||||
puts("help - this message");
|
||||
#ifdef CSR_RTIO_CRG_BASE
|
||||
puts("clksrc <n> - select RTIO clock source");
|
||||
#endif
|
||||
puts("ttloe <n> <v> - set TTL output enable");
|
||||
puts("ttlo <n> <v> - set TTL output value");
|
||||
puts("ddsbus <n> - select the DDS bus RTIO channel");
|
||||
puts("ddssel <n> - select a DDS");
|
||||
puts("ddsinit - reset, config, FUD DDS");
|
||||
puts("ddsreset - reset DDS");
|
||||
puts("ddsw <a> <d> - write to DDS register");
|
||||
puts("ddsr <a> - read DDS register");
|
||||
puts("ddsfud - pulse FUD");
|
||||
puts("ddsftw <n> <d> - write FTW");
|
||||
puts("ddstest <c> <n> - perform test sequence on DDS");
|
||||
#ifdef CSR_LEDS_BASE
|
||||
puts("leds <n> - set LEDs");
|
||||
#endif
|
||||
#if (defined CSR_SPIFLASH_BASE && defined CONFIG_SPIFLASH_PAGE_SIZE)
|
||||
puts("fserase - erase flash storage");
|
||||
puts("fswrite <k> <v> - write to flash storage");
|
||||
puts("fsread <k> - read flash storage");
|
||||
puts("fsremove <k> - remove a key-value record from flash storage");
|
||||
puts("fstest - run flash storage tests. WARNING: erases the storage area");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void readstr(char *s, int size)
|
||||
{
|
||||
char c[2];
|
||||
int ptr;
|
||||
|
||||
c[1] = 0;
|
||||
ptr = 0;
|
||||
while(1) {
|
||||
c[0] = readchar();
|
||||
switch(c[0]) {
|
||||
case 0x7f:
|
||||
case 0x08:
|
||||
if(ptr > 0) {
|
||||
ptr--;
|
||||
putsnonl("\x08 \x08");
|
||||
}
|
||||
break;
|
||||
case 0x07:
|
||||
break;
|
||||
case '\r':
|
||||
case '\n':
|
||||
s[ptr] = 0x00;
|
||||
putsnonl("\n");
|
||||
return;
|
||||
default:
|
||||
putsnonl(c);
|
||||
s[ptr] = c[0];
|
||||
ptr++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static char *get_token(char **str)
|
||||
{
|
||||
char *c, *d;
|
||||
|
||||
c = (char *)strchr(*str, ' ');
|
||||
if(c == NULL) {
|
||||
d = *str;
|
||||
*str = *str+strlen(*str);
|
||||
return d;
|
||||
}
|
||||
*c = 0;
|
||||
d = *str;
|
||||
*str = c+1;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
static void do_command(char *c)
|
||||
{
|
||||
char *token;
|
||||
|
||||
token = get_token(&c);
|
||||
|
||||
if(strcmp(token, "help") == 0) help();
|
||||
#ifdef CSR_LEDS_BASE
|
||||
else if(strcmp(token, "leds") == 0) leds(get_token(&c));
|
||||
#endif
|
||||
|
||||
#ifdef CSR_RTIO_CRG_BASE
|
||||
else if(strcmp(token, "clksrc") == 0) clksrc(get_token(&c));
|
||||
#endif
|
||||
|
||||
else if(strcmp(token, "ttloe") == 0) ttloe(get_token(&c), get_token(&c));
|
||||
else if(strcmp(token, "ttlo") == 0) ttlo(get_token(&c), get_token(&c));
|
||||
|
||||
#if ((defined CONFIG_RTIO_DDS_COUNT) && (CONFIG_RTIO_DDS_COUNT > 0))
|
||||
else if(strcmp(token, "ddsbus") == 0) ddsbus(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, "ddsr") == 0) ddsr(get_token(&c));
|
||||
else if(strcmp(token, "ddsreset") == 0) ddsreset();
|
||||
else if(strcmp(token, "ddsinit") == 0) ddsinit();
|
||||
else if(strcmp(token, "ddsfud") == 0) ddsfud();
|
||||
else if(strcmp(token, "ddsftw") == 0) ddsftw(get_token(&c), get_token(&c));
|
||||
else if(strcmp(token, "ddstest") == 0) ddstest(get_token(&c), get_token(&c));
|
||||
#endif
|
||||
|
||||
#if (defined CSR_SPIFLASH_BASE && defined CONFIG_SPIFLASH_PAGE_SIZE)
|
||||
else if(strcmp(token, "fserase") == 0) fs_erase();
|
||||
else if(strcmp(token, "fswrite") == 0) fswrite(get_token(&c), c, strlen(c));
|
||||
else if(strcmp(token, "fsread") == 0) fsread(get_token(&c));
|
||||
else if(strcmp(token, "fsremove") == 0) fs_remove(get_token(&c));
|
||||
else if(strcmp(token, "fstest") == 0) fs_test();
|
||||
#endif
|
||||
|
||||
else if(strcmp(token, "") != 0)
|
||||
printf("Command not found\n");
|
||||
}
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
char buffer[64];
|
||||
|
||||
brg_start();
|
||||
|
||||
while(1) {
|
||||
putsnonl("\e[1mtest>\e[0m ");
|
||||
readstr(buffer, 64);
|
||||
do_command(buffer);
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef __TEST_MODE_H
|
||||
#define __TEST_MODE_H
|
||||
|
||||
void test_main(void);
|
||||
|
||||
#endif
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef __TTL_H
|
||||
#define __TTL_H
|
||||
|
||||
#define TTL_O_ADDR 0
|
||||
#define TTL_OE_ADDR 1
|
||||
#define TTL_SENSITIVITY_ADDR 2
|
||||
|
||||
#endif /* __TTL_H */
|
Loading…
Reference in New Issue