buffer.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* The industrial I/O core - generic buffer interfaces.
  2. *
  3. * Copyright (c) 2008 Jonathan Cameron
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. */
  9. #ifndef _IIO_BUFFER_GENERIC_H_
  10. #define _IIO_BUFFER_GENERIC_H_
  11. #include <linux/sysfs.h>
  12. #include <linux/iio/iio.h>
  13. struct iio_buffer;
  14. void iio_buffer_set_attrs(struct iio_buffer *buffer,
  15. const struct attribute **attrs);
  16. int iio_push_to_buffers(struct iio_dev *indio_dev, const 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. bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev,
  41. const unsigned long *mask);
  42. void iio_device_attach_buffer(struct iio_dev *indio_dev,
  43. struct iio_buffer *buffer);
  44. #endif /* _IIO_BUFFER_GENERIC_H_ */