usart_backup.c

Go to the documentation of this file.
00001 #include <avr32/io.h>
00002 #include <sys/interrupts.h>
00003 // #include <stdio.h>
00004 #include "usart.h"
00005 #include "../pio/pio.h"
00006 #include "../debug/print_funcs.h"
00007 #include "../inc/macro.h"
00008 #include "../power_manager/pm.h"
00009 #include "../running_lights/running_lights.h"
00010 
00011 #include <avr32/intc.h>
00012 #include <sys/interrupts.h>
00013 
00014 extern void set_irq_handler(void*);
00015 
00016 /* Interrupt handlers for USART */
00017 __int_handler *usart_rxrdy()
00018 {
00019   volatile avr32_usart_t * usart = (void *) AVR32_USART0_ADDRESS;
00020 //  usart_write_char( usart, usart_getchar(usart) );
00021   print(usart, "RXRDY interrupt\n\r");
00022 //  print_ulong(usart,pm_read_mclk() );
00023   return (void *) AVR32_RAR_SUP;
00024 }
00025 
00026 __int_handler *usart_txrdy()
00027 {
00028   volatile avr32_usart_t * usart = (void *) AVR32_USART0_ADDRESS;
00029   print(usart, "TXRDY interrupt\n\r");
00030   return (void *) AVR32_RAR_SUP;
00031 }
00032 
00033 __int_handler *usart_rxbrk()
00034 {
00035   volatile avr32_usart_t * usart = (void *) AVR32_USART0_ADDRESS;
00036   print(usart, "RXBRK interrupt\n\r");
00037   return (void *) AVR32_RAR_SUP;
00038 }
00039 
00040 __int_handler *usart_endrx()
00041 {
00042   volatile avr32_usart_t * usart = (void *) AVR32_USART0_ADDRESS;
00043   print(usart, "ENDRX interrupt\n\r");
00044   return (void *) AVR32_RAR_SUP;
00045 }
00046 
00047 __int_handler *usart_endtx()
00048 {
00049   volatile avr32_usart_t * usart = (void *) AVR32_USART0_ADDRESS;
00050   print(usart, "ENDTX interrupt\n\r");
00051   return (void *) AVR32_RAR_SUP;
00052 }
00053 
00054 __int_handler *usart_txbfe()
00055 {
00056   volatile avr32_usart_t * usart = (void *) AVR32_USART0_ADDRESS;
00057   print(usart, "TXBUFE interrupt\n\r");
00058   return (void *) AVR32_RAR_SUP;
00059 }
00060 
00061 __int_handler *usart_rxbuff()
00062 {
00063   volatile avr32_usart_t * usart = (void *) AVR32_USART0_ADDRESS;
00064   print(usart, "RXBUFF interrupt\n\r");
00065   return (void *) AVR32_RAR_SUP;
00066 }
00067 
00068 
00069 int main( void )
00070 {
00071   int cpu_hz = 20000000;
00072   struct usart_options_t opt;
00073 
00074   volatile avr32_usart_t * usart = (void *) AVR32_USART0_ADDRESS;
00075 
00076   avr32_piomap_t usart0_piomap = {                              \
00077     {AVR32_USART0_RXD_0_PIN, AVR32_USART0_RXD_0_FUNCTION},      \
00078     {AVR32_USART0_TXD_0_PIN, AVR32_USART0_TXD_0_FUNCTION},      \
00079     {AVR32_USART0_CLK_0_PIN, AVR32_USART0_CLK_0_FUNCTION},      \
00080     {AVR32_USART0_CTS_0_PIN, AVR32_USART0_CTS_0_FUNCTION},      \
00081     {AVR32_USART0_RTS_0_PIN, AVR32_USART0_RTS_0_FUNCTION}       \
00082   };
00083 
00084   /* Set 12 MHz clock */
00085 
00086 
00087 
00088   /* Set options for the USART */
00089   opt.baudrate = 19200;
00090   opt.charlength = 8;
00091   opt.paritytype = USART_NO_PARITY;
00092   opt.stopbits = USART_1_STOPBIT;
00093   opt.channelmode = USART_NORMAL_CHMODE;
00094 
00095   /* Initialize it in RS232 mode */
00096   usart_init_rs232(usart, &opt, cpu_hz);
00097 
00098   /* Setup pio for USART */
00099   pio_setup_port(usart0_piomap, 2);
00100 
00101   /* Setup interrupts */
00102   set_interrupts_base( (void *) AVR32_INTC_ADDRESS );
00103   init_interrupts();
00104   /* Add handlers here */
00105   register_interrupt( (__int_handler) (usart_rxrdy), AVR32_USART0_IRQ/32, AVR32_USART0_IRQ % 32, INT0);
00106 
00107   /* Enable usasrt interrupts here */
00108   usart->ier = 0x00FFffff;
00109   // (1<<INT_RXRDY) | (1<<INT_TXRDY) | (1<<INT_RXBRK) | (1<<INT_ENDRX) | (1<<INT_ENDTX) | (1<<INT_TXBUFE) | (1<<INT_RXBUFF);
00110 
00111   while(1);
00112 
00113   return 42;
00114 }

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