| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- #ifndef _SYS_DEVICE_H_
- #define _SYS_DEVICE_H_
- /*
- * Copyright (C) 2001-2003 by egnite Software GmbH. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the copyright holders nor the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
- * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * For additional information see http://www.ethernut.de/
- *
- */
- /*
- * $Log: device.h,v $
- * Revision 1.7 2006/03/16 15:25:34 haraldkipp
- * Changed human readable strings from u_char to char to stop GCC 4 from
- * nagging about signedness.
- *
- * Revision 1.6 2006/01/05 16:45:34 haraldkipp
- * Added a new driver type IFTYP_FS.
- *
- * Revision 1.5 2005/08/02 17:46:49 haraldkipp
- * Major API documentation update.
- *
- * Revision 1.4 2004/06/07 15:07:00 olereinhardt
- * Added IFTYP_CAN
- *
- * Revision 1.3 2004/03/18 13:49:00 haraldkipp
- * Deprecated functions removed.
- * IFSTREAM structure taken from ifstream
- * header file.
- *
- * Revision 1.2 2004/03/16 16:48:44 haraldkipp
- * Added Jan Dubiec's H8/300 port.
- *
- * Revision 1.1.1.1 2003/05/09 14:41:19 haraldkipp
- * Initial using 3.2.1
- *
- * Revision 1.18 2003/05/06 17:58:04 harald
- * ATmega128 definitions moved to compiler include
- *
- * Revision 1.17 2003/03/31 14:34:08 harald
- * Added character device
- *
- * Revision 1.16 2003/02/04 18:00:52 harald
- * Version 3 released
- *
- * Revision 1.15 2003/01/14 16:35:04 harald
- * Definitions moved
- *
- * Revision 1.14 2002/11/02 15:17:01 harald
- * Library dependencies moved to compiler.h
- *
- * Revision 1.13 2002/09/15 16:46:28 harald
- * *** empty log message ***
- *
- * Revision 1.12 2002/08/08 17:24:21 harald
- * Using time constants by KU
- *
- * Revision 1.11 2002/07/03 16:45:41 harald
- * Using GCC 3.2
- *
- * Revision 1.10 2002/06/26 17:29:28 harald
- * First pre-release with 2.4 stack
- *
- */
- #include <sys/file.h>
- /*!
- * \file sys/device.h
- * \brief Nut/OS device definitions.
- */
- __BEGIN_DECLS
- // wait times for emulation and reality
- // has to be overworked
- #ifndef __EMULATION__
- #define WAIT5 5
- #define WAIT50 50
- #define WAIT100 100
- #define WAIT250 250
- #define WAIT500 500
- #else
- #define WAIT5 1
- #define WAIT50 5
- #define WAIT100 10
- #define WAIT250 25
- #define WAIT500 50
- #endif
- /*!
- * \addtogroup xgDevice
- */
- /*@{*/
- #define IFTYP_RAM 0 /*!< \brief RAM device */
- #define IFTYP_ROM 1 /*!< \brief ROM device */
- #define IFTYP_STREAM 2 /*!< \brief Stream device */
- #define IFTYP_NET 3 /*!< \brief Net device */
- #define IFTYP_TCPSOCK 4 /*!< \brief TCP socket */
- #define IFTYP_CHAR 5 /*!< \brief Character stream device */
- #define IFTYP_CAN 6 /*!< \brief CAN device */
- #define IFTYP_FS 16 /*!< \brief file system device */
- /*!
- * \brief Device structure type.
- */
- typedef struct _NUTDEVICE NUTDEVICE;
- /*!
- * \brief Device structure.
- *
- * Each device driver provides a global variable of this type.
- * Applications use NutRegisterDevice() to bind the device
- * driver to the application code. Except this call, applications
- * refer to device drivers by the name of the device when using
- * standard C functions like _open() or fopen().
- *
- * More than one device driver may be available for the same
- * hardware device. Typically these drivers provide the same
- * name for the device and applications must not refer to
- * more than one device driver with the same name.
- */
- struct _NUTDEVICE {
- /*!
- * \brief Link to the next device structure.
- */
- NUTDEVICE *dev_next;
- /*!
- * \brief Unique device name.
- */
- char dev_name[9];
- /*!
- * \brief Type of interface.
- *
- * May be any of the following:
- * - IFTYP_RAM
- * - IFTYP_ROM
- * - IFTYP_STREAM
- * - IFTYP_NET
- * - IFTYP_TCPSOCK
- * - IFTYP_CHAR
- */
- u_char dev_type;
- /*!
- * \brief Hardware base address.
- *
- * Will be set by calling NutRegisterDevice(). On some device
- * drivers this address may be fixed.
- */
- uptr_t dev_base;
- /*! \brief Interrupt registration number.
- *
- * Will be set by calling NutRegisterDevice(). On some device
- * drivers the interrupt may be fixed.
- */
- u_char dev_irq;
- /*! \brief Interface control block.
- *
- * With stream devices, this points to the IFSTREAM structure and
- * with network devices this is a pointer to the IFNET structure.
- */
- void *dev_icb;
- /*!
- * \brief Driver control block.
- *
- * Points to a device specific information block.
- */
- void *dev_dcb;
- /*!
- * \brief Driver initialization routine.
- *
- * This routine is called during device registration.
- */
- int (*dev_init) (NUTDEVICE *);
- /*!
- * \brief Driver control function.
- *
- * Used to modify or query device specific settings.
- */
- int (*dev_ioctl) (NUTDEVICE *, int, void *);
- /*!
- * \brief Read from device.
- */
- int (*dev_read) (NUTFILE *, void *, int);
- /*!
- * \brief Write to device.
- */
- int (*dev_write) (NUTFILE *, CONST void *, int);
- /*!
- * \brief Write to device.
- */
- #ifdef __HARVARD_ARCH__
- int (*dev_write_P) (NUTFILE *, PGM_P, int);
- #endif
- /*!
- * \brief Open a device or file.
- */
- NUTFILE * (*dev_open) (NUTDEVICE *, CONST char *, int, int);
- /*!
- * \brief Close a device or file.
- */
- int (*dev_close) (NUTFILE *);
- /*!
- * \brief Request file size.
- */
- long (*dev_size) (NUTFILE *);
- };
- /*!
- * \brief Device structure type.
- */
- typedef struct _NUTVIRTUALDEVICE NUTVIRTUALDEVICE;
- /*!
- * \brief Virtual device structure.
- */
- struct _NUTVIRTUALDEVICE {
- NUTVIRTUALDEVICE *vdv_next;
- NUTVIRTUALDEVICE *vdv_zero;
- u_char vdv_type;
- int (*vdv_read) (void *, void *, int);
- int (*vdv_write) (void *, CONST void *, int);
- #ifdef __HARVARD_ARCH__
- int (*vdv_write_P) (void *, PGM_P, int);
- #endif
- int (*vdv_ioctl) (void *, int, void *);
- };
- /*!
- * \brief Stream interface type.
- */
- typedef struct _IFSTREAM IFSTREAM;
- /*!
- * \brief Stream interface information structure.
- *
- * Deprecated structure. Device drivers should use
- * the device control block.
- */
- struct _IFSTREAM {
- int (*if_input)(NUTDEVICE *); /*!< \brief Wait for input. */
- int (*if_output)(NUTDEVICE *); /*!< \brief Initiate output. */
- int (*if_flush)(NUTDEVICE *); /*!< \brief Wait until output buffer empty. */
- volatile u_char if_rx_idx; /*!< \brief Next input index. */
- u_char if_rd_idx; /*!< \brief Next read index. */
- volatile u_char if_tx_idx; /*!< \brief Next output index. */
- u_char if_wr_idx; /*!< \brief Next write index. */
- volatile u_char if_tx_act; /*!< \brief Set if transmitter running. */
- u_char if_last_eol; /*!< \brief Last end of line character read. */
- u_char if_rx_buf[256]; /*!< \brief Input buffer. */
- u_char if_tx_buf[256]; /*!< \brief Output buffer. */
- };
- /*@}*/
- extern NUTDEVICE *nutDeviceList;
- extern int NutRegisterDevice(NUTDEVICE * dev, uptr_t base, u_char irq);
- extern NUTDEVICE *NutDeviceLookup(CONST char *name);
- __END_DECLS
- #endif
|