usart.h File Reference


Detailed Description

PDC example application.

This file gives an example of using the PDC to burst data on the USART.

Author:
Atmel Corporation: http://www.atmel.com
Support email: avr32@atmel.com
$Name$
Revision
42
$RCSfile$
Date
2006-03-22 09:08:08 +0100 (Wed, 22 Mar 2006)

Definition in file usart.h.

#include <avr32/io.h>
#include "settings.h"

Include dependency graph for usart.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  usart_options_t
 Input parameters when initializing rs232 mode. More...

Defines

#define USART_1_5_STOPBITS   1
#define USART_1_STOPBIT   0
#define USART_2_STOPBITS   2
#define USART_ADDR_RECEIVED   1
#define USART_AUTO_ECHO   1
#define USART_DEFAULT_TIMEOUT   10000
#define USART_ERROR_ARGUMENT   1
#define USART_EVEN_PARITY   0
#define USART_FAILURE   -1
#define USART_LOCAL_LOOPBACK   2
#define USART_MARK_PARITY   3
#define USART_MODE_FAULT   5
#define USART_MODE_HW_HSH   0x02
#define USART_MODE_IRDA   0x08
#define USART_MODE_ISO7816_T0   0x04
#define USART_MODE_ISO7816_T1   0x06
#define USART_MODE_MODEM   0x03
#define USART_MODE_NORMAL   0x00
#define USART_MODE_RS485   0x01
#define USART_MODE_SW_HSH   0x0C
#define USART_MULTIDROP_PARITY   6
#define USART_NO_PARITY   4
#define USART_NORMAL_CHMODE   0
#define USART_ODD_PARITY   1
#define USART_OK   0
#define USART_REMOTE_LOOPBACK   3
#define USART_RX_EMPTY   3
#define USART_RX_ERROR   4
#define USART_SPACE_PARITY   2
#define USART_TX_BUSY   2

Functions

int usart_init2 (volatile avr32_usart_t *usart, struct usart_options_t *opt, long cpuHz)
 Setup the usart to use the standard RS232 protocol.
int usart_puthcar (volatile avr32_usart_t *usart, int character)
void usart_reset (volatile avr32_usart_t *usart)
 This function will reset the USART, and disable TX and RX.
int usart_writeLine (volatile avr32_usart_t *usart, char *string)
 write one character string to the usart


Define Documentation

#define USART_1_5_STOPBITS   1

Use 1.5 stop bits

Definition at line 92 of file usart.h.

#define USART_1_STOPBIT   0

Use 1 stop bit

Definition at line 90 of file usart.h.

Referenced by init_dbg_rs232(), and main().

#define USART_2_STOPBITS   2

Use 2 stop bits (for more, just give the number of bits)

Definition at line 94 of file usart.h.

#define USART_ADDR_RECEIVED   1

Value returned by receiver function when an address character was received

Definition at line 45 of file usart.h.

#define USART_AUTO_ECHO   1

Set usart channel to echo data

Definition at line 83 of file usart.h.

#define USART_DEFAULT_TIMEOUT   10000

Default timeout value; number of tries before timing out

Definition at line 48 of file usart.h.

Referenced by usart_putchar().

#define USART_ERROR_ARGUMENT   1

Value returned by function when the input paramters are out of range

Definition at line 33 of file usart.h.

Referenced by usart_init2(), and usart_set_baudrate().

#define USART_EVEN_PARITY   0

Use even parity on character transmission

Definition at line 51 of file usart.h.

#define USART_FAILURE   -1

Value returned by function when it was unable to complete successfully for some unspecified reason

Definition at line 31 of file usart.h.

#define USART_LOCAL_LOOPBACK   2

Set usart channel to local loopback

Definition at line 85 of file usart.h.

#define USART_MARK_PARITY   3

Use a mark as parity bit

Definition at line 57 of file usart.h.

#define USART_MODE_FAULT   5

Value returned by a function when the usart is not in the appropriate mode

Definition at line 42 of file usart.h.

Referenced by usart_send_address().

#define USART_MODE_HW_HSH   0x02

