usart_example1.c

Go to the documentation of this file.
00001 #include "usart.h"
00002 #include "../pio/pio.h"
00003 #include "../debug/print_funcs.h"
00004 
00005 #include <sys/interrupts.h>
00006 #include <avr32/intc.h>
00007 
00008 /*
00009 Huskeliste for å forandre innstans:
00010 - USART_ADDR må forandres
00011 - PIOMAP må oppdateres
00012 - Riktig IRQ må settes
00013 */
00014 
00015 #define USART_ADDR AVR32_USART2_ADDRESS
00016 
00017 /* interrupt handler for usart */
00018 __int_handler *usart_int_handler()
00019 {
00020   volatile avr32_usart_t * usart = (void *) USART_ADDR;
00021 /*
00022   print_hex( usart, usart->csr);
00023   print(usart, "\n\r");
00024 */
00025   print_char( usart, usart_getchar(usart) );
00026 
00027   return (void *) 0;
00028 }
00029 
00030 int main( void )
00031 {
00032   int cpu_hz = 20000000;
00033   struct usart_options_t opt;
00034 
00035   volatile avr32_usart_t *usart = (void *) USART_ADDR;
00036 
00037   avr32_piomap_t usart_piomap = {                               \
00038     {AVR32_USART2_RXD_0_PIN, AVR32_USART2_RXD_0_FUNCTION},      \
00039     {AVR32_USART2_TXD_0_PIN, AVR32_USART2_TXD_0_FUNCTION},      \
00040     {AVR32_USART0_CLK_0_PIN, AVR32_USART0_CLK_0_FUNCTION},      \
00041     {AVR32_USART0_CTS_0_PIN, AVR32_USART0_CTS_0_FUNCTION},      \
00042     {AVR32_USART0_RTS_0_PIN, AVR32_USART0_RTS_0_FUNCTION}       \
00043   };
00044 
00045   // Set options for the USART
00046   opt.baudrate = 57600;
00047   opt.charlength = 8;
00048   opt.paritytype = USART_NO_PARITY;
00049   opt.stopbits = USART_1_STOPBIT;
00050   opt.channelmode = USART_NORMAL_CHMODE;
00051 
00052   // Initialize it in RS232 mode
00053   usart_init_rs232(usart, &opt, cpu_hz);
00054 
00055   // Setup pio for USART
00056   pio_enable_module(usart_piomap, 2);
00057 
00058   print(usart, "soo many assholes,so few.... bullets.\n");
00059 
00060   /* Setup interrupts */
00061   set_interrupts_base( (void *) AVR32_INTC_ADDRESS );
00062   print(usart, "\nSetting interrupts base...\n");
00063   register_interrupt( (__int_handler) (usart_int_handler), AVR32_USART2_IRQ/32, AVR32_USART2_IRQ % 32, INT0);
00064   print(usart, "Adding interrupt handler...\n");
00065   init_interrupts();
00066   print(usart, "Initializing interrupts\n");
00067   usart->ier = 0x000Fffff;
00068   // (1<<INT_RXRDY) | (1<<INT_TXRDY) | (1<<INT_RXBRK) | (1<<INT_ENDRX) | (1<<INT_ENDTX) | (1<<INT_TXBUFE) | (1<<INT_RXBUFF)
00069 
00070   while(1);
00071 
00072   return 42;
00073 }

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