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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/**
 * @file
 * Real-Time Driver Model for Xenomai, serial device profile header
 *
 * @note Copyright (C) 2005-2007 Jan Kiszka <jan.kiszka@web.de>
 *
 * 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 rtserial
 */
#ifndef _RTDM_UAPI_SERIAL_H
#define _RTDM_UAPI_SERIAL_H
 
#define RTSER_PROFILE_VER        3
 
/*!
 * @anchor RTSER_DEF_BAUD   @name RTSER_DEF_BAUD
 * Default baud rate
 * @{ */
#define RTSER_DEF_BAUD            9600
/** @} */
 
/*!
 * @anchor RTSER_xxx_PARITY   @name RTSER_xxx_PARITY
 * Number of parity bits
 * @{ */
#define RTSER_NO_PARITY            0x00
#define RTSER_ODD_PARITY        0x01
#define RTSER_EVEN_PARITY        0x03
#define RTSER_DEF_PARITY        RTSER_NO_PARITY
/** @} */
 
/*!
 * @anchor RTSER_xxx_BITS   @name RTSER_xxx_BITS
 * Number of data bits
 * @{ */
#define RTSER_5_BITS            0x00
#define RTSER_6_BITS            0x01
#define RTSER_7_BITS            0x02
#define RTSER_8_BITS            0x03
#define RTSER_DEF_BITS            RTSER_8_BITS
/** @} */
 
/*!
 * @anchor RTSER_xxx_STOPB   @name RTSER_xxx_STOPB
 * Number of stop bits
 * @{ */
#define RTSER_1_STOPB            0x00
/** valid only in combination with 5 data bits */
#define RTSER_1_5_STOPB            0x01
#define RTSER_2_STOPB            0x01
#define RTSER_DEF_STOPB            RTSER_1_STOPB
/** @} */
 
/*!
 * @anchor RTSER_xxx_HAND   @name RTSER_xxx_HAND
 * Handshake mechanisms
 * @{ */
#define RTSER_NO_HAND            0x00
#define RTSER_RTSCTS_HAND        0x01
#define RTSER_DEF_HAND            RTSER_NO_HAND
/** @} */
 
/*!
 * @anchor RTSER_RS485_xxx   @name RTSER_RS485_xxx
 * RS485 mode with automatic RTS handling
 * @{ */
#define RTSER_RS485_DISABLE        0x00
#define RTSER_RS485_ENABLE        0x01
#define RTSER_DEF_RS485            RTSER_RS485_DISABLE
/** @} */
 
/*!
 * @anchor RTSER_FIFO_xxx   @name RTSER_FIFO_xxx
 * Reception FIFO interrupt threshold
 * @{ */
#define RTSER_FIFO_DEPTH_1        0x00
#define RTSER_FIFO_DEPTH_4        0x40
#define RTSER_FIFO_DEPTH_8        0x80
#define RTSER_FIFO_DEPTH_14        0xC0
#define RTSER_DEF_FIFO_DEPTH        RTSER_FIFO_DEPTH_1
/** @} */
 
/*!
 * @anchor RTSER_TIMEOUT_xxx   @name RTSER_TIMEOUT_xxx
 * Special timeout values, see also @ref RTDM_TIMEOUT_xxx
 * @{ */
#define RTSER_TIMEOUT_INFINITE        RTDM_TIMEOUT_INFINITE
#define RTSER_TIMEOUT_NONE        RTDM_TIMEOUT_NONE
#define RTSER_DEF_TIMEOUT        RTDM_TIMEOUT_INFINITE
/** @} */
 
/*!
 * @anchor RTSER_xxx_TIMESTAMP_HISTORY   @name RTSER_xxx_TIMESTAMP_HISTORY
 * Timestamp history control
 * @{ */
#define RTSER_RX_TIMESTAMP_HISTORY    0x01
#define RTSER_DEF_TIMESTAMP_HISTORY    0x00
/** @} */
 
/*!
 * @anchor RTSER_EVENT_xxx   @name RTSER_EVENT_xxx
 * Events bits
 * @{ */
#define RTSER_EVENT_RXPEND        0x01
#define RTSER_EVENT_ERRPEND        0x02
#define RTSER_EVENT_MODEMHI        0x04
#define RTSER_EVENT_MODEMLO        0x08
#define RTSER_EVENT_TXEMPTY        0x10
#define RTSER_DEF_EVENT_MASK        0x00
/** @} */
 
 
/*!
 * @anchor RTSER_SET_xxx   @name RTSER_SET_xxx
 * Configuration mask bits
 * @{ */
