hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/**
 * @file
 * Analogy for Linux, descriptor related features
 *
 * @note Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
 * @note Copyright (C) 2008 Alexis Berlemont <alexis.berlemont@free.fr>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 */
 
/*!
 * @ingroup analogy
 * @defgroup analogy_lib Analogy user API
 *
 * This is the API interface of Analogy library
 *
 */
 
/*!
 * @ingroup analogy_lib
 * @defgroup analogy_lib_syscall Level 0 API
 *
 * System call interface to core Analogy services
 *
 * This interface should not be used directly by applications.
 */
 
#include <rtdm/analogy.h>
#include "internal.h"
 
/*!
 * @ingroup analogy_lib_syscall
 * @defgroup analogy_lib_core Basic Syscall API
 * @{
 */
 
/**
 * @brief Open an Analogy device
 *
 * @param[in] fname Device name
 *
 * @return Positive file descriptor value on success, otherwise a negative
 * error code.
 *
 */
int a4l_sys_open(const char *fname)
{
   return __sys_open(fname);
}
 
/**
 * @brief Close an Analogy device
 *
 * @param[in] fd File descriptor as returned by a4l_sys_open()
 *
 * @return 0 on success, otherwise a negative error code.
 *
 */
int a4l_sys_close(int fd)
{
   return __sys_close(fd);
}
 
/**
 * @brief Read from an Analogy device
 *
 * The function a4l_read() is only useful for acquisition
 * configured through an Analogy command.
 *
 * @param[in] fd File descriptor as returned by a4l_sys_open()
 * @param[out] buf Input buffer
 * @param[in] nbyte Number of bytes to read
 *
 * @return Number of bytes read. Otherwise:
 *
 * - -EINVAL is returned if some argument is missing or wrong (Please,
 *    type "dmesg" for more info)
 * - -ENOENT is returned if the device's reading subdevice is idle (no
 *    command was sent)
 * - -EFAULT is returned if a user <-> kernel transfer went wrong
 * - -EINTR is returned if calling task has been unblocked by a signal
 *
 */
int a4l_sys_read(int fd, void *buf, size_t nbyte)
{
   return __sys_read(fd, buf, nbyte);
}
 
/**
 * @brief Write to an Analogy device
 *
 * The function a4l_write() is only useful for acquisition
 * configured through an Analogy command.
 *
 * @param[in] fd File descriptor as returned by a4l_sys_open()
 * @param[in] buf Output buffer
 * @param[in] nbyte Number of bytes to write
 *
 * @return Number of bytes written. Otherwise:
 *
 * - -EINVAL is returned if some argument is missing or wrong (Please,
 *    type "dmesg" for more info)
 * - -ENOENT is returned if the device's writing subdevice is idle (no
 *    command was sent)
 * - -EFAULT is returned if a user <-> kernel transfer went wrong
 * - -EINTR is returned if calling task has been unblocked by a signal
 *
 */
int a4l_sys_write(int fd, void *buf, size_t nbyte)
{
   return __sys_write(fd, buf, nbyte);
}
 
/** @} */
 
/*!
 * @ingroup analogy_lib_syscall
 * @defgroup analogy_lib_attach Attach / detach Syscall API
 * @{
 */
 
/**
 * @brief Attach an Analogy device to a driver
 *
 * @param[in] fd File descriptor as returned by a4l_sys_open()
 * @param[in] arg Link descriptor argument
 *
 * @return 0 on success. Otherwise:
 *
 * - -ENOMEM is returned if the system is out of memory
 * - -EINVAL is returned if some argument is missing or wrong (Please,
 *    type "dmesg" for more info)
 * - -EFAULT is returned if a user <-> kernel transfer went wrong
 * - -ENODEV is returned in case of internal error (Please, type
 *    "dmesg" for more info)
 * - -ENXIO is returned in case of internal error (Please, type
 *    "dmesg" for more info)
 *
 */
int a4l_sys_attach(int fd, a4l_lnkdesc_t * arg)
{
   return __sys_ioctl(fd, A4L_DEVCFG, arg);
}
 
/**
 * @brief Detach an Analogy device from a driver
 *
 * @param[in] fd File descriptor as returned by a4l_sys_open()
 *
 * @return 0 on success. Otherwise:
 *
 * - -EINVAL is returned if some argument is missing or wrong (Please,
 *    type "dmesg" for more info)
 * - -EBUSY is returned if the device to be detached is in use
 * - -EPERM is returned if the devive to be detached still has some
 *    buffer mapped in user-space
 * - -ENODEV is returned in case of internal error (Please, type
 *    "dmesg" for more info)
 * - -ENXIO is returned in case of internal error (Please, type
 *    "dmesg" for more info)
 *
 */
int a4l_sys_detach(int fd)
{
   return __sys_ioctl(fd, A4L_DEVCFG, NULL);
}
 
/**
 * @brief Configure the buffer size
 *
 *
 * This function can configure the buffer size of the file descriptor
 * currently in use. If the subdevice index is set to
 * A4L_BUF_DEFMAGIC, it can also define the default buffser size at
 * open time.
 *
 * @param[in] fd File descriptor as returned by a4l_sys_open()
 * @param[in] idx_subd Index of the concerned subdevice
 * @param[in] size Buffer size to be set
 *
 * @return 0 on success. Otherwise:
 *
 * - -EINVAL is returned if some argument is missing or wrong (Please,
 *    type "dmesg" for more info)
 * - -EPERM is returned if the function is called in an RT context or
 *    if the buffer to resize is mapped in user-space (Please, type
 *    "dmesg" for more info)
 * - -EFAULT is returned if a user <-> kernel transfer went wrong
 * - -EBUSY is returned if the selected subdevice is already
 *    processing an asynchronous operation
 * - -ENOMEM is returned if the system is out of memory
 *
 */
int a4l_sys_bufcfg(int fd, unsigned int idx_subd, unsigned long size)
{
   a4l_bufcfg_t cfg = { idx_subd, size };
 
   return __sys_ioctl(fd, A4L_BUFCFG, &cfg);
}
 
/** @} */