pevc_example2.c File Reference


Detailed Description

PEVC example 2 application for AVR32 using Generic Clock as generator and DMA has event user.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file pevc_example2.c.

#include <avr32/io.h>
#include "board.h"
#include "intc.h"
#include "power_clocks_lib.h"
#include "pevc.h"
#include "gpio.h"
#include "usart.h"
#include "print_funcs.h"
#include "pdca.h"
#include "delay.h"

Go to the source code of this file.

Defines

#define FCPU_HZ   60000000
#define FPBA_HZ   60000000
#define PDCA_CHANNEL_IRQ   AVR32_PDCA_IRQ_0
#define PDCA_CHANNEL_USART   0
 The PDCA channel instance for the USART0 Tx.
#define PEVC_PDCA_SOT_USER   AVR32_PEVC_ID_USER_PDCA_0
#define STRING_TRANSFER_SIZE   36

Functions

void init_gclk (void)
void init_pdca (void)
void init_pevc (void)
void init_usart (void)
static void pdca_int_handler (void)
System Clock Frequencies
Initializes the MCU system clocks.

int main (void)

Variables

unsigned char aDataTransfered [STRING_TRANSFER_SIZE]
volatile avr32_pdca_channel_t * pdca_channel
volatile avr32_pm_t * pm = &AVR32_PM
volatile avr32_pevc_t * ppevc = &AVR32_PEVC
static volatile U32 u32PdcaIsr


Define Documentation

#define FCPU_HZ   60000000

Definition at line 114 of file pevc_example2.c.

#define FPBA_HZ   60000000

Definition at line 115 of file pevc_example2.c.

#define PDCA_CHANNEL_IRQ   AVR32_PDCA_IRQ_0

Definition at line 100 of file pevc_example2.c.

#define PDCA_CHANNEL_USART   0

The PDCA channel instance for the USART0 Tx.

Definition at line 99 of file pevc_example2.c.

#define PEVC_PDCA_SOT_USER   AVR32_PEVC_ID_USER_PDCA_0

Definition at line 101 of file pevc_example2.c.

#define STRING_TRANSFER_SIZE   36

Definition at line 95 of file pevc_example2.c.


Function Documentation

void init_gclk ( void   ) 

GCLK init.

Definition at line 220 of file pevc_example2.c.

Referenced by main().

00221 {
00222     scif_osc32_opt_t opt =
00223   {
00224     .mode = SCIF_OSC_MODE_2PIN_CRYSTAL,
00225     .startup = AVR32_SCIF_OSCCTRL32_STARTUP_0_RCOSC
00226   };
00227     
00228   scif_start_osc32(&opt,true);
00229   
00230   // Init GCLK clock
00231   scif_gclk_opt_t gclkOpt = 
00232   {
00233     .clock_source = SCIF_GCCTRL_OSC32K,
00234     .divider      = 255, 
00235     .diven        = 1
00236   }; // 32 678 / 512 = 64hz
00237   
00238   if(scif_start_gclk(AVR32_SCIF_GCLK_GCLK2_EVENT, &gclkOpt))
00239   {   
00240     // Error   
00241     while(1);    
00242   }
00243 }

void init_pdca ( void   ) 

PDCA init.

Definition at line 184 of file pevc_example2.c.

References aDataTransfered, pdca_channel, PDCA_CHANNEL_IRQ, PDCA_CHANNEL_USART, and pdca_int_handler().

00185 {
00186   // PDCA channel 0/1 options
00187   static const pdca_channel_options_t PDCA_CH_OPTIONS =
00188   {
00189     .addr = (void *)aDataTransfered,          // memory address
00190     .pid = AVR32_PDCA_PID_USART2_TX,          // select peripheral - data are transmit on USART TX line.
00191     .size = 0,                                // transfer counter
00192     .r_addr = (void *)aDataTransfered,        // next memory address
00193     .r_size = sizeof(aDataTransfered),        // next transfer counter
00194     .transfer_size = PDCA_TRANSFER_SIZE_BYTE, // select size of one data packet
00195     .etrig = ENABLED                          // Trigger transfer on event.
00196   };
00197   
00198   Disable_global_interrupt();
00199 
00200   // Register the PDCA interrupt handler to the interrupt controller.
00201   INTC_register_interrupt(&pdca_int_handler, PDCA_CHANNEL_IRQ, AVR32_INTC_INT0);
00202   
00203   Enable_global_interrupt();
00204     
00205   // Init PDCA channel with the pdca_options.
00206   pdca_init_channel(PDCA_CHANNEL_USART, &PDCA_CH_OPTIONS);
00207   pdca_channel = pdca_get_handler(PDCA_CHANNEL_USART); // For use in the pdca interrupt handler.
00208 
00209   // Enable pdca transfer error interrupt & transfer complete interrupt.
00210   pdca_enable_interrupt_transfer_error(PDCA_CHANNEL_USART);
00211   pdca_enable_interrupt_transfer_complete(PDCA_CHANNEL_USART);  
00212   
00213   // Enable the PDCA.
00214   pdca_enable(PDCA_CHANNEL_USART);
00215 }

void init_pevc ( void   ) 

PEVC init.

Definition at line 152 of file pevc_example2.c.

References AVR32_PEVC_ID_GEN_GCLK_0, pevc_channel_configure(), pevc_channels_enable(), PEVC_EVS_EVF_OFF, PEVC_EVS_EVR_ON, PEVC_EVS_IGF_OFF, PEVC_PDCA_SOT_USER, and ppevc.

00153 {
00154   
00155   // PEVC Event Shaper options.
00156   static const pevc_evs_opt_t PEVC_EVS_OPTIONS = 
00157   {
00158     .igfdr = 0x0A,            // Set the IGF clock (don't care here).
00159     .igf = PEVC_EVS_IGF_OFF,  // Input Glitch Filter off
00160     .evf = PEVC_EVS_EVF_OFF,   // Enable Event on falling edge
00161     .evr = PEVC_EVS_EVR_ON    // Enable Event on rising edge
00162   };
00163     
00164   // Configuring the PEVC path: 
00165   //  Change on pevc input pin0 event -> PDCA channel 0/1 trigger one transfer
00166   if(FAIL == pevc_channel_configure(ppevc, 
00167                                     PEVC_PDCA_SOT_USER, 
00168                                     AVR32_PEVC_ID_GEN_GCLK_0, 
00169                                     &PEVC_EVS_OPTIONS))
00170   {
00171     print_dbg("PEVC channel config failed!!!\r\n");
00172     gpio_clr_gpio_pin(LED2_GPIO);
00173     while(1);
00174   }
00175     
00176   // Enable the PEVC channel 0.
00177   pevc_channels_enable(ppevc, 1<<PEVC_PDCA_SOT_USER);
00178   
00179 }

void init_usart ( void   ) 

USART init.

Definition at line 141 of file pevc_example2.c.

References FCPU_HZ.

00142 {
00143 
00144   init_dbg_rs232(FCPU_HZ);
00145   print_dbg("\x0CPEVC Dirver - EXAMPLE 2\r\n");
00146   print_dbg("USART transfert using PEVC, Generic Clock and PDCA\r\n");
00147 }

int main ( void   ) 

Definition at line 268 of file pevc_example2.c.

References aDataTransfered, FCPU_HZ, init_gclk(), init_pdca(), init_pevc(), and init_usart().

00269 {
00270   int i;
00271  
00272   // Init the string with a simple recognizable pattern.
00273   for(i=0;i<sizeof(aDataTransfered);i++) {
00274     aDataTransfered[i] = '0' + (i%36);
00275   }
00276 
00277   init_sys_clocks();
00278     
00279   delay_init(FCPU_HZ);
00280   
00281   init_usart();
00282   
00283   gpio_clr_gpio_pin(LED0_GPIO);
00284   
00285   init_pdca();
00286   
00287   init_pevc();
00288   
00289   init_gclk();
00290   
00291   while(1)
00292   {
00293     gpio_tgl_gpio_pin(LED1_GPIO);
00294     delay_ms(500); //Wait 500Ms
00295   }
00296 }

static void pdca_int_handler ( void   )  [static]

PDCA Interrupts handler.

Definition at line 127 of file pevc_example2.c.

References aDataTransfered, pdca_channel, PDCA_CHANNEL_USART, and u32PdcaIsr.

00128 {
00129   u32PdcaIsr = pdca_channel->isr;
00130   if( u32PdcaIsr & (1<<AVR32_PDCA_ISR0_TRC_OFFSET) )
00131   {
00132     // Count the number of Transfer Complete interrupts.
00133     pdca_reload_channel(PDCA_CHANNEL_USART, (void *)aDataTransfered, sizeof( aDataTransfered ));
00134     print_dbg("\n");
00135   }
00136 }


Variable Documentation

unsigned char aDataTransfered[STRING_TRANSFER_SIZE]

Definition at line 118 of file pevc_example2.c.

volatile avr32_pdca_channel_t* pdca_channel

Definition at line 108 of file pevc_example2.c.

volatile avr32_pm_t* pm = &AVR32_PM

Definition at line 110 of file pevc_example2.c.

volatile avr32_pevc_t* ppevc = &AVR32_PEVC

Definition at line 109 of file pevc_example2.c.

volatile U32 u32PdcaIsr [static]

Definition at line 112 of file pevc_example2.c.


Generated on Thu Dec 17 19:58:50 2009 for AVR32 - PEVC Driver by  doxygen 1.5.5