23 #ifndef __ANALOGY_BUFFER_H__
24 #define __ANALOGY_BUFFER_H__
30 #include <linux/version.h>
40 #define A4L_BUF_EOBUF_NR 0
41 #define A4L_BUF_EOBUF (1 << A4L_BUF_EOBUF_NR)
43 #define A4L_BUF_ERROR_NR 1
44 #define A4L_BUF_ERROR (1 << A4L_BUF_ERROR_NR)
46 #define A4L_BUF_EOA_NR 2
47 #define A4L_BUF_EOA (1 << A4L_BUF_EOA_NR)
51 #define A4L_BUF_BULK_NR 8
52 #define A4L_BUF_BULK (1 << A4L_BUF_BULK_NR)
54 #define A4L_BUF_MAP_NR 9
55 #define A4L_BUF_MAP (1 << A4L_BUF_MAP_NR)
71 unsigned long *pg_list;
77 unsigned long end_count;
78 unsigned long prd_count;
79 unsigned long cns_count;
80 unsigned long tmp_count;
89 unsigned long mng_count;
93 unsigned long wake_count;
95 typedef struct a4l_buffer a4l_buf_t;
103 static inline int __produce(a4l_cxt_t *cxt,
104 a4l_buf_t *buf,
void *pin,
unsigned long count)
106 unsigned long start_ptr = (buf->prd_count % buf->size);
107 unsigned long tmp_cnt = count;
110 while (ret == 0 && tmp_cnt != 0) {
112 unsigned long blk_size = (start_ptr + tmp_cnt > buf->size) ?
113 buf->size - start_ptr : tmp_cnt;
117 memcpy(buf->buf + start_ptr, pin, blk_size);
120 buf->buf + start_ptr,
135 static inline int __consume(a4l_cxt_t *cxt,
136 a4l_buf_t *buf,
void *pout,
unsigned long count)
138 unsigned long start_ptr = (buf->cns_count % buf->size);
139 unsigned long tmp_cnt = count;
142 while (ret == 0 && tmp_cnt != 0) {
144 unsigned long blk_size = (start_ptr + tmp_cnt > buf->size) ?
145 buf->size - start_ptr : tmp_cnt;
149 memcpy(pout, buf->buf + start_ptr, blk_size);
153 buf->buf + start_ptr,
170 void *,
unsigned long),
171 a4l_buf_t * buf,
unsigned long count)
173 unsigned long start_ptr = (buf->mng_count % buf->size);
174 unsigned long tmp_cnt = count;
176 while (tmp_cnt != 0) {
178 unsigned long blk_size = (start_ptr + tmp_cnt > buf->size) ?
179 buf->size - start_ptr : tmp_cnt;
182 munge(subd, buf->
buf + start_ptr, blk_size);
193 static inline int __handle_event(a4l_buf_t * buf)
199 if (test_bit(A4L_BUF_EOA_NR, &buf->flags)) {
203 if (test_bit(A4L_BUF_ERROR_NR, &buf->flags)) {
243 static inline int __pre_abs_put(a4l_buf_t * buf,
unsigned long count)
245 if (count - buf->tmp_count > buf->size) {
246 set_bit(A4L_BUF_ERROR_NR, &buf->flags);
250 buf->tmp_count = buf->cns_count;
255 static inline int __pre_put(a4l_buf_t * buf,
unsigned long count)
257 return __pre_abs_put(buf, buf->tmp_count + count);
260 static inline int __pre_abs_get(a4l_buf_t * buf,
unsigned long count)
265 if (buf->tmp_count == 0 || buf->cns_count == 0)
273 if (buf->end_count != 0 && (
long)(count - buf->end_count) > 0)
285 if ((
long)(count - buf->tmp_count) > 0) {
286 set_bit(A4L_BUF_ERROR_NR, &buf->flags);
291 buf->tmp_count = buf->prd_count;
296 static inline int __pre_get(a4l_buf_t * buf,
unsigned long count)
298 return __pre_abs_get(buf, buf->tmp_count + count);
301 static inline int __abs_put(a4l_buf_t * buf,
unsigned long count)
303 unsigned long old = buf->prd_count;
305 if ((
long)(buf->prd_count - count) >= 0)
308 buf->prd_count = count;
310 if ((old / buf->size) != (count / buf->size))
311 set_bit(A4L_BUF_EOBUF_NR, &buf->flags);
313 if (buf->end_count != 0 && (
long)(count - buf->end_count) >= 0)
314 set_bit(A4L_BUF_EOA_NR, &buf->flags);
319 static inline int __put(a4l_buf_t * buf,
unsigned long count)
321 return __abs_put(buf, buf->prd_count + count);
324 static inline int __abs_get(a4l_buf_t * buf,
unsigned long count)
326 unsigned long old = buf->cns_count;
328 if ((
long)(buf->cns_count - count) >= 0)
331 buf->cns_count = count;
333 if ((old / buf->size) != count / buf->size)
334 set_bit(A4L_BUF_EOBUF_NR, &buf->flags);
336 if (buf->end_count != 0 && (
long)(count - buf->end_count) >= 0)
337 set_bit(A4L_BUF_EOA_NR, &buf->flags);
342 static inline int __get(a4l_buf_t * buf,
unsigned long count)
344 return __abs_get(buf, buf->cns_count + count);
347 static inline unsigned long __count_to_put(a4l_buf_t * buf)
351 if ((
long) (buf->size + buf->cns_count - buf->prd_count) > 0)
352 ret = buf->size + buf->cns_count - buf->prd_count;
359 static inline unsigned long __count_to_get(a4l_buf_t * buf)
365 if (buf->end_count == 0 || (
long)(buf->end_count - buf->prd_count) > 0)
366 ret = buf->prd_count;
368 ret = buf->end_count;
370 if ((
long)(ret - buf->cns_count) > 0)
371 ret -= buf->cns_count;
378 static inline unsigned long __count_to_end(a4l_buf_t * buf)
380 unsigned long ret = buf->end_count - buf->cns_count;
382 if (buf->end_count == 0)
385 return ((
long)ret) < 0 ? 0 : ret;
390 int a4l_alloc_buffer(a4l_buf_t *buf_desc,
int buf_size);
392 void a4l_free_buffer(a4l_buf_t *buf_desc);
394 void a4l_init_buffer(a4l_buf_t * buf_desc);
396 void a4l_cleanup_buffer(a4l_buf_t * buf_desc);
398 int a4l_setup_buffer(a4l_cxt_t *cxt,
a4l_cmd_t *cmd);
400 int a4l_cancel_buffer(a4l_cxt_t *cxt);
403 unsigned long count);
406 unsigned long count);
409 unsigned long count);
412 unsigned long count);
415 void *bufdata,
unsigned long count);
418 unsigned long count);
421 unsigned long count);
424 unsigned long count);
427 unsigned long count);
430 void *bufdata,
unsigned long count);
440 return (subd->
buf) ? subd->
buf->cur_cmd : NULL;
449 int a4l_ioctl_mmap(a4l_cxt_t * cxt,
void *arg);
450 int a4l_ioctl_bufcfg(a4l_cxt_t * cxt,
void *arg);
451 int a4l_ioctl_bufcfg2(a4l_cxt_t * cxt,
void *arg);
452 int a4l_ioctl_bufinfo(a4l_cxt_t * cxt,
void *arg);
453 int a4l_ioctl_bufinfo2(a4l_cxt_t * cxt,
void *arg);
454 int a4l_ioctl_poll(a4l_cxt_t * cxt,
void *arg);
455 ssize_t a4l_read_buffer(a4l_cxt_t * cxt,
void *bufdata,
size_t nbytes);
456 ssize_t a4l_write_buffer(a4l_cxt_t * cxt,
const void *bufdata,
size_t nbytes);
457 int a4l_select(a4l_cxt_t *cxt,
458 rtdm_selector_t *selector,
464 struct a4l_mmap_arg {
465 unsigned int idx_subd;
469 typedef struct a4l_mmap_arg a4l_mmap_t;
473 #define A4L_BUF_MAXSIZE 0x1000000
474 #define A4L_BUF_DEFSIZE 0x10000
475 #define A4L_BUF_DEFMAGIC 0xffaaff55
478 struct a4l_buffer_config {
486 unsigned int idx_subd;
487 unsigned long buf_size;
489 typedef struct a4l_buffer_config a4l_bufcfg_t;
492 struct a4l_buffer_info {
493 unsigned int idx_subd;
494 unsigned long buf_size;
495 unsigned long rw_count;
497 typedef struct a4l_buffer_info a4l_bufinfo_t;
500 struct a4l_buffer_config2 {
501 unsigned long wake_count;
502 unsigned long reserved[3];
504 typedef struct a4l_buffer_config2 a4l_bufcfg2_t;
508 unsigned int idx_subd;
int a4l_buf_commit_absput(a4l_subd_t *subd, unsigned long count)
Set the absolute count of data which was sent from the device to the buffer since the start of the ac...
int a4l_buf_commit_absget(a4l_subd_t *subd, unsigned long count)
Set the absolute count of data which was sent from the buffer to the device since the start of the ac...
struct a4l_buffer * buf
Linked buffer.
Definition: subdevice.h:191
int a4l_buf_get(a4l_subd_t *subd, void *bufdata, unsigned long count)
Copy some data from the buffer to the device driver.
int rtdm_safe_copy_from_user(rtdm_user_info_t *user_info, void *dst, const void __user *src, size_t size)
Check if read access to user-space memory block and copy it to specified buffer.
Analogy for Linux, context structure / macros declarations.
Structure describing the asynchronous instruction.
Definition: command.h:198
int rtdm_safe_copy_to_user(rtdm_user_info_t *user_info, void __user *dst, const void *src, size_t size)
Check if read/write access to user-space memory block is safe and copy specified buffer to it...
int a4l_buf_prepare_get(a4l_subd_t *subd, unsigned long count)
Set the count of data which is to be sent from the buffer to the device at the next DMA shot...
a4l_cmd_t * a4l_get_cmd(a4l_subd_t *subd)
Get the current Analogy command descriptor.
int a4l_buf_evt(a4l_subd_t *subd, unsigned long evts)
Signal some event(s) to a user-space program involved in some read / write operation.
int a4l_get_chan(a4l_subd_t *subd)
Get the channel index according to its type.
unsigned long a4l_buf_count(a4l_subd_t *subd)
Get the data amount available in the Analogy buffer.
Structure describing the subdevice.
Definition: subdevice.h:180
int a4l_poll(a4l_desc_t *dsc, unsigned int idx_subd, unsigned long ms_timeout)
Get the available data count.
Definition: async.c:289
Analogy for Linux, Operation system facilities.
int a4l_buf_prepare_absput(a4l_subd_t *subd, unsigned long count)
Update the absolute count of data sent from the device to the buffer since the start of the acquisiti...
int a4l_buf_prepare_absget(a4l_subd_t *subd, unsigned long count)
Update the absolute count of data sent from the buffer to the device since the start of the acquisiti...
rtdm_selecttype
Definition: rtdm_driver.h:139
int a4l_buf_prepare_put(a4l_subd_t *subd, unsigned long count)
Set the count of data which is to be sent to the buffer at the next DMA shot.
Real-Time Driver Model for Xenomai, driver API header.
int a4l_buf_commit_get(a4l_subd_t *subd, unsigned long count)
Set the count of data sent from the buffer to the device during the last completed DMA shots...
int a4l_buf_put(a4l_subd_t *subd, void *bufdata, unsigned long count)
Copy some data from the device driver to the buffer.
unsigned long flags
Type flags.
Definition: subdevice.h:199
int a4l_buf_commit_put(a4l_subd_t *subd, unsigned long count)
Set the count of data sent to the buffer during the last completed DMA shots.