Operate usart in rs232 with hardware handshaking

Definition at line 68 of file usart.h.

Referenced by usart_init_handshaking().

#define USART_MODE_IRDA   0x08

Oparte usart in irda mode

Definition at line 76 of file usart.h.

#define USART_MODE_ISO7816_T0   0x04

Operate usart in iso7816, T=0 mode

Definition at line 72 of file usart.h.

Referenced by usart_init_iso7816().

#define USART_MODE_ISO7816_T1   0x06

Operate usart in iso7816, T=1 mode

Definition at line 74 of file usart.h.

Referenced by usart_init_iso7816().

#define USART_MODE_MODEM   0x03

Operate usart in modem mode

Definition at line 70 of file usart.h.

Referenced by usart_init_modem().

#define USART_MODE_NORMAL   0x00

Operate usart in normal rs232 mode

Definition at line 64 of file usart.h.

#define USART_MODE_RS485   0x01

Operate usart in rs485 mode

Definition at line 66 of file usart.h.

Referenced by usart_init_rs485().

#define USART_MODE_SW_HSH   0x0C

Operate usart in rs232 with software handshaking

Definition at line 78 of file usart.h.

Referenced by usart_init_handshaking().

#define USART_MULTIDROP_PARITY   6

Parity bit is used to flag address characters

Definition at line 61 of file usart.h.

#define USART_NO_PARITY   4

Don't use a parity bit

Definition at line 59 of file usart.h.

Referenced by init_dbg_rs232(), and main().

#define USART_NORMAL_CHMODE   0

Set usart channel to normal communcation

Definition at line 81 of file usart.h.

Referenced by init_dbg_rs232(), and main().

#define USART_ODD_PARITY   1

Use odd parity on character transmission

Definition at line 53 of file usart.h.

#define USART_OK   0

Value returned by function when it completed successfully

Definition at line 28 of file usart.h.

Referenced by usart_init2(), usart_putchar(), usart_set_baudrate(), and usart_writeLine().

#define USART_REMOTE_LOOPBACK   3

Set usart channel to remote loopback

Definition at line 87 of file usart.h.

#define USART_RX_EMPTY   3

Value returned by receiver function when nothing was received

Definition at line 37 of file usart.h.

Referenced by usart_getchar(), and usart_read_char().

#define USART_RX_ERROR   4

Value returned by receiver function when transmission error occured

Definition at line 39 of file usart.h.

Referenced by usart_getchar(), and usart_read_char().

#define USART_SPACE_PARITY   2

Use a space as parity bit

Definition at line 55 of file usart.h.

#define USART_TX_BUSY   2

Value returned by transmission function when transmitter was busy

Definition at line 35 of file usart.h.

Referenced by usart_putchar(), and usart_write_char().


Function Documentation

int usart_init2 ( volatile avr32_usart_t *  usart,
struct usart_options_t opt,
long  cpuHz 
)

Setup the usart to use the standard RS232 protocol.

Parameters:
usart base address of the usart
opt options needed to set up RS232 communcation (see usart_options_t)
cpuHz frequency of the selected clock
Returns:
status
Return values:
USART_OK on success
USART_ERROR_ARGUMENT on wrong arguments

Definition at line 120 of file usart.c.

References usart_options_t::baudrate, usart_options_t::channelmode, usart_options_t::charlength, usart_options_t::paritytype, usart_options_t::stopbits, USART_ERROR_ARGUMENT, USART_OK, usart_reset(), and usart_set_baudrate().

Referenced by main().

