device.h

Go to the documentation of this file.
00001 #ifndef _SYS_DEVICE_H_
00002 #define _SYS_DEVICE_H_
00003 
00004 /*
00005  * Copyright (C) 2001-2003 by egnite Software GmbH. All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. Neither the name of the copyright holders nor the names of
00017  *    contributors may be used to endorse or promote products derived
00018  *    from this software without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00021  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00024  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00027  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00028  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00029  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00030  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  * For additional information see http://www.ethernut.de/
00034  *
00035  */
00036 
00037 /*
00038  * $Log: device.h,v $
00039  * Revision 1.7  2006/03/16 15:25:34  haraldkipp
00040  * Changed human readable strings from u_char to char to stop GCC 4 from
00041  * nagging about signedness.
00042  *
00043  * Revision 1.6  2006/01/05 16:45:34  haraldkipp
00044  * Added a new driver type IFTYP_FS.
00045  *
00046  * Revision 1.5  2005/08/02 17:46:49  haraldkipp
00047  * Major API documentation update.
00048  *
00049  * Revision 1.4  2004/06/07 15:07:00  olereinhardt
00050  * Added IFTYP_CAN
00051  *
00052  * Revision 1.3  2004/03/18 13:49:00  haraldkipp
00053  * Deprecated functions removed.
00054  * IFSTREAM structure taken from ifstream
00055  * header file.
00056  *
00057  * Revision 1.2  2004/03/16 16:48:44  haraldkipp
00058  * Added Jan Dubiec's H8/300 port.
00059  *
00060  * Revision 1.1.1.1  2003/05/09 14:41:19  haraldkipp
00061  * Initial using 3.2.1
00062  *
00063  * Revision 1.18  2003/05/06 17:58:04  harald
00064  * ATmega128 definitions moved to compiler include
00065  *
00066  * Revision 1.17  2003/03/31 14:34:08  harald
00067  * Added character device
00068  *
00069  * Revision 1.16  2003/02/04 18:00:52  harald
00070  * Version 3 released
00071  *
00072  * Revision 1.15  2003/01/14 16:35:04  harald
00073  * Definitions moved
00074  *
00075  * Revision 1.14  2002/11/02 15:17:01  harald
00076  * Library dependencies moved to compiler.h
00077  *
00078  * Revision 1.13  2002/09/15 16:46:28  harald
00079  * *** empty log message ***
00080  *
00081  * Revision 1.12  2002/08/08 17:24:21  harald
00082  * Using time constants by KU
00083  *
00084  * Revision 1.11  2002/07/03 16:45:41  harald
00085  * Using GCC 3.2
00086  *
00087  * Revision 1.10  2002/06/26 17:29:28  harald
00088  * First pre-release with 2.4 stack
00089  *
00090  */
00091 
00092 #include <sys/file.h>
00093 
00099 __BEGIN_DECLS
00100 
00101 // wait times for emulation and reality
00102 // has to be overworked
00103 
00104 #ifndef __EMULATION__
00105 #define WAIT5       5
00106 #define WAIT50      50
00107 #define WAIT100     100
00108 #define WAIT250     250
00109 #define WAIT500     500
00110 #else
00111 #define WAIT5       1
00112 #define WAIT50      5
00113 #define WAIT100     10
00114 #define WAIT250     25
00115 #define WAIT500     50
00116 #endif
00117 
00122 
00123 #define IFTYP_RAM       0   
00124 #define IFTYP_ROM       1   
00125 #define IFTYP_STREAM    2   
00126 #define IFTYP_NET       3   
00127 #define IFTYP_TCPSOCK   4   
00128 #define IFTYP_CHAR      5   
00129 #define IFTYP_CAN       6       
00130 #define IFTYP_FS       16   
00135 typedef struct _NUTDEVICE NUTDEVICE;
00136 
00151 struct _NUTDEVICE {
00152 
00156     NUTDEVICE *dev_next;
00157 
00161     char dev_name[9];
00162 
00174     u_char dev_type;
00175 
00182     uptr_t dev_base;
00183 
00189     u_char dev_irq;
00190 
00196     void *dev_icb;
00197 
00203     void *dev_dcb;
00204 
00210     int (*dev_init) (NUTDEVICE *);
00211 
00217     int (*dev_ioctl) (NUTDEVICE *, int, void *);
00218 
00222     int (*dev_read) (NUTFILE *, void *, int);
00223 
00227     int (*dev_write) (NUTFILE *, CONST void *, int);
00228 
00232 #ifdef __HARVARD_ARCH__
00233     int (*dev_write_P) (NUTFILE *, PGM_P, int);
00234 #endif
00235 
00239     NUTFILE * (*dev_open) (NUTDEVICE *, CONST char *, int, int);
00240 
00244     int (*dev_close) (NUTFILE *);
00245 
00249     long (*dev_size) (NUTFILE *);
00250 
00251 };
00252 
00256 typedef struct _NUTVIRTUALDEVICE NUTVIRTUALDEVICE;
00257 
00261 struct _NUTVIRTUALDEVICE {
00262     NUTVIRTUALDEVICE *vdv_next;
00263     NUTVIRTUALDEVICE *vdv_zero;
00264     u_char vdv_type;
00265     int (*vdv_read) (void *, void *, int);
00266     int (*vdv_write) (void *, CONST void *, int);
00267 #ifdef __HARVARD_ARCH__
00268     int (*vdv_write_P) (void *, PGM_P, int);
00269 #endif
00270     int (*vdv_ioctl) (void *, int, void *);
00271 };
00272 
00276 typedef struct _IFSTREAM IFSTREAM;
00277 
00284 struct _IFSTREAM {
00285     int  (*if_input)(NUTDEVICE *);  
00286     int  (*if_output)(NUTDEVICE *); 
00287     int  (*if_flush)(NUTDEVICE *);  
00288     volatile u_char if_rx_idx;      
00289     u_char if_rd_idx;               
00290     volatile u_char if_tx_idx;      
00291     u_char if_wr_idx;               
00292     volatile u_char if_tx_act;      
00293     u_char if_last_eol;             
00294     u_char if_rx_buf[256];          
00295     u_char if_tx_buf[256];          
00296 };
00297 
00301 extern NUTDEVICE *nutDeviceList;
00302 
00303 extern int NutRegisterDevice(NUTDEVICE * dev, uptr_t base, u_char irq);
00304 extern NUTDEVICE *NutDeviceLookup(CONST char *name);
00305 
00306 __END_DECLS
00307 
00308 #endif

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/