usart_example3.c

Go to the documentation of this file.
00001 #include <avr32/io.h>
00002 #include <avr32/intc.h>
00003 #include <sys/interrupts.h>
00004 
00005 
00006 #include "usart.h"
00007 #include "../pio/pio.h"
00008 #include "../debug/print_funcs.h"
00009 #include "../inc/macro.h"
00010 #include "../pdc/pdc.h"
00011 
00012 /*
00013 Huskeliste for å forandre innstans:
00014 - USART_ADDR må forandres
00015 - PIOMAP må oppdateres
00016 - Riktig usart modul på apba
00017 */
00018 
00019 /*SETTINGS */
00020 #define USART_ADDR AVR32_USART2_ADDRESS
00021 
00022 /*PDC stuff */
00023 char *usart_rx_buf = "1234";
00024 static int usart_rx_buf_size = 4;
00025 char *usart_tx_buf = "From pdc: Type 4 chars";
00026 static int usart_tx_buf_size= 22;
00027 
00028 void tick_delay();
00029 
00030 __int_handler *usart_int_handler()
00031 {
00032   volatile avr32_usart_t *usart = (void *) USART_ADDR;
00033 
00034   // RX PDC
00035         print(usart, "\n" );
00036         print_hex(usart, usart->csr);
00037         print(usart, "\n");
00038     print(usart, pdc_translatePtr(usart_rx_buf) );
00039         pdc_flushCache( pdc_translatePtr(usart_rx_buf), usart_rx_buf_size );
00040         pdc_setRxNextBuf( (void *) usart,
00041                         pdc_translatePtr( usart_rx_buf ), usart_rx_buf_size );
00042 
00043   return (void *) 0;
00044 }
00045 
00046 
00047 int main( void )
00048 {
00049   int cpu_hz = 20000000;
00050 
00051   volatile avr32_usart_t *usart = (void *) USART_ADDR;
00052   struct usart_options_t usart_opt;
00053 
00054   avr32_piomap_t usart_piomap = {                               \
00055     {AVR32_USART2_RXD_0_PIN, AVR32_USART2_RXD_0_FUNCTION},      \
00056     {AVR32_USART2_TXD_0_PIN, AVR32_USART2_TXD_0_FUNCTION},      \
00057     {AVR32_USART0_CLK_0_PIN, AVR32_USART0_CLK_0_FUNCTION},      \
00058     {AVR32_USART0_CTS_0_PIN, AVR32_USART0_CTS_0_FUNCTION},      \
00059     {AVR32_USART0_RTS_0_PIN, AVR32_USART0_RTS_0_FUNCTION}       \
00060   };
00061 
00062 
00063   /* Set options for the USART */
00064   usart_opt.baudrate = 57600;
00065   usart_opt.charlength = 8;
00066   usart_opt.paritytype = USART_NO_PARITY;
00067   usart_opt.stopbits = USART_1_STOPBIT;
00068   usart_opt.channelmode = USART_NORMAL_CHMODE;
00069 
00070   pio_enable_module( usart_piomap, 5 );
00071   usart_init_rs232( usart, &usart_opt, cpu_hz);
00072   print(usart, "\n\n.: USART PDC TEST :.\n");
00073 
00074   /* Setup interrupts */
00075   set_interrupts_base( (void *) AVR32_INTC_ADDRESS );
00076   print(usart, "\nInitializing interrupts\n");
00077   register_interrupt( (__int_handler) (usart_int_handler), AVR32_USART2_IRQ/32, AVR32_USART2_IRQ % 32, INT0);
00078   usart->ier = AVR32_USART_IER_ENDRX_MASK;
00079 
00080   //print(usart, "Setting up PDC\n");
00081   pdc_enable( (void *) USART_ADDR );
00082   pdc_setRxBuf((void *) USART_ADDR,
00083                 (void *) pdc_translatePtr(usart_rx_buf),
00084                 usart_rx_buf_size,
00085                 (void *) 0,
00086                 0);
00087   pdc_setTxBuf( (void *) USART_ADDR,
00088                 (void *) usart_tx_buf,
00089                 usart_tx_buf_size,
00090                 (void *) 0,
00091                 0);
00092 
00093   init_interrupts();
00094 
00095   while(1)
00096         tick_delay();
00097 
00098   return 42;
00099 
00100 }
00101 
00102 void tick_delay()
00103 {
00104         volatile avr32_usart_t *usart = (void *) USART_ADDR;
00105         int i;
00106 
00107         for(i=0; i<5000000;i++);
00108         print(usart, ".");
00109 }

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