OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [serial/] [current/] [src/] [common/] [termios.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/* ====================================================================
2
//
3
//      termios.c
4
//
5
//      POSIX termios API implementation
6
//
7
// ====================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later
16
// version.
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21
// for more details.
22
//
23
// You should have received a copy of the GNU General Public License
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
26
//
27
// As a special exception, if other files instantiate templates or use
28
// macros or inline functions from this file, or you compile this file
29
// and link it with other works to produce a work based on this file,
30
// this file does not by itself cause the resulting work to be covered by
31
// the GNU General Public License. However the source code for this file
32
// must still be made available in accordance with section (3) of the GNU
33
// General Public License v2.
34
//
35
// This exception does not invalidate any other reasons why a work based
36
// on this file might be covered by the GNU General Public License.
37
// -------------------------------------------
38
// ####ECOSGPLCOPYRIGHTEND####
39
// ====================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    jlarmour
43
// Contributors:
44
// Date:         2000-07-22
45
// Purpose:      POSIX termios API support
46
// Description:  Most of the real work happens in the POSIX termios tty
47
//               drivers
48
//
49
//####DESCRIPTIONEND####
50
//
51
// ==================================================================*/
52
 
53
// CONFIGURATION
54
 
55
#include <pkgconf/io_serial.h>
56
 
57
#ifdef CYGPKG_IO_SERIAL_TERMIOS
58
 
59
// INCLUDES
60
 
61
#include <termios.h>             // Header for this file
62
#include <cyg/infra/cyg_type.h>  // Common stuff
63
#include <cyg/infra/cyg_ass.h>   // Assertion support
64
#include <cyg/infra/cyg_trac.h>  // Tracing support
65
#include <cyg/io/serialio.h>     // eCos serial implementation
66
#include <cyg/fileio/fileio.h>   // file operations
67
#include <cyg/io/io.h>
68
#include <errno.h>               // errno
69
#include <unistd.h>              // isatty()
70
 
71
// TYPES
72
 
73
typedef struct {
74
    const struct termios *termios_p;
75
    int optact;
76
} setattr_struct;
77
 
78
// FUNCTIONS
79
 
80
extern speed_t
81
cfgetospeed( const struct termios *termios_p )
82
{
83
    CYG_REPORT_FUNCTYPE( "returning speed code %d" );
84
    CYG_CHECK_DATA_PTRC( termios_p );
85
    CYG_REPORT_FUNCARG1XV( termios_p );
86
    CYG_REPORT_RETVAL( termios_p->c_ospeed );
87
    return termios_p->c_ospeed;
88
} // cfgetospeed()
89
 
90
 
91
extern int
92
cfsetospeed( struct termios *termios_p, speed_t speed )
93
{
94
    CYG_REPORT_FUNCTYPE( "returning %d" );
95
    CYG_CHECK_DATA_PTRC( termios_p );
96
    CYG_REPORT_FUNCARG2( "termios_p=%08x, speed=%d", termios_p, speed );
97
    CYG_REPORT_RETVAL( termios_p->c_ospeed );
98
    if ( speed > B4000000 ) {
99
        errno = EINVAL;
100
        CYG_REPORT_RETVAL( -1 );
101
        return -1;
102
    }
103
    termios_p->c_ospeed = speed;
104
    CYG_REPORT_RETVAL( 0 );
105
    return 0;
106
} // cfsetospeed()
107
 
108
 
109
extern speed_t
110
cfgetispeed( const struct termios *termios_p )
111
{
112
    CYG_REPORT_FUNCTYPE( "returning speed code %d" );
113
    CYG_CHECK_DATA_PTRC( termios_p );
114
    CYG_REPORT_FUNCARG1XV( termios_p );
115
    CYG_REPORT_RETVAL( termios_p->c_ispeed );
116
    return termios_p->c_ispeed;
117
} // cfgetispeed()
118
 
119
 
120
extern int
121
cfsetispeed( struct termios *termios_p, speed_t speed )
122
{
123
    CYG_REPORT_FUNCTYPE( "returning %d" );
124
    CYG_CHECK_DATA_PTRC( termios_p );
125
    CYG_REPORT_FUNCARG2( "termios_p=%08x, speed=%d", termios_p, speed );
126
    if ( speed > B115200 ) {
127
        errno = EINVAL;
128
        CYG_REPORT_RETVAL( -1 );
129
        return -1;
130
    }
131
    termios_p->c_ispeed = speed;
132
    CYG_REPORT_RETVAL( 0 );
133
    return 0;
134
} // cfsetispeed()
135
 
136
 
137
__externC cyg_file *
138
cyg_fp_get( int fd );
139
 
140
__externC void
141
cyg_fp_free( cyg_file *fp );
142
 
143
extern int
144
tcgetattr( int fildes, struct termios *termios_p )
145
{
146
    cyg_file *fp;
147
    int ret;
148
    int len = sizeof( *termios_p );
149
 
150
    CYG_REPORT_FUNCTYPE( "returning %d" );
151
    CYG_REPORT_FUNCARG2( "fildes=%d, termios_p=%08x", fildes, termios_p );
152
    CYG_CHECK_DATA_PTRC( termios_p );
153
 
154
    if ( !isatty(fildes) ) {
155
        errno = ENOTTY;
156
        CYG_REPORT_RETVAL( -1 );
157
        return -1;
158
    }
159
 
160
    fp = cyg_fp_get( fildes );
161
 
162
    if ( NULL == fp ) {
163
        errno = EBADF;
164
        CYG_REPORT_RETVAL( -1 );
165
        return -1;
166
    }
167
 
168
    ret = fp->f_ops->fo_getinfo( fp, CYG_IO_GET_CONFIG_TERMIOS, termios_p,
169
                                 len);
170
    cyg_fp_free( fp );
171
 
172
    if ( ret > 0 ) {
173
        errno = ret;
174
        CYG_REPORT_RETVAL( -1 );
175
        return -1;
176
    }
177
    CYG_REPORT_RETVAL( 0 );
178
    return 0;
179
} // tcgetattr()
180
 
181
 
182
extern int
183
tcsetattr( int fildes, int optact, const struct termios *termios_p )
184
{
185
    cyg_file *fp;
186
    int ret;
187
    setattr_struct attr;
188
    int len = sizeof( attr );
189
 
190
    CYG_REPORT_FUNCTYPE( "returning %d" );
191
    CYG_REPORT_FUNCARG3( "fildes=%d, optact=%d, termios_p=%08x",
192
                         fildes, optact, termios_p );
193
    CYG_CHECK_DATA_PTRC( termios_p );
194
 
195
    if ( !isatty(fildes) ) {
196
        errno = ENOTTY;
197
        CYG_REPORT_RETVAL( -1 );
198
        return -1;
199
    }
200
 
201
    if ( (optact != TCSANOW) && (optact != TCSADRAIN) &&
202
         (optact != TCSAFLUSH) ) {
203
        errno = EINVAL;
204
        CYG_REPORT_RETVAL( -1 );
205
        return -1;
206
    }
207
 
208
    fp = cyg_fp_get( fildes );
209
 
210
    if ( NULL == fp ) {
211
        errno = EBADF;
212
        CYG_REPORT_RETVAL( -1 );
213
        return -1;
214
    }
215
 
216
    attr.termios_p = termios_p;
217
    attr.optact = optact;
218
 
219
    ret = fp->f_ops->fo_setinfo( fp, CYG_IO_SET_CONFIG_TERMIOS, &attr,
220
                                 len);
221
 
222
    cyg_fp_free( fp );
223
 
224
    if ( ret > 0 ) {
225
        errno = ret;
226
        CYG_REPORT_RETVAL( -1 );
227
        return -1;
228
    }
229
    CYG_REPORT_RETVAL( 0 );
230
    return 0;
231
} // tcsetattr()
232
 
233
 
234
extern int
235
tcsendbreak( int fildes, int duration )
236
{
237
    // FIXME
238
    return -EINVAL;
239
} // tcsendbreak()
240
 
241
extern int
242
tcdrain( int fildes )
243
{
244
    cyg_file *fp;
245
    int ret;
246
 
247
    CYG_REPORT_FUNCTYPE( "returning %d" );
248
    CYG_REPORT_FUNCARG1DV( fildes );
249
 
250
    if ( !isatty(fildes) ) {
251
        errno = ENOTTY;
252
        CYG_REPORT_RETVAL( -1 );
253
        return -1;
254
    }
255
 
256
    fp = cyg_fp_get( fildes );
257
 
258
    if ( NULL == fp ) {
259
        errno = EBADF;
260
        CYG_REPORT_RETVAL( -1 );
261
        return -1;
262
    }
263
 
264
    ret = fp->f_ops->fo_getinfo( fp,
265
                                 CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN,
266
                                 NULL, 1 );
267
    cyg_fp_free( fp );
268
 
269
    if ( ret > 0 ) {
270
        errno = ret;
271
        CYG_REPORT_RETVAL( -1 );
272
        return -1;
273
    }
274
    CYG_REPORT_RETVAL( 0 );
275
    return 0;
276
} // tcdrain()
277
 
278
extern int
279
tcflush( int fildes, int queue_sel )
280
{
281
    cyg_file *fp;
282
    int ret;
283
 
284
    CYG_REPORT_FUNCTYPE( "returning %d" );
285
    CYG_REPORT_FUNCARG2DV( fildes, queue_sel );
286
 
287
    if ( !isatty(fildes) ) {
288
        errno = ENOTTY;
289
        CYG_REPORT_RETVAL( -1 );
290
        return -1;
291
    }
292
 
293
    fp = cyg_fp_get( fildes );
294
 
295
    if ( NULL == fp ) {
296
        errno = EBADF;
297
        CYG_REPORT_RETVAL( -1 );
298
        return -1;
299
    }
300
 
301
    switch( queue_sel ) {
302
    case TCIOFLUSH:
303
        ret = fp->f_ops->fo_getinfo( fp,
304
                                     CYG_IO_GET_CONFIG_SERIAL_OUTPUT_FLUSH,
305
                                     NULL, 1 );
306
        // fallthrough
307
    case TCIFLUSH:
308
        ret = fp->f_ops->fo_getinfo( fp,
309
                                     CYG_IO_GET_CONFIG_SERIAL_INPUT_FLUSH,
310
                                     NULL, 1 );
311
        break;
312
    case TCOFLUSH:
313
        ret = fp->f_ops->fo_getinfo( fp,
314
                                     CYG_IO_GET_CONFIG_SERIAL_OUTPUT_FLUSH,
315
                                     NULL, 1 );
316
        break;
317
    default:
318
        ret = EINVAL;
319
        break;
320
    }
321
 
322
    cyg_fp_free( fp );
323
 
324
    if ( ret > 0 ) {
325
        errno = ret;
326
        CYG_REPORT_RETVAL( -1 );
327
        return -1;
328
    }
329
    CYG_REPORT_RETVAL( 0 );
330
    return 0;
331
} // tcflush()
332
 
333
extern int
334
tcflow( int fildes, int action )
335
{
336
    cyg_file *fp;
337
    int ret;
338
    cyg_uint32 forcearg;
339
    int len = sizeof(forcearg);
340
 
341
    CYG_REPORT_FUNCTYPE( "returning %d" );
342
    CYG_REPORT_FUNCARG2DV( fildes, action );
343
 
344
    if ( !isatty(fildes) ) {
345
        errno = ENOTTY;
346
        CYG_REPORT_RETVAL( -1 );
347
        return -1;
348
    }
349
 
350
    fp = cyg_fp_get( fildes );
351
 
352
    if ( NULL == fp ) {
353
        errno = EBADF;
354
        CYG_REPORT_RETVAL( -1 );
355
        return -1;
356
    }
357
 
358
    switch( action ) {
359
    case TCOOFF:
360
        forcearg = CYGNUM_SERIAL_FLOW_THROTTLE_TX;
361
        ret = fp->f_ops->fo_setinfo( fp,
362
                                    CYG_IO_SET_CONFIG_SERIAL_FLOW_CONTROL_FORCE,
363
                                     &forcearg, len );
364
        break;
365
    case TCOON:
366
        forcearg = CYGNUM_SERIAL_FLOW_RESTART_TX;
367
        ret = fp->f_ops->fo_setinfo( fp,
368
                                    CYG_IO_SET_CONFIG_SERIAL_FLOW_CONTROL_FORCE,
369
                                     &forcearg, len );
370
        break;
371
    case TCIOFF:
372
        forcearg = CYGNUM_SERIAL_FLOW_THROTTLE_RX;
373
        ret = fp->f_ops->fo_setinfo( fp,
374
                                    CYG_IO_SET_CONFIG_SERIAL_FLOW_CONTROL_FORCE,
375
                                     &forcearg, len );
376
        break;
377
    case TCION:
378
        forcearg = CYGNUM_SERIAL_FLOW_RESTART_RX;
379
        ret = fp->f_ops->fo_setinfo( fp,
380
                                    CYG_IO_SET_CONFIG_SERIAL_FLOW_CONTROL_FORCE,
381
                                     &forcearg, len );
382
        break;
383
    default:
384
        ret = EINVAL;
385
        break;
386
    }
387
 
388
    cyg_fp_free( fp );
389
 
390
    if ( ret > 0 ) {
391
        errno = ret;
392
        CYG_REPORT_RETVAL( -1 );
393
        return -1;
394
    }
395
    CYG_REPORT_RETVAL( 0 );
396
    return 0;
397
} // tcflow()
398
 
399
#endif // ifdef CYGPKG_IO_SERIAL_TERMIOS
400
 
401
// EOF termios.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.