#define RTSER_SET_BAUD            0x0001
#define RTSER_SET_PARITY        0x0002
#define RTSER_SET_DATA_BITS        0x0004
#define RTSER_SET_STOP_BITS        0x0008
#define RTSER_SET_HANDSHAKE        0x0010
#define RTSER_SET_FIFO_DEPTH        0x0020
#define RTSER_SET_TIMEOUT_RX        0x0100
#define RTSER_SET_TIMEOUT_TX        0x0200
#define RTSER_SET_TIMEOUT_EVENT        0x0400
#define RTSER_SET_TIMESTAMP_HISTORY    0x0800
#define RTSER_SET_EVENT_MASK        0x1000
#define RTSER_SET_RS485            0x2000
/** @} */
 
 
/*!
 * @anchor RTSER_LSR_xxx   @name RTSER_LSR_xxx
 * Line status bits
 * @{ */
#define RTSER_LSR_DATA            0x01
#define RTSER_LSR_OVERRUN_ERR        0x02
#define RTSER_LSR_PARITY_ERR        0x04
#define RTSER_LSR_FRAMING_ERR        0x08
#define RTSER_LSR_BREAK_IND        0x10
#define RTSER_LSR_THR_EMTPY        0x20
#define RTSER_LSR_TRANSM_EMPTY        0x40
#define RTSER_LSR_FIFO_ERR        0x80
#define RTSER_SOFT_OVERRUN_ERR        0x0100
/** @} */
 
 
/*!
 * @anchor RTSER_MSR_xxx   @name RTSER_MSR_xxx
 * Modem status bits
 * @{ */
#define RTSER_MSR_DCTS            0x01
#define RTSER_MSR_DDSR            0x02
#define RTSER_MSR_TERI            0x04
#define RTSER_MSR_DDCD            0x08
#define RTSER_MSR_CTS            0x10
#define RTSER_MSR_DSR            0x20
#define RTSER_MSR_RI            0x40
#define RTSER_MSR_DCD            0x80
/** @} */
 
 
/*!
 * @anchor RTSER_MCR_xxx   @name RTSER_MCR_xxx
 * Modem control bits
 * @{ */
#define RTSER_MCR_DTR            0x01
#define RTSER_MCR_RTS            0x02
#define RTSER_MCR_OUT1            0x04
#define RTSER_MCR_OUT2            0x08
#define RTSER_MCR_LOOP            0x10
/** @} */
 
 
/*!
 * @anchor RTSER_BREAK_xxx   @name RTSER_BREAK_xxx
 * Break control
 * @{ */
#define RTSER_BREAK_CLR            0x00
#define RTSER_BREAK_SET            0x01
 
 
/**
 * Serial device configuration
 */
typedef struct rtser_config {
   /** mask specifying valid fields, see @ref RTSER_SET_xxx */
   int        config_mask;
 
   /** baud rate, default @ref RTSER_DEF_BAUD */
   int        baud_rate;
 
   /** number of parity bits, see @ref RTSER_xxx_PARITY */
   int        parity;
 
   /** number of data bits, see @ref RTSER_xxx_BITS */
   int        data_bits;
 
   /** number of stop bits, see @ref RTSER_xxx_STOPB */
   int        stop_bits;
 
   /** handshake mechanisms, see @ref RTSER_xxx_HAND */
   int        handshake;
 
   /** reception FIFO interrupt threshold, see @ref RTSER_FIFO_xxx */
   int        fifo_depth;
 
   int        reserved;
 
   /** reception timeout, see @ref RTSER_TIMEOUT_xxx for special
    *  values */
   nanosecs_rel_t    rx_timeout;
 
   /** transmission timeout, see @ref RTSER_TIMEOUT_xxx for special
    *  values */
   nanosecs_rel_t    tx_timeout;
 
   /** event timeout, see @ref RTSER_TIMEOUT_xxx for special values */
   nanosecs_rel_t    event_timeout;
 
   /** enable timestamp history, see @ref RTSER_xxx_TIMESTAMP_HISTORY */
   int        timestamp_history;
 
   /** event mask to be used with @ref RTSER_RTIOC_WAIT_EVENT, see
    *  @ref RTSER_EVENT_xxx */
   int        event_mask;
 
   /** enable RS485 mode, see @ref RTSER_RS485_xxx */
   int        rs485;
} rtser_config_t;
 
/**
 * Serial device status
 */
typedef struct rtser_status {
   /** line status register, see @ref RTSER_LSR_xxx */
   int        line_status;
 
   /** modem status register, see @ref RTSER_MSR_xxx */
   int        modem_status;
} rtser_status_t;
 
/**
 * Additional information about serial device events
 */
