#ifndef CYGONCE_IO_PIPE_H #define CYGONCE_IO_PIPE_H //========================================================================== // // pipe.h // // A Pipe (FIFO) Driver // //========================================================================== //####ECOSGPLCOPYRIGHTBEGIN#### // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. // Copyright (C) 2004 eCosCentric Ltd. // // 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. // // ------------------------------------------- //####ECOSGPLCOPYRIGHTEND#### //========================================================================== //#####DESCRIPTIONBEGIN#### // // Author(s): Alex Paulis // Contributors: Cameron Taylor // Date: Nov 8, 2004 // Purpose: Provide a simple pipe driver that allows data to transfered from // one thread to another via a file (implemented by the pipe driver). // Description: Access to the data in the driver is FIFO. Selects are provided // for both reads and writes. The read returns when there is at // one character in the buffer. The write returns when all of the // data has been written. // //####DESCRIPTIONEND#### // //========================================================================== #include #include // device stuff #include // select - selinfo // ---------------------------------------------------------------------------- // PRIVATE information. The following info should not be used by caller // ---------------------------------------------------------------------------- typedef struct pipe_info_s { void *storage_pv; // pipe data storage area (buffer) cyg_uint32 storageSize_u32;// size of storage area in bytes volatile cyg_uint32 dataLength_u32; // number of bytes currently in buffer volatile cyg_uint32 readIndex_u32; // read buffer index volatile cyg_uint32 writeIndex_u32; // write buffer index cyg_cond_t wait_t; // buffer access condition variable cyg_mutex_t lock_t; // buffer mutex struct CYG_SELINFO_TAG selinfoRx; // select info for reading struct CYG_SELINFO_TAG selinfoTx; // select info for writing } PIPE_INFO_S; extern cyg_devio_table_t pipeDevioTable; // ---------------------------------------------------------------------------- // Provided for symbol information only. Do not call directly bool pipe_init ( struct cyg_devtab_entry *tab); // ---------------------------------------------------------------------------- // End PRIVATE information. // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // This macro creates a pipe device in the device table. // The application calls this macro at file scope to instantiate a pipe // instance, supplying a static buffer as storage for data in the pipe. // It then uses open() with the name to get a file descriptor to read, // write and select on the pipe. // PIPE_DEVICE( // label, // a unique label (not used by app) // char *name, // name of the device, must begin with "/dev/" // // for lookup to work. eg: "/dev/pipe0" // void *storageArea, // pointer to the storage area // cyg_uint32 storageAreaSize, // size of the storage area #define PIPE_DEVICE(_l_pipe,_pipeName,_pipeStorageArea,_pipeStorageAreaSize)\ static PIPE_INFO_S _l_pipe##_private = \ { \ _pipeStorageArea, \ _pipeStorageAreaSize, \ }; \ DEVTAB_ENTRY(_l_pipe,_pipeName,0,&pipeDevioTable,pipe_init,NULL,&_l_pipe##_private); // Note that all data in the pipe can be discarded with a call to fsync() #endif // CYGONCE_IO_PIPE_H