pdc_example.c File Reference


Detailed Description

PDC and interrupt control example application.

This file gives an example of using the PDC to burst data on the USART. With and without the use of interrupts.

Author:
Atmel Corporation: http://www.atmel.com
Support email: avr32@atmel.com
Name
RELEASE_1_0
Revision
1.11
RCSfile
pdc_example.c,v
Date
2006/05/09 10:32:56

Definition in file pdc_example.c.

#include <avr32/io.h>
#include "settings.h"
#include "usart.h"
#include "pdc.h"
#include "interrupt_gcc.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

Typedefs

typedef unsigned char avr32_piomap_t [][2]
 Map over PIO for setup of peripherals.

Functions

void delay (int delay)
 Delay function.
void do_interrupt_mode (volatile avr32_pio_t *piob, volatile avr32_pio_t *pioc, int *mode, unsigned char *leds)
 Function while operating in interrupt mode.
int main ()
 Main function, application starts executing here after stack pointer is initialized.
int pio_enable_module (avr32_piomap_t piomap, unsigned int size)
 Set the pins under module control.
void rgb_setColor (volatile avr32_pio_t *pio, unsigned char color)
 Function to set the color of the RGB LEDs.


Define Documentation

#define MODE_INT   2
 

Definition at line 119 of file pdc_example.c.

#define MODE_PDC   1
 

Definition at line 118 of file pdc_example.c.

#define MODE_POLLED   0
 

Definition at line 117 of file pdc_example.c.

Referenced by do_interrupt_mode(), and main().

#define RGB_BLUE   3
 

Definition at line 113 of file pdc_example.c.

Referenced by rgb_setColor().

#define RGB_GREEN   2
 

Definition at line 112 of file pdc_example.c.

Referenced by rgb_setColor().

#define RGB_OFF   0
 

Definition at line 110 of file pdc_example.c.

Referenced by rgb_setColor().

#define RGB_ORANGE   4
 

Definition at line 114 of file pdc_example.c.

Referenced by rgb_setColor().

#define RGB_RED   1
 

Definition at line 111 of file pdc_example.c.

Referenced by do_interrupt_mode(), main(), and rgb_setColor().

#define RGB_WHITE   5
 

Definition at line 115 of file pdc_example.c.

Referenced by rgb_setColor().


Typedef Documentation

typedef unsigned char avr32_piomap_t[][2]
 

Map over PIO for setup of peripherals.

Definition at line 122 of file pdc_example.c.


Function Documentation

void delay int  delay  ) 
 

Delay function.

Definition at line 129 of file pdc_example.c.

References TIMEOUT.

00130 {
00131     unsigned int timeout = delay * TIMEOUT;
00132 
00133     do {
00134         --timeout;
00135     } while (timeout > 0);
00136 }

void do_interrupt_mode volatile avr32_pio_t *  piob,
volatile avr32_pio_t *  pioc,
int *  mode,
unsigned char *  leds
 

Function while operating in interrupt mode.

Definition at line 180 of file pdc_example.c.

References MODE_POLLED, RGB_RED, rgb_setColor(), and start_interrupts().

00183 {
00184     start_interrupts();
00185 
00186     for (;;) {
00187         /* SW7 and SW6 disables interrupts */
00188         if ((piob->pdsr & AVR32_PIO_P7_MASK) == 0) {
00189             rgb_setColor(pioc, RGB_RED);
00190             *mode = MODE_POLLED;
00191             goto stop_int;
00192         } else if ((piob->pdsr & AVR32_PIO_P6_MASK) == 0) {
00193             rgb_setColor(pioc, RGB_GREEN);
00194             *mode = MODE_PDC;
00195             goto stop_int;
00196         }
00197 
00198         *leds <<= 1;
00199         *leds ^= (*leds ^ 0x80) >> 7;
00200         pioc->codr = 0x000000FF;
00201         pioc->sodr = (long) *leds;
00202         delay(10);
00203     }
00204 
00205 stop_int:
00206     stop_interrupts();
00207 }

Here is the call graph for this function:

int main  ) 
 

Main function, application starts executing here after stack pointer is initialized.

Definition at line 213 of file pdc_example.c.

