Commit a9d0d7b3 authored by Federico Vaga's avatar Federico Vaga

[fix][add] libfmcadc: fix mask control and add a new error

The library was checking the flags field, but it must check the mask field
to verify if there is a configuration to apply. To avoid situations where
the user is convinced to apply a configuration but he forgots to set
the bit mask, now the library return an error if the user tries to configure
with an empty mask.

Thank to "Michel Arruat <michel.arruat@cern.ch>" who found the problem
Signed-off-by: 's avatarFederico Vaga <federico.vaga@gmail.com>
parent 7ae2ba9b
......@@ -175,9 +175,10 @@ int fmcadc_apply_config(struct fmcadc_dev *dev, unsigned int flags,
errno = EINVAL;
return -1;
}
if (!conf->flags)
return 0; /* Nothing to do */
if (!conf->mask) {
errno = FMCADC_ENOMASK;
return -1; /* Nothing to do */
}
cap_mask = b->board->capabilities[conf->type];
if ((cap_mask & conf->mask) != conf->mask) {
/* Unsupported capabilities */
......@@ -214,7 +215,10 @@ int fmcadc_retrieve_config(struct fmcadc_dev *dev, struct fmcadc_conf *conf)
errno = EINVAL;
return -1;
}
if (!conf->mask) {
errno = FMCADC_ENOMASK;
return -1; /* Nothing to do */
}
cap_mask = b->board->capabilities[conf->type];
if ((cap_mask & conf->mask) != conf->mask) {
/* Unsupported capabilities */
......@@ -307,7 +311,7 @@ char *fmcadc_strerror(struct fmcadc_dev *dev, int errnum)
return NULL;
}
if (errnum >= FMCADC_ENOP && errnum <= FMCADC_ENOCHAN) {
if (errnum >= FMCADC_ENOP && errnum <= FMCADC_ENOMASK) {
switch (errnum) {
case FMCADC_ENOP:
str = "Operation not supported";
......@@ -327,6 +331,9 @@ char *fmcadc_strerror(struct fmcadc_dev *dev, int errnum)
case FMCADC_ENOCHAN:
str = "Invalid channel";
break;
case FMCADC_ENOMASK:
str = "Missing configuration mask";
break;
}
goto out;
}
......
......@@ -12,6 +12,7 @@
#define FMCADC_ENOGET 1027
#define FMCADC_ENOSET 1028
#define FMCADC_ENOCHAN 1029
#define FMCADC_ENOMASK 1030
struct fmcadc_dev;
......
......@@ -140,7 +140,7 @@ int main(int argc, char *argv[])
fmcadc_set_attr(&trg, FMCADC_CONF_TRG_POLARITY,
trgval[FMCADC_CONF_TRG_POLARITY]);
err = fmcadc_apply_config(adc, 0 , &trg);
if (err) {
if (err && errno != FMCADC_ENOMASK) {
printf("Cannot apply trigger configuration: (%d) %s\n",
errno, fmcadc_strerror(adc, errno));
exit(1);
......@@ -150,7 +150,7 @@ int main(int argc, char *argv[])
/* Configure acquisition parameter */
acq.type = FMCADC_CONF_TYPE_ACQ;
err = fmcadc_apply_config(adc, 0 , &acq);
if (err) {
if (err && errno != FMCADC_ENOMASK) {
printf("Cannot apply acquisition configuration: (%d) %s\n",
errno, fmcadc_strerror(adc, errno));
exit(1);
......
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