Commit 3fcbbe75 authored by Federico Vaga's avatar Federico Vaga

lib: add explicit adc_acq_flush() operation

Before this patch, flushing was a special option available during
opening or starting. Users may want to flush independently at any time.
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 5e3cf64d
......@@ -332,6 +332,10 @@ The full acquisition flow is represented in the following picture
config -> start -> poll -> stop;
poll -> poll;
*flush*
The user can flush any previously acquisition from software or hardware
buffers. This can be done with :cpp:func:`adc_acq_flush()`
The usage of these functions depends on the configuration and the board type;
indeed, in some cases you don't need/want to *poll* or manually *stop* because
those operations are automatically performed. For example, most of the ADC
......
......@@ -33,6 +33,7 @@ struct adc_operations {
typeof(adc_acq_start) *acq_start; /**< @related adc_acq_start */
typeof(adc_acq_poll) *acq_poll; /**< @related adc_acq_poll */
typeof(adc_acq_stop) *acq_stop; /**< @related adc_acq_stop */
typeof(adc_acq_flush) *acq_flush; /*< @related adc_acq_flash */
typeof(adc_apply_config) *apply_config; /**< @related adc_apply_config */
typeof(adc_retrieve_config) *retrieve_config; /**< @related adc_retrieve_config */
......@@ -152,6 +153,8 @@ int adc_zio_acq_poll(struct adc_dev *dev,
int adc_zio_acq_stop(struct adc_dev *dev, unsigned int flags);
int adc_zio_acq_flush(struct adc_dev *dev, unsigned int flags);
struct adc_buffer *adc_zio_request_buffer(struct adc_dev *dev,
int nsamples,
void *(*alloc)(size_t),
......
......@@ -32,6 +32,7 @@ extern "C" {
#define ADC_ENOP_OFFCLRSW 1036
#define ADC_OFF_AC_RESTORE_S 1037
#define ADC_OFF_AC_RESTORE_R 1038
#define ADC_ENOFLAGS 1039
/**
* Opaque type. any instance of this should be used as token
......@@ -276,7 +277,8 @@ struct adc_conf {
#define ADC_F_USERMASK 0xffff0000 /**< Flag mask -- low-bits are used
by lib-int.h */
#define ADC_F_FLUSH 0x00010000 /**< Flag used to flush the buffer
(used by adc_open) */
(used by adc_open). It is equivalent of
adc_acq_flush(adc, ADC_FLUSH_F_ANY) */
#define ADC_F_VERBOSE 0x00020000 /**< Flag used to verbose on stdout/stderr
(usable by any function)*/
#define ADC_F_FIXUP 0x00400000 /**< Flag used to fixup a buffer when
......@@ -304,6 +306,16 @@ enum adc_offset_auto_clear_flags {
ADC_OFFSET_AC_F_ZERO), /**< used internally */
};
/**
* Enumeration of all possible flags to drive flushing
*/
enum adc_flush_flags {
ADC_FLUSH_F_ANY = 0x0,
ADC_FLUSH_F_SW = 0x1,
ADC_FLUSH_F_HW = 0x2,
ADC_FLUSH_F_ALL = ADC_FLUSH_F_SW | ADC_FLUSH_F_HW,
};
/**
* @defgroup dev Basic
* Basic library functions
......@@ -340,6 +352,7 @@ extern int adc_acq_start(struct adc_dev *dev, unsigned int flags,
extern int adc_acq_poll(struct adc_dev *dev, unsigned int flags,
struct timeval *timeout);
extern int adc_acq_stop(struct adc_dev *dev, unsigned int flags);
extern int adc_acq_flush(struct adc_dev *dev, unsigned int flags);
/**@}*/
/**
......
......@@ -94,9 +94,10 @@ struct adc_dev *adc_zio_open(const struct adc_board_type *b,
if (fa->fdc < 0 || fa->fdd < 0)
goto out_fa_open;
if (flags & ADC_F_FLUSH)
if (adc_flush_input(fa) < 0)
goto out_fa_open;
if (flags & ADC_F_FLUSH) {
if (adc_acq_flush((void *)&fa->gid, ADC_FLUSH_F_ANY) < 0)
goto out_fa_open;
}
fa->gid.board = b;
......@@ -169,10 +170,8 @@ int adc_zio_acq_poll(struct adc_dev *dev,
int adc_zio_acq_start(struct adc_dev *dev,
unsigned int flags, struct timeval *timeout)
{
struct __adc_dev_zio *fa = to_dev_zio(dev);
if (flags & ADC_F_FLUSH)
if (adc_flush_input(fa) < 0)
if (adc_acq_flush(dev, ADC_FLUSH_F_ANY) < 0)
return -1;
......@@ -187,3 +186,15 @@ int adc_zio_acq_stop(struct adc_dev *dev, unsigned int flags)
/*A portable stop-command could be inserted here*/
return 0;
}
int adc_zio_acq_flush(struct adc_dev *dev, unsigned int flags)
{
struct __adc_dev_zio *fa = to_dev_zio(dev);
if (!(flags & ADC_FLUSH_F_SW)) {
errno = ADC_ENOFLAGS;
return -1;
}
return adc_flush_input(fa);
}
......@@ -247,6 +247,13 @@ static int adc_100m14b4cha_acq_stop(struct adc_dev *dev, unsigned int flags)
return adc_set_param(dev, "cset0/fsm-command", NULL, &cmd);
}
/**
* @copydoc adc_acq_flush
*/
static int adc_100m14b4cha_acq_flush(struct adc_dev *dev, unsigned int flags)
{
return adc_zio_acq_flush(dev, flags);
}
/**
* It configures the options related to the board
......@@ -1273,6 +1280,7 @@ static struct adc_operations fa_100ms_4ch_14bit_op = {
.acq_start = adc_100m14b4cha_acq_start,
.acq_poll = adc_zio_acq_poll,
.acq_stop = adc_100m14b4cha_acq_stop,
.acq_flush = adc_100m14b4cha_acq_flush,
.apply_config = adc_100m14b4cha_apply_config,
.retrieve_config = adc_100m14b4cha_retrieve_config,
......
......@@ -38,6 +38,7 @@ static struct adc_errors {
{ADC_ENOP_OFFCLRSW, "Operation not supported: offset auto-clear software"},
{ADC_OFF_AC_RESTORE_S, "Offset auto-clear: cannot store configuration"},
{ADC_OFF_AC_RESTORE_R, "Offset auto-clear: cannot restore configuration"},
{ADC_ENOFLAGS, "Unsupported flags"},
{ 0, }
};
......@@ -158,7 +159,11 @@ int adc_offset_auto_clear_sw_avg(struct adc_dev *dev,
if (!buf)
return -1;
err = adc_acq_start(dev, ADC_F_FLUSH, &tv);
err = adc_acq_flush(dev, ADC_FLUSH_F_ANY);
if (err)
goto out;
err = adc_acq_start(dev, 0, &tv);
if (err)
goto out;
......
......@@ -249,6 +249,30 @@ int adc_acq_stop(struct adc_dev *dev, unsigned int flags)
return b->adc_op->acq_stop(dev, flags);
}
/**
* Flush any acquired data from any software or hardware buffer
* @param[in] dev ADC device token
* @param[in] flags flags for fine control
* @return 0 on success, -1 on error and errno is set appropriately
*/
int adc_acq_flush(struct adc_dev *dev, unsigned int flags)
{
struct adc_gid *g = (struct adc_gid *)dev;
const struct adc_board_type *b = g->board;
if (!b->adc_op->acq_flush) {
errno = ADC_ENOP;
return -1;
}
if (flags & ADC_FLUSH_F_ALL) {
errno = ADC_ENOFLAGS;
return -1;
}
return b->adc_op->acq_flush(dev, flags);
}
/**
* It applies the given configuration to the device
......
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