libiio  0.23
Library for interfacing with IIO devices
iio-backend.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * libiio - Library for interfacing industrial I/O (IIO) devices
4  *
5  * Copyright (C) 2020 Analog Devices, Inc.
6  */
7 
8 #ifndef __IIO_BACKEND_H__
9 #define __IIO_BACKEND_H__
10 
11 #include <stdbool.h>
12 
13 struct iio_device;
14 struct iio_context;
15 
16 enum iio_backend_api_ver {
17  IIO_BACKEND_API_V1 = 1,
18 };
19 
20 enum iio_attr_type {
21  IIO_ATTR_TYPE_DEVICE = 0,
22  IIO_ATTR_TYPE_DEBUG,
23  IIO_ATTR_TYPE_BUFFER,
24 };
25 
26 struct iio_backend_ops {
27  struct iio_context * (*clone)(const struct iio_context *ctx);
28  ssize_t (*read)(const struct iio_device *dev, void *dst, size_t len,
29  uint32_t *mask, size_t words);
30  ssize_t (*write)(const struct iio_device *dev,
31  const void *src, size_t len);
32  int (*open)(const struct iio_device *dev,
33  size_t samples_count, bool cyclic);
34  int (*close)(const struct iio_device *dev);
35  int (*get_fd)(const struct iio_device *dev);
36  int (*set_blocking_mode)(const struct iio_device *dev, bool blocking);
37 
38  void (*cancel)(const struct iio_device *dev);
39 
40  int (*set_kernel_buffers_count)(const struct iio_device *dev,
41  unsigned int nb_blocks);
42  ssize_t (*get_buffer)(const struct iio_device *dev,
43  void **addr_ptr, size_t bytes_used,
44  uint32_t *mask, size_t words);
45 
46  ssize_t (*read_device_attr)(const struct iio_device *dev,
47  const char *attr, char *dst, size_t len, enum iio_attr_type);
48  ssize_t (*write_device_attr)(const struct iio_device *dev,
49  const char *attr, const char *src,
50  size_t len, enum iio_attr_type);
51  ssize_t (*read_channel_attr)(const struct iio_channel *chn,
52  const char *attr, char *dst, size_t len);
53  ssize_t (*write_channel_attr)(const struct iio_channel *chn,
54  const char *attr, const char *src, size_t len);
55 
56  int (*get_trigger)(const struct iio_device *dev,
57  const struct iio_device **trigger);
58  int (*set_trigger)(const struct iio_device *dev,
59  const struct iio_device *trigger);
60 
61  void (*shutdown)(struct iio_context *ctx);
62 
63  char * (*get_description)(const struct iio_context *ctx);
64 
65  int (*get_version)(const struct iio_context *ctx, unsigned int *major,
66  unsigned int *minor, char git_tag[8]);
67 
68  int (*set_timeout)(struct iio_context *ctx, unsigned int timeout);
69 };
70 
79 struct iio_backend {
80  unsigned int api_version;
81  const char *name;
82  const char *uri_prefix;
83  const struct iio_backend_ops *ops;
84  unsigned int sizeof_context_pdata;
85 };
86 
87 struct iio_context * iio_context_create_from_backend(
88  const struct iio_backend *backend,
89  const char *description);
90 
91 #endif /* __IIO_BACKEND_H__ */
Represents an input or output channel of a device.
Contains the representation of an IIO context.
Represents a device in the IIO context.