Commit 1dc4045e authored by Federico Vaga's avatar Federico Vaga

Merge branch 'release/v2.5.1' into master

parents 61a6d23d 97531247
......@@ -5,6 +5,8 @@ REPO_PARENT ?= $(shell /bin/pwd)/..
DIRS = lib tools
CPPCHECK ?= cppcheck
all clean modules install modules_install: $(DIRS)
clean: TARGET = clean
......@@ -16,4 +18,7 @@ tools: lib
$(DIRS):
$(MAKE) -C $@ $(TARGET)
cppcheck:
$(CPPCHECK) --enable=all ./
.PHONY: all clean modules install modules_install $(DIRS)
......@@ -39,6 +39,7 @@ CFLAGS += $(EXTRACFLAGS)
LDFLAGS = -L. -ladc
CC ?= $(CROSS_COMPILE)gcc
CPPCHECK ?= cppcheck
modules all: $(LIB) $(LIBS)
......@@ -52,6 +53,9 @@ $(LIB): $(LOBJ)
$(LIBS): $(LIB)
$(CC) -shared -o $@ -Wl,--whole-archive,-soname,$@ $^ -Wl,--no-whole-archive
cppcheck:
$(CPPCHECK) --enable=all ./
clean:
rm -f $(LIB) $(LIBS) .depend *.o *~
......@@ -61,4 +65,3 @@ clean:
install modules_install:
-include .depend
......@@ -105,11 +105,12 @@ static int adc_genfake_set_param(struct adc_dev *dev, char *name,
struct __adc_dev_genfake,
gid);
unsigned int ind, type;
if (name == NULL) {
ind = fg->conf_index;
type = fg->conf_type;
} else
sscanf(name, "%d/%d", &type, &ind);
sscanf(name, "%u/%u", &type, &ind);
switch(type){
case ADC_CONF_TYPE_BRD:
......@@ -155,13 +156,13 @@ static int adc_genfake_get_param(struct adc_dev *dev, char *name,
struct __adc_dev_genfake *fg = container_of(dev,
struct __adc_dev_genfake,
gid);
unsigned int ind, type;
if (name == NULL) {
ind = fg->conf_index;
type = fg->conf_type;
} else
sscanf(name, "%d/%d", &type, &ind);
sscanf(name, "%u/%u", &type, &ind);
switch (type) {
case ADC_CONF_TYPE_BRD:
......@@ -208,8 +209,9 @@ static int adc_genfake_apply_config(struct adc_dev *dev, unsigned int flags,
struct __adc_dev_genfake,
gid);
int i, err, val;
for (i=0; i < __ADC_CONF_LEN; i++) {
if (!(conf->mask & (1LL << i)))
if (!(conf->mask & (1ULL << i)))
continue;
fg->conf_index = i;
fg->conf_type = conf->type;
......@@ -230,7 +232,7 @@ static int adc_genfake_retrieve_config(struct adc_dev *dev,
gid);
int i, err, val;
for (i=0; i < __ADC_CONF_LEN; i++) {
if (!(conf->mask & (1LL << i)))
if (!(conf->mask & (1ULL << i)))
continue;
fg->conf_index = i;
fg->conf_type = conf->type;
......@@ -324,7 +326,7 @@ static int adc_genfake_fill_buffer(struct adc_dev *dev,
for (i=0; i < datalen; i += sizeof(datum)) {
datum = rand() % 256;
sprintf(buf->data+i, "%c", datum);
sprintf(buf->data + i, "%c", datum);
}
return 0;
......
......@@ -38,16 +38,18 @@ static int adc_flush_input(struct __adc_dev_zio *fa)
.fd = fa->fdc,
.events = POLLIN | POLLERR,
};
int i;
/* Read the control until one is there; data is discarded by zio */
while (1) {
i = poll(&p, 1, 0);
int ret;
int i = poll(&p, 1, 0);
if (i < 0)
return -1;
if ((p.revents & POLLIN) == 0)
return 0;
read(fa->fdc, &ctrl, sizeof(ctrl));
ret = read(fa->fdc, &ctrl, sizeof(ctrl));
if (ret != sizeof(ctrl))
return -1;
}
}
......@@ -62,17 +64,24 @@ struct adc_dev *adc_zio_open(const struct adc_board_type *b,
struct stat st;
char *syspath, *devpath, fname[128];
int udev_zio_dir = 1;
int ret;
/* Check if device exists by looking in sysfs */
asprintf(&syspath, "%s/%s-%04x", ZIO_SYS_PATH, b->devname, dev_id);
ret = asprintf(&syspath, "%s/%s-%04x", ZIO_SYS_PATH,
b->devname, dev_id);
if (ret < 0)
goto out_str_alloc_syspath;
if (stat(syspath, &st))
goto out_fa_stat; /* ENOENT or equivalent */
/* ZIO char devices are in /dev/zio or just /dev (older udev) */
if (stat("/dev/zio", &st) < 0)
udev_zio_dir = 0;
asprintf(&devpath, "%s/%s-%04x", (udev_zio_dir ? "/dev/zio" : "/dev"),
b->devname, dev_id);
ret = asprintf(&devpath, "%s/%s-%04x",
(udev_zio_dir ? "/dev/zio" : "/dev"),
b->devname, dev_id);
if (ret < 0)
goto out_str_alloc_devpath;
/* Sysfs path exists, so device is there, hopefully */
fa = calloc(1, sizeof(*fa));
......@@ -82,18 +91,19 @@ struct adc_dev *adc_zio_open(const struct adc_board_type *b,
fa->devbase = devpath;
fa->cset = cset;
fa->chan = chan;
fa->dev_id = dev_id;
/* Open char devices */
if (chan == ~0) {
sprintf(fname, "%s-%d-i-ctrl", fa->devbase, fa->cset);
sprintf(fname, "%s-%u-i-ctrl", fa->devbase, fa->cset);
fa->fdc = open(fname, O_RDONLY);
sprintf(fname, "%s-%d-i-data", fa->devbase, fa->cset);
sprintf(fname, "%s-%u-i-data", fa->devbase, fa->cset);
fa->fdd = open(fname, O_RDONLY);
} else {
sprintf(fname, "%s-%d-%d-ctrl",
sprintf(fname, "%s-%u-%d-ctrl",
fa->devbase, fa->cset, fa->chan);
fa->fdc = open(fname, O_RDONLY);
sprintf(fname, "%s-%d-%d-data",
sprintf(fname, "%s-%u-%d-data",
fa->devbase, fa->cset, fa->chan);
fa->fdd = open(fname, O_RDONLY);
}
......@@ -125,9 +135,10 @@ out_fa_open:
free(fa);
out_fa_alloc:
free(devpath);
out_str_alloc_devpath:
out_fa_stat:
free(syspath);
out_str_alloc_syspath:
return NULL;
}
......
......@@ -29,7 +29,6 @@
static int adc_zio_read_ctrl(struct __adc_dev_zio *fa,
struct adc_buffer *buf)
{
struct zio_control *ctrl;
int i;
i = read(fa->fdc, buf->metadata, sizeof(struct zio_control));
......@@ -49,8 +48,8 @@ static int adc_zio_read_ctrl(struct __adc_dev_zio *fa,
return -1;
default:
if (fa->flags & ADC_FLAG_VERBOSE)
fprintf(stderr, "%s: read: %i bytes (expected %zi)\n",
__func__, i, sizeof(ctrl));
fprintf(stderr, "%s: read: %i bytes (expected %zu)\n",
__func__, i, sizeof(struct zio_control));
return -1;
}
}
......@@ -117,10 +116,11 @@ struct adc_buffer *adc_zio_request_buffer(struct adc_dev *dev,
{
struct __adc_dev_zio *fa = to_dev_zio(dev);
struct adc_buffer *buf;
char s[16];
/* If this is the first buffer, we need to know which kind it is */
if ((fa->flags & (ADC_FLAG_MALLOC | ADC_FLAG_MMAP)) == 0) {
char s[16];
adc_get_param(dev, "cset0/current_buffer", s, NULL);
if (!strcmp(s, "vmalloc"))
fa->flags |= ADC_FLAG_MMAP;
......
......@@ -225,28 +225,28 @@ static int adc_zio_config_chn(struct __adc_dev_zio *fa, unsigned int ch,
switch (index) {
case ADC_CONF_CHN_RANGE:
sprintf(path, "cset%d/ch%d-vref", fa->cset, ch);
sprintf(path, "cset%u/ch%u-vref", fa->cset, ch);
if (direction)
return adc_zio_sysfs_set(fa, path, value);
else
return adc_zio_sysfs_get(fa, path, value);
break;
case ADC_CONF_CHN_TERMINATION:
sprintf(path, "cset%d/ch%d-50ohm-term", fa->cset, ch);
sprintf(path, "cset%u/ch%u-50ohm-term", fa->cset, ch);
if (direction)
return adc_zio_sysfs_set(fa, path, value);
else
return adc_zio_sysfs_get(fa, path, value);
break;
case ADC_CONF_CHN_OFFSET:
sprintf(path, "cset%d/ch%d-offset", fa->cset, ch);
sprintf(path, "cset%u/ch%u-offset", fa->cset, ch);
if (direction)
return adc_zio_sysfs_set(fa, path, value);
else
return adc_zio_sysfs_get(fa, path, value);
break;
case ADC_CONF_CHN_SATURATION:
sprintf(path, "cset%d/ch%d-saturation", fa->cset, ch);
sprintf(path, "cset%u/ch%u-saturation", fa->cset, ch);
if (direction)
return adc_zio_sysfs_set(fa, path, value);
else
......@@ -298,7 +298,7 @@ static int adc_zio_config(struct __adc_dev_zio *fa, unsigned int flags,
}
for (i = 0; i < __ADC_CONF_LEN; ++i) {
if (!(conf->mask & (1LL << i)))
if (!(conf->mask & (1ULL << i)))
continue;
/* Parameter to configure */
......
......@@ -53,7 +53,9 @@
(1LL << ADC_CONF_BRD_N_CHAN) | \
(1LL << ADC_CONF_BRD_N_TRG_EXT) | \
(1LL << ADC_CONF_BRD_N_TRG_THR) | \
(1LL << ADC_CONF_BRD_N_TRG_TIM)
(1LL << ADC_CONF_BRD_N_TRG_TIM) | \
(1LL << ADC_CONF_UTC_TIMING_BASE_S) | \
(1LL << ADC_CONF_UTC_TIMING_BASE_T)
#define ADC_100M_4CH_14BIT_CUS_MASK (1ULL << ADC_CONF_100M14B4CHA_BUF_TYPE) | \
(1ULL << ADC_CONF_100M14B4CHA_TRG_SW_EN) | \
(1ULL << ADC_CONF_100M14B4CHA_ACQ_MSHOT_MAX) | \
......@@ -100,7 +102,7 @@ static int adc_100m14b4cha_buffer_resize(struct adc_dev *dev,
struct __adc_dev_zio *fa = to_dev_zio(dev);
unsigned long max = nbuffers * (totalsamples * fa->samplesize);
enum adc_100m14b4cha_buf_type type;
char str[32];
char str[34];
int err, val;
err = adc_get_param(dev, "cset0/current_buffer", str, NULL);
......@@ -312,7 +314,23 @@ static int adc_100m14b4cha_config_brd(struct adc_dev *adc,
*value = 1;
return 0;
}
case ADC_CONF_UTC_TIMING_BASE_S:
if (direction) {
errno = ADC_ENOSET;
return -1;
} else {
return adc_get_param(adc, "cset0/tstamp-base-sl",
NULL, (int *)value);
}
case ADC_CONF_UTC_TIMING_BASE_T:
if (direction) {
errno = ADC_ENOSET;
return -1;
} else {
*value = 1;
return adc_get_param(adc, "cset0/tstamp-base-t",
NULL, (int *)value);
}
default:
errno = ADC_ENOCAP;
return -1;
......@@ -414,19 +432,19 @@ static int adc_100m14b4cha_config_chn(struct adc_dev *adc,
switch (index) {
case ADC_CONF_CHN_RANGE:
sprintf(path, "cset%d/ch%d-vref", fa->cset, source);
sprintf(path, "cset%u/ch%u-vref", fa->cset, source);
break;
case ADC_CONF_CHN_TERMINATION:
sprintf(path, "cset%d/ch%d-50ohm-term", fa->cset, source);
sprintf(path, "cset%u/ch%u-50ohm-term", fa->cset, source);
break;
case ADC_CONF_CHN_OFFSET:
sprintf(path, "cset%d/ch%d-offset", fa->cset, source);
sprintf(path, "cset%u/ch%u-offset", fa->cset, source);
break;
case __ADC_CONF_CHN_OFFSET_ZERO:
sprintf(path, "cset%d/ch%d-offset-zero", fa->cset, source);
sprintf(path, "cset%u/ch%u-offset-zero", fa->cset, source);
break;
case ADC_CONF_CHN_SATURATION:
sprintf(path, "cset%d/ch%d-saturation", fa->cset, source);
sprintf(path, "cset%u/ch%u-saturation", fa->cset, source);
break;
default:
errno = ADC_ENOCAP;
......@@ -475,7 +493,7 @@ static int __config_trg_enable(struct adc_dev *adc,
*value = !!(tmp & mask);
}
return 0;
return err;
}
......@@ -596,13 +614,13 @@ static int adc_100m14b4cha_config_trg_thr(struct adc_dev *adc,
}
break;
case ADC_CONF_TRG_THR_DELAY:
sprintf(path, "cset0/trigger/ch%d-delay", source);
sprintf(path, "cset0/trigger/ch%u-delay", source);
return adc_param[direction](adc, path, NULL, (int *)value);
case ADC_CONF_TRG_THR_THRESHOLD:
sprintf(path, "cset0/trigger/ch%d-threshold", source);
sprintf(path, "cset0/trigger/ch%u-threshold", source);
return adc_param[direction](adc, path, NULL, (int *)value);
case ADC_CONF_TRG_THR_HYSTERESIS:
sprintf(path, "cset0/trigger/ch%d-hysteresis", source);
sprintf(path, "cset0/trigger/ch%u-hysteresis", source);
return adc_param[direction](adc, path, NULL, (int *)value);
default:
errno = ADC_ENOCAP;
......@@ -748,7 +766,7 @@ static int adc_100m14b4cha_config(struct adc_dev *adc,
}
for (i = 0; i < __ADC_CONF_LEN; ++i) {
if (!(conf->mask & (1LL << i)))
if (!(conf->mask & (1ULL << i)))
continue;
/* Parameter to configure */
......@@ -853,10 +871,24 @@ static int adc_100m14b4cha_retrieve_config(struct adc_dev *dev,
*/
static int adc_100m14b4cha_trigger_fire(struct adc_dev *dev)
{
int value = 1;
return adc_set_param(dev, "cset0/trigger/sw-trg-fire",
NULL, &value);
struct __adc_dev_zio *fa = to_dev_zio(dev);
char pathname[128];
int fd, ret;
snprintf(pathname, sizeof(pathname),
"/sys/kernel/debug/adc-100m14b-%04x/trigger_software",
fa->dev_id);
fd = open(pathname, O_WRONLY);
if (fd < 0)
return -1;
ret = write(fd, "1", 1);
close(fd);
if (ret < 0)
return -1;
if (ret == 1)
return 0;
errno = EIO;
return -1;
}
static int adc_100m14b4cha_buffer_get_sample(struct adc_buffer *buf,
......@@ -1170,13 +1202,13 @@ static int adc_100m14b4cha_offset_zero_set(struct adc_dev *dev)
static int adc_100m14b4cha_range_set_all(struct adc_dev *dev,
enum adc_configuration_100m14b4cha_channel_range range)
{
int i, err;
int i;
for (i = 0; i < FA100M14B4C_NCHAN; ++i) {
err = adc_100m14b4cha_config_chn(dev, i,
ADC_CONF_CHN_RANGE,
&range,
ADC_CONF_SET);
int err = adc_100m14b4cha_config_chn(dev, i,
ADC_CONF_CHN_RANGE,
&range,
ADC_CONF_SET);
if (err)
return err;
}
......
......@@ -133,6 +133,7 @@ int adc_get_conf(struct adc_conf *conf, unsigned int conf_index,
*val = conf->value[conf_index];
return 0;
} else {
errno = ADC_ENOMASK;
return -1;
}
}
......
......@@ -127,7 +127,7 @@ struct adc_dev *adc_open_by_lun(char *name, int lun,
ssize_t ret;
char dev_id_str[8];
char path[PATH_MAX];
int dev_id;
uint32_t dev_id;
ret = snprintf(path, sizeof(path), "/dev/%s.%d",
"adc-100m14b" /* FIXME: this must be generic */,
......@@ -137,6 +137,8 @@ struct adc_dev *adc_open_by_lun(char *name, int lun,
return NULL;
}
ret = readlink(path, dev_id_str, sizeof(dev_id_str));
if (ret < 0)
return NULL;
if (sscanf(dev_id_str, "%4x", &dev_id) != 1) {
errno = ENODEV;
return NULL;
......
......@@ -23,6 +23,7 @@ LDLIBS += -Wl,-Bdynamic -lrt
DEMOS := adc-acq
DEMOS += example
CPPCHECK ?= cppcheck
all: demo
......@@ -35,6 +36,9 @@ install:
%: %.c $(LIBADC)/libadc.a
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(LDLIBS)
cppcheck:
$(CPPCHECK) --enable=all ./
# make nothing for modules_install, but avoid errors
modules_install:
......
This diff is collapsed.
......@@ -196,11 +196,11 @@ static int current_config_acquisition(struct adc_dev *adc)
}
adc_get_conf(&cfg, ADC_CONF_ACQ_N_SHOTS, &sh);
fprintf(stdout, "Number of shots: %d\n", sh);
fprintf(stdout, "Number of shots: %u\n", sh);
adc_get_conf(&cfg, ADC_CONF_ACQ_POST_SAMP, &po);
fprintf(stdout, "Number of post-samples: %d\n", po);
fprintf(stdout, "Number of post-samples: %u\n", po);
adc_get_conf(&cfg, ADC_CONF_ACQ_PRE_SAMP, &pr);
fprintf(stdout, "Number of pre-samples: %d\n", pr);
fprintf(stdout, "Number of pre-samples: %u\n", pr);
return 0;
......
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