Skip to content

Commit

Permalink
local: Add support for setting watermark
Browse files Browse the repository at this point in the history
Add support for setting the watermark value, if the driver supports it.
The watermark value represents the number of samples that will be read
in one burst from the hardware. Since we read data at the granularity of
iio_buffer blocks, it makes sense to use the highest watermark value up
to the buffer's size. If the value is too high, the driver will
automatically adjust it to the maximum watermark value possible.

Fixes #780.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
  • Loading branch information
pcercuei committed Jan 28, 2022
1 parent 87699e7 commit 5b4cd21
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions local.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ static const char * const device_attrs_blacklist[] = {
static const char * const buffer_attrs_reserved[] = {
"length",
"enable",
"watermark",
};

static int ioctl_nointr(int fd, unsigned long request, void *data)
Expand Down Expand Up @@ -923,6 +924,15 @@ static int local_open(const struct iio_device *dev,
if (ret < 0)
return ret;

/*
* Set watermark to the buffer size; the driver will adjust to its
* maximum if it's too high without issueing an error.
*/
ret = local_write_dev_attr(dev, "buffer/watermark",
buf, strlen(buf) + 1, false);
if (ret < 0 && ret != -ENOENT)
return ret;

pdata->cancel_fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
if (pdata->cancel_fd == -1)
return -errno;
Expand Down

0 comments on commit 5b4cd21

Please sign in to comment.