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 #ifdef __GNUC__
00061         #include <avr32/io.h>
00062 #elif __ICCAVR32__
00063         #include <avr32/ioap7000.h>
00064 #else
00065         #error No known compiler used
00066 #endif
00067 
00068 
00072 struct usart_options_t
00073 {
00077         unsigned long baudrate;
00078 
00082         unsigned char charlength;
00083 
00089         unsigned char paritytype;
00090 
00097         unsigned short stopbits;
00098 
00104         unsigned char channelmode;
00105 };
00106 
00107 
00108 struct iso7816_options_t
00109 {
00110         /*
00111          * Set the frequency of the ISO7816 clock
00112          */
00113         unsigned long iso7816_hz;
00114 
00115         /*
00116          * The number of ISO7816 clock tick in every bit period (1-2047, 0=disable clock)
00117          * Bit rate = iso7816_hz / fidi_ratio
00118          */
00119         unsigned short fidi_ratio;
00120 
00121         /*
00122          * Inhibit Non Acknowledge
00123          * - 0 - The NACK is generated
00124          * - 1 - The NACK is not generated
00125          * .
00126          * Note: This bit will be used only in ISO7816 mode, protocol T = 0 receiver
00127          */
00128         int inhibit_nack;
00129 
00130         /*
00131          * Disable Successive NACK \n\n
00132          * Successive parity errors are counted up to the value in the max_iterations field. \n
00133          * These parity errors generate a NACK on the ISO line. As soon as this value is reached, \n
00134          * no addititional NACK is sent on the ISO line. The flag ITERATION is asserted. \n
00135          */
00136         int dis_suc_nack;
00137 
00138         /*
00139          * Max number of repetitions (0 - 7)
00140          */
00141         unsigned char max_iterations;
00142 
00143         /*
00144          * Bitorder in transmitted characters
00145          * - 0 - LSB first
00146          * - 1 - MSB first
00147          */
00148         int bit_order;
00149 };
00150 
00151  /*---------------------------------------------------------------------------+
00152  |                                                                                                |
00153  |                           INITIALIZATION FUNCTIONS                |
00154  |                                                                                                |
00155  +---------------------------------------------------------------------------*/
00156 
00162 void usart_reset( volatile struct avr32_usart_t * usart );
00163 
00164 
00173 int usart_init_rs232( volatile struct avr32_usart_t * usart, struct usart_options_t * opt, long cpu_hz );
00174 
00175 
00176  /*---------------------------------------------------------------------------+
00177  |                                                                                                |
00178  |                         TRANSMIT/RECEIVE FUNCTIONS         |
00179  |                                                                                                |
00180  +---------------------------------------------------------------------------*/
00181 
00192 int usart_send_addr(volatile struct avr32_usart_t * usart, int addr);
00193 
00194 
00202 int usart_write_char(volatile struct avr32_usart_t * usart, int c);
00203 
00204 
00211 inline void usart_bw_write_char(volatile struct avr32_usart_t * usart, int c);
00212 
00220 int usart_putchar(volatile struct avr32_usart_t * usart, int c);
00221 
00233 int usart_read_char(volatile struct avr32_usart_t * usart, int * c);
00234 
00240 int usart_getchar(volatile struct avr32_usart_t * usart);
00241 
00250 void usart_reset_status(volatile struct avr32_usart_t * usart);
00251 
00253 #define USART_SUCCESS 0
00254 
00256 #define USART_FAILURE -1
00257 
00258 #define USART_INVALID_INPUT 1
00259 #define USART_INVALID_ARGUMENT -1
00260 
00261 #define USART_TX_BUSY  2
00262 
00263 #define USART_RX_EMPTY 3
00264 
00265 #define USART_RX_ERROR 4
00266 
00268 #define USART_MODE_FAULT 5
00269 
00271 #define USART_ADDR_RECEIVED 1
00272 
00274 #define USART_DEFAULT_TIMEOUT  10000
00275 
00277 #define USART_EVEN_PARITY       0
00278 
00279 #define USART_ODD_PARITY        1
00280 
00281 #define USART_SPACE_PARITY      2
00282 
00283 #define USART_MARK_PARITY       3
00284 
00285 #define USART_NO_PARITY         4
00286 
00287 #define USART_MULTIDROP_PARITY  6
00288 
00290 #define USART_MODE_NORMAL       0x00
00291 
00292 #define USART_MODE_RS485        0x01
00293 
00294 #define USART_MODE_HW_HSH       0x02
00295 
00296 #define USART_MODE_MODEM        0x03
00297 
00298 #define USART_MODE_ISO7816_T0   0x04
00299 
00300 #define USART_MODE_ISO7816_T1   0x06
00301 
00302 #define USART_MODE_IRDA         0x08
00303 
00304 #define USART_MODE_SW_HSH       0x0C
00305 
00307 #define USART_NORMAL_CHMODE     0
00308 
00309 #define USART_AUTO_ECHO         1
00310 
00311 #define USART_LOCAL_LOOPBACK    2
00312 
00313 #define USART_REMOTE_LOOPBACK   3
00314 
00316 #define USART_1_STOPBIT         0
00317 
00318 #define USART_1_5_STOPBITS      1
00319 
00320 #define USART_2_STOPBITS        2
00321 
00322 /*
00323         Interrupt sources. Use with interrupt registers in USART
00324 */
00325 
00326 #define INT_RXRDY      0
00327 #define INT_TXRDY      1
00328 #define INT_RXBRK      2
00329 #define INT_ENDRX      3
00330 #define INT_ENDTX      4
00331 #define INT_OVRE       5
00332 #define INT_FRAM       6
00333 #define INT_PARE       7
00334 #define INT_TIMEOUT    8
00335 #define INT_TXEMPTY    9
00336 #define INT_ITERATION 10
00337 #define INT_TXBUFE    11
00338 #define INT_RXBUFF    12
00339 #define INT_NACK      13
00340 #define INT_RIIC      16
00341 #define INT_DSRIC     17
00342 #define INT_DCDIC     18
00343 #define INT_CTSIC     19
00344 #define INT_MANE      20
00345 
00346 #endif //#ifndef _AVR32_USART_H_

Generated on Thu May 10 14:17:56 2007 for AVR321000 Communication with the AVR32 USART by  doxygen 1.5.1