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