pevc_example2.c File Reference


Detailed Description

PEVC example 2 application for AVR32 using Generic Clock as generator and PDCA as 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
 Size of the string to transfer to USART0 through the PDCA.

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 108 of file pevc_example2.c.

Referenced by init_usart(), and main().

#define FPBA_HZ   60000000

Definition at line 109 of file pevc_example2.c.

Referenced by main(), and twi_init().

#define PDCA_CHANNEL_IRQ   AVR32_PDCA_IRQ_0

Definition at line 98 of file pevc_example2.c.

Referenced by init_pdca().

#define PDCA_CHANNEL_USART   0

The PDCA channel instance for the USART0 Tx.

Definition at line 97 of file pevc_example2.c.

Referenced by init_pdca(), and pdca_int_handler().

#define PEVC_PDCA_SOT_USER   AVR32_PEVC_ID_USER_PDCA_0

Definition at line 99 of file pevc_example2.c.

Referenced by init_pevc().

#define STRING_TRANSFER_SIZE   36

Size of the string to transfer to USART0 through the PDCA.

Definition at line 93 of file pevc_example2.c.


Function Documentation

void init_gclk ( void   ) 

GCLK init.

Definition at line 214 of file pevc_example2.c.

Referenced by main().

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

void init_pdca ( void   ) 

PDCA init.

Definition at line 178 of file pevc_example2.c.

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

Referenced by main().

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

void init_pevc ( void   ) 

PEVC init.

Definition at line 147 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.

Referenced by main().

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

void init_usart ( void   ) 

USART init.

Definition at line 136 of file pevc_example2.c.

References FCPU_HZ.

Referenced by main().

00137 {
00138 
00139   init_dbg_rs232(FCPU_HZ);
00140   print_dbg("\x0CPEVC Driver - EXAMPLE 2\r\n");
00141   print_dbg("USART transfer using PEVC, Generic Clock and PDCA\r\n");
00142 }

int main ( void   ) 

Definition at line 262 of file pevc_example2.c.

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

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

static void pdca_int_handler ( void   )  [static]

PDCA Interrupts handler.

Definition at line 122 of file pevc_example2.c.

References aDataTransfered, pdca_channel, PDCA_CHANNEL_USART, and u32PdcaIsr.

Referenced by init_pdca().

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


Variable Documentation

unsigned char aDataTransfered[STRING_TRANSFER_SIZE]

Definition at line 112 of file pevc_example2.c.

Referenced by init_pdca(), main(), and pdca_int_handler().

volatile avr32_pdca_channel_t* pdca_channel

Definition at line 101 of file pevc_example2.c.

Referenced by init_pdca(), and pdca_int_handler().

volatile avr32_pm_t* pm = &AVR32_PM

Definition at line 103 of file pevc_example2.c.

volatile avr32_pevc_t* ppevc = &AVR32_PEVC

Definition at line 102 of file pevc_example2.c.

Referenced by init_pevc(), pevc_ovr_int_handler(), and pevc_trg_int_handler().

volatile U32 u32PdcaIsr [static]

Definition at line 105 of file pevc_example2.c.

Referenced by pdca_int_handler().


Generated on Fri Feb 19 02:25:32 2010 for AVR32 - PEVC Driver Example 3 by  doxygen 1.5.5