From 5b4cd21e86247a81d5ceaec4b4ad8200c4314f38 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 17 Jan 2022 09:30:30 +0000 Subject: [PATCH] local: Add support for setting watermark 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 --- local.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/local.c b/local.c index 10a4a993d..df85f8133 100644 --- a/local.c +++ b/local.c @@ -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) @@ -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;