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 THE COPYRIGHT HOLDERS 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 THE 00024 * COPYRIGHT OWNER 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$ 00039 * Revision 1.10 2009/01/17 11:26:51 haraldkipp 00040 * Getting rid of two remaining BSD types in favor of stdint. 00041 * Replaced 'u_int' by 'unsinged int' and 'uptr_t' by 'uintptr_t'. 00042 * 00043 * Revision 1.9 2009/01/09 17:54:28 haraldkipp 00044 * Added SPI bus controller for AVR and AT91. 00045 * 00046 * Revision 1.8 2008/08/11 07:00:25 haraldkipp 00047 * BSD types replaced by stdint types (feature request #1282721). 00048 * 00049 * Revision 1.7 2006/03/16 15:25:34 haraldkipp 00050 * Changed human readable strings from u_char to char to stop GCC 4 from 00051 * nagging about signedness. 00052 * 00053 * Revision 1.6 2006/01/05 16:45:34 haraldkipp 00054 * Added a new driver type IFTYP_FS. 00055 * 00056 * Revision 1.5 2005/08/02 17:46:49 haraldkipp 00057 * Major API documentation update. 00058 * 00059 * Revision 1.4 2004/06/07 15:07:00 olereinhardt 00060 * Added IFTYP_CAN 00061 * 00062 * Revision 1.3 2004/03/18 13:49:00 haraldkipp 00063 * Deprecated functions removed. 00064 * IFSTREAM structure taken from ifstream 00065 * header file. 00066 * 00067 * Revision 1.2 2004/03/16 16:48:44 haraldkipp 00068 * Added Jan Dubiec's H8/300 port. 00069 * 00070 * Revision 1.1.1.1 2003/05/09 14:41:19 haraldkipp 00071 * Initial using 3.2.1 00072 * 00073 * Revision 1.18 2003/05/06 17:58:04 harald 00074 * ATmega128 definitions moved to compiler include 00075 * 00076 * Revision 1.17 2003/03/31 14:34:08 harald 00077 * Added character device 00078 * 00079 * Revision 1.16 2003/02/04 18:00:52 harald 00080 * Version 3 released 00081 * 00082 * Revision 1.15 2003/01/14 16:35:04 harald 00083 * Definitions moved 00084 * 00085 * Revision 1.14 2002/11/02 15:17:01 harald 00086 * Library dependencies moved to compiler.h 00087 * 00088 * Revision 1.13 2002/09/15 16:46:28 harald 00089 * *** empty log message *** 00090 * 00091 * Revision 1.12 2002/08/08 17:24:21 harald 00092 * Using time constants by KU 00093 * 00094 * Revision 1.11 2002/07/03 16:45:41 harald 00095 * Using GCC 3.2 00096 * 00097 * Revision 1.10 2002/06/26 17:29:28 harald 00098 * First pre-release with 2.4 stack 00099 * 00100 */ 00101 00102 #include <sys/file.h> 00103 00104 #include <stdint.h> 00105 00111 // wait times for emulation and reality 00112 // has to be overworked 00113 00114 #ifndef __EMULATION__ 00115 #define WAIT5 5 00116 #define WAIT50 50 00117 #define WAIT100 100 00118 #define WAIT250 250 00119 #define WAIT500 500 00120 #else 00121 #define WAIT5 1 00122 #define WAIT50 5 00123 #define WAIT100 10 00124 #define WAIT250 25 00125 #define WAIT500 50 00126 #endif 00127 00132 00133 #define IFTYP_RAM 0 00134 #define IFTYP_ROM 1 00135 #define IFTYP_STREAM 2 00136 #define IFTYP_NET 3 00137 #define IFTYP_TCPSOCK 4 00138 #define IFTYP_CHAR 5 00139 #define IFTYP_CAN 6 00140 #define IFTYP_BLKIO 7 00141 #define IFTYP_FS 16 00146 typedef struct _NUTDEVICE NUTDEVICE; 00147 00162 struct _NUTDEVICE { 00163 00167 NUTDEVICE *dev_next; 00168 00172 char dev_name[9]; 00173 00185 uint8_t dev_type; 00186 00193 uintptr_t dev_base; 00194 00200 uint8_t dev_irq; 00201 00207 void *dev_icb; 00208 00214 void *dev_dcb; 00215 00221 int (*dev_init) (NUTDEVICE *); 00222 00228 int (*dev_ioctl) (NUTDEVICE *, int, void *); 00229 00233 int (*dev_read) (NUTFILE *, void *, int); 00234 00238 int (*dev_write) (NUTFILE *, const void *, int); 00239 00243 #ifdef __HARVARD_ARCH__ 00244 int (*dev_write_P) (NUTFILE *, PGM_P, int); 00245 #endif 00246 00250 NUTFILE * (*dev_open) (NUTDEVICE *, const char *, int, int); 00251 00255 int (*dev_close) (NUTFILE *); 00256 00260 long (*dev_size) (NUTFILE *); 00261 00262 }; 00263 00267 typedef struct _NUTVIRTUALDEVICE NUTVIRTUALDEVICE; 00268 00272 struct _NUTVIRTUALDEVICE { 00273 NUTVIRTUALDEVICE *vdv_next; 00274 NUTVIRTUALDEVICE *vdv_zero; 00275 uint8_t vdv_type; 00276 int (*vdv_read) (void *, void *, int); 00277 int (*vdv_write) (void *, const void *, int); 00278 #ifdef __HARVARD_ARCH__ 00279 int (*vdv_write_P) (void *, PGM_P, int); 00280 #endif 00281 int (*vdv_ioctl) (void *, int, void *); 00282 }; 00283 00287 typedef struct _IFSTREAM IFSTREAM; 00288 00295 struct _IFSTREAM { 00296 int (*if_input)(NUTDEVICE *); 00297 int (*if_output)(NUTDEVICE *); 00298 int (*if_flush)(NUTDEVICE *); 00299 volatile uint8_t if_rx_idx; 00300 uint8_t if_rd_idx; 00301 volatile uint8_t if_tx_idx; 00302 uint8_t if_wr_idx; 00303 volatile uint8_t if_tx_act; 00304 uint8_t if_last_eol; 00305 uint8_t if_rx_buf[256]; 00306 uint8_t if_tx_buf[256]; 00307 }; 00308 00312 extern NUTDEVICE *nutDeviceList; 00313 00314 extern int NutRegisterDevice(NUTDEVICE * dev, uintptr_t base, uint8_t irq); 00315 extern NUTDEVICE *NutDeviceLookup(const char *name); 00316 extern NUTDEVICE *NutDeviceLookupType(NUTDEVICE *dev, uint_fast8_t type); 00317 00318 #endif