buffer.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* The industrial I/O core - generic buffer interfaces.
  3. *
  4. * Copyright (c) 2008 Jonathan Cameron
  5. */
  6. #ifndef _IIO_BUFFER_GENERIC_H_
  7. #define _IIO_BUFFER_GENERIC_H_
  8. #include <linux/sysfs.h>
  9. #include <linux/iio/iio.h>
  10. struct iio_buffer;
  11. enum iio_buffer_direction {
  12. IIO_BUFFER_DIRECTION_IN,
  13. IIO_BUFFER_DIRECTION_OUT,
  14. };
  15. int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data);
  16. int iio_pop_from_buffer(struct iio_buffer *buffer, void *data);
  17. /**
  18. * iio_push_to_buffers_with_timestamp() - push data and timestamp to buffers
  19. * @indio_dev: iio_dev structure for device.
  20. * @data: sample data
  21. * @timestamp: timestamp for the sample data
  22. *
  23. * Pushes data to the IIO device's buffers. If timestamps are enabled for the
  24. * device the function will store the supplied timestamp as the last element in
  25. * the sample data buffer before pushing it to the device buffers. The sample
  26. * data buffer needs to be large enough to hold the additional timestamp
  27. * (usually the buffer should be indio->scan_bytes bytes large).
  28. *
  29. * Returns 0 on success, a negative error code otherwise.
  30. */
  31. static inline int iio_push_to_buffers_with_timestamp(struct iio_dev *indio_dev,
  32. void *data, int64_t timestamp)
  33. {
  34. if (indio_dev->scan_timestamp) {
  35. size_t ts_offset = indio_dev->scan_bytes / sizeof(int64_t) - 1;
  36. ((int64_t *)data)[ts_offset] = timestamp;
  37. }
  38. return iio_push_to_buffers(indio_dev, data);
  39. }
  40. int iio_push_to_buffers_with_ts_unaligned(struct iio_dev *indio_dev,
  41. const void *data, size_t data_sz,
  42. int64_t timestamp);
  43. bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev,
  44. const unsigned long *mask);
  45. int iio_device_attach_buffer(struct iio_dev *indio_dev,
  46. struct iio_buffer *buffer);
  47. #endif /* _IIO_BUFFER_GENERIC_H_ */