usart.h File Reference


Detailed Description

PDC and interrupt control example application.

This file gives an example of using the PDC to burst data on the USART. With and without the use of interrupts.

Author:
Atmel Corporation: http://www.atmel.com
Support email: avr32@atmel.com
Name
RELEASE_1_0
Revision
1.13
RCSfile
usart.h,v
Date
2006/05/09 10:32:56

Definition in file usart.h.

#include <avr32/io.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_linit (volatile struct avr32_usart_t *usart, const struct usart_options_t *opt, const long cpuHz)
 Setup the usart to use the standard RS232 protocol.
int usart_lwriteLine (volatile struct avr32_usart_t *usart, const char *string)
 write one character string to the usart
int usart_putchar (volatile struct avr32_usart_t *usart, const int character)
 Send a character with the usart.
void usart_reset (volatile struct avr32_usart_t *usart)
 This function will reset the USART, and disable TX and RX.


Define Documentation

#define USART_1_5_STOPBITS   1
 

Use 1.5 stop bits

Definition at line 125 of file usart.h.

#define USART_1_STOPBIT   0
 

Use 1 stop bit

Definition at line 123 of file usart.h.

Referenced by main().

#define USART_2_STOPBITS   2
 

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

Definition at line 127 of file usart.h.

#define USART_ADDR_RECEIVED   1
 

Value returned by receiver function when an address character was received

Definition at line 78 of file usart.h.

#define USART_AUTO_ECHO   1
 

Set usart channel to echo data

Definition at line 116 of file usart.h.

#define USART_DEFAULT_TIMEOUT   10000
 

Default timeout value; number of tries before timing out

Definition at line 81 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 66 of file usart.h.

Referenced by pio_enable_module(), usart_linit(), and usart_set_baudrate().

#define USART_EVEN_PARITY   0
 

Use even parity on character transmission

Definition at line 84 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 64 of file usart.h.

#define USART_LOCAL_LOOPBACK   2
 

Set usart channel to local loopback

Definition at line 118 of file usart.h.

#define USART_MARK_PARITY   3
 

Use a mark as parity bit

Definition at line 90 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 75 of file usart.h.

#define USART_MODE_HW_HSH   0x02
 

Operate usart in rs232 with hardware handshaking

Definition at line 101 of file usart.h.

#define USART_MODE_IRDA   0x08
 

Oparte usart in irda mode

Definition at line 109 of file usart.h.

#define USART_MODE_ISO7816_T0   0x04
 

Operate usart in iso7816, T=0 mode

Definition at line 105 of file usart.h.

#define USART_MODE_ISO7816_T1   0x06
 

Operate usart in iso7816, T=1 mode

Definition at line 107 of file usart.h.

#define USART_MODE_MODEM   0x03
 

Operate usart in modem mode

Definition at line 103 of file usart.h.

#define USART_MODE_NORMAL   0x00
 

Operate usart in normal rs232 mode

Definition at line 97 of file usart.h.

#define USART_MODE_RS485   0x01
 

Operate usart in rs485 mode

Definition at line 99 of file usart.h.

#define USART_MODE_SW_HSH   0x0C
 

Operate usart in rs232 with software handshaking

Definition at line 111 of file usart.h.

#define USART_MULTIDROP_PARITY   6
 

Parity bit is used to flag address characters

Definition at line 94 of file usart.h.

#define USART_NO_PARITY   4
 

Don't use a parity bit

Definition at line 92 of file usart.h.

Referenced by main().

#define USART_NORMAL_CHMODE   0
 

Set usart channel to normal communcation

Definition at line 114 of file usart.h.

Referenced by main().

#define USART_ODD_PARITY   1
 

Use odd parity on character transmission

Definition at line 86 of file usart.h.

#define USART_OK   0
 

Value returned by function when it completed successfully

Definition at line 61 of file usart.h.

Referenced by usart_linit(), usart_lwriteLine(), usart_putchar(), and usart_set_baudrate().

#define USART_REMOTE_LOOPBACK   3
 

Set usart channel to remote loopback

Definition at line 120 of file usart.h.

#define USART_RX_EMPTY   3
 

Value returned by receiver function when nothing was received

Definition at line 70 of file usart.h.

#define USART_RX_ERROR   4
 

Value returned by receiver function when transmission error occured

Definition at line 72 of file usart.h.

#define USART_SPACE_PARITY   2
 

Use a space as parity bit

Definition at line 88 of file usart.h.

#define USART_TX_BUSY   2
 

Value returned by transmission function when transmitter was busy

Definition at line 68 of file usart.h.

Referenced by usart_putchar().


Function Documentation

int usart_linit volatile struct avr32_usart_t *  usart,
const struct usart_options_t opt,
const 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 147 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().

