Commit 33cfe823 authored by Federico Vaga's avatar Federico Vaga

kernel: fix post-sample=1 acquisition

The ADC start an acquisition only if post-samples > 0. So the acquired
samples are always greater or equal 2. The driver previously tried to
fix this by descrease the number of required post-samples directly in
the hardware. But on user request of post-samples=1 this means request
post-samples=0 to the ADC: so, it will not work.

This patch leave unchanged the logic of the ADC and remove the extra
samples directly from the acquired buffer.

We are aware that this will waste 10ns of acquisition, but the software
implementation to handle this issue is more expensive
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 8c1e79a4
......@@ -140,9 +140,14 @@ void zfad_dma_done(struct zio_cset *cset)
ctrl->attr_channel.ext_val[ZFAD_ATTR_ACQ_START_C] = ztstamp.ticks;
ctrl->attr_channel.ext_val[ZFAD_ATTR_ACQ_START_F] = ztstamp.bins;
/* resize the datalen and clear stamp from data block */
block->datalen -= FA_TRIG_TIMETAG_BYTES;
/*
* resize the datalen, by removing the trigger tstamp and the
* extra samples (trigger samples, 1 for each channel)
*/
block->datalen = block->datalen - FA_TRIG_TIMETAG_BYTES -
- (ctrl->ssize * FA_NCHAN);
memset(block->data+block->datalen, 0, FA_TRIG_TIMETAG_BYTES);
/* update seq num */
ctrl->seq_num = i;
}
......
......@@ -99,21 +99,10 @@ static int zfat_conf_set(struct device *dev, struct zio_attribute *zattr,
}
break;
case ZFAT_POST:
/*
* actually the HW adds systematically a sample
* corresponding to the trigger itself. therefore the
* client ask pre-samp+post-samp and the HW returns
* pre-samp+1+post-samp To make this behaviour
* invisible from the user we consider that the sample
* corresponding to the trigger is part of the post
* samples. Therefore the value written in the HW is
* post-samples-1 and value 0 is excluded
*/
if (!tmp_val) {
dev_err(dev, "post samples cannot be 0 (minimum 1)\n");
return -EINVAL;
}
tmp_val -= 1;
break;
case ZFAT_SW:
/* Fire if software trigger is enabled (index 5) */
......@@ -155,13 +144,6 @@ static int zfat_info_get(struct device *dev, struct zio_attribute *zattr,
*usr_val = fa_readl(fa, fa->fa_adc_csr_base, &zfad_regs[zattr->id]);
/*
* See in zfat-conf-set explanations (just above)
* Post sample value read from the HW is incrmented by 1
*/
if (zattr->id == ZFAT_POST)
*usr_val += 1;
return 0;
}
static const struct zio_sysfs_operations zfat_s_op = {
......@@ -333,8 +315,11 @@ static int zfat_arm_trigger(struct zio_ti *ti)
* (4*32bits word) size should be 32bits word aligned
* ti->nsamples is the sum of (pre-samp+ post-samp)*4chan
* because it's the interleave channel.
*
* +FA_NCHAN because of the trigger samples (1 for each channel) which
* will discard later on DMA done
*/
size = (interleave->current_ctrl->ssize * ti->nsamples)
size = (interleave->current_ctrl->ssize * (ti->nsamples + FA_NCHAN))
+ FA_TRIG_TIMETAG_BYTES;
/* check if size is 32 bits word aligned: should be always the case */
if (size % 4) {
......
......@@ -417,6 +417,10 @@ static inline int zfat_overflow_detection(struct zio_ti *ti, unsigned int addr,
nshot_t = addr == ZFAT_SHOTS_NB ? val :
ti_zattr[ZIO_ATTR_TRIG_N_SHOTS].value;
/*
* +1 because of the trigger samples, which is not counted as
* post-sample by the ADC
*/
shot_size = ((pre_t + post_t + 1) * ti->cset->ssize) * FA_NCHAN;
if ( (shot_size * nshot_t) >= FA_MAX_ACQ_BYTE ) {
dev_err(&ti->head.dev, "Cannot acquire, dev memory overflow\n");
......
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