00123 {
00124         int retval;
00125 
00126         /* reset the usart and shutdown RX and TX */
00127         usart_reset(usart);
00128 
00129         /* control input values */
00130         if( opt == 0 ) {
00131                 return USART_ERROR_ARGUMENT;
00132         }
00133         if( opt->charlength < 5 || opt->charlength > 9 ) {
00134                 return USART_ERROR_ARGUMENT;
00135         }
00136         if( opt->paritytype > 7 ) {
00137                 return USART_ERROR_ARGUMENT;
00138         }
00139         if( opt->stopbits > 2+255 ) {
00140                 return USART_ERROR_ARGUMENT;
00141         }
00142         if( opt->channelmode > 3 ) {
00143                 return USART_ERROR_ARGUMENT;
00144         }
00145 
00146         retval = usart_set_baudrate( usart, opt->baudrate, cpuHz );
00147 
00148         if( retval != USART_OK ) {
00149                 return retval;
00150         }
00151 
00152         if( opt->charlength == 9 ) {
00153                 /* charlength set to 9 bits; MODE9 dominates CHRL */
00154                 usart->mr |= (1<<AVR32_USART_MR_MODE9_OFFSET);
00155         } else {
00156                 /* CHRL gives the charlength( - 5) when USART_MODE9=0 */
00157                 usart->mr |=
00158                         ((opt->charlength-5) << AVR32_USART_MR_CHRL_OFFSET);
00159         }
00160 
00161         usart->mr |= (opt->channelmode << AVR32_USART_MR_CHMODE_OFFSET) |
00162                      (opt->paritytype << AVR32_USART_MR_PAR_OFFSET);
00163 
00164         if( opt->stopbits > 2 ) {
00165                 /* set two stop bits */
00166                 usart->mr |= (2 << AVR32_USART_MR_NBSTOP_OFFSET);
00167                 /* and a timeguard period gives the rest */
00168                 usart->ttgr = (opt->stopbits-2);
00169         } else {
00170                 /* insert 1, 1.5 or 2 stop bits */
00171                 usart->mr |= (opt->stopbits << AVR32_USART_MR_NBSTOP_OFFSET);
00172         }
00173 
00174         /* enable TX and RX */
00175         usart->cr |= (1<<AVR32_USART_CR_TXEN_OFFSET) |
00176                      (1<<AVR32_USART_CR_RXEN_OFFSET);
00177 
00178         return USART_OK;
00179 }

Here is the call graph for this function:

int usart_puthcar ( volatile avr32_usart_t *  usart,
int  character 
)

void usart_reset ( volatile avr32_usart_t *  usart  ) 

This function will reset the USART, and disable TX and RX.

Parameters:
usart Base address of the usart

Definition at line 27 of file usart.c.

00028 {
00029         /* Disable all usart interrupts, interrupts needed should be set
00030            explicitly on every reset */
00031         usart->idr = 0xFFFFffff;
00032 
00033         /* Reset mode and other registers that could cause unpredictable
00034            behaviour after reset */
00035         usart->mr = 0;
00036         usart->rtor = 0;
00037         usart->ttgr = 0;
00038 
00039         /* Shutdown RX and TX (will be reenabled when setup
00040            is completed successfully), reset status bits and turn
00041            off DTR and RTS */
00042         usart->cr = (1<<AVR32_USART_CR_RSTRX_OFFSET)|
00043                     (1<<AVR32_USART_CR_RSTTX_OFFSET)|
00044                     (1<<AVR32_USART_CR_RSTSTA_OFFSET)|
00045                     (1<<AVR32_USART_CR_RSTIT_OFFSET)|
00046                     (1<<AVR32_USART_CR_RSTNACK_OFFSET)|
00047                     (1<<AVR32_USART_CR_DTRDIS_OFFSET)|
00048                     (1<<AVR32_USART_CR_RTSDIS_OFFSET);
00049 }

int usart_writeLine ( volatile avr32_usart_t *  usart,
char *  string 
)

write one character string to the usart

Parameters:
usart base address of the usart
string pointer to an array of chars
Returns:
status
Return values:
USART_OK on success
USART_TX_BUSY on timeout

Definition at line 218 of file usart.c.

References USART_OK, and usart_putchar().

00219 {
00220         int retVal = USART_OK;
00221 
00222         while( *string != '\0' ) {
00223                 retVal = usart_putchar( usart, *string++ );
00224         }
00225 
00226         if( retVal != USART_OK ) {
00227                 return retVal;
00228         }
00229 
00230         return USART_OK;
00231 }

Here is the call graph for this function:


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