00150 {
00151     int retval;
00152 
00153     /* reset the usart and shutdown RX and TX */
00154     usart_reset(usart);
00155 
00156     /* control input values */
00157     if (opt == 0) {
00158         return USART_ERROR_ARGUMENT;
00159     }
00160     if (opt->charlength < 5 || opt->charlength > 9) {
00161         return USART_ERROR_ARGUMENT;
00162     }
00163     if (opt->paritytype > 7) {
00164         return USART_ERROR_ARGUMENT;
00165     }
00166     if (opt->stopbits > 2+255) {
00167         return USART_ERROR_ARGUMENT;
00168     }
00169     if (opt->channelmode > 3) {
00170         return USART_ERROR_ARGUMENT;
00171     }
00172 
00173     retval = usart_set_baudrate(usart, opt->baudrate, cpuHz);
00174 
00175     if (retval != USART_OK) {
00176         return retval;
00177     }
00178 
00179     if (opt->charlength == 9) {
00180         /* charlength set to 9 bits; MODE9 dominates CHRL */
00181         usart->mr |= AVR32_USART_MR_MODE9_MASK;
00182     } else {
00183         /* CHRL gives the charlength(- 5) when USART_MODE9=0 */
00184         usart->mr |=
00185             ((opt->charlength-5)<<AVR32_USART_MR_CHRL_OFFSET);
00186     }
00187 
00188     usart->mr |= (opt->channelmode<<AVR32_USART_MR_CHMODE_OFFSET)|
00189                  (opt->paritytype<<AVR32_USART_MR_PAR_OFFSET);
00190 
00191     if (opt->stopbits > 2) {
00192         /* set two stop bits */
00193         usart->mr |= (2<<AVR32_USART_MR_NBSTOP_OFFSET);
00194         /* and a timeguard period gives the rest */
00195         usart->ttgr = (opt->stopbits-2);
00196     } else {
00197         /* insert 1, 1.5 or 2 stop bits */
00198         usart->mr |= (opt->stopbits<<AVR32_USART_MR_NBSTOP_OFFSET);
00199     }
00200 
00201     /* enable TX and RX */
00202     usart->cr |= AVR32_USART_CR_TXEN_MASK|AVR32_USART_CR_RXEN_MASK;
00203 
00204     return USART_OK;
00205 }

Here is the call graph for this function:

int usart_lwriteLine volatile struct avr32_usart_t *  usart,
const 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 244 of file usart.c.

References USART_OK, and usart_putchar().

00245 {
00246     int retVal = USART_OK;
00247 
00248     while (*string != '\0') {
00249         retVal = usart_putchar(usart, *string++);
00250 
00251         if (retVal != USART_OK) {
00252             return retVal;
00253         }
00254     }
00255 
00256     return USART_OK;
00257 }

Here is the call graph for this function:

int usart_putchar volatile struct avr32_usart_t *  usart,
const int  character
 

Send a character with the usart.

Parameters:
usart base address of the usart
character character to write
Returns:
status
Return values:
USART_OK on success
USART_TX_BUSY on timeout

Definition at line 217 of file usart.c.

References USART_DEFAULT_TIMEOUT, USART_OK, and USART_TX_BUSY.

Referenced by usart_lwriteLine().

00218 {
00219     int timeout = USART_DEFAULT_TIMEOUT;
00220 
00221     do {
00222         --timeout;
00223     } while ((usart->csr & AVR32_USART_CSR_TXRDY_MASK) == 0 && timeout > 0);
00224 
00225     if (timeout == 0) {
00226         return USART_TX_BUSY;
00227     }
00228 
00229     usart->thr = character;
00230 
00231     return USART_OK;
00232 }

void usart_reset volatile struct 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 55 of file usart.c.

Referenced by usart_linit().

00056 {
00057     /* Disable all usart interrupts, interrupts needed should be set
00058        explicitly on every reset */
00059     usart->idr = 0xFFFFffff;
00060 
00061     /* Reset mode and other registers that could cause unpredictable
00062        behaviour after reset */
00063     usart->mr = 0;
00064     usart->rtor = 0;
00065     usart->ttgr = 0;
00066 
00067     /* Shutdown RX and TX (will be reenabled when setup
00068        is completed successfully), reset status bits and turn
00069        off DTR and RTS */
00070     usart->cr = AVR32_USART_CR_RSTRX_MASK|
00071                 AVR32_USART_CR_RSTTX_MASK|
00072                 AVR32_USART_CR_RSTSTA_MASK|
00073                 AVR32_USART_CR_RSTIT_MASK|
00074                 AVR32_USART_CR_RSTNACK_MASK|
00075                 AVR32_USART_CR_DTRDIS_MASK|
00076                 AVR32_USART_CR_RTSDIS_MASK;
00077 }


Generated on Wed May 10 15:03:15 2006 for AVR32108 - Peripheral Direct Memory Access Driver by  doxygen 1.4.6-NO