pevc_example1.c File Reference


Detailed Description

PEVC example 1 application for AVR32 using AST 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_example1.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 "ast.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
#define PEVC_PDCA_SOT_USER   AVR32_PEVC_ID_USER_PDCA_0
String transfert size
#define STRING_TRANSFER_SIZE   36

Functions

void init_ast (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)
 This example show a DMA transfert to USART controlled by the AST peridic alarm using the PEVC.

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 94 of file pevc_example1.c.

Referenced by init_usart(), and main().

#define FPBA_HZ   60000000

Definition at line 95 of file pevc_example1.c.

Referenced by main(), and twi_init().

#define PDCA_CHANNEL_IRQ   AVR32_PDCA_IRQ_0

Definition at line 111 of file pevc_example1.c.

Referenced by init_pdca().

#define PDCA_CHANNEL_USART   0

The PDCA channel instance for the USART0 Tx

Definition at line 110 of file pevc_example1.c.

Referenced by init_pdca(), and pdca_int_handler().

#define PEVC_PDCA_SOT_USER   AVR32_PEVC_ID_USER_PDCA_0

Definition at line 112 of file pevc_example1.c.

Referenced by init_pdca(), and init_pevc().

#define STRING_TRANSFER_SIZE   36

Definition at line 100 of file pevc_example1.c.


Function Documentation

void init_ast ( void   ) 

AST Init.

Definition at line 221 of file pevc_example1.c.

Referenced by main().

00222 {
00223   
00224   avr32_ast_pir0_t pir = {
00225     .insel = 14 // Set a event every second 
00226   };
00227   
00228   ast_calendar_t ast_calendar;
00229   ast_calendar.FIELD.sec  = 30;
00230   ast_calendar.FIELD.min  = 45;
00231   ast_calendar.FIELD.hour = 12;
00232   ast_calendar.FIELD.day  = 7;
00233   ast_calendar.FIELD.month= 10;
00234   ast_calendar.FIELD.year = 9;    
00235 
00236   
00237   // Initialize the AST
00238   if (!ast_init_calendar(&AVR32_AST, AST_OSC_32KHZ, AST_PSEL_32KHZ_1HZ, ast_calendar))
00239   {
00240     print_dbg("Error initializing the AST\r\n");
00241     while(1);
00242   }
00243   
00244   ast_set_periodic0_value(&AVR32_AST,pir);
00245   
00246   ast_enable_periodic0(&AVR32_AST);
00247  
00248   // Clear All Interrupt
00249   AVR32_AST.scr=0xFFFFFFFF;
00250 
00251   // Enable the AST
00252   ast_enable(&AVR32_AST);
00253 }

void init_pdca ( void   ) 

PDCA Init.

Definition at line 182 of file pevc_example1.c.

References aDataTransfered, pdca_channel, PDCA_CHANNEL_IRQ, PDCA_CHANNEL_USART, pdca_int_handler(), PEVC_CHANNELS_ENABLE, PEVC_PDCA_SOT_USER, and ppevc.

Referenced by main().

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

void init_pevc ( void   ) 

PEVC Init.

Definition at line 160 of file pevc_example1.c.

References AVR32_PEVC_ID_GEN_AST_PER0, pevc_channel_configure(), pevc_channels_enable(), PEVC_PDCA_SOT_USER, and ppevc.

Referenced by main().

00161 {
00162   
00163   // Configuring the PEVC path: Change on pevc input pin0 event -> PDCA channel 0/1 trigger one transfer
00164   if(FAIL == pevc_channel_configure(ppevc, 
00165                                     PEVC_PDCA_SOT_USER, 
00166                                     AVR32_PEVC_ID_GEN_AST_PER0, 
00167                                     NULL))
00168   {
00169     print_dbg("PEVC channel config failed!!!\r\n");
00170     gpio_clr_gpio_pin(LED2_GPIO);
00171     while(1);
00172   }
00173     
00174   // Enable the PEVC channel 0.
00175   pevc_channels_enable(ppevc, 1<<PEVC_PDCA_SOT_USER);
00176   
00177 }

void init_usart ( void   ) 

USART init.

Definition at line 150 of file pevc_example1.c.

References FCPU_HZ.

Referenced by main().

00151 {
00152   init_dbg_rs232(FCPU_HZ);
00153   print_dbg("\x0CPEVC Dirver - EXAMPLE 1\r\n");
00154   print_dbg("USART transfert using PEVC, AST and PDCA\r\n");
00155 }

int main ( void   ) 

This example show a DMA transfert to USART controlled by the AST peridic alarm using the PEVC.

Definition at line 281 of file pevc_example1.c.

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

00282 {
00283   int i;
00284   
00285   // Init the string with a simple recognizable pattern.
00286   for(i=0;i<sizeof(aDataTransfered);i++)
00287     aDataTransfered[i] = '0' + (i%36);
00288   
00289   init_sys_clocks();
00290     
00291   delay_init(FCPU_HZ);
00292   
00293   init_usart();
00294   
00295   gpio_clr_gpio_pin(LED0_GPIO);
00296     
00297   init_pevc();
00298 
00299   init_ast();
00300   
00301   init_pdca();
00302   
00303   while(1)
00304   {
00305     gpio_tgl_gpio_pin(LED1_GPIO);
00306     delay_ms(500); //Wait 500Ms
00307   }
00308 }

static void pdca_int_handler ( void   )  [static]

PDCA Interrupts handler.

Definition at line 136 of file pevc_example1.c.

References aDataTransfered, pdca_channel, PDCA_CHANNEL_USART, and u32PdcaIsr.

Referenced by init_pdca().

00137 {
00138   u32PdcaIsr = pdca_channel->isr;
00139   if( u32PdcaIsr & (1<<AVR32_PDCA_ISR0_TRC_OFFSET) )
00140   {
00141     // Count the number of Transfer Complete interrupts.
00142     pdca_reload_channel(PDCA_CHANNEL_USART, (void *)aDataTransfered, sizeof( aDataTransfered ));
00143     print_dbg("\n");
00144   }
00145 }


Variable Documentation

unsigned char aDataTransfered[STRING_TRANSFER_SIZE]

Definition at line 126 of file pevc_example1.c.

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

volatile avr32_pdca_channel_t* pdca_channel

Definition at line 119 of file pevc_example1.c.

Referenced by init_pdca(), and pdca_int_handler().

volatile avr32_pm_t* pm = &AVR32_PM

Definition at line 121 of file pevc_example1.c.

volatile avr32_pevc_t* ppevc = &AVR32_PEVC

Definition at line 120 of file pevc_example1.c.

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

volatile U32 u32PdcaIsr [static]

Definition at line 123 of file pevc_example1.c.

Referenced by pdca_int_handler().


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