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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [termios/] [termios.c] - Blame information for rev 199

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/* Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk> This
2
 * file is part of the Linux-8086 C library and is distributed under the
3
 * GNU Library General Public License.
4
 */
5
 
6
/* Note: This is based loosely on the Glib termios routines. */
7
 
8
#ifndef __MSDOS__
9
 
10
#include <errno.h>
11
#include <stddef.h>
12
#include <sys/ioctl.h>
13
#include <termios.h>
14
 
15
#ifdef L_isatty
16
isatty(fd)
17
int fd;
18
{
19
   struct termios term;
20
   int rv, err = errno;
21
   rv= (ioctl(fd, TCGETS, &term)==0);
22
   if( rv==0 && errno == ENOSYS )
23
      rv = (fd<3);
24
   errno = err;
25
   return rv;
26
}
27
#endif 
28
 
29
#ifdef L_tcgetattr
30
int
31
tcgetattr(fd, term)
32
int   fd;
33
struct termios *term;
34
{
35
   return ioctl(fd, TCGETS, term);
36
}
37
#endif
38
 
39
#ifdef L_tcsetattr
40
int
41
tcsetattr(fildes, optional_actions, termios_p)
42
int fildes;
43
int optional_actions;
44
struct termios *termios_p;
45
{
46
   switch (optional_actions)
47
   {
48
   case TCSANOW:
49
      return ioctl(fildes, TCSETS, termios_p);
50
   case TCSADRAIN:
51
      return ioctl(fildes, TCSETSW, termios_p);
52
   case TCSAFLUSH:
53
      return ioctl(fildes, TCSETSF, termios_p);
54
   default:
55
      errno = EINVAL;
56
      return -1;
57
   }
58
}
59
#endif
60
 
61
#ifdef L_tcdrain
62
/* Wait for pending output to be written on FD.  */
63
int
64
tcdrain(fd)
65
int   fd;
66
{
67
   /* With an argument of 1, TCSBRK just waits for output to drain.  */
68
   return ioctl(fd, TCSBRK, 1);
69
}
70
#endif
71
 
72
#ifdef L_tcflow
73
int
74
tcflow(fd, action)
75
int fd;
76
int action;
77
{
78
   return ioctl(fd, TCXONC, action);
79
}
80
#endif
81
 
82
#ifdef L_tcflush
83
/* Flush pending data on FD.  */
84
int
85
tcflush(fd, queue_selector)
86
int   fd;
87
int   queue_selector;
88
{
89
   return ioctl(fd, TCFLSH, queue_selector);
90
}
91
#endif
92
 
93
#ifdef L_tcsendbreak
94
/* Send zero bits on FD.  */
95
int
96
tcsendbreak(fd, duration)
97
int   fd;
98
int   duration;
99
{
100
   /*
101
    * The break lasts 0.25 to 0.5 seconds if DURATION is zero, and an
102
    * implementation-defined period if DURATION is nonzero. We define a
103
    * positive DURATION to be number of milliseconds to break.
104
    */
105
   if (duration <= 0)
106
      return ioctl(fd, TCSBRK, 0);
107
 
108
   /*
109
    * ioctl can't send a break of any other duration for us. This could be
110
    * changed to use trickery (e.g. lower speed and send a '\0') to send
111
    * the break, but for now just return an error.
112
    */
113
   errno = EINVAL;
114
   return -1;
115
}
116
#endif
117
 
118
#ifdef L_tcsetpgrp
119
/* Set the foreground process group ID of FD set PGRP_ID.  */
120
int
121
tcsetpgrp(fd, pgrp_id)
122
int   fd;
123
pid_t pgrp_id;
124
{
125
   return ioctl(fd, TIOCSPGRP, &pgrp_id);
126
}
127
#endif
128
 
129
#ifdef L_tcgetpgrp
130
/* Return the foreground process group ID of FD.  */
131
pid_t
132
tcgetpgrp(fd)
133
int   fd;
134
{
135
   int   pgrp;
136
   if (ioctl(fd, TIOCGPGRP, &pgrp) < 0)
137
      return (pid_t) - 1;
138
   return (pid_t) pgrp;
139
}
140
#endif
141
 
142
#ifdef L_cfgetospeed
143
speed_t cfgetospeed(tp)
144
struct termios *tp;
145
{
146
    return (tp->c_cflag & CBAUD);
147
}
148
#endif
149
 
150
#ifdef L_cfgetispeed
151
speed_t cfgetispeed(tp)
152
struct termios *tp;
153
{
154
    return (tp->c_cflag & CBAUD);
155
}
156
#endif
157
 
158
#ifdef L_cfsetospeed
159
int cfsetospeed(tp, speed)
160
struct termios *tp; speed_t speed;
161
{
162
#ifdef CBAUDEX
163
    if ((speed & ~CBAUD) ||
164
        ((speed & CBAUDEX) && (speed < B57600 || speed > B115200)))
165
        return 0;
166
#else
167
    if (speed & ~CBAUD)
168
        return 0;
169
#endif
170
    tp->c_cflag &= ~CBAUD;
171
    tp->c_cflag |= speed;
172
 
173
    return 0;
174
}
175
#endif
176
 
