Mercurial > ecos
annotate packages/io/serial/current/src/common/tty.c @ 3292:7f8e529b4d82 default tip
Fix FREESCALE_EDMA_NBYTES_MLOFFYES_MLOFF() so it works with negative offsets.
| author | vae |
|---|---|
| date | Wed, 29 Apr 2015 23:31:48 +0000 |
| parents | 4df50cbc6176 |
| children |
| rev | line source |
|---|---|
| 2 | 1 //========================================================================== |
| 2 // | |
| 3 // io/serial/common/tty.c | |
| 4 // | |
| 5 // TTY (terminal-like interface) I/O driver | |
| 6 // | |
| 7 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
9 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
136
diff
changeset
|
12 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
13 // eCos is free software; you can redistribute it and/or modify it under |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
14 // the terms of the GNU General Public License as published by the Free |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
15 // Software Foundation; either version 2 or (at your option) any later |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
16 // version. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
136
diff
changeset
|
17 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
18 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
21 // for more details. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
136
diff
changeset
|
22 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
23 // You should have received a copy of the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
24 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
136
diff
changeset
|
26 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
27 // As a special exception, if other files instantiate templates or use |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
28 // macros or inline functions from this file, or you compile this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
29 // and link it with other works to produce a work based on this file, |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
30 // this file does not by itself cause the resulting work to be covered by |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
31 // the GNU General Public License. However the source code for this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
32 // must still be made available in accordance with section (3) of the GNU |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
33 // General Public License v2. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
136
diff
changeset
|
34 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
35 // This exception does not invalidate any other reasons why a work based |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
36 // on this file might be covered by the GNU General Public License. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
37 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2284
diff
changeset
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
| 2 | 39 //========================================================================== |
| 40 //#####DESCRIPTIONBEGIN#### | |
| 41 // | |
| 42 // Author(s): gthomas | |
| 43 // Contributors: gthomas | |
| 44 // Date: 1999-02-04 | |
| 45 // Purpose: Device driver for tty I/O, layered on top of serial I/O | |
| 46 // Description: | |
| 47 // | |
| 48 //####DESCRIPTIONEND#### | |
| 49 // | |
| 50 //========================================================================== | |
| 51 | |
| 52 #include <pkgconf/io.h> | |
| 53 #include <pkgconf/io_serial.h> | |
| 54 #ifdef CYGPKG_IO_SERIAL_TTY | |
| 55 #include <cyg/io/io.h> | |
| 56 #include <cyg/io/devtab.h> | |
| 57 #include <cyg/io/ttyio.h> | |
| 58 #include <cyg/infra/diag.h> | |
| 59 | |
| 60 static bool tty_init(struct cyg_devtab_entry *tab); | |
| 61 static Cyg_ErrNo tty_lookup(struct cyg_devtab_entry **tab, | |
| 62 struct cyg_devtab_entry *sub_tab, | |
| 63 const char *name); | |
| 64 static Cyg_ErrNo tty_write(cyg_io_handle_t handle, const void *buf, cyg_uint32 *len); | |
| 65 static Cyg_ErrNo tty_read(cyg_io_handle_t handle, void *buf, cyg_uint32 *len); | |
|
1196
ecbb5d87bfe0
* src/common/tty.c: Make tty_select prototype match implementation.
jlarmour
parents:
456
diff
changeset
|
66 static cyg_bool tty_select(cyg_io_handle_t handle, cyg_uint32 which, CYG_ADDRWORD info); |
| 2 | 67 static Cyg_ErrNo tty_get_config(cyg_io_handle_t handle, cyg_uint32 key, void *buf, cyg_uint32 *len); |
| 68 static Cyg_ErrNo tty_set_config(cyg_io_handle_t handle, cyg_uint32 key, const void *buf, cyg_uint32 *len); | |
| 69 | |
| 70 struct tty_private_info { | |
| 71 cyg_tty_info_t dev_info; | |
| 72 cyg_io_handle_t dev_handle; | |
| 73 }; | |
| 74 | |
| 75 static DEVIO_TABLE(tty_devio, | |
| 76 tty_write, | |
| 77 tty_read, | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
80
diff
changeset
|
78 tty_select, |
| 2 | 79 tty_get_config, |
| 80 tty_set_config | |
| 81 ); | |
| 82 | |
| 83 #ifdef CYGPKG_IO_SERIAL_TTY_TTYDIAG | |
| 84 static struct tty_private_info tty_private_info_diag; | |
| 85 DEVTAB_ENTRY(tty_io_diag, | |
| 86 // "/dev/console", | |
| 87 // CYGDAT_IO_SERIAL_TTY_CONSOLE, // Based on driver for this device | |
| 88 "/dev/ttydiag", | |
| 89 "/dev/haldiag", | |
| 90 &tty_devio, | |
| 91 tty_init, | |
| 92 tty_lookup, // Execute this when device is being looked up | |
| 93 &tty_private_info_diag); | |
| 94 #endif | |
| 95 | |
| 96 #ifdef CYGPKG_IO_SERIAL_TTY_TTY0 | |
| 97 static struct tty_private_info tty_private_info0; | |
| 98 DEVTAB_ENTRY(tty_io0, | |
| 99 "/dev/tty0", | |
| 100 CYGDAT_IO_SERIAL_TTY_TTY0_DEV, | |
| 101 &tty_devio, | |
| 102 tty_init, | |
| 103 tty_lookup, // Execute this when device is being looked up | |
| 104 &tty_private_info0); | |
| 105 #endif | |
| 106 | |
| 107 #ifdef CYGPKG_IO_SERIAL_TTY_TTY1 | |
| 108 static struct tty_private_info tty_private_info1; | |
| 109 DEVTAB_ENTRY(tty_io1, | |
| 110 "/dev/tty1", | |
| 111 CYGDAT_IO_SERIAL_TTY_TTY1_DEV, | |
| 112 &tty_devio, | |
| 113 tty_init, | |
| 114 tty_lookup, // Execute this when device is being looked up | |
| 115 &tty_private_info1); | |
| 116 #endif | |
| 117 | |
| 118 #ifdef CYGPKG_IO_SERIAL_TTY_TTY2 | |
| 119 static struct tty_private_info tty_private_info2; | |
| 120 DEVTAB_ENTRY(tty_io2, | |
| 121 "/dev/tty2", | |
| 122 CYGDAT_IO_SERIAL_TTY_TTY2_DEV, | |
| 123 &tty_devio, | |
| 124 tty_init, | |
| 125 tty_lookup, // Execute this when device is being looked up | |
| 126 &tty_private_info2); | |
| 127 #endif | |
| 128 | |
| 2284 | 129 #ifdef CYGPKG_IO_SERIAL_TTY_TTY3 |
| 130 static struct tty_private_info tty_private_info3; | |
| 131 DEVTAB_ENTRY(tty_io3, | |
| 132 "/dev/tty3", | |
| 133 CYGDAT_IO_SERIAL_TTY_TTY3_DEV, | |
| 134 &tty_devio, | |
| 135 tty_init, | |
| 136 tty_lookup, // Execute this when device is being looked up | |
| 137 &tty_private_info3); | |
| 138 #endif | |
| 139 | |
|
3027
4df50cbc6176
* src/common/termiostty.c: Add a possibility to define a few
sergeig
parents:
2729
diff
changeset
|
140 // More DEVTAB entries can be added using an inclusion |
|
4df50cbc6176
* src/common/termiostty.c: Add a possibility to define a few
sergeig
parents:
2729
diff
changeset
|
141 #ifdef CYGDAT_IO_SERIAL_TTY_ADD_INL |
|
4df50cbc6176
* src/common/termiostty.c: Add a possibility to define a few
sergeig
parents:
2729
diff
changeset
|
142 # include CYGDAT_IO_SERIAL_TTY_ADD_INL |
|
4df50cbc6176
* src/common/termiostty.c: Add a possibility to define a few
sergeig
parents:
2729
diff
changeset
|
143 #endif |
|
4df50cbc6176
* src/common/termiostty.c: Add a possibility to define a few
sergeig
parents:
2729
diff
changeset
|
144 |
| 2 | 145 static bool |
| 146 tty_init(struct cyg_devtab_entry *tab) | |
| 147 { | |
| 148 struct tty_private_info *priv = (struct tty_private_info *)tab->priv; | |
| 149 #ifdef CYGDBG_IO_INIT | |
|
2196
5c4a2415fdf4
* src/common/tty.c (tty_init): Fix compiler warning with
asl
parents:
2035
diff
changeset
|
150 diag_printf("Init tty channel: %p\n", tab); |
| 2 | 151 #endif |
| 152 priv->dev_info.tty_out_flags = CYG_TTY_OUT_FLAGS_DEFAULT; | |
| 153 priv->dev_info.tty_in_flags = CYG_TTY_IN_FLAGS_DEFAULT; | |
| 154 return true; | |
| 155 } | |
| 156 | |
| 157 static Cyg_ErrNo | |
| 158 tty_lookup(struct cyg_devtab_entry **tab, | |
| 159 struct cyg_devtab_entry *sub_tab, | |
| 160 const char *name) | |
| 161 { | |
| 162 cyg_io_handle_t chan = (cyg_io_handle_t)sub_tab; | |
| 163 struct tty_private_info *priv = (struct tty_private_info *)(*tab)->priv; | |
| 164 #if 0 | |
| 165 cyg_int32 len; | |
| 166 #endif | |
| 167 priv->dev_handle = chan; | |
| 168 #if 0 | |
| 169 len = sizeof(cyg_serial_info_t); | |
| 170 // Initialize configuration | |
| 171 cyg_io_get_config(chan, CYG_SERIAL_GET_CONFIG, | |
| 172 (void *)&priv->dev_info.serial_config, &len); | |
| 173 #endif | |
| 174 return ENOERR; | |
| 175 } | |
| 176 | |
| 177 #define BUFSIZE 64 | |
| 178 | |
| 179 static Cyg_ErrNo | |
| 180 tty_write(cyg_io_handle_t handle, const void *_buf, cyg_uint32 *len) | |
| 181 { | |
| 182 cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle; | |
| 183 struct tty_private_info *priv = (struct tty_private_info *)t->priv; | |
| 184 cyg_io_handle_t chan = (cyg_io_handle_t)priv->dev_handle; | |
| 2035 | 185 cyg_uint32 size; |
| 186 cyg_int32 bytes_successful, actually_written; | |
| 2 | 187 cyg_uint8 xbuf[BUFSIZE]; |
| 188 cyg_uint8 c; | |
| 189 cyg_uint8 *buf = (cyg_uint8 *)_buf; | |
| 190 Cyg_ErrNo res = -EBADF; | |
| 191 // assert(chan) | |
| 192 size = 0; | |
| 193 bytes_successful = 0; | |
| 194 actually_written = 0; | |
| 195 while (bytes_successful++ < *len) { | |
|
80
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
196 c = *buf++; |
| 2 | 197 if ((c == '\n') && |
| 198 (priv->dev_info.tty_out_flags & CYG_TTY_OUT_FLAGS_CRLF)) { | |
| 199 xbuf[size++] = '\r'; | |
| 200 } | |
|
80
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
201 xbuf[size++] = c; |
| 2 | 202 // Always leave room for possible CR/LF expansion |
|
136
a9ac27ec7abc
Merge from eCos master repository on 2000-11-17-18:24:25-GMT
jlarmour
parents:
115
diff
changeset
|
203 if ((size >= (BUFSIZE-1)) || |
| 2 | 204 (bytes_successful == *len)) { |
| 205 res = cyg_io_write(chan, xbuf, &size); | |
| 206 if (res != ENOERR) { | |
| 207 *len = actually_written; | |
| 208 return res; | |
| 209 } | |
| 210 actually_written += size; | |
| 211 size = 0; | |
| 212 } | |
| 213 } | |
| 214 return res; | |
| 215 } | |
| 216 | |
| 217 static Cyg_ErrNo | |
| 218 tty_read(cyg_io_handle_t handle, void *_buf, cyg_uint32 *len) | |
| 219 { | |
| 220 cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle; | |
| 221 struct tty_private_info *priv = (struct tty_private_info *)t->priv; | |
| 222 cyg_io_handle_t chan = (cyg_io_handle_t)priv->dev_handle; | |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
223 cyg_uint32 clen; |
|
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
224 cyg_int32 size; |
| 2 | 225 Cyg_ErrNo res; |
| 226 cyg_uint8 c; | |
| 227 cyg_uint8 *buf = (cyg_uint8 *)_buf; | |
| 228 // assert(chan) | |
| 229 size = 0; | |
| 230 while (size < *len) { | |
| 231 clen = 1; | |
| 232 res = cyg_io_read(chan, &c, &clen); | |
| 233 if (res != ENOERR) { | |
| 234 *len = size; | |
| 235 return res; | |
| 236 } | |
| 237 buf[size++] = c; | |
| 238 if ((priv->dev_info.tty_in_flags & CYG_TTY_IN_FLAGS_BINARY) == 0) { | |
|
80
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
239 switch (c) { |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
240 case '\b': /* drop through */ |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
241 case 0x7f: |
| 2 | 242 size -= 2; // erase one character + 'backspace' char |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
243 if (size < 0) { |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
244 size = 0; |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
245 } else if (priv->dev_info.tty_in_flags & CYG_TTY_IN_FLAGS_ECHO) { |
| 2 | 246 clen = 3; |
| 247 cyg_io_write(chan, "\b \b", &clen); | |
| 248 } | |
|
80
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
249 break; |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
250 case '\r': |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
251 if (priv->dev_info.tty_in_flags & CYG_TTY_IN_FLAGS_CRLF) { |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
252 /* Don't do anything because a '\n' will come next */ |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
253 break; |
| 2 | 254 } |
|
80
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
255 if (priv->dev_info.tty_in_flags & CYG_TTY_IN_FLAGS_CR) { |
| 2 | 256 c = '\n'; // Map CR -> LF |
| 257 } | |
|
80
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
258 /* drop through */ |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
259 case '\n': |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
260 if (priv->dev_info.tty_in_flags & CYG_TTY_IN_FLAGS_ECHO) { |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
261 if (priv->dev_info.tty_out_flags & CYG_TTY_OUT_FLAGS_CRLF) { |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
262 clen = 2; |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
263 cyg_io_write(chan, "\r\n", &clen); |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
264 } else { |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
265 clen = 1; |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
266 cyg_io_write(chan, &c, &clen); |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
267 } |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
268 } |
| 2 | 269 buf[size-1] = c; |
|
80
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
270 *len = size; |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
271 return ENOERR; |
|
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
272 default: |
| 2 | 273 if (priv->dev_info.tty_in_flags & CYG_TTY_IN_FLAGS_ECHO) { |
| 274 clen = 1; | |
| 275 cyg_io_write(chan, &c, &clen); | |
| 276 } | |
|
80
2085233a121a
Merge from eCos master repository on 2000-04-07-07:52:29-BST
jlarmour
parents:
66
diff
changeset
|
277 break; |
| 2 | 278 } |
| 279 } | |
| 280 } | |
| 281 *len = size; | |
| 282 return ENOERR; | |
| 283 } | |
| 284 | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
80
diff
changeset
|
285 static cyg_bool |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
80
diff
changeset
|
286 tty_select(cyg_io_handle_t handle, cyg_uint32 which, CYG_ADDRWORD info) |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
80
diff
changeset
|
287 { |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
80
diff
changeset
|
288 cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle; |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
80
diff
changeset
|
289 struct tty_private_info *priv = (struct tty_private_info *)t->priv; |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
80
diff
changeset
|
290 cyg_io_handle_t chan = (cyg_io_handle_t)priv->dev_handle; |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
80
diff
changeset
|
291 |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
80
diff
changeset
|
292 // Just pass it on to next driver level |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
80
diff
changeset
|
293 return cyg_io_select( chan, which, info ); |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
80
diff
changeset
|
294 } |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
80
diff
changeset
|
295 |
| 2 | 296 static Cyg_ErrNo |
| 297 tty_get_config(cyg_io_handle_t handle, cyg_uint32 key, void *buf, cyg_uint32 *len) | |
| 298 { | |
| 299 cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle; | |
| 300 struct tty_private_info *priv = (struct tty_private_info *)t->priv; | |
| 301 cyg_io_handle_t chan = (cyg_io_handle_t)priv->dev_handle; | |
| 302 Cyg_ErrNo res = ENOERR; | |
| 303 #if 0 | |
| 304 cyg_int32 current_len; | |
| 305 #endif | |
| 306 // assert(chan) | |
| 307 switch (key) { | |
| 308 case CYG_IO_GET_CONFIG_TTY_INFO: | |
| 309 if (*len < sizeof(cyg_tty_info_t)) { | |
| 310 return -EINVAL; | |
| 311 } | |
| 312 #if 0 | |
| 313 current_len = sizeof(cyg_serial_info_t); | |
| 314 res = cyg_io_get_config(chan, CYG_SERIAL_GET_CONFIG, | |
| 315 (void *)&priv->dev_info.serial_config, ¤t_len); | |
| 316 if (res != ENOERR) { | |
| 317 return res; | |
| 318 } | |
| 319 #endif | |
| 320 *(cyg_tty_info_t *)buf = priv->dev_info; | |
| 321 *len = sizeof(cyg_tty_info_t); | |
| 322 break; | |
| 323 default: // Assume this is a 'serial' driver control | |
| 324 res = cyg_io_get_config(chan, key, buf, len); | |
| 325 } | |
| 326 return res; | |
| 327 } | |
| 328 | |
| 329 static Cyg_ErrNo | |
| 330 tty_set_config(cyg_io_handle_t handle, cyg_uint32 key, const void *buf, cyg_uint32 *len) | |
| 331 { | |
| 332 cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle; | |
| 333 struct tty_private_info *priv = (struct tty_private_info *)t->priv; | |
| 334 cyg_io_handle_t chan = (cyg_io_handle_t)priv->dev_handle; | |
| 335 #if 0 | |
| 336 cyg_int32 current_len; | |
| 337 #endif | |
| 338 Cyg_ErrNo res = ENOERR; | |
| 339 // assert(chan) | |
| 340 switch (key) { | |
| 341 case CYG_IO_SET_CONFIG_TTY_INFO: | |
| 342 if (*len != sizeof(cyg_tty_info_t)) { | |
| 343 return -EINVAL; | |
| 344 } | |
| 345 priv->dev_info = *(cyg_tty_info_t *)buf; | |
| 346 break; | |
| 347 default: // Pass on to serial driver | |
| 348 res = cyg_io_set_config(chan, key, buf, len); | |
| 349 } | |
| 350 return res; | |
| 351 } | |
| 352 #endif // CYGPKG_IO_SERIAL_TTY |
