no-OS
iiod.h
Go to the documentation of this file.
1 /***************************************************************************/
40 #ifndef IIOD_H
41 #define IIOD_H
42 
43 #include <stdint.h>
44 #include <stdbool.h>
45 
46 /* Maximum nomber of iiod connections to allocate simultaneously */
47 #define IIOD_MAX_CONNECTIONS 10
48 #define IIOD_VERSION "1.1.0000000"
49 #define IIOD_VERSION_LEN (sizeof(IIOD_VERSION) - 1)
50 
57 };
58 
59 struct iiod_attr {
61  /*
62  * Attribute name.
63  * If empty (""), all attributes of the specified iio_attr_type must
64  * be read/wrote
65  */
66  const char *name;
67  const char *channel;
68 };
69 
70 struct iiod_ctx {
71  /* Value specified in iiod_init_param.instance in iiod_init */
72  void *instance;
73  /* Value specified in iiod_conn_data.conn in iiod_conn_add */
74  void *conn;
75 };
76 
78  /* Value to be used in iiod_ctx */
79  void *conn;
80  /* Buffer to store attributes or buffer data for a connection. */
81  char *buf;
82  /* Size of the provided buffer. It must fit the max attribute size */
83  uint32_t len;
84 };
85 
86 /* Functions should return a negative error code on failure */
87 struct iiod_ops {
88  /*
89  * I/O operations
90  * Send and recv are used to send or receive data to/from a connection.
91  * They should send/receive the at maximum len bytes.
92  * They must return the number of bytes sent/received.
93  * They can return 0 or -EAGAIN when no data was processed.
94  * They can do not block. They will be called again if there is still
95  * data to be sent/recevied
96  */
97  int (*send)(struct iiod_ctx *ctx, uint8_t *buf, uint32_t len);
98  int (*recv)(struct iiod_ctx *ctx, uint8_t *buf, uint32_t len);
99 
100  /*
101  * This is the equivalent of libiio iio_device_create_buffer.
102  * Called in order to create a buffer to read or write data.
103  * read_buffer or write_buffer will follow with a maximum of samples
104  * (depending on the internal buffer).
105  * All calls with the same ctx will refer to this buffer until close is
106  * called.
107  */
108  int (*open)(struct iiod_ctx *ctx, const char *device, uint32_t samples,
109  uint32_t mask, bool cyclic);
110  /* Equivalent of iio_buffer_destroy */
111  int (*close)(struct iiod_ctx *ctx, const char *device);
112 
113  /* Read data from opened buffer */
114  int (*read_buffer)(struct iiod_ctx *ctx, const char *device, char *buf,
115  uint32_t bytes);
116  /* Called to notify that buffer must be refiiled */
117  int (*refill_buffer)(struct iiod_ctx *ctx, const char *device);
118 
119  /* Write data to opened buffer */
120  int (*write_buffer)(struct iiod_ctx *ctx, const char *device,
121  const char *buf, uint32_t bytes);
122  /* Called to notify that buffer must be pushed to hardware */
123  int (*push_buffer)(struct iiod_ctx *ctx, const char *device);
124 
125  /*
126  * Attribute has to be read in buf and return the number of bytes
127  * written.
128  */
129  int (*read_attr)(struct iiod_ctx *ctx, const char *device,
130  struct iiod_attr *attr, char *buf, uint32_t len);
131  /* Attribute buf is filled with the attribute value. */
132  int (*write_attr)(struct iiod_ctx *ctx, const char *device,
133  struct iiod_attr *attr, char *buf, uint32_t len);
134  /* Simular with read_attr but trigger must be filled */
135  int (*get_trigger)(struct iiod_ctx *ctx, const char *device,
136  char *trigger, uint32_t len);
137  /*
138  * Simular with write_attr but trigger name is in trigger.
139  * If trigger is equals to "". Trigger must be removed.
140  */
141  int (*set_trigger)(struct iiod_ctx *ctx, const char *device,
142  const char *trigger, uint32_t len);
143 
144  /* I don't know what this should be used for :) */
145  int (*set_timeout)(struct iiod_ctx *ctx, uint32_t timeout);
146 
147  /* I don't know what this should be used for :) */
148  int (*set_buffers_count)(struct iiod_ctx *ctx, const char *device,
149  uint32_t buffers_count);
150 };
151 
152 /*
153  * Internal structure.
154  * It is created in iiod_init and must be passed to all fucntions
155  */
156 struct iiod_desc;
157 
158 /* Parameter to initialize iiod_desc */
160  struct iiod_ops *ops;
161  /* Value to be send in each iiod_ctx from iiod_ops functions */
162  void *instance;
163  /*
164  * Xml description of the context and devices. It should exist until
165  * iiod_remove is called
166  */
167  char *xml;
168  /* Size of xml in bytes */
169  uint32_t xml_len;
170 };
171 
172 /* Initialize desc. */
173 int32_t iiod_init(struct iiod_desc **desc, struct iiod_init_param *param);
174 /* Remove desc resources */
175 void iiod_remove(struct iiod_desc *desc);
176 
177 /*
178  * Notify iiod about a new connection in order to store context for it.
179  * new_conn_id is set in order to reference the connection in iiod_conn_step
180  */
181 int32_t iiod_conn_add(struct iiod_desc *desc, struct iiod_conn_data *data,
182  uint32_t *new_conn_id);
183 /* Remove conn_id from iiod. Provided data is returned in data */
184 int32_t iiod_conn_remove(struct iiod_desc *desc, uint32_t conn_id,
185  struct iiod_conn_data *data);
186 /* Advance in the state machine of a connection. Will not block */
187 int32_t iiod_conn_step(struct iiod_desc *desc, uint32_t conn_id);
188 
189 #endif //IIOD_H
comand_desc::attr
const char * attr
Definition: iiod_private.h:95
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:140
IIOD_CMD_EXIT
@ IIOD_CMD_EXIT
Definition: iiod_private.h:66
iiod_conn_priv::used
bool used
Definition: iiod_private.h:121
comand_desc::timeout
uint32_t timeout
Definition: iiod_private.h:88
iiod_ops::open
int(* open)(struct iiod_ctx *ctx, const char *device, uint32_t samples, uint32_t mask, bool cyclic)
Definition: iiod.h:108
iiod_ctx::instance
void * instance
Definition: iiod.h:72
iiod_buff
Definition: iiod_private.h:101
iiod_conn_priv::conn
void * conn
Definition: iiod_private.h:119
IIOD_CMD_OPEN
@ IIOD_CMD_OPEN
Definition: iiod_private.h:70
iiod.h
Header file of iiod.
iiod_conn_data::conn
void * conn
Definition: iiod.h:79
IIOD_CMD_SET
@ IIOD_CMD_SET
Definition: iiod_private.h:78
iiod_conn_priv::buf_mask
char buf_mask[10]
Definition: iiod_private.h:157
iiod_desc
Definition: iiod_private.h:163
NO_OS_IS_ERR_VALUE
#define NO_OS_IS_ERR_VALUE(x)
Definition: no_os_error.h:56
iiod_attr::channel
const char * channel
Definition: iiod.h:67
iiod_init_param::xml_len
uint32_t xml_len
Definition: iiod.h:169
iiod_str::str
char * str
Definition: iiod_private.h:56
iiod_run_cmd_result::write_val
bool write_val
Definition: iiod_private.h:111
IIOD_RD
#define IIOD_RD
Definition: iiod_private.h:45
comand_desc::trigger
const char * trigger
Definition: iiod_private.h:96
iiod_str
Definition: iiod_private.h:55
device
Definition: ad9361_util.h:75
iiod_desc::xml_len
uint32_t xml_len
Definition: iiod_private.h:173
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:53
IIOD_ENDL
#define IIOD_ENDL
Definition: iiod_private.h:44
iiod_remove
void iiod_remove(struct iiod_desc *desc)
Definition: iiod.c:382
iio_attr_type
iio_attr_type
Definition: iiod.h:51
iiod_ops::close
int(* close)(struct iiod_ctx *ctx, const char *device)
Definition: iiod.h:111
IIOD_CMD_READ
@ IIOD_CMD_READ
Definition: iiod_private.h:72
iiod_conn_priv::payload_buf
char * payload_buf
Definition: iiod_private.h:148
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:399
iiod_init_param::instance
void * instance
Definition: iiod.h:162
IIOD_CMD_WRITEBUF
@ IIOD_CMD_WRITEBUF
Definition: iiod_private.h:75
iiod_str::len
uint32_t len
Definition: iiod_private.h:57
iiod_buff::idx
uint32_t idx
Definition: iiod_private.h:103
no_os_min
#define no_os_min(x, y)
Definition: no_os_util.h:63
iiod_ctx
Definition: iiod.h:70
iiod_conn_priv
Definition: iiod_private.h:117
iiod_init_param
Definition: iiod.h:159
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:399
no_os_error.h
Error codes definition.
IIOD_STR
#define IIOD_STR(cmd)
Definition: iiod_private.h:48
IIOD_MAX_CONNECTIONS
#define IIOD_MAX_CONNECTIONS
Definition: iiod.h:47
iiod_init_param::xml
char * xml
Definition: iiod.h:167
comand_desc::type
enum iio_attr_type type
Definition: iiod_private.h:97
iiod_ops::refill_buffer
int(* refill_buffer)(struct iiod_ctx *ctx, const char *device)
Definition: iiod.h:117
iiod_conn_step
int32_t iiod_conn_step(struct iiod_desc *desc, uint32_t conn_id)
Definition: iiod.c:833
iiod_conn_priv::state
enum iiod_conn_priv::@2 state
comand_desc::mask
uint32_t mask
Definition: iiod_private.h:87
iiod_init_param::ops
struct iiod_ops * ops
Definition: iiod.h:160
IIOD_VERSION_LEN
#define IIOD_VERSION_LEN
Definition: iiod.h:49
iiod_conn_data::buf
char * buf
Definition: iiod.h:81
iiod_init
int32_t iiod_init(struct iiod_desc **desc, struct iiod_init_param *param)
Definition: iiod.c:354
iiod_ops::write_buffer
int(* write_buffer)(struct iiod_ctx *ctx, const char *device, const char *buf, uint32_t bytes)
Definition: iiod.h:120
iiod_conn_priv::mask
uint32_t mask
Definition: iiod_private.h:155
IIOD_CMD_PRINT
@ IIOD_CMD_PRINT
Definition: iiod_private.h:67
IIO_ATTR_TYPE_DEVICE
@ IIO_ATTR_TYPE_DEVICE
Definition: iiod.h:56
iiod_ops::set_buffers_count
int(* set_buffers_count)(struct iiod_ctx *ctx, const char *device, uint32_t buffers_count)
Definition: iiod.h:148
comand_desc::cyclic
bool cyclic
Definition: iiod_private.h:92
iiod_ops::get_trigger
int(* get_trigger)(struct iiod_ctx *ctx, const char *device, char *trigger, uint32_t len)
Definition: iiod.h:135
iiod_desc::conns
struct iiod_conn_priv conns[IIOD_MAX_CONNECTIONS]
Definition: iiod_private.h:165
iiod_ctx::conn
void * conn
Definition: iiod.h:74
comand_desc::cmd
enum iiod_cmd cmd
Definition: iiod_private.h:86
iiod_remove
void iiod_remove(struct iiod_desc *desc)
Definition: iiod.c:382
iiod_buff::buf
char * buf
Definition: iiod_private.h:102
iiod_conn_remove
int32_t iiod_conn_remove(struct iiod_desc *desc, uint32_t conn_id, struct iiod_conn_data *data)
Definition: iiod.c:429
IIOD_PARSER_MAX_BUF_SIZE
#define IIOD_PARSER_MAX_BUF_SIZE
Definition: iiod_private.h:46
SET_DUMMY_IF_NULL
#define SET_DUMMY_IF_NULL(func, dummy)
Definition: iiod.c:53
comand_desc::device
const char * device
Definition: iiod_private.h:93
IIOD_CTX
#define IIOD_CTX(desc, conn)
Definition: iiod_private.h:50
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:129
iiod_conn_priv::nb_buf
struct iiod_buff nb_buf
Definition: iiod_private.h:152
IIO_ATTR_TYPE_DEBUG
@ IIO_ATTR_TYPE_DEBUG
Definition: iiod.h:52
comand_desc::count
uint32_t count
Definition: iiod_private.h:91
iiod_desc::ops
struct iiod_ops ops
Definition: iiod_private.h:167
iiod_copy_ops
int32_t iiod_copy_ops(struct iiod_ops *ops, struct iiod_ops *new_ops)
Definition: iiod.c:327
IIOD_VERSION
#define IIOD_VERSION
Definition: iiod.h:48
iiod_conn_priv::cmd_data
struct comand_desc cmd_data
Definition: iiod_private.h:124
IIOD_CMD_CLOSE
@ IIOD_CMD_CLOSE
Definition: iiod_private.h:71
iiod_attr::name
const char * name
Definition: iiod.h:66
iiod_conn_data
Definition: iiod.h:77
iiod_ops::set_trigger
int(* set_trigger)(struct iiod_ctx *ctx, const char *device, const char *trigger, uint32_t len)
Definition: iiod.h:141
iiod_ops::read_buffer
int(* read_buffer)(struct iiod_ctx *ctx, const char *device, char *buf, uint32_t bytes)
Definition: iiod.h:114
IIOD_CMD_GETTRIG
@ IIOD_CMD_GETTRIG
Definition: iiod_private.h:76
iiod_run_cmd_result::buf
struct iiod_buff buf
Definition: iiod_private.h:113
iiod_conn_data::len
uint32_t len
Definition: iiod.h:83
comand_desc::sample_count
uint32_t sample_count
Definition: iiod_private.h:89
IIO_ATTR_TYPE_CH_IN
@ IIO_ATTR_TYPE_CH_IN
Definition: iiod.h:55
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:233
iiod_attr::type
enum iio_attr_type type
Definition: iiod.h:60
IIO_ATTR_TYPE_CH_OUT
@ IIO_ATTR_TYPE_CH_OUT
Definition: iiod.h:54
iiod_ops::set_timeout
int(* set_timeout)(struct iiod_ctx *ctx, uint32_t timeout)
Definition: iiod.h:145
iiod_private.h
Private header file of iiod.
IIOD_CMD_WRITE
@ IIOD_CMD_WRITE
Definition: iiod_private.h:73
iiod_conn_priv::payload_buf_len
uint32_t payload_buf_len
Definition: iiod_private.h:150
comand_desc::bytes_count
uint32_t bytes_count
Definition: iiod_private.h:90
iiod_ops::send
int(* send)(struct iiod_ctx *ctx, uint8_t *buf, uint32_t len)
Definition: iiod.h:97
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:132
iiod_ops::push_buffer
int(* push_buffer)(struct iiod_ctx *ctx, const char *device)
Definition: iiod.h:123
IIOD_WR
#define IIOD_WR
Definition: iiod_private.h:43
iiod_buff::len
uint32_t len
Definition: iiod_private.h:104
iiod_conn_step
int32_t iiod_conn_step(struct iiod_desc *desc, uint32_t conn_id)
Definition: iiod.c:833
iiod_ops
Definition: iiod.h:87
IIO_ATTR_TYPE_BUFFER
@ IIO_ATTR_TYPE_BUFFER
Definition: iiod.h:53
iiod_attr
Definition: iiod.h:59
IIOD_CMD_SETTRIG
@ IIOD_CMD_SETTRIG
Definition: iiod_private.h:77
iiod_init
int32_t iiod_init(struct iiod_desc **desc, struct iiod_init_param *param)
Definition: iiod.c:354
IIOD_CMD_HELP
@ IIOD_CMD_HELP
Definition: iiod_private.h:65
no_os_util.h
Implementation of utility functions.
iiod_conn_priv::res
struct iiod_run_cmd_result res
Definition: iiod_private.h:126
iiod_conn_remove
int32_t iiod_conn_remove(struct iiod_desc *desc, uint32_t conn_id, struct iiod_conn_data *data)
Definition: iiod.c:429
IIOD_CMD_READBUF
@ IIOD_CMD_READBUF
Definition: iiod_private.h:74
IIOD_CMD_TIMEOUT
@ IIOD_CMD_TIMEOUT
Definition: iiod_private.h:69
IIOD_CMD_VERSION
@ IIOD_CMD_VERSION
Definition: iiod_private.h:68
iiod_conn_priv::parser_idx
uint32_t parser_idx
Definition: iiod_private.h:146
iiod_ops::recv
int(* recv)(struct iiod_ctx *ctx, uint8_t *buf, uint32_t len)
Definition: iiod.h:98
comand_desc::channel
const char * channel
Definition: iiod_private.h:94
iiod_run_cmd_result::val
uint32_t val
Definition: iiod_private.h:109
comand_desc
Definition: iiod_private.h:85