Nut/OS  5.0.5
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 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  * $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 
00130 #ifndef ENABLE
00131 #define ENABLE 1
00132 #endif
00133 
00134 #ifndef DISABLE
00135 #define DISABLE 0
00136 #endif
00137 
00138 
00143 typedef struct _RINGBUF RINGBUF;
00144 
00149 struct _RINGBUF {
00150 
00155     uint8_t * volatile rbf_head;
00156 
00161     uint8_t * volatile rbf_tail;
00162 
00165     uint8_t *rbf_start;
00166 
00169     uint8_t *rbf_last;
00170 
00175     size_t rbf_siz;
00176 
00181     volatile size_t rbf_cnt;
00182 
00188     size_t rbf_lwm;
00189 
00195     size_t rbf_hwm;
00196 
00202     HANDLE rbf_que;
00203 
00210     size_t volatile rbf_blockcnt;
00211 
00217     uint8_t* volatile rbf_blockptr;
00218 };
00219 
00227 
00232 #define USART_INITSPEED   115200
00233 
00237 #define USART_MF_RTSCONTROL     0x0001  
00238 #define USART_MF_CTSSENSE       0x0002  
00239 #define USART_MF_DTRCONTROL     0x0004  
00240 #define USART_MF_DSRSENSE       0x0008  
00241 #define USART_MF_DCDSENSE       0x0010  
00243 #define USART_MF_SENSEMASK      0x001A  
00244 #define USART_MF_CONTROLMASK    0x0005  
00253 #define USART_MF_XONXOFF        0x0020
00254 
00262 #define USART_MF_LOCALECHO      0x0040  
00264 #define USART_MF_COOKEDMODE     0x0080  
00266 #define USART_MF_NOBUFFER       0x0100  
00267 #define USART_MF_LINEBUFFER     0x0200  
00268 #define USART_MF_BUFFERMASK     0x0300  
00270 #define USART_MF_HALFDUPLEX     0x0400  
00272 #define USART_MF_BLOCKREAD      0x0800  
00273 #define USART_MF_BLOCKWRITE     0x1000  
00275 #define USART_MF_FLOWMASK       (USART_MF_XONXOFF| USART_MF_HALFDUPLEX|USART_MF_LOCALECHO|USART_MF_BLOCKREAD|USART_MF_BLOCKWRITE)
00276 
00277 #define USART_SF_RTSOFF         0x0001  
00278 #define USART_SF_CTSOFF         0x0002  
00279 #define USART_SF_DTROFF         0x0004  
00280 #define USART_SF_DSROFF         0x0008  
00281 #define USART_SF_DCDOFF         0x0010  
00283 #define USART_SF_TXDISABLED     0x0040  
00284 #define USART_SF_RXDISABLED     0x0080  
00291 struct _USARTDCB {
00292 
00295     uint32_t dcb_modeflags;
00296 
00299     uint32_t dcb_statusflags;
00300 
00303     uint32_t dcb_rtimeout;
00304 
00307     uint32_t dcb_wtimeout;
00308 
00311     RINGBUF dcb_tx_rbf;
00312 
00315     RINGBUF dcb_rx_rbf;
00316 
00319     uint8_t dcb_last_eol;
00320 
00325     int (*dcb_init) (void);
00326 
00330     int (*dcb_deinit) (void);
00331 
00335     void (*dcb_tx_start) (void);
00336 
00340     void (*dcb_rx_start) (void);
00341 
00345     int (*dcb_set_flow_control) (uint32_t flags);
00346 
00350      uint32_t(*dcb_get_flow_control) (void);
00351 
00355     int (*dcb_set_speed) (uint32_t rate);
00356 
00360      uint32_t(*dcb_get_speed) (void);
00361 
00365     int (*dcb_set_data_bits) (uint8_t bits);
00366 
00370      uint8_t(*dcb_get_data_bits) (void);
00371 
00375     int (*dcb_set_parity) (uint8_t bits);
00376 
00380      uint8_t(*dcb_get_parity) (void);
00381 
00385     int (*dcb_set_stop_bits) (uint8_t bits);
00386 
00390      uint8_t(*dcb_get_stop_bits) (void);
00391 
00395     int (*dcb_set_status) (uint32_t flags);
00396 
00400      uint32_t(*dcb_get_status) (void);
00401 
00405     int (*dcb_set_clock_mode) (uint8_t mode);
00406 
00410      uint8_t(*dcb_get_clock_mode) (void);
00411 };
00412 
00416 typedef struct _USARTDCB USARTDCB;
00417 
00421 extern int UsartInit(NUTDEVICE * dev);
00422 extern int UsartIOCtl(NUTDEVICE * dev, int req, void *conf);
00423 extern int UsartRead(NUTFILE * fp, void *buffer, int size);
00424 extern int UsartWrite(NUTFILE * fp, const void *buffer, int len);
00425 #ifdef __HARVARD_ARCH__
00426 extern int UsartWrite_P(NUTFILE * fp, PGM_P buffer, int len);
00427 #endif
00428 extern NUTFILE *UsartOpen(NUTDEVICE * dev, const char *name, int mode, int acc);
00429 extern int UsartClose(NUTFILE * fp);
00430 extern long UsartSize (NUTFILE *fp);
00431 
00432 #endif