libiio
include
iio
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 <
iio/iio.h
>
12
13
#include <stdbool.h>
14
15
#define __api __iio_api
16
17
#define __api_export_if(x) ___api_export_if(x)
18
#define ___api_export_if(x) ___api_export_if_##x
19
#define ___api_export_if_0
20
#define ___api_export_if_1 __iio_api_export
21
22
/* https://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html
23
* {NAME_MAX} : Maximum number of bytes in a filename
24
* {PATH_MAX} : Maximum number of bytes in a pathname
25
* {PAGESIZE} : Size in bytes of a page
26
* Too bad we work on non-POSIX systems
27
*/
28
#ifndef NAME_MAX
29
# define NAME_MAX 256
30
#endif
31
#ifndef PATH_MAX
32
# define PATH_MAX 4096
33
#endif
34
#ifndef PAGESIZE
35
# define PAGESIZE 4096
36
#endif
37
38
#ifdef _MSC_BUILD
39
#define inline __inline
40
#define iio_sscanf sscanf_s
41
#else
42
#define iio_sscanf sscanf
43
#endif
44
45
#define ARRAY_SIZE(x) (sizeof(x) ? sizeof(x) / sizeof((x)[0]) : 0)
46
47
struct
iio_device
;
48
struct
iio_context
;
49
struct
iio_channel
;
50
struct
iio_block_pdata
;
51
struct
iio_buffer_pdata
;
52
struct
iio_context_pdata
;
53
struct
iio_device_pdata
;
54
struct
iio_channel_pdata
;
55
56
enum
iio_backend_api_ver {
57
IIO_BACKEND_API_V1 = 1,
58
};
59
60
enum
iio_attr_type {
61
IIO_ATTR_TYPE_DEVICE = 0,
62
IIO_ATTR_TYPE_DEBUG,
63
IIO_ATTR_TYPE_BUFFER,
64
};
65
66
struct
iio_backend_ops
{
67
int (*scan)(
const
struct
iio_context_params
*params,
68
struct
iio_scan
*ctx,
const
char
*args);
69
struct
iio_context
* (*create)(
const
struct
iio_context_params
*params,
70
const
char
*uri);
71
72
ssize_t (*read_device_attr)(
const
struct
iio_device
*dev,
73
unsigned
int
buf_id,
const
char
*attr,
74
char
*dst,
size_t
len,
enum
iio_attr_type);
75
ssize_t (*write_device_attr)(
const
struct
iio_device
*dev,
76
unsigned
int
buf_id,
const
char
*attr,
77
const
char
*src,
size_t
len,
78
enum
iio_attr_type);
79
ssize_t (*read_channel_attr)(
const
struct
iio_channel
*chn,
80
const
char
*attr,
char
*dst,
size_t
len);
81
ssize_t (*write_channel_attr)(
const
struct
iio_channel
*chn,
82
const
char
*attr,
const
char
*src,
size_t
len);
83
84
int (*get_trigger)(
const
struct
iio_device
*dev,
85
const
struct
iio_device
**trigger);
86
int (*set_trigger)(
const
struct
iio_device
*dev,
87
const
struct
iio_device
*trigger);
88
89
void (*shutdown)(
struct
iio_context
*ctx);
90
91
int (*get_version)(
const
struct
iio_context
*ctx,
unsigned
int
*major,
92
unsigned
int
*minor,
char
git_tag[8]);
93
94
int (*set_timeout)(
struct
iio_context
*ctx,
unsigned
int
timeout);
95
96
struct
iio_buffer_pdata
*(*create_buffer)(
const
struct
iio_device
*dev,
97
unsigned
int
idx,
98
struct
iio_channels_mask
*mask);
99
void (*free_buffer)(
struct
iio_buffer_pdata
*pdata);
100
int (*enable_buffer)(
struct
iio_buffer_pdata
*pdata,
101
size_t
nb_samples,
bool
enable);
102
void (*cancel_buffer)(
struct
iio_buffer_pdata
*pdata);
103
104
ssize_t (*readbuf)(
struct
iio_buffer_pdata
*pdata,
105
void
*dst,
size_t
len);
106
ssize_t (*writebuf)(
struct
iio_buffer_pdata
*pdata,
107
const
void
*src,
size_t
len);
108
109
struct
iio_block_pdata
*(*create_block)(
struct
iio_buffer_pdata
*pdata,
110
size_t
size,
void
**data);
111
void (*free_block)(
struct
iio_block_pdata
*pdata);
112
113
int (*enqueue_block)(
struct
iio_block_pdata
*pdata,
114
size_t
bytes_used,
bool
cyclic);
115
int (*dequeue_block)(
struct
iio_block_pdata
*pdata,
bool
nonblock);
116
117
int (*get_dmabuf_fd)(
struct
iio_block_pdata
*pdata);
118
};
119
127
struct
iio_backend
{
128
unsigned
int
api_version;
129
const
char
*name;
130
const
char
*uri_prefix;
131
const
struct
iio_backend_ops
*ops;
132
unsigned
int
default_timeout_ms;
133
};
134
135
struct
iio_context
* iio_context_create_from_backend(
136
const
struct
iio_backend
*backend,
137
const
char
*description);
138
139
__api
struct
iio_context_pdata
*
140
iio_context_get_pdata(
const
struct
iio_context
*ctx);
141
142
__api
void
143
iio_context_set_pdata(
struct
iio_context
*ctx,
struct
iio_context_pdata
*data);
144
145
__api
struct
iio_device_pdata
*
146
iio_device_get_pdata(
const
struct
iio_device
*dev);
147
148
__api
void
149
iio_device_set_pdata(
struct
iio_device
*dev,
struct
iio_device_pdata
*data);
150
151
__api
struct
iio_channel_pdata
*
152
iio_channel_get_pdata(
const
struct
iio_channel
*chn);
153
154
__api
void
155
iio_channel_set_pdata(
struct
iio_channel
*chn,
struct
iio_channel_pdata
*data);
156
157
__api
int
158
iio_scan_add_result(
struct
iio_scan
*ctx,
const
char
*desc,
const
char
*uri);
159
160
#if defined(__MINGW32__)
161
# define __iio_printf __attribute__((__format__(gnu_printf, 3, 4)))
162
#elif defined(__GNUC__)
163
# define __iio_printf __attribute__((__format__(printf, 3, 4)))
164
#else
165
# define __iio_printf
166
#endif
167
168
__api __iio_printf ssize_t
169
iio_snprintf(
char
*buf,
size_t
len,
const
char
*fmt, ...);
170
__api
char
*iio_strdup(
const
char
*str);
171
__api
size_t
iio_strlcpy(
char
* __restrict dst,
const
char
* __restrict src,
size_t
dsize);
172
173
__api
struct
iio_context
*
174
iio_create_context_from_xml(
const
struct
iio_context_params
*params,
175
const
char
*uri,
const
struct
iio_backend
*backend,
176
const
char
*description,
const
char
**ctx_attr,
177
const
char
**ctx_values,
unsigned
int
nb_ctx_attrs);
178
179
/* Allocate zeroed out memory */
180
static
inline
void
*zalloc(
size_t
size)
181
{
182
return
calloc(1, size);
183
}
184
185
#undef __api
186
187
#endif
/* __IIO_BACKEND_H__ */
iio_backend
Definition:
iio-backend.h:127
iio_buffer_pdata
Definition:
local.h:20
iio_scan
Structure holding scanning information.
Definition:
scan.c:16
iio_channel
Represents an input or output channel of a device.
Definition:
iio-private.h:106
iio_device
Represents a device in the IIO context.
Definition:
iio-private.h:130
iio_device_pdata
Definition:
ops.h:110
iio_context_pdata
Definition:
network.c:56
iio.h
Public interface.
iio_channels_mask
Definition:
iio-private.h:169
iio_context_params
IIO context creation information.
Definition:
iio.h:126
iio_channel_pdata
Definition:
local.c:53
iio_block_pdata
Definition:
iiod-client.c:58
iio_backend_ops
Definition:
iio-backend.h:66
iio_context
Contains the representation of an IIO context.
Definition:
iio-private.h:81
Generated by
1.8.13