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.8  2008/08/11 07:00:25  haraldkipp
00040  * BSD types replaced by stdint types (feature request #1282721).
00041  *
00042  * Revision 1.7  2006/03/16 15:25:34  haraldkipp
00043  * Changed human readable strings from u_char to char to stop GCC 4 from
00044  * nagging about signedness.
00045  *
00046  * Revision 1.6  2006/01/05 16:45:34  haraldkipp
00047  * Added a new driver type IFTYP_FS.
00048  *
00049  * Revision 1.5  2005/08/02 17:46:49  haraldkipp
00050  * Major API documentation update.
00051  *
00052  * Revision 1.4  2004/06/07 15:07:00  olereinhardt
00053  * Added IFTYP_CAN
00054  *
00055  * Revision 1.3  2004/03/18 13:49:00  haraldkipp
00056  * Deprecated functions removed.
00057  * IFSTREAM structure taken from ifstream
00058  * header file.
00059  *
00060  * Revision 1.2  2004/03/16 16:48:44  haraldkipp
00061  * Added Jan Dubiec's H8/300 port.
00062  *
00063  * Revision 1.1.1.1  2003/05/09 14:41:19  haraldkipp
00064  * Initial using 3.2.1
00065  *
00066  * Revision 1.18  2003/05/06 17:58:04  harald
00067  * ATmega128 definitions moved to compiler include
00068  *
00069  * Revision 1.17  2003/03/31 14:34:08  harald
00070  * Added character device
00071  *
00072  * Revision 1.16  2003/02/04 18:00:52  harald
00073  * Version 3 released
00074  *
00075  * Revision 1.15  2003/01/14 16:35:04  harald
00076  * Definitions moved
00077  *
00078  * Revision 1.14  2002/11/02 15:17:01  harald
00079  * Library dependencies moved to compiler.h
00080  *
00081  * Revision 1.13  2002/09/15 16:46:28  harald
00082  * *** empty log message ***
00083  *
00084  * Revision 1.12  2002/08/08 17:24:21  harald
00085  * Using time constants by KU
00086  *
00087  * Revision 1.11  2002/07/03 16:45:41  harald
00088  * Using GCC 3.2
00089  *
00090  * Revision 1.10  2002/06/26 17:29:28  harald
00091  * First pre-release with 2.4 stack
00092  *
00093  */
00094 
00095 #include <sys/file.h>
00096 
00097 #include <stdint.h>
00098 
00104 __BEGIN_DECLS
00105 
00106 // wait times for emulation and reality
00107 // has to be overworked
00108 
00109 #ifndef __EMULATION__
00110 #define WAIT5       5
00111 #define WAIT50      50
00112 #define WAIT100     100
00113 #define WAIT250     250
00114 #define WAIT500     500
00115 #else
00116 #define WAIT5       1
00117 #define WAIT50      5
00118 #define WAIT100     10
00119 #define WAIT250     25
00120 #define WAIT500     50
00121 #endif
00122 
00127 
00128 #define IFTYP_RAM       0   
00129 #define IFTYP_ROM       1   
00130 #define IFTYP_STREAM    2   
00131 #define IFTYP_NET       3   
00132 #define IFTYP_TCPSOCK   4   
00133 #define IFTYP_CHAR      5   
00134 #define IFTYP_CAN       6       
00135 #define IFTYP_FS       16   
00140 typedef struct _NUTDEVICE NUTDEVICE;
00141 
00156 struct _NUTDEVICE {
00157 
00161     NUTDEVICE *dev_next;
00162 
00166     char dev_name[9];
00167 
00179     uint8_t dev_type;
00180 
00187     uptr_t dev_base;
00188 
00194     uint8_t dev_irq;
00195 
00201     void *dev_icb;
00202 
00208     void *dev_dcb;
00209 
00215     int (*dev_init) (NUTDEVICE *);
00216 
00222     int (*dev_ioctl) (NUTDEVICE *, int, void *);
00223 
00227     int (*dev_read) (NUTFILE *, void *, int);
00228 
00232     int (*dev_write) (NUTFILE *, CONST void *, int);
00233 
00237 #ifdef __HARVARD_ARCH__
00238     int (*dev_write_P) (NUTFILE *, PGM_P, int);
00239 #endif
00240 
00244     NUTFILE * (*dev_open) (NUTDEVICE *, CONST char *, int, int);
00245 
00249     int (*dev_close) (NUTFILE *);
00250 
00254     long (*dev_size) (NUTFILE *);
00255 
00256 };
00257 
00261 typedef struct _NUTVIRTUALDEVICE NUTVIRTUALDEVICE;
00262 
00266 struct _NUTVIRTUALDEVICE {
00267     NUTVIRTUALDEVICE *vdv_next;
00268     NUTVIRTUALDEVICE *vdv_zero;
00269     uint8_t vdv_type;
00270     int (*vdv_read) (void *, void *, int);
00271     int (*vdv_write) (void *, CONST void *, int);
00272 #ifdef __HARVARD_ARCH__
00273     int (*vdv_write_P) (void *, PGM_P, int);
00274 #endif
00275     int (*vdv_ioctl) (void *, int, void *);
00276 };
00277 
00281 typedef struct _IFSTREAM IFSTREAM;
00282 
00289 struct _IFSTREAM {
00290     int  (*if_input)(NUTDEVICE *);  
00291     int  (*if_output)(NUTDEVICE *); 
00292     int  (*if_flush)(NUTDEVICE *);  
00293     volatile uint8_t if_rx_idx;      
00294     uint8_t if_rd_idx;               
00295     volatile uint8_t if_tx_idx;      
00296     uint8_t if_wr_idx;               
00297     volatile uint8_t if_tx_act;      
00298     uint8_t if_last_eol;             
00299     uint8_t if_rx_buf[256];          
00300     uint8_t if_tx_buf[256];          
00301 };
00302 
00306 extern NUTDEVICE *nutDeviceList;
00307 
00308 extern int NutRegisterDevice(NUTDEVICE * dev, uptr_t base, uint8_t irq);
00309 extern NUTDEVICE *NutDeviceLookup(CONST char *name);
00310 
00311 __END_DECLS
00312 
00313 #endif

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