00001
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #include "usart.h"
00060
00061 #define SUCCESS 0;
00062 #define FAILURE -1;
00063
00064 typedef unsigned char avr32_piomap_t[][2];
00065
00066
00067 void print(volatile struct avr32_usart_t * usart, char *str);
00068
00069
00070 int pio_enable_module(avr32_piomap_t piomap, unsigned int size);
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 #ifdef __ICCAVR32__
00084 #define AVR32_USART1_RXD_0_PIN 17
00085 #define AVR32_USART1_RXD_0_FUNCTION 0
00086 #define AVR32_USART1_TXD_0_PIN 18
00087 #define AVR32_USART1_TXD_0_FUNCTION 0
00088 #endif
00089
00090
00096 int main( void )
00097 {
00098 int cpu_hz = 20000000;
00099 struct usart_options_t opt;
00100
00101 volatile struct avr32_usart_t *usart = &AVR32_USART1;
00102
00103 avr32_piomap_t usart_piomap = { \
00104 {AVR32_USART1_RXD_0_PIN, AVR32_USART1_RXD_0_FUNCTION}, \
00105 {AVR32_USART1_TXD_0_PIN, AVR32_USART1_TXD_0_FUNCTION} \
00106 };
00107
00108
00109 opt.baudrate = 115200;
00110 opt.charlength = 8;
00111 opt.paritytype = USART_NO_PARITY;
00112 opt.stopbits = USART_1_STOPBIT;
00113 opt.channelmode = USART_NORMAL_CHMODE;
00114
00115
00116 usart_init_rs232(usart, &opt, cpu_hz);
00117
00118
00119 pio_enable_module(usart_piomap, 2);
00120
00121 print(usart, "This is AVR32 saying hello from the STK1000!\n");
00122
00123 return SUCCESS;
00124 }
00125
00126
00134 void print(volatile struct avr32_usart_t * usart, char *str)
00135 {
00136 while (*str != '\0')
00137 usart_putchar(usart, *str++);
00138 }
00139
00140
00150 int pio_enable_module(avr32_piomap_t piomap, unsigned int size)
00151 {
00152 int i;
00153 volatile struct avr32_pio_t *pio;
00154
00155
00156 switch (**piomap/32) {
00157
00158 case 0:
00159 pio = &AVR32_PIOA;
00160 break;
00161 case 1:
00162 pio = &AVR32_PIOB;
00163 break;
00164 case 2:
00165 pio = &AVR32_PIOC;
00166 break;
00167 case 3:
00168 pio = &AVR32_PIOD;
00169 break;
00170 case 4:
00171 pio = &AVR32_PIOE;
00172 break;
00173 default :
00174 return FAILURE;
00175
00176 }
00177
00178 for(i=0; i<size; i++){
00179
00180 pio->pdr |= ( 1<<( (**piomap) % 32) );
00181 pio->pudr |= ( 1<<( (**piomap) % 32) );
00182
00183 switch( *(*piomap+1) ){
00184 case 0:
00185 pio->asr |= ( 1<<( (**piomap) % 32) );
00186 break;
00187 case 1:
00188 pio->bsr |= ( 1<<( (**piomap) % 32) );
00189 break;
00190 default:
00191 return FAILURE;
00192 }
00193
00194 ++piomap;
00195
00196 }
00197
00198 return SUCCESS;
00199 }