Nut/OS  4.10.3
API Reference
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$
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 __BEGIN_DECLS
00112 
00113 // wait times for emulation and reality
00114 // has to be overworked
00115 
00116 #ifndef __EMULATION__
00117 #define WAIT5           5
00118 #define WAIT50          50
00119 #define WAIT100         100
00120 #define WAIT250         250
00121 #define WAIT500         500
00122 #else
00123 #define WAIT5           1
00124 #define WAIT50          5
00125 #define WAIT100         10
00126 #define WAIT250         25
00127 #define WAIT500         50
00128 #endif
00129 
00134 
00135 #define IFTYP_RAM       0       
00136 #define IFTYP_ROM       1       
00137 #define IFTYP_STREAM    2       
00138 #define IFTYP_NET       3       
00139 #define IFTYP_TCPSOCK   4       
00140 #define IFTYP_CHAR      5       
00141 #define IFTYP_CAN       6       
00142 #define IFTYP_BLKIO     7   
00143 #define IFTYP_FS       16   
00148 typedef struct _NUTDEVICE NUTDEVICE;
00149 
00164 struct _NUTDEVICE {
00165 
00169     NUTDEVICE *dev_next;
00170 
00174     char dev_name[9];
00175 
00187     uint8_t dev_type;
00188 
00195     uintptr_t dev_base;
00196 
00202     uint8_t dev_irq;
00203 
00209     void *dev_icb;
00210 
00216     void *dev_dcb;
00217 
00223     int (*dev_init) (NUTDEVICE *);
00224 
00230     int (*dev_ioctl) (NUTDEVICE *, int, void *);
00231 
00235     int (*dev_read) (NUTFILE *, void *, int);
00236 
00240     int (*dev_write) (NUTFILE *, CONST void *, int);
00241 
00245 #ifdef __HARVARD_ARCH__
00246     int (*dev_write_P) (NUTFILE *, PGM_P, int);
00247 #endif
00248 
00252     NUTFILE * (*dev_open) (NUTDEVICE *, CONST char *, int, int);
00253 
00257     int (*dev_close) (NUTFILE *);
00258 
00262     long (*dev_size) (NUTFILE *);
00263 
00264 };
00265 
00269 typedef struct _NUTVIRTUALDEVICE NUTVIRTUALDEVICE;
00270 
00274 struct _NUTVIRTUALDEVICE {
00275     NUTVIRTUALDEVICE *vdv_next;
00276     NUTVIRTUALDEVICE *vdv_zero;
00277     uint8_t vdv_type;
00278     int (*vdv_read) (void *, void *, int);
00279     int (*vdv_write) (void *, CONST void *, int);
00280 #ifdef __HARVARD_ARCH__
00281     int (*vdv_write_P) (void *, PGM_P, int);
00282 #endif
00283     int (*vdv_ioctl) (void *, int, void *);
00284 };
00285 
00289 typedef struct _IFSTREAM IFSTREAM;
00290 
00297 struct _IFSTREAM {
00298     int  (*if_input)(NUTDEVICE *);  
00299     int  (*if_output)(NUTDEVICE *); 
00300     int  (*if_flush)(NUTDEVICE *);  
00301     volatile uint8_t if_rx_idx;      
00302     uint8_t if_rd_idx;               
00303     volatile uint8_t if_tx_idx;      
00304     uint8_t if_wr_idx;               
00305     volatile uint8_t if_tx_act;      
00306     uint8_t if_last_eol;             
00307     uint8_t if_rx_buf[256];          
00308     uint8_t if_tx_buf[256];          
00309 };
00310 
00314 extern NUTDEVICE *nutDeviceList;
00315 
00316 extern int NutRegisterDevice(NUTDEVICE * dev, uintptr_t base, uint8_t irq);
00317 extern NUTDEVICE *NutDeviceLookup(CONST char *name);
00318 
00319 __END_DECLS
00320 
00321 #endif