Commit 5d7b8075 authored by Alessandro Rubini's avatar Alessandro Rubini

lib: reviewed apply/retrieve config. Minor details

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent e688cd5f
......@@ -39,8 +39,9 @@ struct fmcadc_operations fa_100ms_4ch_14bit_op = {
.acq_poll = fmcadc_zio_acq_poll,
.acq_stop = fmcadc_zio_acq_stop,
.apply_config = fmcadc_zio_apply_config,
.retrieve_config = fmcadc_zio_retrieve_config,
.apply_config = fmcadc_zio_apply_config,
.retrieve_config = fmcadc_zio_retrieve_config,
.request_buffer = fmcadc_zio_request_buffer,
.release_buffer = fmcadc_zio_release_buffer,
};
......
......@@ -34,12 +34,9 @@ struct fmcadc_operations {
typeof(fmcadc_acq_poll) *acq_poll;
typeof(fmcadc_acq_stop) *acq_stop;
/* Handle configuration */
int (*apply_config)(struct fmcadc_dev *dev,
unsigned int flags,
struct fmcadc_conf *conf);
int (*retrieve_config)(struct fmcadc_dev *dev,
struct fmcadc_conf *conf);
typeof(fmcadc_apply_config) *apply_config;
typeof(fmcadc_retrieve_config) *retrieve_config;
/* Handle buffers */
struct fmcadc_buffer *(*request_buffer)(struct fmcadc_dev *dev,
int nsamples,
......
......@@ -48,87 +48,43 @@ int fmcadc_acq_stop(struct fmcadc_dev *dev, unsigned int flags)
return b->fa_op->acq_stop(dev, flags);
}
/* * * * * * * * * * * * * * Handle Configuration * * * * * * * * * * * * * */
/*
* fmcadc_apply_config
* @dev: device to configure
* @flags:
* @conf: configuration to apply on device.
*/
int fmcadc_apply_config(struct fmcadc_dev *dev, unsigned int flags,
struct fmcadc_conf *conf)
{
struct fmcadc_gid *b = (void *)dev;
struct fmcadc_gid *g = (void *)dev;
const struct fmcadc_board_type *b = g->board;
uint64_t cap_mask;
if (!conf || !dev) {
/* conf and dev cannot be NULL*/
errno = EINVAL;
return -1;
}
if (!conf->mask) {
errno = FMCADC_ENOMASK;
return -1; /* Nothing to do */
}
cap_mask = b->board->capabilities[conf->type];
cap_mask = b->capabilities[conf->type];
if ((cap_mask & conf->mask) != conf->mask) {
/* Unsupported capabilities */
fprintf(stderr, "Apply Config, wrong mask 0x%llx (0x%llx)",
conf->mask, cap_mask);
errno = FMCADC_ENOCAP;
return -1;
}
if (b->board->fa_op->apply_config) {
/* Apply config */
return b->board->fa_op->apply_config(dev, flags, conf);
} else {
/* Unsupported */
errno = FMCADC_ENOP;
return -1;
}
return b->fa_op->apply_config(dev, flags, conf);
}
/*
* fmcadc_retrieve_config
* @dev: device where retireve configuration
* @flags:
* @conf: configuration to retrieve. The mask tell which value acquire, then
* the library will acquire and set the value in the "value" array
*/
int fmcadc_retrieve_config(struct fmcadc_dev *dev, struct fmcadc_conf *conf)
{
struct fmcadc_gid *b = (void *)dev;
struct fmcadc_gid *g = (void *)dev;
const struct fmcadc_board_type *b = g->board;
uint64_t cap_mask;
if (!conf || !dev) {
/* conf and dev cannot be NULL*/
errno = EINVAL;
return -1;
}
if (!conf->mask) {
errno = FMCADC_ENOMASK;
return -1; /* Nothing to do */
}
cap_mask = b->board->capabilities[conf->type];
cap_mask = b->capabilities[conf->type];
if ((cap_mask & conf->mask) != conf->mask) {
/* Unsupported capabilities */
fprintf(stderr, "Apply Config, wrong mask 0x%llx (0x%llx)",
conf->mask, cap_mask);
errno = FMCADC_ENOCAP;
return -1;
}
if (b->board->fa_op->retrieve_config) {
/* Apply config */
return b->board->fa_op->retrieve_config(dev, conf);
} else {
/* Unsupported */
errno = FMCADC_ENOP;
return -1;
}
return b->fa_op->retrieve_config(dev, conf);
}
/*
......
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