libiio  0.21
Library for interfacing with IIO devices
iio-backend.h
1 /*
2  * libiio - Library for interfacing industrial I/O (IIO) devices
3  *
4  * Copyright (C) 2020 Analog Devices, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * */
17 
18 #ifndef __IIO_BACKEND_H__
19 #define __IIO_BACKEND_H__
20 
21 #include <stdbool.h>
22 
23 struct iio_device;
24 struct iio_context;
25 
26 enum iio_backend_api_ver {
27  IIO_BACKEND_API_V1 = 1,
28 };
29 
30 enum iio_attr_type {
31  IIO_ATTR_TYPE_DEVICE = 0,
32  IIO_ATTR_TYPE_DEBUG,
33  IIO_ATTR_TYPE_BUFFER,
34 };
35 
36 struct iio_backend_ops {
37  struct iio_context * (*clone)(const struct iio_context *ctx);
38  ssize_t (*read)(const struct iio_device *dev, void *dst, size_t len,
39  uint32_t *mask, size_t words);
40  ssize_t (*write)(const struct iio_device *dev,
41  const void *src, size_t len);
42  int (*open)(const struct iio_device *dev,
43  size_t samples_count, bool cyclic);
44  int (*close)(const struct iio_device *dev);
45  int (*get_fd)(const struct iio_device *dev);
46  int (*set_blocking_mode)(const struct iio_device *dev, bool blocking);
47 
48  void (*cancel)(const struct iio_device *dev);
49 
50  int (*set_kernel_buffers_count)(const struct iio_device *dev,
51  unsigned int nb_blocks);
52  ssize_t (*get_buffer)(const struct iio_device *dev,
53  void **addr_ptr, size_t bytes_used,
54  uint32_t *mask, size_t words);
55 
56  ssize_t (*read_device_attr)(const struct iio_device *dev,
57  const char *attr, char *dst, size_t len, enum iio_attr_type);
58  ssize_t (*write_device_attr)(const struct iio_device *dev,
59  const char *attr, const char *src,
60  size_t len, enum iio_attr_type);
61  ssize_t (*read_channel_attr)(const struct iio_channel *chn,
62  const char *attr, char *dst, size_t len);
63  ssize_t (*write_channel_attr)(const struct iio_channel *chn,
64  const char *attr, const char *src, size_t len);
65 
66  int (*get_trigger)(const struct iio_device *dev,
67  const struct iio_device **trigger);
68  int (*set_trigger)(const struct iio_device *dev,
69  const struct iio_device *trigger);
70 
71  void (*shutdown)(struct iio_context *ctx);
72 
73  char * (*get_description)(const struct iio_context *ctx);
74 
75  int (*get_version)(const struct iio_context *ctx, unsigned int *major,
76  unsigned int *minor, char git_tag[8]);
77 
78  int (*set_timeout)(struct iio_context *ctx, unsigned int timeout);
79 };
80 
89 struct iio_backend {
90  unsigned int api_version;
91  const char *name;
92  const char *uri_prefix;
93  const struct iio_backend_ops *ops;
94  unsigned int sizeof_context_pdata;
95 };
96 
97 __api struct iio_context * iio_context_create_from_backend(
98  const struct iio_backend *backend,
99  const char *description);
100 
101 #endif /* __IIO_BACKEND_H__ */
Represents an input or output channel of a device.
Represents a device in the IIO context.
Contains the representation of an IIO context.