no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
iiod.h
Go to the documentation of this file.
1/***************************************************************************/
33
34#ifndef IIOD_H
35#define IIOD_H
36
37#include <stdint.h>
38#include <stdbool.h>
39
40#include "iio.h"
41
42/* Maximum nomber of iiod connections to allocate simultaneously */
43#define IIOD_MAX_CONNECTIONS 10
44#define IIOD_VERSION "1.1.0000000"
45#define IIOD_VERSION_LEN (sizeof(IIOD_VERSION) - 1)
46
47#define MAX_DEV_ID 64
48#define MAX_TRIG_ID 64
49#define MAX_CHN_ID 64
50#define MAX_ATTR_NAME 256
51
59
60struct iiod_attr {
62 /*
63 * Attribute name.
64 * If empty (""), all attributes of the specified iio_attr_type must
65 * be read/wrote
66 */
67 const char *name;
68 const char *channel;
69};
70
71struct iiod_ctx {
72 /* Value specified in iiod_init_param.instance in iiod_init */
73 void *instance;
74 /* Value specified in iiod_conn_data.conn in iiod_conn_add */
75 void *conn;
76};
77
79 /* Value to be used in iiod_ctx */
80 void *conn;
81 /* Buffer to store attributes or buffer data for a connection. */
82 char *buf;
83 /* Size of the provided buffer. It must fit the max attribute size */
84 uint32_t len;
85};
86
87/* Functions should return a negative error code on failure */
88struct iiod_ops {
89 /*
90 * I/O operations
91 * Send and recv are used to send or receive data to/from a connection.
92 * They should send/receive the at maximum len bytes.
93 * They must return the number of bytes sent/received.
94 * They can return 0 or -EAGAIN when no data was processed.
95 * They can do not block. They will be called again if there is still
96 * data to be sent/recevied
97 */
98 int (*send)(struct iiod_ctx *ctx, uint8_t *buf, uint32_t len);
99 int (*recv)(struct iiod_ctx *ctx, uint8_t *buf, uint32_t len);
100
101 /*
102 * This is the equivalent of libiio iio_device_create_buffer.
103 * Called in order to create a buffer to read or write data.
104 * read_buffer or write_buffer will follow with a maximum of samples
105 * (depending on the internal buffer).
106 * All calls with the same ctx will refer to this buffer until close is
107 * called.
108 */
109 int (*open)(struct iiod_ctx *ctx, const char *device, uint32_t samples,
110 uint32_t mask, bool cyclic);
111 /* Equivalent of iio_buffer_destroy */
112 int (*close)(struct iiod_ctx *ctx, const char *device);
113
114 /* Read data from opened buffer */
115 int (*read_buffer)(struct iiod_ctx *ctx, const char *device, char *buf,
116 uint32_t bytes);
117 /* Called to notify that buffer must be refiiled */
118 int (*refill_buffer)(struct iiod_ctx *ctx, const char *device);
119
120 /* Write data to opened buffer */
121 int (*write_buffer)(struct iiod_ctx *ctx, const char *device,
122 const char *buf, uint32_t bytes);
123 /* Called to notify that buffer must be pushed to hardware */
124 int (*push_buffer)(struct iiod_ctx *ctx, const char *device);
125
126 /*
127 * Attribute has to be read in buf and return the number of bytes
128 * written.
129 */
130 int (*read_attr)(struct iiod_ctx *ctx, const char *device,
131 struct iiod_attr *attr, char *buf, uint32_t len);
132 /* Attribute buf is filled with the attribute value. */
133 int (*write_attr)(struct iiod_ctx *ctx, const char *device,
134 struct iiod_attr *attr, char *buf, uint32_t len);
135 /* Simular with read_attr but trigger must be filled */
136 int (*get_trigger)(struct iiod_ctx *ctx, const char *device,
137 char *trigger, uint32_t len);
138 /*
139 * Simular with write_attr but trigger name is in trigger.
140 * If trigger is equals to "". Trigger must be removed.
141 */
142 int (*set_trigger)(struct iiod_ctx *ctx, const char *device,
143 const char *trigger, uint32_t len);
144
145 /* I don't know what this should be used for :) */
146 int (*set_timeout)(struct iiod_ctx *ctx, uint32_t timeout);
147
148 /* I don't know what this should be used for :) */
149 int (*set_buffers_count)(struct iiod_ctx *ctx, const char *device,
150 uint32_t buffers_count);
151};
152
153/*
154 * Internal structure.
155 * It is created in iiod_init and must be passed to all fucntions
156 */
157struct iiod_desc;
158
159/* Parameter to initialize iiod_desc */
161 struct iiod_ops *ops;
162 /* Value to be send in each iiod_ctx from iiod_ops functions */
163 void *instance;
164 /*
165 * Xml description of the context and devices. It should exist until
166 * iiod_remove is called
167 */
168 char *xml;
169 /* Size of xml in bytes */
170 uint32_t xml_len;
171 /* Backend used by IIOD */
173};
174
175/* Initialize desc. */
176int32_t iiod_init(struct iiod_desc **desc, struct iiod_init_param *param);
177/* Remove desc resources */
178void iiod_remove(struct iiod_desc *desc);
179
180/*
181 * Notify iiod about a new connection in order to store context for it.
182 * new_conn_id is set in order to reference the connection in iiod_conn_step
183 */
184int32_t iiod_conn_add(struct iiod_desc *desc, struct iiod_conn_data *data,
185 uint32_t *new_conn_id);
186/* Remove conn_id from iiod. Provided data is returned in data */
187int32_t iiod_conn_remove(struct iiod_desc *desc, uint32_t conn_id,
188 struct iiod_conn_data *data);
189/* Advance in the state machine of a connection. Will not block */
190int32_t iiod_conn_step(struct iiod_desc *desc, uint32_t conn_id);
191
192#endif //IIOD_H
uint32_t timeout
Definition ad413x.c:46
Header file of iio.
physical_link_type
Definition iio.h:44
int32_t iiod_init(struct iiod_desc **desc, struct iiod_init_param *param)
Definition iiod.c:347
int32_t iiod_conn_remove(struct iiod_desc *desc, uint32_t conn_id, struct iiod_conn_data *data)
Definition iiod.c:423
void iiod_remove(struct iiod_desc *desc)
Definition iiod.c:376
int32_t iiod_conn_add(struct iiod_desc *desc, struct iiod_conn_data *data, uint32_t *new_conn_id)
Definition iiod.c:393
iio_attr_type
Definition iiod.h:52
@ IIO_ATTR_TYPE_BUFFER
Definition iiod.h:54
@ IIO_ATTR_TYPE_DEVICE
Definition iiod.h:57
@ IIO_ATTR_TYPE_CH_OUT
Definition iiod.h:55
@ IIO_ATTR_TYPE_DEBUG
Definition iiod.h:53
@ IIO_ATTR_TYPE_CH_IN
Definition iiod.h:56
int32_t iiod_conn_step(struct iiod_desc *desc, uint32_t conn_id)
Definition iiod.c:905
Definition ad9361_util.h:63
Definition iiod.h:60
const char * channel
Definition iiod.h:68
enum iio_attr_type type
Definition iiod.h:61
const char * name
Definition iiod.h:67
Definition iiod.h:78
char * buf
Definition iiod.h:82
uint32_t len
Definition iiod.h:84
void * conn
Definition iiod.h:80
Definition iiod.h:71
void * conn
Definition iiod.h:75
void * instance
Definition iiod.h:73
Definition iiod_private.h:163
Definition iiod.h:160
char * xml
Definition iiod.h:168
struct iiod_ops * ops
Definition iiod.h:161
void * instance
Definition iiod.h:163
enum physical_link_type phy_type
Definition iiod.h:172
uint32_t xml_len
Definition iiod.h:170
Definition iiod.h:88
int(* open)(struct iiod_ctx *ctx, const char *device, uint32_t samples, uint32_t mask, bool cyclic)
Definition iiod.h:109
int(* read_buffer)(struct iiod_ctx *ctx, const char *device, char *buf, uint32_t bytes)
Definition iiod.h:115
int(* set_trigger)(struct iiod_ctx *ctx, const char *device, const char *trigger, uint32_t len)
Definition iiod.h:142
int(* write_attr)(struct iiod_ctx *ctx, const char *device, struct iiod_attr *attr, char *buf, uint32_t len)
Definition iiod.h:133
int(* write_buffer)(struct iiod_ctx *ctx, const char *device, const char *buf, uint32_t bytes)
Definition iiod.h:121
int(* refill_buffer)(struct iiod_ctx *ctx, const char *device)
Definition iiod.h:118
int(* read_attr)(struct iiod_ctx *ctx, const char *device, struct iiod_attr *attr, char *buf, uint32_t len)
Definition iiod.h:130
int(* set_buffers_count)(struct iiod_ctx *ctx, const char *device, uint32_t buffers_count)
Definition iiod.h:149
int(* push_buffer)(struct iiod_ctx *ctx, const char *device)
Definition iiod.h:124
int(* get_trigger)(struct iiod_ctx *ctx, const char *device, char *trigger, uint32_t len)
Definition iiod.h:136
int(* close)(struct iiod_ctx *ctx, const char *device)
Definition iiod.h:112
int(* set_timeout)(struct iiod_ctx *ctx, uint32_t timeout)
Definition iiod.h:146
int(* send)(struct iiod_ctx *ctx, uint8_t *buf, uint32_t len)
Definition iiod.h:98
int(* recv)(struct iiod_ctx *ctx, uint8_t *buf, uint32_t len)
Definition iiod.h:99