usart.h

Go to the documentation of this file.
00001 #ifndef _DEV_USART_H_
00002 #define _DEV_USART_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  * $Log: usart.h,v $
00038  * Revision 1.6  2004/11/12 11:55:39  freckle
00039  * marked rbf_blockcnt and rbf_blockptr as volatile
00040  *
00041  * Revision 1.5  2004/11/12 11:25:43  freckle
00042  * added rbf_blockcnt and rbf_blockptr to _RINGBUF (if UART_BLOCKING_READ is
00043  * defined). added USART_MF_BLOCKREAD mode define
00044  *
00045  * Revision 1.4  2004/11/08 18:14:09  haraldkipp
00046  * Marked RINGBUF members volatile, which are modified within
00047  * interrupt routines.
00048  *
00049  * Revision 1.3  2004/05/24 20:19:49  drsung
00050  * Added function UsartSize to return number of chars in input buffer.
00051  *
00052  * Revision 1.2  2004/03/16 16:48:28  haraldkipp
00053  * Added Jan Dubiec's H8/300 port.
00054  *
00055  * Revision 1.1  2003/12/18 09:33:58  haraldkipp
00056  * First check in
00057  *
00058  */
00059 
00060 #include <dev/uart.h>
00061 
00071 
00076 
00080 #ifndef USART_RXBUFSIZ
00081 #define USART_RXBUFSIZ    256
00082 #endif
00083 
00089 #ifndef USART_RXHIWMARK
00090 #define USART_RXHIWMARK   240
00091 #endif
00092 
00098 #ifndef USART_RXLOWMARK
00099 #define USART_RXLOWMARK   208
00100 #endif
00101 
00105 #ifndef USART_TXBUFSIZ
00106 #define USART_TXBUFSIZ    64
00107 #endif
00108 
00114 #ifndef USART_TXHIWMARK
00115 #define USART_TXHIWMARK   56
00116 #endif
00117 
00123 #ifndef USART_TXLOWMARK
00124 #define USART_TXLOWMARK   40
00125 #endif
00126 
00131 typedef struct _RINGBUF RINGBUF;
00132 
00137 struct _RINGBUF {
00138 
00143     u_char * volatile rbf_head;
00144 
00149     u_char * volatile rbf_tail;
00150 
00153     u_char *rbf_start;
00154 
00157     u_char *rbf_last;
00158 
00163     size_t rbf_siz;
00164 
00169     volatile size_t rbf_cnt;
00170 
00176     size_t rbf_lwm;
00177 
00183     size_t rbf_hwm;
00184 
00190     HANDLE rbf_que;
00191 
00192 #ifdef UART_BLOCKING_READ    
00193 
00199     size_t volatile rbf_blockcnt;
00200     
00206     u_char* volatile rbf_blockptr;
00207 #endif
00208 
00209 };
00210 
00218 
00223 #define USART_INITSPEED   115200
00224 
00228 #define USART_MF_RTSCONTROL     0x0001  
00229 #define USART_MF_CTSSENSE       0x0002  
00230 #define USART_MF_DTRCONTROL     0x0004  
00231 #define USART_MF_DSRSENSE       0x0008  
00232 #define USART_MF_DCDSENSE       0x0010  
00234 #define USART_MF_SENSEMASK      0x001A  
00235 #define USART_MF_CONTROLMASK    0x0005  
00244 #define USART_MF_XONXOFF        0x0020
00245 
00246 #define USART_MF_LOCALECHO      0x0040  
00247 #define USART_MF_COOKEDMODE     0x0080  
00249 #define USART_MF_NOBUFFER       0x0100  
00250 #define USART_MF_LINEBUFFER     0x0200  
00251 #define USART_MF_BUFFERMASK     0x0300  
00253 #define USART_MF_HALFDUPLEX     0x0400  
00254 #define USART_MF_BLOCKREAD      0x0800  
00256 #define USART_SF_RTSOFF         0x0001  
00257 #define USART_SF_CTSOFF         0x0002  
00258 #define USART_SF_DTROFF         0x0004  
00259 #define USART_SF_DSROFF         0x0008  
00260 #define USART_SF_DCDOFF         0x0010  
00262 #define USART_SF_TXDISABLED     0x0040  
00263 #define USART_SF_RXDISABLED     0x0080  
00271 struct _USARTDCB {
00272 
00275     u_long dcb_modeflags;
00276 
00279     u_long dcb_statusflags;
00280 
00283     u_long dcb_rtimeout;
00284 
00287     u_long dcb_wtimeout;
00288 
00291     RINGBUF dcb_tx_rbf;
00292 
00295     RINGBUF dcb_rx_rbf;
00296 
00299     u_char dcb_last_eol;
00300 
00305     int (*dcb_init) (void);
00306 
00310     int (*dcb_deinit) (void);
00311 
00315     void (*dcb_tx_start) (void);
00316 
00320     void (*dcb_rx_start) (void);
00321 
00325     int (*dcb_set_flow_control) (u_long flags);
00326 
00330      u_long(*dcb_get_flow_control) (void);
00331 
00335     int (*dcb_set_speed) (u_long rate);
00336 
00340      u_long(*dcb_get_speed) (void);
00341 
00345     int (*dcb_set_data_bits) (u_char bits);
00346 
00350      u_char(*dcb_get_data_bits) (void);
00351 
00355     int (*dcb_set_parity) (u_char bits);
00356 
00360      u_char(*dcb_get_parity) (void);
00361 
00365     int (*dcb_set_stop_bits) (u_char bits);
00366 
00370      u_char(*dcb_get_stop_bits) (void);
00371 
00375     int (*dcb_set_status) (u_long flags);
00376 
00380      u_long(*dcb_get_status) (void);
00381 
00385     int (*dcb_set_clock_mode) (u_char mode);
00386 
00390      u_char(*dcb_get_clock_mode) (void);
00391 };
00392 
00396 typedef struct _USARTDCB USARTDCB;
00397 
00401 __BEGIN_DECLS
00402 
00405 extern int UsartInit(NUTDEVICE * dev);
00406 extern int UsartIOCtl(NUTDEVICE * dev, int req, void *conf);
00407 extern int UsartRead(NUTFILE * fp, void *buffer, int size);
00408 extern int UsartWrite(NUTFILE * fp, CONST void *buffer, int len);
00409 #ifdef __HARVARD_ARCH__
00410 extern int UsartWrite_P(NUTFILE * fp, PGM_P buffer, int len);
00411 #endif
00412 extern NUTFILE *UsartOpen(NUTDEVICE * dev, CONST char *name, int mode, int acc);
00413 extern int UsartClose(NUTFILE * fp);
00414 extern long UsartSize (NUTFILE *fp);
00417 __END_DECLS
00418 
00419 #endif

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