Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /* The industrial I/O core - generic buffer interfaces.
0003  *
0004  * Copyright (c) 2008 Jonathan Cameron
0005  */
0006 
0007 #ifndef _IIO_BUFFER_GENERIC_H_
0008 #define _IIO_BUFFER_GENERIC_H_
0009 #include <linux/sysfs.h>
0010 #include <linux/iio/iio.h>
0011 
0012 struct iio_buffer;
0013 
0014 enum iio_buffer_direction {
0015     IIO_BUFFER_DIRECTION_IN,
0016     IIO_BUFFER_DIRECTION_OUT,
0017 };
0018 
0019 int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data);
0020 
0021 int iio_pop_from_buffer(struct iio_buffer *buffer, void *data);
0022 
0023 /**
0024  * iio_push_to_buffers_with_timestamp() - push data and timestamp to buffers
0025  * @indio_dev:      iio_dev structure for device.
0026  * @data:       sample data
0027  * @timestamp:      timestamp for the sample data
0028  *
0029  * Pushes data to the IIO device's buffers. If timestamps are enabled for the
0030  * device the function will store the supplied timestamp as the last element in
0031  * the sample data buffer before pushing it to the device buffers. The sample
0032  * data buffer needs to be large enough to hold the additional timestamp
0033  * (usually the buffer should be indio->scan_bytes bytes large).
0034  *
0035  * Returns 0 on success, a negative error code otherwise.
0036  */
0037 static inline int iio_push_to_buffers_with_timestamp(struct iio_dev *indio_dev,
0038     void *data, int64_t timestamp)
0039 {
0040     if (indio_dev->scan_timestamp) {
0041         size_t ts_offset = indio_dev->scan_bytes / sizeof(int64_t) - 1;
0042         ((int64_t *)data)[ts_offset] = timestamp;
0043     }
0044 
0045     return iio_push_to_buffers(indio_dev, data);
0046 }
0047 
0048 int iio_push_to_buffers_with_ts_unaligned(struct iio_dev *indio_dev,
0049                       const void *data, size_t data_sz,
0050                       int64_t timestamp);
0051 
0052 bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev,
0053                    const unsigned long *mask);
0054 
0055 int iio_device_attach_buffer(struct iio_dev *indio_dev,
0056                  struct iio_buffer *buffer);
0057 
0058 #endif /* _IIO_BUFFER_GENERIC_H_ */