Nut/OS  4.10.3
API Reference
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$
00038  * Revision 1.7  2008/08/11 06:59:59  haraldkipp
00039  * BSD types replaced by stdint types (feature request #1282721).
00040  *
00041  * Revision 1.6  2004/11/12 11:55:39  freckle
00042  * marked rbf_blockcnt and rbf_blockptr as volatile
00043  *
00044  * Revision 1.5  2004/11/12 11:25:43  freckle
00045  * added rbf_blockcnt and rbf_blockptr to _RINGBUF (if UART_BLOCKING_READ is
00046  * defined). added USART_MF_BLOCKREAD mode define
00047  *
00048  * Revision 1.4  2004/11/08 18:14:09  haraldkipp
00049  * Marked RINGBUF members volatile, which are modified within
00050  * interrupt routines.
00051  *
00052  * Revision 1.3  2004/05/24 20:19:49  drsung
00053  * Added function UsartSize to return number of chars in input buffer.
00054  *
00055  * Revision 1.2  2004/03/16 16:48:28  haraldkipp
00056  * Added Jan Dubiec's H8/300 port.
00057  *
00058  * Revision 1.1  2003/12/18 09:33:58  haraldkipp
00059  * First check in
00060  *
00061  */
00062 
00063 #include <dev/uart.h>
00064 
00074 
00079 
00083 #ifndef USART_RXBUFSIZ
00084 #define USART_RXBUFSIZ    256
00085 #endif
00086 
00092 #ifndef USART_RXHIWMARK
00093 #define USART_RXHIWMARK   240
00094 #endif
00095 
00101 #ifndef USART_RXLOWMARK
00102 #define USART_RXLOWMARK   208
00103 #endif
00104 
00108 #ifndef USART_TXBUFSIZ
00109 #define USART_TXBUFSIZ    64
00110 #endif
00111 
00117 #ifndef USART_TXHIWMARK
00118 #define USART_TXHIWMARK   56
00119 #endif
00120 
00126 #ifndef USART_TXLOWMARK
00127 #define USART_TXLOWMARK   40
00128 #endif
00129 
00134 typedef struct _RINGBUF RINGBUF;
00135 
00140 struct _RINGBUF {
00141 
00146     uint8_t * volatile rbf_head;
00147 
00152     uint8_t * volatile rbf_tail;
00153 
00156     uint8_t *rbf_start;
00157 
00160     uint8_t *rbf_last;
00161 
00166     size_t rbf_siz;
00167 
00172     volatile size_t rbf_cnt;
00173 
00179     size_t rbf_lwm;
00180 
00186     size_t rbf_hwm;
00187 
00193     HANDLE rbf_que;
00194 
00195 #ifdef UART_BLOCKING_READ    
00196 
00202         size_t volatile rbf_blockcnt;
00203         
00209         uint8_t* volatile rbf_blockptr;
00210 #endif
00211 
00212 };
00213 
00221 
00226 #define USART_INITSPEED   115200
00227 
00231 #define USART_MF_RTSCONTROL     0x0001  
00232 #define USART_MF_CTSSENSE       0x0002  
00233 #define USART_MF_DTRCONTROL     0x0004  
00234 #define USART_MF_DSRSENSE       0x0008  
00235 #define USART_MF_DCDSENSE       0x0010  
00237 #define USART_MF_SENSEMASK      0x001A  
00238 #define USART_MF_CONTROLMASK    0x0005  
00247 #define USART_MF_XONXOFF        0x0020
00248 
00249 #define USART_MF_LOCALECHO      0x0040  
00250 #define USART_MF_COOKEDMODE     0x0080  
00252 #define USART_MF_NOBUFFER       0x0100  
00253 #define USART_MF_LINEBUFFER     0x0200  
00254 #define USART_MF_BUFFERMASK     0x0300  
00256 #define USART_MF_HALFDUPLEX     0x0400  
00257 #define USART_MF_BLOCKREAD              0x0800  
00259 #define USART_SF_RTSOFF         0x0001  
00260 #define USART_SF_CTSOFF         0x0002  
00261 #define USART_SF_DTROFF         0x0004  
00262 #define USART_SF_DSROFF         0x0008  
00263 #define USART_SF_DCDOFF         0x0010  
00265 #define USART_SF_TXDISABLED     0x0040  
00266 #define USART_SF_RXDISABLED     0x0080  
00274 struct _USARTDCB {
00275 
00278     uint32_t dcb_modeflags;
00279 
00282     uint32_t dcb_statusflags;
00283 
00286     uint32_t dcb_rtimeout;
00287 
00290     uint32_t dcb_wtimeout;
00291 
00294     RINGBUF dcb_tx_rbf;
00295 
00298     RINGBUF dcb_rx_rbf;
00299 
00302     uint8_t dcb_last_eol;
00303 
00308     int (*dcb_init) (void);
00309 
00313     int (*dcb_deinit) (void);
00314 
00318     void (*dcb_tx_start) (void);
00319 
00323     void (*dcb_rx_start) (void);
00324 
00328     int (*dcb_set_flow_control) (uint32_t flags);
00329 
00333      uint32_t(*dcb_get_flow_control) (void);
00334 
00338     int (*dcb_set_speed) (uint32_t rate);
00339 
00343      uint32_t(*dcb_get_speed) (void);
00344 
00348     int (*dcb_set_data_bits) (uint8_t bits);
00349 
00353      uint8_t(*dcb_get_data_bits) (void);
00354 
00358     int (*dcb_set_parity) (uint8_t bits);
00359 
00363      uint8_t(*dcb_get_parity) (void);
00364 
00368     int (*dcb_set_stop_bits) (uint8_t bits);
00369 
00373      uint8_t(*dcb_get_stop_bits) (void);
00374 
00378     int (*dcb_set_status) (uint32_t flags);
00379 
00383      uint32_t(*dcb_get_status) (void);
00384 
00388     int (*dcb_set_clock_mode) (uint8_t mode);
00389 
00393      uint8_t(*dcb_get_clock_mode) (void);
00394 };
00395 
00399 typedef struct _USARTDCB USARTDCB;
00400 
00404 __BEGIN_DECLS
00405 
00408 extern int UsartInit(NUTDEVICE * dev);
00409 extern int UsartIOCtl(NUTDEVICE * dev, int req, void *conf);
00410 extern int UsartRead(NUTFILE * fp, void *buffer, int size);
00411 extern int UsartWrite(NUTFILE * fp, CONST void *buffer, int len);
00412 #ifdef __HARVARD_ARCH__
00413 extern int UsartWrite_P(NUTFILE * fp, PGM_P buffer, int len);
00414 #endif
00415 extern NUTFILE *UsartOpen(NUTDEVICE * dev, CONST char *name, int mode, int acc);
00416 extern int UsartClose(NUTFILE * fp);
00417 extern long UsartSize (NUTFILE *fp);
00420 __END_DECLS
00421 
00422 #endif