This file gives an example of using the PDC to burst data on the USART. With and without the use of interrupts.
$Name$
Definition in file pdc_example.c.
#include <avr32/io.h>
#include "settings.h"
#include "usart.h"
#include "pdc.h"
Include dependency graph for pdc_example.c:
Go to the source code of this file.
Defines | |
| #define | MODE_INT 2 |
| #define | MODE_PDC 1 |
| #define | MODE_POLLED 0 |
| #define | RGB_BLUE 3 |
| #define | RGB_GREEN 2 |
| #define | RGB_OFF 0 |
| #define | RGB_ORANGE 4 |
| #define | RGB_RED 1 |
| #define | RGB_WHITE 5 |
Functions | |
| void | delay () |
| int | main (int argc, char *argv[]) |
| void | rgb_setColor (unsigned char color) |
| Function to set the color of the RGB LEDs. | |
| void | runningleds () |
Variables | |
| volatile avr32_pio_t * | pioa |
| volatile avr32_pio_t * | piob |
| unsigned char | runningleds_status |
| char * | string |
| char * | stringPDC |
| int | stringSize |
| int | stringSizePDC |
| volatile avr32_usart_t * | usart0 |
| #define MODE_INT 2 |
Definition at line 42 of file pdc_example.c.
| #define MODE_PDC 1 |
| #define MODE_POLLED 0 |
| #define RGB_BLUE 3 |
| #define RGB_GREEN 2 |
| #define RGB_OFF 0 |
| #define RGB_ORANGE 4 |
| #define RGB_RED 1 |
| #define RGB_WHITE 5 |
| void delay | ( | void | ) |
This function is a delay function that lasts for 1/4 second.
| none |
Definition at line 54 of file pdc_example.c.
References TIMEOUT.
Referenced by main().
00055 { 00056 unsigned int timeout = TIMEOUT; 00057 00058 do { 00059 --timeout; 00060 } while ( timeout > 0 ); 00061 }
| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) |
Definition at line 110 of file pdc_example.c.
References usart_options_t::baudrate, usart_options_t::channelmode, usart_options_t::charlength, CPUHZ, MODE_PDC, MODE_POLLED, usart_options_t::paritytype, pdc_flushCache(), pioa, piob, RGB_ORANGE, RGB_RED, rgb_setColor(), runningleds_status, usart_options_t::stopbits, string, stringPDC, stringSize, stringSizePDC, usart0, USART_1_STOPBIT, USART_BAUD, USART_BITS, usart_init2(), USART_NO_PARITY, and USART_NORMAL_CHMODE.
00111 { 00112 struct usart_options_t usartOptions; 00113 00114 /* Select PIO */ 00115 pioa = (volatile avr32_pio_t *) AVR32_PIOA_ADDRESS; 00116 piob = (volatile avr32_pio_t *) AVR32_PIOB_ADDRESS; 00117 00118 /* Select USART */ 00119 usart0 = (volatile avr32_usart_t *) AVR32_USART0_ADDRESS; 00120 00121 /* disable all interrupts on PIO */ 00122 pioa->idr = 0xFFFFffff; 00123 piob->idr = 0xFFFFffff; 00124 00125 /* Enable USART0, SPI and I2S on PIOA 00126 * USART0 is PA26 and PA27 00127 * USART0 is module A on PIOA 00128 */ 00129 pioa->pdr = 0x0C000000; 00130 pioa->asr = 0x0C000000; 00131 00132 /* Enable PIOB as debug output/input 00133 * Output: PB0, PB1, PB2, PB3, PB4, PB5, PB6 and PB7 00134 * Input: PB8, PB9, PB10, PB11, PB12, PB13, PB14 AND PB15 00135 */ 00136 piob->per = 0x000000FF; 00137 piob->oer = 0x00FF00FF; 00138 piob->odr = 0x0000FF00; 00139 piob->ifer = 0x0000FF00; 00140 piob->codr = 0xFFFFffff; 00141 piob->ower = 0x00FF00FF; 00142 00143 /* Set options for the USART */ 00144 usartOptions.baudrate = USART_BAUD; 00145 usartOptions.charlength = USART_BITS; 00146 usartOptions.paritytype = USART_NO_PARITY; 00147 usartOptions.stopbits = USART_1_STOPBIT; 00148 usartOptions.channelmode = USART_NORMAL_CHMODE; 00149 00150 /* Initialize USART in RS232 mode */ 00151 usart_init2( usart0, &usartOptions, CPUHZ ); 00152 00153 string = "POL: AVR32 PDC application demo\r\n"; 00154 stringPDC = "PDC: AVR32 PDC application demo\r\n"; 00155 00156 stringSize = 33; 00157 stringSizePDC = 33; 00158 00159 pdc_flushCache( string, stringSize ); 00160 pdc_flushCache( stringPDC, stringSizePDC ); 00161 00162 int mode = MODE_POLLED; 00163 rgb_setColor(RGB_RED); 00164 runningleds_status = 0; 00165 00166 for( ;; ) { 00167 00168 /* Actions 00169 * SW7 change mode to POLL 00170 * SW6 change mode to PDC 00171 * SW5 change mode to PDC + Interrupt 00172 */ 00173 if( (piob->pdsr & (1<<AVR32_PIO_P15)) == 0 ) { 00174 rgb_setColor(RGB_RED); 00175 mode = MODE_POLLED; 00176 } else if( (piob->pdsr & (1<<AVR32_PIO_P14)) == 0 ) { 00177 rgb_setColor(RGB_ORANGE); 00178 mode = MODE_PDC; 00179 } else if( (piob->pdsr & (1<<AVR32_PIO_P13)) == 0 ) { 00180 rgb_setColor(RGB_GREEN); 00181 mode = MODE_INT; 00182 } 00183 00184 00185 if( mode == MODE_POLLED ) { 00186 usart_writeLine( usart0, string ); 00187 } 00188 else if( mode == MODE_PDC ) { 00189 if( pdc_txBytesLeft( (void *) usart0 ) == 0 ) { 00190 pdc_setTxBuf( (void *) usart0, 00191 pdc_translatePtr( stringPDC ), 00192 stringSizePDC, 00193 0, 00194 0 ); 00195 } 00196 } 00197 else if( mode == MODE_INT ) { 00198 int interrupts_on = 1; 00199 00200 start_interrupts(); 00201 00202 do { 00203 /* SW7 and SW6 disables interrupts */ 00204 if( (piob->pdsr & (1<<AVR32_PIO_P15)) == 0 ) { 00205 rgb_setColor(RGB_RED); 00206 mode = MODE_POLLED; 00207 interrupts_on = 0; 00208 } else if( (piob->pdsr & (1<<AVR32_PIO_P14)) == 0 ) { 00209 rgb_setColor(RGB_ORANGE); 00210 mode = MODE_PDC; 00211 interrupts_on = 0; 00212 } 00213 00214 runningleds(); 00215 delay(); 00216 } while( interrupts_on == 1 ); 00217 00218 stop_interrupts(); 00219 } 00220 00221 runningleds(); 00222 delay(); 00223 } 00224 }
Here is the call graph for this function:
| void rgb_setColor | ( | unsigned char | color | ) |
Function to set the color of the RGB LEDs.
| color | The color of the LED
|
Definition at line 82 of file pdc_example.c.
References piob, RGB_BLUE, RGB_GREEN, RGB_OFF, RGB_ORANGE, RGB_RED, and RGB_WHITE.
Referenced by main().
00083 { 00084 piob->codr = 0x003F0000; 00085 00086 switch( color ) { 00087 case RGB_OFF: 00088 break; 00089 case RGB_RED: 00090 piob->sodr = 0x00030000; 00091 break; 00092 case RGB_GREEN: 00093 piob->sodr = 0x000C0000; 00094 break; 00095 case RGB_BLUE: 00096 piob->sodr = 0x00300000; 00097 break; 00098 case RGB_ORANGE: 00099 piob->sodr = 0x000F0000; 00100 break; 00101 case RGB_WHITE: 00102 piob->sodr = 0x003F0000; 00103 break; 00104 default: 00105 break; 00106 } 00107 }
| void runningleds | ( | ) |
Definition at line 64 of file pdc_example.c.
References piob, and runningleds_status.
00065 { 00066 runningleds_status <<= 1; 00067 runningleds_status ^= ( runningleds_status ^ 0x80 ) >> 7; 00068 piob->codr = 0x000000FF; 00069 piob->sodr = (long)runningleds_status; 00070 }
| volatile avr32_pio_t* pioa |
| volatile avr32_pio_t* piob |
Definition at line 50 of file pdc_example.c.
Referenced by main(), rgb_setColor(), and runningleds().
| unsigned char runningleds_status |
| char* string |
| char* stringPDC |
| int stringSize |
| int stringSizePDC |
| volatile avr32_usart_t* usart0 |
Definition at line 51 of file pdc_example.c.
Referenced by init_dbg_rs232(), main(), print_dbg(), print_dbg_hex(), and print_dbg_ulong().
1.5.1