References __attribute__(), usart_options_t::baudrate, usart_options_t::channelmode, usart_options_t::charlength, CPUHZ, init_usart_interrupts(), MODE_POLLED, usart_options_t::paritytype, pdc_flushCache(), pio_enable_module(), RGB_RED, rgb_setColor(), usart_options_t::stopbits, USART_1_STOPBIT, USART_BAUD, USART_BITS, usart_linit(), USART_MODULE, USART_NO_PARITY, and USART_NORMAL_CHMODE.

00214 {
00215     /* Initialize interrupts */
00216     init_usart_interrupts();
00217 
00218     avr32_piomap_t usart_piomap = {
00219         {AVR32_USART1_RXD_0_PIN, AVR32_USART1_RXD_0_FUNCTION}, \
00220         {AVR32_USART1_TXD_0_PIN, AVR32_USART1_TXD_0_FUNCTION}, \
00221     };
00222 
00223     char * string;
00224     int stringSize;
00225 #ifdef __GNUC__
00226     char * stringPDC __attribute__((aligned(32)));
00227 #elif __ICCAVR32__
00228     char * stringPDC;
00229 #else
00230 #error Unknown compiler used, stringPDC must be alligned to work as intended
00231 #endif
00232     int stringSizePDC;
00233     volatile avr32_pio_t * piob;
00234     volatile avr32_pio_t * pioc;
00235     volatile struct avr32_usart_t * usart;
00236     struct usart_options_t usartOptions;
00237 
00238     /* Select PIO */
00239     piob = &AVR32_PIOB;
00240     pioc = &AVR32_PIOC;
00241 
00242     /* Select USART */
00243     usart = &USART_MODULE;
00244 
00245     /* disable all interrupts on PIO */
00246     piob->idr = 0xFFFFffff;
00247     pioc->idr = 0xFFFFffff;
00248 
00249     /* Enable USART on PIOA */
00250     pio_enable_module(usart_piomap, 2);
00251 
00252     /* Enable PIOB as debug output
00253      * Output: PC0 => PC15
00254      *
00255      * Enable PIOC as debug input
00256      * Input: PB0 => BP7
00257      */
00258     piob->per = 0x000000FF;
00259     piob->odr = 0x000000FF;
00260     piob->puer = 0x000000FF;
00261 
00262     pioc->per = 0x0000FFFF;
00263     pioc->oer = 0x0000FFFF;
00264     pioc->ower = 0x0000FFFF;
00265     pioc->odsr = 0x0000FFFF;
00266 
00267     /* Set options for the USART */
00268     usartOptions.baudrate = USART_BAUD;
00269     usartOptions.charlength = USART_BITS;
00270     usartOptions.paritytype = USART_NO_PARITY;
00271     usartOptions.stopbits = USART_1_STOPBIT;
00272     usartOptions.channelmode = USART_NORMAL_CHMODE;
00273 
00274     /* Initialize USART in RS232 mode */
00275     usart_linit(usart, &usartOptions, CPUHZ);
00276 
00277     string = "POL: AVR32 PDC application demo\r\n";
00278     stringPDC = "PDC: AVR32 PDC application demo\r\n";
00279 
00280     stringSize = 33;
00281     stringSizePDC = 33;
00282 
00283     pdc_flushCache(string, stringSize/4);
00284     pdc_flushCache(stringPDC, stringSizePDC/4);
00285 
00286     int mode = MODE_POLLED;
00287     rgb_setColor(pioc, RGB_RED);
00288 
00289     unsigned char leds = 0;
00290 
00291     for (;;) {
00292         leds <<= 1;
00293         leds ^= (leds ^ 0x80) >> 7;
00294         pioc->codr = 0x000000FF;
00295         pioc->sodr = (long) leds;
00296 
00297         /* Actions
00298          * SW7 change mode to POLL
00299          * SW6 change mode to PDC
00300          * SW5 change mode to PDC + Interrupt
00301          */
00302         if ((piob->pdsr & AVR32_PIO_P7_MASK) == 0) {
00303             rgb_setColor(pioc, RGB_RED);
00304             mode = MODE_POLLED;
00305         } else if ((piob->pdsr & AVR32_PIO_P6_MASK) == 0) {
00306             rgb_setColor(pioc, RGB_GREEN);
00307             mode = MODE_PDC;
00308         } else if ((piob->pdsr & AVR32_PIO_P5_MASK) == 0) {
00309             rgb_setColor(pioc, RGB_BLUE);
00310             mode = MODE_INT;
00311         }
00312 
00313 
00314         if (mode == MODE_POLLED) {
00315             usart_lwriteLine(usart, string);
00316         }
00317         else if (mode == MODE_PDC) {
00318             if (pdc_txBytesLeft((void *) usart) == 0) {
00319                 pdc_setTxBuf((void *) usart,
00320                         pdc_translatePtr(stringPDC),
00321                         stringSizePDC,
00322                         pdc_translatePtr(stringPDC),
00323                         stringSizePDC);
00324             }
00325         }
00326         else if (mode == MODE_INT) {
00327             do_interrupt_mode(piob, pioc, &mode, &leds);
00328         }
00329 
00330         delay(10);
00331     }
00332 }

Here is the call graph for this function:

int pio_enable_module avr32_piomap_t  piomap,
unsigned int  size
 

Set the pins under module control.

Parameters:
piomap a map describing how the setup of the PIO
size number of elements in the map
Returns:
Status or error code
Return values:
USART_OK on success
USART_ERROR_ARGUMENT on bad values in piomap

Definition at line 344 of file pdc_example.c.

References USART_ERROR_ARGUMENT.

Referenced by main().

00345 {
00346     int i;
00347     volatile struct avr32_pio_t *pio;
00348 
00349     /* get the base address for the port */
00350     switch(**piomap/32) {
00351 
00352         case 0:
00353             pio = &AVR32_PIOA;
00354             break;
00355         case 1:
00356             pio = &AVR32_PIOB;
00357             break;
00358         case 2:
00359             pio = &AVR32_PIOC;
00360             break;
00361         case 3:
00362             pio = &AVR32_PIOD;
00363             break;
00364         case 4:
00365             pio = &AVR32_PIOE;
00366             break;
00367         default :
00368             return USART_ERROR_ARGUMENT;
00369 
00370     }
00371 
00372     for (i = 0; i < size; i++){
00373 
00374         pio->pdr |= (1<<((**piomap) % 32));
00375         pio->pudr |= (1<<((**piomap) % 32));
00376 
00377         switch(*(*piomap+1)){
00378             case 0:
00379                 pio->asr |= (1<<((**piomap) % 32));
00380                 break;
00381             case 1:
00382                 pio->bsr |= (1<<((**piomap) % 32));
00383                 break;
00384             default:
00385                 return USART_ERROR_ARGUMENT;
00386         }
00387 
00388         ++piomap;
00389 
00390     }
00391 
00392     return USART_OK;
00393 }

void rgb_setColor volatile avr32_pio_t *  pio,
unsigned char  color
 

Function to set the color of the RGB LEDs.

Parameters:
pio pointer to the base address of PIO connected to RGBs
color The color of the LED
  • 0 Off
  • 1 red
  • 2 green
  • 3 blue
  • 4 orange
  • 5 white

Definition at line 150 of file pdc_example.c.

References RGB_BLUE, RGB_GREEN, RGB_OFF, RGB_ORANGE, RGB_RED, and RGB_WHITE.

Referenced by do_interrupt_mode(), and main().

00151 {
00152     pio->codr = 0x00003F00;
00153 
00154     switch(color) {
00155         case RGB_OFF:
00156             break;
00157         case RGB_RED:
00158             pio->sodr = 0x00000300;
00159             break;
00160         case RGB_GREEN:
00161             pio->sodr = 0x00000C00;
00162             break;
00163         case RGB_BLUE:
00164             pio->sodr = 0x00003000;
00165             break;
00166         case RGB_ORANGE:
00167             pio->sodr = 0x00000F00;
00168             break;
00169         case RGB_WHITE:
00170             pio->sodr = 0x00003F00;
00171             break;
00172         default:
00173             break;
00174     }
00175 }


Generated on Wed May 10 15:03:14 2006 for AVR32108 - Peripheral Direct Memory Access Driver by  doxygen 1.4.6-NO