#ifndef CYGONCE_IO_PTYLIB_H #define CYGONCE_IO_PTYLIB_H //========================================================================== // // ptylib.h // // A PTY driver library // //========================================================================== //####ECOSGPLCOPYRIGHTBEGIN#### // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. // Copyright (C) 2003 Waverider Communications Inc. // // eCos is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 or (at your option) any later version. // // eCos is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. // // You should have received a copy of the GNU General Public License along // with eCos; if not, write to the Free Software Foundation, Inc., // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. // // As a special exception, if other files instantiate templates or use macros // or inline functions from this file, or you compile this file and link it // with other works to produce a work based on this file, this file does not // by itself cause the resulting work to be covered by the GNU General Public // License. However the source code for this file must still be made available // in accordance with section (3) of the GNU General Public License. // // This exception does not invalidate any other reasons why a work based on // this file might be covered by the GNU General Public License. // // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. // at http://sources.redhat.com/ecos/ecos-license/ // ------------------------------------------- //####ECOSGPLCOPYRIGHTEND#### //========================================================================== //#####DESCRIPTIONBEGIN#### // // Author(s): Alex Paulis // Contributors: // Date: Nov 8, 2004 // Purpose: Provide a psuedo-terminal driver library. (For full pty functionality // use this pty as the back-end driver for a tty device). // Description: PTY drivers allow data written to the Master device to // be read from the Slave device AND data written to the // Slave device to be read from the Master device. The PTY // driver does not filter any data. Each PTY device needs // two pipes, one as a stream from the Master side to the // slave, and a second pipe as a stream from the Slave to // the Master." // //####DESCRIPTIONEND#### // //========================================================================== #include #include // device stuff #include #include // select - selinfo // ---------------------------------------------------------------------------- // PRIVATE information. The following info should not be used by caller // ---------------------------------------------------------------------------- typedef struct ptylib_private_info { cyg_io_handle_t *readDev_pt; cyg_io_handle_t *writeDev_pt; cyg_io_handle_t *readSelectDev_pt; cyg_io_handle_t *writeSelectDev_pt; } PTYLIB_PRIVATE_INFO_T; extern cyg_devio_table_t ptylibDevioTable; // ---------------------------------------------------------------------------- // Provided for symbol information only. Do not call directly bool ptylib_init ( struct cyg_devtab_entry *tab); // ---------------------------------------------------------------------------- // End PRIVATE information. // ---------------------------------------------------------------------------- // The name of the master side of the pty, given the base name it was // instantiated with. (open() requires that device names begin with "/dev/") // in both macro and function form (_buf is space to put the full name - // strlen _name + 12 bytes). #define PTYLIB_MASTER_DEV_NAME(_name) "/dev/"_name"master" #define ptylib_master_dev_name(_name, _buf) sprintf(_buf, "/dev/%smaster", _name) // The name of the slave side of the pty, given the base name #define PTYLIB_SLAVE_DEV_NAME(_name) "/dev/"_name"slave" #define ptylib_slave_dev_name(_name, _buf) sprintf(_buf, "/dev/%sslave", _name) // ---------------------------------------------------------------------------- // This macro creates a pty device in the device table and its two underlying // pipes. // The application calls this macro at file scope to instantiate a pty // instance, supplying static buffer storage for the underlying pipes. Each // communicating end then uses open() with either the pty master name or the // pty slave name to get a file descriptor to read, write and select on. // PTYLIB_DEVICE( // label, // unique label for device // char *name, // base name of device, not including "/dev/" // // e.g. "pty0" // void *bufferA, // storage area for 1st pipe // cyg_uint32 bufferASize, // size of storage area A in bytes // void *bufferB, // storage area for 2nd pipe // cyg_uint32 bufferBSize, // size of storage area B in bytes // cyg_tick_count_t wait) // wait this long for read or write to complete // // may also be PIPE_TIMEOUT_WAIT_FOREVER or PIPE_TIMEOUT_NO_WAIT #define PTYLIB_DEVICE(_label, _name, _bufferA, _bufferASize, _bufferB, _bufferBSize, _wait) \ PIPELIB_DEVICE(_label##APipe_s, "/dev/"_name"_APipe", _bufferA, _bufferASize, _wait); \ PIPELIB_DEVICE(_label##BPipe_s, "/dev/"_name"_BPipe", _bufferB, _bufferBSize, _wait); \ static PTYLIB_PRIVATE_INFO_T _label##_MInfo_s = {(cyg_io_handle_t)&_label##BPipe_s,(cyg_io_handle_t)&_label##APipe_s,(cyg_io_handle_t)&_label##BPipe_s,(cyg_io_handle_t)&_label##APipe_s}; \ static PTYLIB_PRIVATE_INFO_T _label##_SInfo_s = {(cyg_io_handle_t)&_label##APipe_s,(cyg_io_handle_t)&_label##BPipe_s,(cyg_io_handle_t)&_label##APipe_s,(cyg_io_handle_t)&_label##BPipe_s}; \ DEVTAB_ENTRY(_label##MPty_s,PTYLIB_MASTER_DEV_NAME(_name),0,&ptylibDevioTable,ptylib_init,NULL,&_label##_MInfo_s); \ DEVTAB_ENTRY(_label##SPty_s, PTYLIB_SLAVE_DEV_NAME(_name),0,&ptylibDevioTable,ptylib_init,NULL,&_label##_SInfo_s); // ---------------------------------------------------------------------------- // Discard any data that may be in the pty stream void ptylib_purge ( int ptyFd); // the file descriptor of pty to purge #endif // CYGONCE_IO_PTYLIB_H