Commit 67544fe0 authored by Federico Vaga's avatar Federico Vaga

lib: flush channel buffer

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 6374e09c
......@@ -574,4 +574,45 @@ int fmctdc_reference_set(struct fmctdc_board *userb,
}
/**
* It removes all samples from the channel buffer
* @param[in] userb TDC board instance token
* @param[in] channel target channel [1, 5]
* @return 0 on success, otherwise -1 and errno is set appropriately
*/
int fmctdc_flush(struct fmctdc_board *userb, unsigned int channel)
{
struct __fmctdc_board *b = (void *)(userb);
struct fmctdc_time t[10];
char path[64];
int i, en, err;
if (channel > FMCTDC_NUM_CHANNELS || channel <= 0 ) {
errno = EINVAL;
return -1;
}
en = fmctdc_get_acquisition(userb);
if (en < 0)
return -1;
/* Disable acquisition, it will flush the hw buffer */
err = fmctdc_set_acquisition(userb, 0);
if (err)
return err;
/* FIXME when TDC driver will have its zio-trigger this is not
* necessary anymore */
do {
i = fmctdc_read(userb, channel, t, 10, 0);
} while (i > 0);
/* Flush ZIO buffer */
snprintf(path, sizeof(path), "ft-ch%d/chan0/buffer/flush", channel);
err = fmctdc_sysfs_set(b, path, &channel);
if (err) {
return err;
}
/* Re-enable if it was enable */
return fmctdc_set_acquisition(userb, en);
}
......@@ -89,6 +89,7 @@ extern int fmctdc_check_wr_mode(struct fmctdc_board *b);
extern void fmctdc_ts_sub(struct fmctdc_time *a, struct fmctdc_time *b);
extern int fmctdc_reference_set(struct fmctdc_board *userb,
uint32_t ch_target, uint32_t ch_reference);
extern int fmctdc_flush(struct fmctdc_board *userb, unsigned int channel);
/**
*@file fmctdc-lib-math.c
......
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