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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [termios/] [termios.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* Copyright (C) 1992, 1993, 1996, 1997, 1998 Free Software Foundation, Inc.
2
   This file is part of the GNU C Library.
3
 
4
   The GNU C Library is free software; you can redistribute it and/or
5
   modify it under the terms of the GNU Library General Public License as
6
   published by the Free Software Foundation; either version 2 of the
7
   License, or (at your option) any later version.
8
 
9
   The GNU C Library is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
   Library General Public License for more details.
13
 
14
   You should have received a copy of the GNU Library General Public
15
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
16
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
   Boston, MA 02111-1307, USA.
18
 
19
 
20
   About the only thing remaining here fromthe original Linux-8086 C library
21
   version by Robert de Bath <robert@mayday.compulink.co.uk>, is the general
22
   layout.  All else has been recently stolen from GNU libc, since that was
23
   much more current.
24
 */
25
 
26
#include <errno.h>
27
#include <stddef.h>
28
#include <sys/ioctl.h>
29
#include <sys/types.h>
30
#include <unistd.h>
31
#include <termios.h>
32
 
33
#ifdef L_isatty
34
/* Return 1 if FD is a terminal, 0 if not.  */
35
 
36
int isatty(int fd)
37
{
38
    struct termios term;
39
    return (tcgetattr (fd, &term) == 0);
40
}
41
#endif
42
 
43
#ifdef L_tcdrain
44
/* Wait for pending output to be written on FD.  */
45
int __libc_tcdrain (int fd)
46
{
47
      /* With an argument of 1, TCSBRK waits for the output to drain.  */
48
      return ioctl(fd, TCSBRK, 1);
49
}
50
weak_alias(__libc_tcdrain, tcdrain)
51
#endif
52
 
53
#ifdef L_tcflow
54
/* Suspend or restart transmission on FD.  */
55
int tcflow ( int fd, int action)
56
{
57
      return ioctl(fd, TCXONC, action);
58
}
59
#endif
60
 
61
#ifdef L_tcflush
62
/* Flush pending data on FD.  */
63
int tcflush ( int fd, int queue_selector)
64
{
65
      return ioctl(fd, TCFLSH, queue_selector);
66
}
67
#endif
68
 
69
#ifdef L_tcsendbreak
70
/* Send zero bits on FD.  */
71
int tcsendbreak( int fd, int duration)
72
{
73
        /* The break lasts 0.25 to 0.5 seconds if DURATION is zero,
74
           and an implementation-defined period if DURATION is nonzero.
75
           We define a positive DURATION to be number of milliseconds to break.  */
76
        if (duration <= 0)
77
                return ioctl(fd, TCSBRK, 0);
78
 
79
#ifdef TCSBRKP
80
        /* Probably Linux-specific: a positive third TCSBRKP ioctl argument is
81
           defined to be the number of 100ms units to break.  */
82
        return ioctl(fd, TCSBRKP, (duration + 99) / 100);
83
#else
84
        /* ioctl can't send a break of any other duration for us.
85
           This could be changed to use trickery (e.g. lower speed and
86
           send a '\0') to send the break, but for now just return an error.  */
87
        __set_errno (EINVAL);
88
        return -1;
89
#endif
90
}
91
#endif
92
 
93
#ifdef L_tcsetpgrp
94
/* Set the foreground process group ID of FD set PGRP_ID.  */
95
int tcsetpgrp ( int fd, pid_t pgrp_id)
96
{
97
      return ioctl (fd, TIOCSPGRP, &pgrp_id);
98
}
99
#endif
100
 
101
#ifdef L_tcgetpgrp
102
/* Return the foreground process group ID of FD.  */
103
pid_t tcgetpgrp ( int fd)
104
{
105
    int pgrp;
106
 
107
    if (ioctl (fd, TIOCGPGRP, &pgrp) < 0)
108
        return (pid_t) -1;
109
    return (pid_t) pgrp;
110
}
111
#endif
112
 
113
/* This is a gross hack around a kernel bug.  If the cfsetispeed functions is
114
 * called with the SPEED argument set to zero this means use the same speed as
115
 * for output.  But we don't have independent input and output speeds and
116
 * therefore cannot record this.
117
 *
118
 * We use an unused bit in the `c_iflag' field to keep track of this use of
119
 * `cfsetispeed'.  The value here must correspond to the one used in
120
 * `tcsetattr.c'.  */
121
#define IBAUD0  020000000000
122
 
123
#ifdef L_cfgetospeed
124
/* Return the output baud rate stored in *TERMIOS_P.  */
125
speed_t cfgetospeed ( const struct termios *termios_p)
126
{
127
      return termios_p->c_cflag & (CBAUD | CBAUDEX);
128
}
129
#endif
130
 
131
#ifdef L_cfgetispeed
132
 
133
/* Return the input baud rate stored in *TERMIOS_P.
134
 * Although for Linux there is no difference between input and output
135
 * speed, the numerical 0 is a special case for the input baud rate. It
136
 * should set the input baud rate to the output baud rate. */
137
speed_t cfgetispeed (const struct termios *termios_p)
138
{
139
    return ((termios_p->c_iflag & IBAUD0)
140
            ? 0 : termios_p->c_cflag & (CBAUD | CBAUDEX));
141
}
142
#endif
143
 
144
#ifdef L_cfsetospeed
145
/* Set the output baud rate stored in *TERMIOS_P to SPEED.  */
146
int cfsetospeed  (struct termios *termios_p, speed_t speed)
147
{
148
    if ((speed & ~CBAUD) != 0
149
            && (speed < B57600 || speed > B460800))
150
    {
151
        __set_errno(EINVAL);
152
        return -1;
153
    }
154
 
155
    termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
156
    termios_p->c_cflag |= speed;
157
 
158
    return 0;
159
}
160
#endif
161
 
162
#ifdef L_cfsetispeed
163
/* Set the input baud rate stored in *TERMIOS_P to SPEED.
164
 *    Although for Linux there is no difference between input and output
165
 *       speed, the numerical 0 is a special case for the input baud rate.  It
166
 *          should set the input baud rate to the output baud rate.  */
167
int cfsetispeed ( struct termios *termios_p, speed_t speed)
168
{
169
    if ((speed & ~CBAUD) != 0
170
            && (speed < B57600 || speed > B460800))
171
    {
172
        __set_errno(EINVAL);
173
        return -1;
174
    }
175
 
176
    if (speed == 0)
177
        termios_p->c_iflag |= IBAUD0;
178
    else
179
    {
180
        termios_p->c_iflag &= ~IBAUD0;
181
        termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
182
        termios_p->c_cflag |= speed;
183
    }
184
 
185
    return 0;
186
}
187
#endif
188
 
189
#ifdef L_cfsetspeed
190
struct speed_struct
191
{
192
  speed_t value;
193
  speed_t internal;
194
};
195
 
196
static const struct speed_struct speeds[] =
197
  {
198
#ifdef B0
199
    { 0, B0 },
200
#endif
201
#ifdef B50
202
    { 50, B50 },
203
#endif
204
#ifdef B75
205
    { 75, B75 },
206
#endif
207
#ifdef B110
208
    { 110, B110 },
209
#endif
210
#ifdef B134
211
    { 134, B134 },
212
#endif
213
#ifdef B150
214
    { 150, B150 },
215
#endif
216
#ifdef B200
217
    { 200, B200 },
218
#endif
219
#ifdef B300
220
    { 300, B300 },
221
#endif
222
#ifdef B600
223
    { 600, B600 },
224
#endif
225
#ifdef B1200
226
    { 1200, B1200 },
227
#endif
228
#ifdef B1200
229
    { 1200, B1200 },
230
#endif
231
#ifdef B1800
232
    { 1800, B1800 },
233
#endif
234
#ifdef B2400
235
    { 2400, B2400 },
236
#endif
237
#ifdef B4800
238
    { 4800, B4800 },
239
#endif
240
#ifdef B9600
241
    { 9600, B9600 },
242
#endif
243
#ifdef B19200
244
    { 19200, B19200 },
245
#endif
246
#ifdef B38400
247
    { 38400, B38400 },
248
#endif
249
#ifdef B57600
250
    { 57600, B57600 },
251
#endif
252
#ifdef B76800
253
    { 76800, B76800 },
254
#endif
255
#ifdef B115200
256
    { 115200, B115200 },
257
#endif
258
#ifdef B153600
259
    { 153600, B153600 },
260
#endif
261
#ifdef B230400
262
    { 230400, B230400 },
263
#endif
264
#ifdef B307200
265
    { 307200, B307200 },
266
#endif
267
#ifdef B460800
268
    { 460800, B460800 },
269
#endif
270
  };
271
 
272
 
273
/* Set both the input and output baud rates stored in *TERMIOS_P to SPEED.  */
274
int cfsetspeed (struct termios *termios_p, speed_t speed)
275
{
276
  size_t cnt;
277
 
278
  for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt)
279
    if (speed == speeds[cnt].internal)
280
      {
281
        cfsetispeed (termios_p, speed);
282
        cfsetospeed (termios_p, speed);
283
        return 0;
284
      }
285
    else if (speed == speeds[cnt].value)
286
      {
287
        cfsetispeed (termios_p, speeds[cnt].internal);
288
        cfsetospeed (termios_p, speeds[cnt].internal);
289
        return 0;
290
      }
291
 
292
  __set_errno (EINVAL);
293
 
294
  return -1;
295
}
296
#endif
297
 
298
#ifdef L_cfmakeraw
299
/* Copyright (C) 1992, 1996, 1997 Free Software Foundation, Inc.
300
   This file is part of the GNU C Library.
301
*/
302
#include <termios.h>
303
 
304
/* Set *T to indicate raw mode.  */
305
void
306
cfmakeraw (struct termios *t)
307
{
308
  t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
309
  t->c_oflag &= ~OPOST;
310
  t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
311
  t->c_cflag &= ~(CSIZE|PARENB);
312
  t->c_cflag |= CS8;
313
  t->c_cc[VMIN] = 1;            /* read returns when one char is available.  */
314
  t->c_cc[VTIME] = 0;
315
}
316
#endif
317
 

powered by: WebSVN 2.1.0

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