Commit d91fec21 authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Adam Wujek

dac_log: optionally stream out the dac values

This commit adds a tool to send out, through ethernet, a complete log of
DAC values for the main oscillator. It allows to see if there are
oscillations (and there currently are) and what happens when tracking
is lost and recovered.

To activate the feature

  * add CONFIG_DAC_LOG (depends on CONFIG_DEVELOPER)

  * activate on the console: "daclog <ipaddr> <macaddr>"

  * collect data on your target host

     netcat -u -l -p 1050  | od -An -t u2 -v -w2 --endian=big > daclog.txt

  * stop it when done, on the console: "daclog off"
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent d78b3dbe
......@@ -349,6 +349,14 @@ config CMD_LL
on the master, because they are just sent to the slave
during the initial handshake
config DAC_LOG
depends on DEVELOPER && EMBEDDED_NODE
bool "Be able send DAC values through UDP"
help
If you want to see the dac output, input to the VCXO main
oscillator, enable this. You'll have a "daclog" shell command
to set ipaddress and mac of the target host. UDP port is 1050.
config FLASH_INIT
depends on DEVELOPER && LM32
default y
......
#include <wrc.h>
#include <wrpc.h>
#include <string.h>
#include <shell.h>
#include <lib/ipv4.h>
/* a tx-only socket: no queue is there */
static struct wrpc_socket __static_daclog_socket = {
.queue.buff = NULL,
.queue.size = 0,
};
static struct wrpc_socket *daclog_socket;
static struct wr_udp_addr daclog_addr;
unsigned char daclog_mac[6];
/* alternate between two buffers */
#define BSIZE 512
struct daclog_buf {
unsigned char hdr[UDP_END];
uint16_t data[BSIZE];
};
static struct daclog_buf buffers[2];
static int ready[2];
void spll_log_dac(int y);
void spll_log_dac(int y)
{
static int bindex, bcount;
buffers[bindex].data[bcount++] = y;
if (bcount == BSIZE) {
ready[bindex] = 1;
bindex = !bindex;
bcount = 0;
}
}
static void daclog_init(void)
{
daclog_socket = ptpd_netif_create_socket(&__static_daclog_socket, NULL,
PTPD_SOCK_UDP, 1050);
daclog_addr.sport = daclog_addr.dport = htons(1050);
}
static int configured;
static int daclog_poll(void)
{
struct wr_sockaddr addr;
int len = sizeof(struct daclog_buf);
struct daclog_buf *b = NULL;
if (!configured)
return 0;
if (ready[0]) {
b = buffers + 0;
ready[0] = 0;
} else if (ready[1]) {
b = buffers + 1;
ready[1] = 0;
}
if (!b)
return 0;
/* format and send */
getIP((void *)&daclog_addr.saddr); /* if we have no ip yet, 0 is ok */
fill_udp((void *)b, len, &daclog_addr);
memcpy(&addr.mac, daclog_mac, 6);
ptpd_netif_sendto(daclog_socket, &addr, b, len, 0);
return 1;
}
DEFINE_WRC_TASK(daclog) = {
.name = "daclog",
.init = daclog_init,
.job = daclog_poll,
};
static int cmd_daclog(const char *args[])
{
char b1[32], b2[32];
if (args[0] && !strcmp(args[0], "off")) {
configured = 0;
return 0;
}
if (!args[1]) {
pp_printf("use: daclog <ipaddr> <macaddr> (or just \"off\"\n");
return -1;
}
decode_ip(args[0], (void *)&daclog_addr.daddr);
decode_mac(args[1], daclog_mac);
pp_printf("Dac logger parameters: %s, %s, port 1050\n",
format_ip(b1, (void *)&daclog_addr.daddr),
format_mac(b2, daclog_mac));
configured = 1;
ready[0] = ready[1] = 0; /* try to ensure data ordering */
return 0;
}
DEFINE_WRC_COMMAND(daclog) = {
.name = "daclog",
.exec = cmd_daclog,
};
......@@ -23,6 +23,7 @@ obj-$(CONFIG_WR_SWITCH) += dev/timer-wrs.o dev/ad9516.o
obj-$(CONFIG_LEGACY_EEPROM) += dev/eeprom.o
obj-$(CONFIG_SDB_STORAGE) += dev/sdb-storage.o
obj-$(CONFIG_DAC_LOG) += dev/dac_log.o
obj-$(CONFIG_W1) += dev/w1.o dev/w1-hw.o dev/w1-shell.o
obj-$(CONFIG_W1) += dev/w1-temp.o dev/w1-eeprom.o
obj-$(CONFIG_W1) += dev/temp-w1.o
......
......@@ -16,6 +16,12 @@
#undef WITH_SEQUENCING
#ifdef CONFIG_DAC_LOG
extern void spll_log_dac(int y);
#else
static inline void spll_log_dac(int y) {}
#endif
void mpll_init(struct spll_main_state *s, int id_ref,
int id_out)
{
......@@ -130,6 +136,8 @@ int mpll_update(struct spll_main_state *s, int tag, int source)
y = pi_update((spll_pi_t *)&s->pi, err);
SPLL->DAC_MAIN = SPLL_DAC_MAIN_VALUE_W(y)
| SPLL_DAC_MAIN_DAC_SEL_W(s->dac_index);
if (s->dac_index == 0)
spll_log_dac(y);
spll_debug(DBG_MAIN | DBG_REF, s->tag_ref + s->adder_ref, 0);
spll_debug(DBG_MAIN | DBG_TAG, s->tag_out + s->adder_out, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment