usart.h

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00022 /* *****************************************************************************
00023 Copyright (c) 2006, Atmel Corporation All rights reserved.
00024 
00025 Redistribution and use in source and binary forms, with or without
00026 modification, are permitted provided that the following conditions are met:
00027 
00028 1. Redistributions of source code must retain the above copyright notice,
00029 this list of conditions and the
00030 following disclaimer.
00031 
00032 2. Redistributions in binary form must reproduce the above copyright notice,
00033 this list of conditions and the following disclaimer in the documentation
00034 and/or other materials provided with the distribution.
00035 
00036 3. The name of ATMEL may not be used to endorse or promote products
00037 derived from this software without specific prior written permission.
00038 
00039 THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS
00040 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00041 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00042 PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY
00043 DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00044 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00045 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00046 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00047 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00048 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00049 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
00050 WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00051 
00052 POSSIBILITY OF SUCH DAMAGE.
00053 
00054 ************************************************************************ */
00055 
00056 
00057 #ifndef _USART_H_
00058 #define _USART_H_
00059 
00060 #include <avr32/io.h>
00061 #include "errno.h"
00062 
00066 struct usart_options_t
00067 {
00071         unsigned long baudrate;
00072 
00076         unsigned char charlength;
00077 
00083         unsigned char paritytype;
00084 
00091         unsigned short stopbits;
00092 
00098         unsigned char channelmode;
00099 };
00100 
00101 
00102 struct iso7816_options_t
00103 {
00104         /*
00105          * Set the frequency of the ISO7816 clock
00106          */
00107         unsigned long iso7816_hz;
00108 
00109         /*
00110          * The number of ISO7816 clock tick in every bit period (1-2047, 0=disable clock)
00111          * Bit rate = iso7816_hz / fidi_ratio
00112          */
00113         unsigned short fidi_ratio;
00114 
00115         /*
00116          * Inhibit Non Acknowledge
00117          * - 0 - The NACK is generated
00118          * - 1 - The NACK is not generated
00119          * .
00120          * Note: This bit will be used only in ISO7816 mode, protocol T = 0 receiver
00121          */
00122         int inhibit_nack;
00123 
00124         /*
00125          * Disable Successive NACK \n\n
00126          * Successive parity errors are counted up to the value in the max_iterations field. \n
00127          * These parity errors generate a NACK on the ISO line. As soon as this value is reached, \n
00128          * no addititional NACK is sent on the ISO line. The flag ITERATION is asserted. \n
00129          */
00130         int dis_suc_nack;
00131 
00132         /*
00133          * Max number of repetitions (0 - 7)
00134          */
00135         unsigned char max_iterations;
00136 
00137         /*
00138          * Bitorder in transmitted characters
00139          * - 0 - LSB first
00140          * - 1 - MSB first
00141          */
00142         int bit_order;
00143 };
00144 
00145  /*---------------------------------------------------------------------------+
00146  |                                                                                                |
00147  |                           INITIALIZATION FUNCTIONS                |
00148  |                                                                                                |
00149  +---------------------------------------------------------------------------*/
00150 
00156 void usart_reset( volatile struct avr32_usart_t * usart );
00157 
00158 
00167 int usart_init_rs232( volatile struct avr32_usart_t * usart, struct usart_options_t * opt, long cpu_hz );
00168 
00169 
00170  /*---------------------------------------------------------------------------+
00171  |                                                                                                |
00172  |                         TRANSMIT/RECEIVE FUNCTIONS         |
00173  |                                                                                                |
00174  +---------------------------------------------------------------------------*/
00175 
00186 int usart_send_addr(volatile struct avr32_usart_t * usart, int addr);
00187 
00188 
00196 int usart_write_char(volatile struct avr32_usart_t * usart, int c);
00197 
00198 
00205 inline void usart_bw_write_char(volatile struct avr32_usart_t * usart, int c);
00206 
00214 int usart_putchar(volatile struct avr32_usart_t * usart, int c);
00215 
00227 int usart_read_char(volatile struct avr32_usart_t * usart, int * c);
00228 
00234 int usart_getchar(volatile struct avr32_usart_t * usart);
00235 
00244 void usart_reset_status(volatile struct avr32_usart_t * usart);
00245 
00247 #define USART_DEFAULT_TIMEOUT  10000
00248 
00250 #define USART_EVEN_PARITY       0
00251 
00252 #define USART_ODD_PARITY        1
00253 
00254 #define USART_SPACE_PARITY      2
00255 
00256 #define USART_MARK_PARITY       3
00257 
00258 #define USART_NO_PARITY         4
00259 
00260 #define USART_MULTIDROP_PARITY  6
00261 
00263 #define USART_MODE_NORMAL       0x00
00264 
00265 #define USART_MODE_RS485        0x01
00266 
00267 #define USART_MODE_HW_HSH       0x02
00268 
00269 #define USART_MODE_MODEM        0x03
00270 
00271 #define USART_MODE_ISO7816_T0   0x04
00272 
00273 #define USART_MODE_ISO7816_T1   0x06
00274 
00275 #define USART_MODE_IRDA         0x08
00276 
00277 #define USART_MODE_SW_HSH       0x0C
00278 
00280 #define USART_NORMAL_CHMODE     0
00281 
00282 #define USART_AUTO_ECHO         1
00283 
00284 #define USART_LOCAL_LOOPBACK    2
00285 
00286 #define USART_REMOTE_LOOPBACK   3
00287 
00289 #define USART_1_STOPBIT         0
00290 
00291 #define USART_1_5_STOPBITS      1
00292 
00293 #define USART_2_STOPBITS        2
00294 
00295 /*
00296         Interrupt sources. Use with interrupt registers in USART
00297 */
00298 
00299 #define INT_RXRDY      0
00300 #define INT_TXRDY      1
00301 #define INT_RXBRK      2
00302 #define INT_ENDRX      3
00303 #define INT_ENDTX      4
00304 #define INT_OVRE       5
00305 #define INT_FRAM       6
00306 #define INT_PARE       7
00307 #define INT_TIMEOUT    8
00308 #define INT_TXEMPTY    9
00309 #define INT_ITERATION 10
00310 #define INT_TXBUFE    11
00311 #define INT_RXBUFF    12
00312 #define INT_NACK      13
00313 #define INT_RIIC      16
00314 #define INT_DSRIC     17
00315 #define INT_DCDIC     18
00316 #define INT_CTSIC     19
00317 #define INT_MANE      20
00318 
00319 #endif //#ifndef _AVR32_USART_H_

Generated on Wed May 7 16:03:17 2008 for AVR32114 Using the AVR32 LCD Controller by  doxygen 1.5.3-20071008