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 transfer 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 FCPU_HZ 60000000 |
#define FPBA_HZ 60000000 |
Definition at line 95 of file pevc_example1.c.
#define PDCA_CHANNEL_IRQ AVR32_PDCA_IRQ_0 |
#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 |
#define STRING_TRANSFER_SIZE 36 |
Definition at line 100 of file pevc_example1.c.
void init_ast | ( | void | ) |
AST Init.
Definition at line 220 of file pevc_example1.c.
Referenced by main().
00221 { 00222 00223 avr32_ast_pir0_t pir = { 00224 .insel = 14 // Set a event every second 00225 }; 00226 00227 ast_calendar_t ast_calendar; 00228 ast_calendar.FIELD.sec = 30; 00229 ast_calendar.FIELD.min = 45; 00230 ast_calendar.FIELD.hour = 12; 00231 ast_calendar.FIELD.day = 7; 00232 ast_calendar.FIELD.month= 10; 00233 ast_calendar.FIELD.year = 9; 00234 00235 00236 // Initialize the AST 00237 if (!ast_init_calendar(&AVR32_AST, AST_OSC_32KHZ, AST_PSEL_32KHZ_1HZ, ast_calendar)) 00238 { 00239 print_dbg("Error initializing the AST\r\n"); 00240 while(1); 00241 } 00242 00243 ast_set_periodic0_value(&AVR32_AST,pir); 00244 00245 ast_enable_periodic0(&AVR32_AST); 00246 00247 // Clear All Interrupt 00248 AVR32_AST.scr=0xFFFFFFFF; 00249 00250 // Enable the AST 00251 ast_enable(&AVR32_AST); 00252 }
void init_pdca | ( | void | ) |
PDCA Init.
Definition at line 181 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().
00182 { 00183 // PDCA channel 0/1 options 00184 static const pdca_channel_options_t PDCA_CH_OPTIONS = 00185 { 00186 .addr = (void *)aDataTransfered, // memory address 00187 .pid = AVR32_PDCA_PID_USART2_TX, // select peripheral - data are transmit on USART TX line. 00188 .size = 0, // transfer counter 00189 .r_addr = (void *)aDataTransfered, // next memory address 00190 .r_size = sizeof(aDataTransfered), // next transfer counter 00191 .transfer_size = PDCA_TRANSFER_SIZE_BYTE, // select size of one data packet 00192 .etrig = ENABLED // Trigger transfer on event. 00193 }; 00194 00195 Disable_global_interrupt(); 00196 00197 // Register the PDCA interrupt handler to the interrupt controller. 00198 INTC_register_interrupt(&pdca_int_handler, PDCA_CHANNEL_IRQ, AVR32_INTC_INT0); 00199 00200 Enable_global_interrupt(); 00201 00202 // Init PDCA channel with the pdca_options. 00203 pdca_init_channel(PDCA_CHANNEL_USART, &PDCA_CH_OPTIONS); 00204 pdca_channel = pdca_get_handler(PDCA_CHANNEL_USART); // For use in the pdca interrupt handler. 00205 00206 // Enable pdca transfer error interrupt & transfer complete interrupt. 00207 pdca_enable_interrupt_transfer_error(PDCA_CHANNEL_USART); 00208 pdca_enable_interrupt_transfer_complete(PDCA_CHANNEL_USART); 00209 00210 // Enable the PEVC channel "PDCA CHANNEL 0/1 ONE-ITEM-TRANSFER" 00211 PEVC_CHANNELS_ENABLE(ppevc, 1<<PEVC_PDCA_SOT_USER); 00212 00213 // Enable the PDCA. 00214 pdca_enable(PDCA_CHANNEL_USART); 00215 }
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 // Configuring the PEVC path: Change on PEVC input pin0 event -> PDCA channel 0/1 trigger one transfer 00163 if(FAIL == pevc_channel_configure(ppevc, 00164 PEVC_PDCA_SOT_USER, 00165 AVR32_PEVC_ID_GEN_AST_PER0, 00166 NULL)) 00167 { 00168 print_dbg("PEVC channel config failed!!!\r\n"); 00169 gpio_clr_gpio_pin(LED2_GPIO); 00170 while(1); 00171 } 00172 00173 // Enable the PEVC channel 0. 00174 pevc_channels_enable(ppevc, 1<<PEVC_PDCA_SOT_USER); 00175 00176 }
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 Driver - 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 280 of file pevc_example1.c.
References aDataTransfered, FCPU_HZ, init_ast(), init_pdca(), init_pevc(), and init_usart().
00281 { 00282 int i; 00283 00284 // Init the string with a simple recognizable pattern. 00285 for(i=0;i<sizeof(aDataTransfered);i++) 00286 aDataTransfered[i] = '0' + (i%36); 00287 00288 init_sys_clocks(); 00289 00290 delay_init(FCPU_HZ); 00291 00292 init_usart(); 00293 00294 gpio_clr_gpio_pin(LED0_GPIO); 00295 00296 init_pevc(); 00297 00298 init_ast(); 00299 00300 init_pdca(); 00301 00302 while(1) 00303 { 00304 gpio_tgl_gpio_pin(LED1_GPIO); 00305 delay_ms(500); //Wait 500ms 00306 } 00307 }
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 }
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 |
volatile avr32_pm_t* pm = &AVR32_PM |
Definition at line 121 of file pevc_example1.c.
volatile avr32_pevc_t* ppevc = &AVR32_PEVC |
volatile U32 u32PdcaIsr [static] |