no-OS
iiod.h
Go to the documentation of this file.
1 /***************************************************************************/
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 
58 };
59 
60 struct 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 
71 struct 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 */
88 struct 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  */
157 struct 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. */
176 int32_t iiod_init(struct iiod_desc **desc, struct iiod_init_param *param);
177 /* Remove desc resources */
178 void 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  */
184 int32_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 */
187 int32_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 */
190 int32_t iiod_conn_step(struct iiod_desc *desc, uint32_t conn_id);
191 
192 #endif //IIOD_H
comand_desc::trigger
char trigger[MAX_TRIG_ID]
Definition: iiod_private.h:92
timeout
uint32_t timeout
Definition: ad413x.c:49
iiod_desc::app_instance
void * app_instance
Definition: iiod_private.h:169
iiod_conn_priv::IIOD_LINE_DONE
@ IIOD_LINE_DONE
Definition: iiod_private.h:136
iiod_desc::phy_type
enum physical_link_type phy_type
Definition: iiod_private.h:175
IIOD_CMD_EXIT
@ IIOD_CMD_EXIT
Definition: iiod_private.h:62
iiod_conn_priv::used
bool used
Definition: iiod_private.h:117
comand_desc::timeout
uint32_t timeout
Definition: iiod_private.h:84
iiod_ops::open
int(* open)(struct iiod_ctx *ctx, const char *device, uint32_t samples, uint32_t mask, bool cyclic)
Definition: iiod.h:109
iiod_ctx::instance
void * instance
Definition: iiod.h:73
iiod_buff
Definition: iiod_private.h:97
iiod_conn_priv::conn
void * conn
Definition: iiod_private.h:115
IIOD_CMD_OPEN
@ IIOD_CMD_OPEN
Definition: iiod_private.h:66
iiod.h
Header file of iiod.
iiod_conn_data::conn
void * conn
Definition: iiod.h:80
IIOD_CMD_SET
@ IIOD_CMD_SET
Definition: iiod_private.h:74
iiod_conn_priv::buf_mask
char buf_mask[10]
Definition: iiod_private.h:155
iiod_desc
Definition: iiod_private.h:163
NO_OS_IS_ERR_VALUE
#define NO_OS_IS_ERR_VALUE(x)
Definition: no_os_error.h:50
iiod_attr::channel
const char * channel
Definition: iiod.h:68
iiod_init_param::xml_len
uint32_t xml_len
Definition: iiod.h:170
iiod_str::str
char * str
Definition: iiod_private.h:52
iiod_run_cmd_result::write_val
bool write_val
Definition: iiod_private.h:107
IIOD_RD
#define IIOD_RD
Definition: iiod_private.h:41
iiod_str
Definition: iiod_private.h:51
device
Definition: ad9361_util.h:69
iiod_desc::xml_len
uint32_t xml_len
Definition: iiod_private.h:173
iiod_init_param::phy_type
enum physical_link_type phy_type
Definition: iiod.h:172
iiod_desc::xml
char * xml
Definition: iiod_private.h:171
NO_OS_ARRAY_SIZE
#define NO_OS_ARRAY_SIZE(x)
Definition: no_os_util.h:49
IIOD_ENDL
#define IIOD_ENDL
Definition: iiod_private.h:40
iiod_remove
void iiod_remove(struct iiod_desc *desc)
Definition: iiod.c:376
iio_attr_type
iio_attr_type
Definition: iiod.h:52
iiod_ops::close
int(* close)(struct iiod_ctx *ctx, const char *device)
Definition: iiod.h:112
IIOD_CMD_READ
@ IIOD_CMD_READ
Definition: iiod_private.h:68
iiod_conn_priv::payload_buf
char * payload_buf
Definition: iiod_private.h:146
iiod_conn_add
int32_t iiod_conn_add(struct iiod_desc *desc, struct iiod_conn_data *data, uint32_t *new_conn_id)
Definition: iiod.c:393
iiod_init_param::instance
void * instance
Definition: iiod.h:163
IIOD_CMD_WRITEBUF
@ IIOD_CMD_WRITEBUF
Definition: iiod_private.h:71
iiod_str::len
uint32_t len
Definition: iiod_private.h:53
iiod_buff::idx
uint32_t idx
Definition: iiod_private.h:99
no_os_min
#define no_os_min(x, y)
Definition: no_os_util.h:59
iiod_ctx
Definition: iiod.h:71
iiod_conn_priv
Definition: iiod_private.h:113
iiod_init_param
Definition: iiod.h:160
iiod_conn_add
int32_t iiod_conn_add(struct iiod_desc *desc, struct iiod_conn_data *data, uint32_t *new_conn_id)
Definition: iiod.c:393
iio.h
Header file of iio.
no_os_error.h
Error codes definition.
USE_NETWORK
@ USE_NETWORK
Definition: iio.h:55
IIOD_STR
#define IIOD_STR(cmd)
Definition: iiod_private.h:44
IIOD_MAX_CONNECTIONS
#define IIOD_MAX_CONNECTIONS
Definition: iiod.h:43
iiod_init_param::xml
char * xml
Definition: iiod.h:168
comand_desc::type
enum iio_attr_type type
Definition: iiod_private.h:93
iiod_ops::refill_buffer
int(* refill_buffer)(struct iiod_ctx *ctx, const char *device)
Definition: iiod.h:118
iiod_conn_step
int32_t iiod_conn_step(struct iiod_desc *desc, uint32_t conn_id)
Definition: iiod.c:905
iiod_conn_priv::state
enum iiod_conn_priv::@2 state
comand_desc::mask
uint32_t mask
Definition: iiod_private.h:83
iiod_init_param::ops
struct iiod_ops * ops
Definition: iiod.h:161
IIOD_VERSION_LEN
#define IIOD_VERSION_LEN
Definition: iiod.h:45
iiod_conn_data::buf
char * buf
Definition: iiod.h:82
iiod_init
int32_t iiod_init(struct iiod_desc **desc, struct iiod_init_param *param)
Definition: iiod.c:347
iiod_ops::write_buffer
int(* write_buffer)(struct iiod_ctx *ctx, const char *device, const char *buf, uint32_t bytes)
Definition: iiod.h:121
iiod_conn_priv::mask
uint32_t mask
Definition: iiod_private.h:153
IIOD_CMD_PRINT
@ IIOD_CMD_PRINT
Definition: iiod_private.h:63
IIO_ATTR_TYPE_DEVICE
@ IIO_ATTR_TYPE_DEVICE
Definition: iiod.h:57
iiod_ops::set_buffers_count
int(* set_buffers_count)(struct iiod_ctx *ctx, const char *device, uint32_t buffers_count)
Definition: iiod.h:149
comand_desc::cyclic
bool cyclic
Definition: iiod_private.h:88
iiod_ops::get_trigger
int(* get_trigger)(struct iiod_ctx *ctx, const char *device, char *trigger, uint32_t len)
Definition: iiod.h:136
iiod_desc::conns
struct iiod_conn_priv conns[IIOD_MAX_CONNECTIONS]
Definition: iiod_private.h:165
iiod_ctx::conn
void * conn
Definition: iiod.h:75
comand_desc::cmd
enum iiod_cmd cmd
Definition: iiod_private.h:82
iiod_remove
void iiod_remove(struct iiod_desc *desc)
Definition: iiod.c:376
iiod_buff::buf
char * buf
Definition: iiod_private.h:98
iiod_conn_remove
int32_t iiod_conn_remove(struct iiod_desc *desc, uint32_t conn_id, struct iiod_conn_data *data)
Definition: iiod.c:423
IIOD_PARSER_MAX_BUF_SIZE
#define IIOD_PARSER_MAX_BUF_SIZE
Definition: iiod_private.h:42
SET_DUMMY_IF_NULL
#define SET_DUMMY_IF_NULL(func, dummy)
Definition: iiod.c:46
comand_desc::device
char device[MAX_DEV_ID]
Definition: iiod_private.h:89
IIOD_CTX
#define IIOD_CTX(desc, conn)
Definition: iiod_private.h:46
iiod_ops::read_attr
int(* read_attr)(struct iiod_ctx *ctx, const char *device, struct iiod_attr *attr, char *buf, uint32_t len)
Definition: iiod.h:130
iiod_conn_priv::nb_buf
struct iiod_buff nb_buf
Definition: iiod_private.h:150
IIO_ATTR_TYPE_DEBUG
@ IIO_ATTR_TYPE_DEBUG
Definition: iiod.h:53
comand_desc::count
uint32_t count
Definition: iiod_private.h:87
iiod_desc::ops
struct iiod_ops ops
Definition: iiod_private.h:167
comand_desc::attr
char attr[MAX_ATTR_NAME]
Definition: iiod_private.h:91
iiod_copy_ops
int32_t iiod_copy_ops(struct iiod_ops *ops, struct iiod_ops *new_ops)
Definition: iiod.c:320
IIOD_VERSION
#define IIOD_VERSION
Definition: iiod.h:44
iiod_conn_priv::cmd_data
struct comand_desc cmd_data
Definition: iiod_private.h:120
IIOD_CMD_CLOSE
@ IIOD_CMD_CLOSE
Definition: iiod_private.h:67
iiod_attr::name
const char * name
Definition: iiod.h:67
iiod_conn_data
Definition: iiod.h:78
iiod_ops::set_trigger
int(* set_trigger)(struct iiod_ctx *ctx, const char *device, const char *trigger, uint32_t len)
Definition: iiod.h:142
iiod_ops::read_buffer
int(* read_buffer)(struct iiod_ctx *ctx, const char *device, char *buf, uint32_t bytes)
Definition: iiod.h:115
IIOD_CMD_GETTRIG
@ IIOD_CMD_GETTRIG
Definition: iiod_private.h:72
iiod_run_cmd_result::buf
struct iiod_buff buf
Definition: iiod_private.h:109
iiod_conn_data::len
uint32_t len
Definition: iiod.h:84
comand_desc::sample_count
uint32_t sample_count
Definition: iiod_private.h:85
IIO_ATTR_TYPE_CH_IN
@ IIO_ATTR_TYPE_CH_IN
Definition: iiod.h:56
NULL
#define NULL
Definition: wrapper.h:64
iiod_parse_line
int32_t iiod_parse_line(char *buf, struct comand_desc *res, char **ctx)
Definition: iiod.c:226
iiod_attr::type
enum iio_attr_type type
Definition: iiod.h:61
IIO_ATTR_TYPE_CH_OUT
@ IIO_ATTR_TYPE_CH_OUT
Definition: iiod.h:55
iiod_ops::set_timeout
int(* set_timeout)(struct iiod_ctx *ctx, uint32_t timeout)
Definition: iiod.h:146
iiod_private.h
Private header file of iiod.
IIOD_CMD_WRITE
@ IIOD_CMD_WRITE
Definition: iiod_private.h:69
iiod_conn_priv::payload_buf_len
uint32_t payload_buf_len
Definition: iiod_private.h:148
comand_desc::bytes_count
uint32_t bytes_count
Definition: iiod_private.h:86
iiod_ops::send
int(* send)(struct iiod_ctx *ctx, uint8_t *buf, uint32_t len)
Definition: iiod.h:98
iiod_ops::write_attr
int(* write_attr)(struct iiod_ctx *ctx, const char *device, struct iiod_attr *attr, char *buf, uint32_t len)
Definition: iiod.h:133
iiod_ops::push_buffer
int(* push_buffer)(struct iiod_ctx *ctx, const char *device)
Definition: iiod.h:124
IIOD_WR
#define IIOD_WR
Definition: iiod_private.h:39
iiod_buff::len
uint32_t len
Definition: iiod_private.h:100
iiod_conn_step
int32_t iiod_conn_step(struct iiod_desc *desc, uint32_t conn_id)
Definition: iiod.c:905
iiod_ops
Definition: iiod.h:88
IIO_ATTR_TYPE_BUFFER
@ IIO_ATTR_TYPE_BUFFER
Definition: iiod.h:54
iiod_attr
Definition: iiod.h:60
IIOD_CMD_SETTRIG
@ IIOD_CMD_SETTRIG
Definition: iiod_private.h:73
iiod_init
int32_t iiod_init(struct iiod_desc **desc, struct iiod_init_param *param)
Definition: iiod.c:347
IIOD_CMD_HELP
@ IIOD_CMD_HELP
Definition: iiod_private.h:61
no_os_util.h
Header file of utility functions.
comand_desc::channel
char channel[MAX_CHN_ID]
Definition: iiod_private.h:90
iiod_conn_priv::res
struct iiod_run_cmd_result res
Definition: iiod_private.h:122
iiod_conn_remove
int32_t iiod_conn_remove(struct iiod_desc *desc, uint32_t conn_id, struct iiod_conn_data *data)
Definition: iiod.c:423
IIOD_CMD_READBUF
@ IIOD_CMD_READBUF
Definition: iiod_private.h:70
IIOD_CMD_TIMEOUT
@ IIOD_CMD_TIMEOUT
Definition: iiod_private.h:65
IIOD_CMD_VERSION
@ IIOD_CMD_VERSION
Definition: iiod_private.h:64
iiod_conn_priv::parser_idx
uint32_t parser_idx
Definition: iiod_private.h:144
iiod_ops::recv
int(* recv)(struct iiod_ctx *ctx, uint8_t *buf, uint32_t len)
Definition: iiod.h:99
iiod_conn_priv::is_cyclic_buffer
bool is_cyclic_buffer
Definition: iiod_private.h:159
physical_link_type
physical_link_type
Definition: iio.h:52
iiod_run_cmd_result::val
uint32_t val
Definition: iiod_private.h:105
comand_desc
Definition: iiod_private.h:81