This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
We have developed a pseudo-terminal implementation which we find useful for
interprocess communication. It is essentially two pipes (see previous
submission) cross connected. To obtain full terminal emulation, use this pty
device as the back end driver for a tty.
The matched pty devices and the two underlying pipes are instantiated
statically using DEVTAB entries. The application then open()s the master and
slave devices and read()s, write()s and select()s to them. Both read and
write selects are supported. Note that for lookup to work correctly, the
name must begin with /dev/. macros are supplied to construct the master and
slave names from a common base name.
A timeout option on reads and writes is supported - FOREVER, NO_WAIT or a
time in ticks (this is separate from the select timeout).
We have inserted the attached files in packages/io/pty/... and made the
following entry in ecos.db:
package CYGPKG_IO_PTYLIB {
alias { "PTY Driver Library"}
directory io/pty
script ptylib.cdl
description "This package contains a device driver for a basic pseudo
terminal. For full terminal function, use this pty as a back end driver for
a tty."
}
Examples of use (without error checks, etc):
#include <cyg/io/ptylib.h>
// Instantiate the pty at file scope (note: only the base name is supplied,
// "/dev/" and "master" or "slave" is added auto-magically)
static char buf1[100];
static char buf2[200];
PTYLIB_DEVICE(pty0, "pty0", buf1, sizeof(buf1), buf2, sizeof(buf2),
PIPE_TIMEOUT_WAIT_FOREVER);
main()
{
// Open both sides
int mFd, sFd;
mFd = open(PTYLIB_MASTER_DEV_NAME("pty0"), O_RDWR);
sFd = open(PTYLIB_SLAVE_DEV_NAME("pty0"), O_RDWR);
// Write from master to slave (they would normally be two different
threads)
write(mFd, "stuff", 5);
// Select on reading
fd_set fds;
FD_ZERO(&fds);
FD_SET(sFd, &fds);
select(FD_SETSIZE, &fds, NULL, NULL, NULL);
// read from the slave
char readbuf[10];
read(sFd, readbuf, sizeof(readbuf));
}
Comments, questions and suggestions are appreciated. This is intended as a
starting point for discussion as some documentation and test cases will also
be required. Hopefully this will be useful to others as well.
Cameron Taylor
WaveRider Communications
Attachment:
ptylib.cdl
Description: Binary data
Attachment:
ptylib.h
Description: Binary data
Attachment:
ptylib.c
Description: Binary data
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |