Commit 1400d2bc authored by John Robert Gill's avatar John Robert Gill

Software changes to support RF timestamps, IQdac timing, and version increment

parent 2ca38be9
......@@ -343,7 +343,7 @@ unsigned libwr2rf_read_fwversion(struct libwr2rf_dev *dev)
int libwr2rf_check_fwversion(struct libwr2rf_dev *dev)
{
return !(libwr2rf_read_fwversion(dev) == 0x00001500);
return !(libwr2rf_read_fwversion(dev) == 0x00001600);
}
void libwr2rf_read_nco_ipinfo(struct libwr2rf_dev *dev,
......@@ -1481,3 +1481,76 @@ libwr2rf_rfframerx_ts(struct libwr2rf_dev *dev, unsigned ts_nco_reset, uint64_t
*ts_cycles = cyc;
return 0;
}
int
libwr2rf_wr_leapsec(struct libwr2rf_dev *dev, uint32_t *ts_leapsec)
{
*ts_leapsec = LIBWR2RF_LEAPSEC;
return 0;
}
int libwr2rf_vtu_timestamps(struct libwr2rf_dev *dev, unsigned id,
uint64_t *ts_vtu_tai_first, uint32_t *ts_vtu_cycles_first,
uint64_t *ts_vtu_tai_last, uint32_t *ts_vtu_cycles_last)
{
unsigned baddr;
unsigned val;
uint64_t secs = 0;
uint32_t cycles = 0;
switch (id) {
case LIBWR2RF_TRIG_ID_RF_1_TRIG_1:
baddr = WR2RF_VME_REGS_CTRL + WR2RF_CTRL_REGS_RF1_VTUS + WR2RF_RFTRIGGER_REGS_T1;
break;
case LIBWR2RF_TRIG_ID_RF_1_TRIG_2:
baddr = WR2RF_VME_REGS_CTRL + WR2RF_CTRL_REGS_RF1_VTUS + WR2RF_RFTRIGGER_REGS_T2;
break;
case LIBWR2RF_TRIG_ID_RF_2_TRIG_1:
baddr = WR2RF_VME_REGS_CTRL + WR2RF_CTRL_REGS_RF2_VTUS + WR2RF_RFTRIGGER_REGS_T1;
break;
case LIBWR2RF_TRIG_ID_RF_2_TRIG_2:
baddr = WR2RF_VME_REGS_CTRL + WR2RF_CTRL_REGS_RF2_VTUS + WR2RF_RFTRIGGER_REGS_T2;
break;
default:
return LIBWR2RF_ERROR_BAD_ID;
}
secs = 0;
val = libwr2rf_read16(dev, baddr + TRIGUNIT_REGS_TS_FIRSTTRIGTAISEC);
secs = secs | ((uint64_t) val) << 48;
val = libwr2rf_read16(dev, baddr + TRIGUNIT_REGS_TS_FIRSTTRIGTAISEC+2);
secs = secs | ((uint64_t) val) << 32;
val = libwr2rf_read16(dev, baddr + TRIGUNIT_REGS_TS_FIRSTTRIGTAISEC+4);
secs = secs | ((uint64_t) val) << 16;
val = libwr2rf_read16(dev, baddr + TRIGUNIT_REGS_TS_FIRSTTRIGTAISEC+6);
secs = secs | ((uint64_t) val) << 0;
*ts_vtu_tai_first = secs;
cycles = 0;
val = libwr2rf_read16(dev, baddr + TRIGUNIT_REGS_TS_FIRSTTRIGTAICYCLES+0);
cycles = cycles | ((uint64_t) val) << 16;
val = libwr2rf_read16(dev, baddr + TRIGUNIT_REGS_TS_FIRSTTRIGTAICYCLES+2);
cycles = cycles | ((uint64_t) val) << 0;
*ts_vtu_cycles_first = cycles;
secs = 0;
val = libwr2rf_read16(dev, baddr + TRIGUNIT_REGS_TS_LASTTRIGTAISEC);
secs = secs | ((uint64_t) val) << 48;
val = libwr2rf_read16(dev, baddr + TRIGUNIT_REGS_TS_LASTTRIGTAISEC+2);
secs = secs | ((uint64_t) val) << 32;
val = libwr2rf_read16(dev, baddr + TRIGUNIT_REGS_TS_LASTTRIGTAISEC+4);
secs = secs | ((uint64_t) val) << 16;
val = libwr2rf_read16(dev, baddr + TRIGUNIT_REGS_TS_LASTTRIGTAISEC+6);
secs = secs | ((uint64_t) val) << 0;
*ts_vtu_tai_last = secs;
cycles = 0;
val = libwr2rf_read16(dev, baddr + TRIGUNIT_REGS_TS_LASTTRIGTAICYCLES+0);
cycles = cycles | ((uint64_t) val) << 16;
val = libwr2rf_read16(dev, baddr + TRIGUNIT_REGS_TS_LASTTRIGTAICYCLES+2);
cycles = cycles | ((uint64_t) val) << 0;
*ts_vtu_cycles_last = cycles;
return 0;
}
......@@ -258,13 +258,13 @@ int libwr2rf_dac_port_timing(struct libwr2rf_dev *dev, unsigned ch)
best = 32;
for (i = 1; i < 31; i++) {
if (results[i].seek == 1) {
if (results[i].seek == 0) {// this is inverted, to avoid two acceptable windows
diff = results[i].hld - results[i].set;
sum = results[i].hld + results[i].set;
if (results[i].set < results[i].hld) {
if ( (results[i].set + results[i].hld) > 8 ) {
printf ("set=%02u hld=%02u diff=%02d, sum=%02u\n", results[i].set, results[i].hld, diff, sum);
if ((diff < min_diff) && (sum > max_sum)) {
if ((diff < min_diff) && (sum >= max_sum)) {
min_diff = diff;
max_sum = sum;
best = i;
......
......@@ -305,4 +305,18 @@ that have elapsed in the current TAI epoch and cycles is the number of WR clock
(16 ns) that have elapsed within the current second. */
int libwr2rf_rfframerx_ts (struct libwr2rf_dev *dev, unsigned ts_nco_reset, uint64_t *ts_tai, uint32_t *ts_cycles);
#define LIBWR2RF_LEAPSEC 37
/* Read the current leapsecond value utilised by White Rabbit. This is the offset between
the TAI seconds and UTC seconds, such that; utc = tai + leapsecs */
int libwr2rf_wr_leapsec (struct libwr2rf_dev *dev, uint32_t *ts_leapsec);
/* Returns timestamps of the first VTU trigger output after a start pulse and also a
timestamp of the last trigger pulse output from the VTU. Timestamps have two components:
tai in seconds and cycles in 8 ns*/
int libwr2rf_vtu_timestamps (struct libwr2rf_dev *dev, unsigned id,
uint64_t *ts_vtu_tai_first, uint32_t *ts_vtu_cycles_first,
uint64_t *ts_vtu_tai_last, uint32_t *ts_vtu_cycles_last);
#endif /* __LIBWR2RF__API__H_ */
......@@ -4080,6 +4080,44 @@ api_tmgio (struct libwr2rf_dev *dev, int argc, char **argv)
printf ("ERROR\n");
}
static void
api_wr_leapsec (struct libwr2rf_dev *dev, int argc, char **argv)
{
unsigned leapsec;
if (libwr2rf_wr_leapsec(dev, &leapsec))
printf ("ERROR\n");
printf("WR leapsec val=%d\n", leapsec);
}
static void
api_vtu_timestamps (struct libwr2rf_dev *dev, int argc, char **argv)
{
int res;
unsigned long id;
uint64_t tai_first;
uint32_t cycles_first;
uint64_t tai_last;
uint32_t cycles_last;
if (argc != 2) {
printf ("usage: %s VTU-ID\n", argv[0]);
return;
}
id = parse_api_vtu (argv[1]);
if (id == BADADDR)
return;
res = libwr2rf_vtu_timestamps(dev, id, &tai_first, &cycles_first, &tai_last, &cycles_last);
if (res != 0)
printf ("%s: failed (status=%d)\n", __FUNCTION__, res);
printf ("%s:\n", __FUNCTION__);
printf("FIRST TAI: %010lu, cycles: %08u \n", tai_first, cycles_first);
printf("LAST TAI: %010lu, cycles: %08u \n", tai_last, cycles_last);
}
static void
calib_dds_ioupdate (struct libwr2rf_dev *dev, int argc, char **argv)
{
......@@ -4187,6 +4225,8 @@ static struct cmds cmds[] =
{ "api-nco-lcfg", api_nco_lcfg, "configures the RFNCO to output a local fixed frequency." },
{ "api-tmgio", api_tmgio, "set lemo io output enable and termination"},
{ "api-tmgclk", api_tmgclk, "set lemo clk output enable and termination"},
{ "api-wr-leapsec", api_wr_leapsec, "retrieve the current leapsec information"},
{ "api-vtu-timestamps", api_vtu_timestamps, "Return timestamps of the first and last vtu trigger output pulses after the VTU has been started"},
{ "api-nco-reset-ignore", api_nco_reset_ignore, "ignore (or not) nco reset"},
{ "ftw-show", ftw_show, "show received ftw" },
{ "ftw-last", framerxtx_last, "display last ftw" },
......
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