offsets: always add {tdc}_zero_offsets

These amounts are *signed*, so we add this kludgy duplication
of code to handle the case of addition of a signed quantity
in fd-irq.c

The arithmetic code was suggested by Alessandro Rubini,
replacing a former, buggy and kludgy implementation by
David Cobas.
Reported-by: 's avatarAlessandro Rubini <ru@gnudd.com>
Reported-by: 's avatarTomasz Wlostowski <twlostow@cern.ch>
parent af31cc69
......@@ -55,6 +55,29 @@ static void fd_ts_sub(struct fd_time *t, uint64_t pico)
}
}
static void fd_ts_add(struct fd_time *t, int64_t pico)
{
uint32_t coarse, frac;
/* FIXME: we really need to pre-convert pico to internal repres. */
if (pico < 0) {
fd_ts_sub(t, -pico);
return;
}
fd_split_pico(pico, &coarse, &frac);
t->frac += frac;
t->coarse += coarse;
if (t->frac >= 4096) {
t->frac -= 4096;
t->coarse++;
}
if (t->coarse >= 125*1000*1000) {
t->coarse -= 125*1000*1000;
t->utc++;
}
}
/* This is called from outside, too */
int fd_read_sw_fifo(struct fd_dev *fd, struct zio_channel *chan)
{
......@@ -88,7 +111,7 @@ int fd_read_sw_fifo(struct fd_dev *fd, struct zio_channel *chan)
t.utc++;
}
fd_ts_sub(&t, fd->calib.tdc_zero_offset);
fd_ts_add(&t, fd->calib.tdc_zero_offset);
/* Write the timestamp in the trigger, it will reach the control */
ti->tstamp.tv_sec = t.utc;
......
......@@ -440,10 +440,13 @@ static void __fd_zio_output(struct fd_dev *fd, int index1_4, uint32_t *attrs)
}
if (mode == FD_OUT_MODE_DELAY) {
fd_attr_sub(attrs + FD_ATTR_OUT_START_H,
fd->calib.zero_offset[ch]);
fd_apply_offset(attrs + FD_ATTR_OUT_START_H,
fd->calib.tdc_zero_offset);
}
fd_apply_offset(attrs + FD_ATTR_OUT_START_H,
fd->calib.zero_offset[ch]);
fd_apply_offset(attrs + FD_ATTR_OUT_START_H,
fd->ch_user_offset[ch]);
......
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