177
#ifdef L_cfsetispeed
178
int cfsetispeed(tp, speed)
179
struct termios *tp; speed_t speed;
180
{
181
    return cfsetospeed(tp, speed);
182
}
183
#endif
184
 
185
#if 0
186
 
187
/* Not POSIX standard, not worth the bother to keep it up */
188
 
189
#ifdef L_tcspeed
190
static struct {
191
        int number;
192
        speed_t code;
193
} tcspeeds[] = {
194
#ifdef B50
195
        {50, B50},
196
#endif
197
#ifdef B75
198
        {75, B75},
199
#endif
200
#ifdef B110
201
        {110, B110},
202
#endif
203
#ifdef B134
204
        {134, B134},
205
#endif
206
#ifdef B150
207
        {150, B150},
208
#endif
209
#ifdef B200
210
        {200, B200},
211
#endif
212
#ifdef B300
213
        {300, B300},
214
#endif
215
#ifdef B600
216
        {600, B600},
217
#endif
218
#ifdef B1200
219
        {1200, B1200},
220
#endif
221
#ifdef B1800
222
        {1800, B1800},
223
#endif
224
#ifdef B2400
225
        {2400, B2400},
226
#endif
227
#ifdef B4800
228
        {4800, B4800},
229
#endif
230
#ifdef B9600
231
        {9600, B9600},
232
#endif
233
#ifdef B19200
234
        {19200, B19200},
235
#endif
236
#ifdef B38400
237
        {38400, B38400},
238
#endif
239
#ifdef B57600
240
        {57600, B57600},
241
#endif
242
#ifdef B115200
243
        {115200, B115200},
244
#endif
245
#ifdef B230400
246
        {230400, B230400},
247
#endif
248
#ifdef B460800
249
        {460800, B460800},
250
#endif
251
#ifdef B0
252
        {0, B0},
253
#endif
254
        {0, 0}
255
};
256
 
257
int tcspeed_to_number(code)
258
speed_t code;
259
{
260
    int i;
261
    code &= CBAUD;
262
    for(i=0;tcspeeds[i].code;i++)
263
        if (tcspeeds[i].code == code)
264
          return tcspeeds[i].number;
265
    return 0;
266
}
267
 
268
speed_t tcspeed_from_number(number)
269
int number;
270
{
271
    int i;
272
    for(i=0;tcspeeds[i].code;i++)
273
        if (tcspeeds[i].number == number)
274
          return tcspeeds[i].code;
275
    return B0;
276
}
277
#endif
278
 
279
#ifdef L_cfgetospeedn
280
int cfgetospeedn(tp)
281
struct termios *tp;
282
{
283
    return tcspeed_to_number(cfgetospeed(tp));
284
}
285
#endif
286
 
287
#ifdef L_cfgetispeedn
288
int cfgetispeedn(tp)
289
struct termios *tp;
290
{
291
    return tcspeed_to_number(cfgetispeed(tp));
292
}
293
#endif
294
 
295
#ifdef L_cfsetospeedn
296
int cfsetospeedn(tp, speed)
297
struct termios *tp; int speed;
298
{
299
    return cfsetospeed(tp, tcspeed_from_number(speed));
300
}
301
#endif
302
 
303
#ifdef L_cfsetispeedn
304
int cfsetispeedn(tp, speed)
305
struct termios *tp; int speed;
306
{
307
    return cfsetispeedn(tp, tcspeed_from_number(speed));
308
}
309
#endif
310
 
311
#endif
312
 
313
/* From linux libc-4.6.27 again */
314
#ifdef L_cfmakeraw
315
/* Copyright (C) 1992 Free Software Foundation, Inc.
316
This file is part of the GNU C Library.*/
317
 
318
void
319
cfmakeraw(t)
320
struct termios *t;
321
{
322
/* I changed it to the current form according to the suggestions
323
 * from Bruce Evans. Thanks Bruce. Please report the problems to
324
 * H.J. Lu (hlu@eecs.wsu.edu).
325
 */
326
 
327
/*
328
 * I took out the bits commented out by #if 1...#else    - RHP
329
 */
330
 
331
    /*  VMIN = 0 means non-blocking for Linux */
332
    t->c_cc[VMIN] = 1; t->c_cc[VTIME] = 1;
333
    /* clear some bits with &= ~(bits), set others with |= */
334
    t->c_cflag &= ~(CSIZE|PARENB|CSTOPB);
335
    t->c_cflag |=  (CS8|HUPCL|CREAD);
336
    t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|INPCK|ISTRIP);
337
    t->c_iflag &= ~(INLCR|IGNCR|ICRNL|IXON|IXOFF);
338
    t->c_iflag |=  (BRKINT|IGNPAR);
339
    t->c_oflag &= ~(OPOST|OLCUC|OCRNL|ONOCR|ONLRET|OFILL|OFDEL);
340
    t->c_oflag &= ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
341
    t->c_oflag |=  (ONLCR|NL0|CR0|TAB3|BS0|VT0|FF0);
342
    t->c_lflag &= ~(ISIG|ICANON|IEXTEN|ECHO|ECHOE|ECHOK|ECHONL);
343
    t->c_lflag &= ~(NOFLSH|XCASE);
344
    t->c_lflag &= ~(ECHOPRT|ECHOCTL|ECHOKE);
345
}
346
#endif
347
 
348
#endif

powered by: WebSVN 2.1.0

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