typedef struct rtser_event {
   /** signalled events, see @ref RTSER_EVENT_xxx */
   int        events;
 
   /** number of pending input characters */
   int        rx_pending;
 
   /** last interrupt timestamp */
   nanosecs_abs_t    last_timestamp;
 
   /** reception timestamp of oldest character in input queue */
   nanosecs_abs_t    rxpend_timestamp;
} rtser_event_t;
 
 
#define RTIOC_TYPE_SERIAL        RTDM_CLASS_SERIAL
 
 
/*!
 * @name Sub-Classes of RTDM_CLASS_SERIAL
 * @{ */
#define RTDM_SUBCLASS_16550A        0
/** @} */
 
 
/*!
 * @anchor SERIOCTLs @name IOCTLs
 * Serial device IOCTLs
 * @{ */
 
/**
 * Get serial device configuration
 *
 * @param[out] arg Pointer to configuration buffer (struct rtser_config)
 *
 * @return 0 on success, otherwise negative error code
 *
 * @coretags{task-unrestricted}
 */
#define RTSER_RTIOC_GET_CONFIG    \
   _IOR(RTIOC_TYPE_SERIAL, 0x00, struct rtser_config)
 
/**
 * Set serial device configuration
 *
 * @param[in] arg Pointer to configuration buffer (struct rtser_config)
 *
 * @return 0 on success, otherwise:
 *
 * - -EPERM is returned if the caller's context is invalid, see note below.
 *
 * - -ENOMEM is returned if a new history buffer for timestamps cannot be
 * allocated.
 *
 * @coretags{task-unrestricted}
 *
 * @note If rtser_config contains a valid timestamp_history and the
 * addressed device has been opened in non-real-time context, this IOCTL must
 * be issued in non-real-time context as well. Otherwise, this command will
 * fail.
 */
#define RTSER_RTIOC_SET_CONFIG    \
   _IOW(RTIOC_TYPE_SERIAL, 0x01, struct rtser_config)
 
/**
 * Get serial device status
 *
 * @param[out] arg Pointer to status buffer (struct rtser_status)
 *
 * @return 0 on success, otherwise negative error code
 *
 * @coretags{task-unrestricted}
 *
 * @note The error states @c RTSER_LSR_OVERRUN_ERR, @c RTSER_LSR_PARITY_ERR,
 * @c RTSER_LSR_FRAMING_ERR, and @c RTSER_SOFT_OVERRUN_ERR that may have
 * occured during previous read accesses to the device will be saved for being
 * reported via this IOCTL. Upon return from @c RTSER_RTIOC_GET_STATUS, the
 * saved state will be cleared.
 */
#define RTSER_RTIOC_GET_STATUS    \
   _IOR(RTIOC_TYPE_SERIAL, 0x02, struct rtser_status)
 
/**
 * Get serial device's modem contol register
 *
 * @param[out] arg Pointer to variable receiving the content (int, see
 *             @ref RTSER_MCR_xxx)
 *
 * @return 0 on success, otherwise negative error code
 *
 * @coretags{task-unrestricted}
 */
#define RTSER_RTIOC_GET_CONTROL    \
   _IOR(RTIOC_TYPE_SERIAL, 0x03, int)
 
/**
 * Set serial device's modem contol register
 *
 * @param[in] arg New control register content (int, see @ref RTSER_MCR_xxx)
 *
 * @return 0 on success, otherwise negative error code
 *
 * @coretags{task-unrestricted}
 */
#define RTSER_RTIOC_SET_CONTROL    \
   _IOW(RTIOC_TYPE_SERIAL, 0x04, int)
 
/**
 * Wait on serial device events according to previously set mask
 *
 * @param[out] arg Pointer to event information buffer (struct rtser_event)
 *
 * @return 0 on success, otherwise:
 *
 * - -EBUSY is returned if another task is already waiting on events of this
 * device.
 *
 * - -EBADF is returned if the file descriptor is invalid or the device has
 * just been closed.
 *
 * @coretags{mode-unrestricted}
 */
#define RTSER_RTIOC_WAIT_EVENT    \
   _IOR(RTIOC_TYPE_SERIAL, 0x05, struct rtser_event)
/** @} */
 
/**
 * Set or clear break on UART output line
 *
 * @param[in] arg @c RTSER_BREAK_SET or @c RTSER_BREAK_CLR (int)
 *
 * @return 0 on success, otherwise negative error code
 *
 * @coretags{task-unrestricted}
 *
 * @note A set break condition may also be cleared on UART line
 * reconfiguration.
 */
#define RTSER_RTIOC_BREAK_CTL    \
   _IOR(RTIOC_TYPE_SERIAL, 0x06, int)
/** @} */
 
/*!
 * @anchor SERutils @name RT Serial example and utility programs
 * @{ */
/** @example cross-link.c */
/** @} */
 
#endif /* !_RTDM_UAPI_SERIAL_H */