dacifb_example2.c File Reference


Detailed Description

DACIFB example driver for AVR32 UC3.

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

Definition in file dacifb_example2.c.

#include "board.h"
#include "print_funcs.h"
#include "gpio.h"
#include "power_clocks_lib.h"
#include "dacifb.h"
#include "intc.h"
#include "pevc.h"
#include "pdca.h"
#include "sinus.h"

Go to the source code of this file.

Defines

DACIFB channels choice
#define AVR32_PDCA_PID_DAC_TX   AVR32_PDCA_PID_DACIFB1_CHB_TX
#define EXAMPLE_DAC_AUDIO_CHANNEL   DACIFB_CHANNEL_SELECTION_B
#define EXAMPLE_DAC_AUDIO_FUNCTION   AVR32_DAC1B_PIN
#define EXAMPLE_DAC_AUDIO_INSTANCE   1
#define EXAMPLE_DAC_AUDIO_PIN   AVR32_DAC1B_PIN
#define EXAMPLE_DAC_PRESCALER_CLOCK   FOSC0/2
#define EXAMPLE_PDCA_CHANNEL_DAC   0

Functions

void init_gclk (void)
void init_pevc (void)
int main (void)
 main function : do init and loop to display ADC values
static void pdca_int_handler (void)
 The PDCA interrupt handler.
void pdca_set_irq (void)
 Init interrupt controller and register pdca_int_handler interrupt.

Variables

U8 dac_channel_audio = EXAMPLE_DAC_AUDIO_CHANNEL
S16 dac_value_audio = -1
volatile avr32_dacifb_t * dacifb = &AVR32_DACIFB1
dacifb_channel_opt_t dacifb_channel_opt
dacifb_opt_t dacifb_opt
volatile avr32_pevc_t * ppevc = &AVR32_PEVC
U16 sin_table [SINUS_SAMPLES]


Define Documentation

#define AVR32_PDCA_PID_DAC_TX   AVR32_PDCA_PID_DACIFB1_CHB_TX

Definition at line 106 of file dacifb_example2.c.

Referenced by main().

#define EXAMPLE_DAC_AUDIO_CHANNEL   DACIFB_CHANNEL_SELECTION_B

Definition at line 102 of file dacifb_example2.c.

#define EXAMPLE_DAC_AUDIO_FUNCTION   AVR32_DAC1B_PIN

Definition at line 104 of file dacifb_example2.c.

Referenced by main().

#define EXAMPLE_DAC_AUDIO_INSTANCE   1

Definition at line 101 of file dacifb_example2.c.

Referenced by main().

#define EXAMPLE_DAC_AUDIO_PIN   AVR32_DAC1B_PIN

Definition at line 103 of file dacifb_example2.c.

Referenced by main().

#define EXAMPLE_DAC_PRESCALER_CLOCK   FOSC0/2

Definition at line 107 of file dacifb_example2.c.

Referenced by main().

#define EXAMPLE_PDCA_CHANNEL_DAC   0

Definition at line 105 of file dacifb_example2.c.

Referenced by main(), and pdca_int_handler().


Function Documentation

void init_gclk ( void   ) 

Definition at line 216 of file dacifb_example2.c.

Referenced by main().

00217 {
00218   // Setup Sampling Rate
00219   // Sampling Rate = (115200/100) = 1152Hz
00220   // Setup the generic clock for EVENT
00221   scif_gc_setup(AVR32_SCIF_GCLK_GCLK2_EVENT, 
00222                 SCIF_GCCTRL_SLOWCLOCK, 
00223                 AVR32_SCIF_GC_DIV_CLOCK, 
00224                 100);  
00225   // Now enable the generic clock
00226   scif_gc_enable(AVR32_SCIF_GCLK_GCLK2_EVENT);
00227 }

void init_pevc ( void   ) 

Definition at line 188 of file dacifb_example2.c.

References ppevc.

Referenced by main().

00189 {
00190   
00191   // PEVC Event Shaper options.
00192   static const pevc_evs_opt_t PEVC_EVS_OPTIONS = 
00193   {
00194     .igfdr = 0x0A,            // Set the IGF clock (don't care here).
00195     .igf = PEVC_EVS_IGF_OFF,  // Input Glitch Filter off
00196     .evf = PEVC_EVS_EVF_OFF,   // Enable Event on falling edge
00197     .evr = PEVC_EVS_EVR_ON    // Enable Event on rising edge
00198   };
00199   //##
00200   //## PEVC Init.
00201   //##
00202   // Configuring the PEVC path: Change on pevc input pin0 event -> PDCA channel 0/1 trigger one transfer
00203   if(FAIL == pevc_channel_configure(ppevc, 
00204                                     AVR32_PEVC_ID_USER_DACIFB1_CHB, 
00205                                     AVR32_PEVC_ID_GEN_GCLK_0, 
00206                                     &PEVC_EVS_OPTIONS))
00207   {
00208     while(1);
00209   }
00210     
00211   // Enable the PEVC channel 0.
00212   pevc_channels_enable(ppevc, 1<<AVR32_PEVC_ID_USER_DACIFB1_CHB);
00213   
00214 }

int main ( void   ) 

main function : do init and loop to display ADC values

Definition at line 232 of file dacifb_example2.c.

References AVR32_PDCA_PID_DAC_TX, dac_channel_audio, dacifb, dacifb_configure(), dacifb_configure_channel(), dacifb_get_calibration_data(), dacifb_start_channel(), EXAMPLE_DAC_AUDIO_FUNCTION, EXAMPLE_DAC_AUDIO_INSTANCE, EXAMPLE_DAC_AUDIO_PIN, EXAMPLE_DAC_PRESCALER_CLOCK, EXAMPLE_PDCA_CHANNEL_DAC, init_gclk(), init_pevc(), pdca_set_irq(), sin_table, and SINUS_SAMPLES.

00233 {
00234   // GPIO pin/dac-function map.
00235   static const gpio_map_t DACIFB_GPIO_MAP =
00236   {
00237     {AVR32_DACREF_PIN,AVR32_DACREF_FUNCTION},
00238     {AVR32_ADCREFP_PIN,AVR32_ADCREFP_FUNCTION},
00239     {AVR32_ADCREFN_PIN,AVR32_ADCREFN_FUNCTION},
00240 #if BOARD == UC3C_EK
00241     {EXAMPLE_DAC_AUDIO_PIN, EXAMPLE_DAC_AUDIO_FUNCTION}
00242 #endif
00243   };
00244 
00245   // switch to oscillator 0
00246   pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
00247   
00248   // init debug serial line
00249   init_dbg_rs232(FOSC0);
00250 
00251   // Assign and enable GPIO pins to the DAC function.
00252   gpio_enable_module(DACIFB_GPIO_MAP, sizeof(DACIFB_GPIO_MAP) / sizeof(DACIFB_GPIO_MAP[0]));
00253 
00254   // Get DACIFB Factory Configuration
00255   dacifb_get_calibration_data(dacifb, 
00256                               &dacifb_opt,
00257                               EXAMPLE_DAC_AUDIO_INSTANCE);
00258                               
00259   // configure DACIFB
00260   dacifb_configure(dacifb,
00261                    &dacifb_opt,
00262                    FOSC0);
00263   
00264   // Enable the DACIFB channels.
00265 #if BOARD == UC3C_EK
00266   // configure channel DACIFB
00267   dacifb_configure_channel(dacifb,
00268                            dac_channel_audio,
00269                            &dacifb_channel_opt,
00270                            EXAMPLE_DAC_PRESCALER_CLOCK);
00271   
00272   dacifb_start_channel(dacifb,
00273                        dac_channel_audio,
00274                        FOSC0);
00275   
00276 #endif
00277 
00278   // Initialize Event Controller
00279   init_pevc();
00280   
00281   // PDCA channel options
00282   static const pdca_channel_options_t PDCA_OPTIONS =
00283   {
00284     .addr = (void *)sin_table,                     // memory address
00285     .pid = AVR32_PDCA_PID_DAC_TX,                  // select peripheral - data are transmit on USART TX line.
00286     .size = SINUS_SAMPLES,                         // transfer counter
00287     .r_addr = NULL,                                // next memory address
00288     .r_size = 0,                                   // next transfer counter
00289     .transfer_size = PDCA_TRANSFER_SIZE_HALF_WORD  // select size of the transfer      
00290   };
00291 
00292   // Init PDCA channel with the pdca_options.
00293   pdca_init_channel(EXAMPLE_PDCA_CHANNEL_DAC, &PDCA_OPTIONS); // init PDCA channel with options.
00294 
00295   // Register PDCA IRQ interrupt.
00296   pdca_set_irq();
00297 
00298   // Enable pdca interrupt each time the reload counter reaches zero.
00299   pdca_enable_interrupt_reload_counter_zero(EXAMPLE_PDCA_CHANNEL_DAC);
00300   
00301   // Enable now the transfer.
00302   pdca_enable(EXAMPLE_PDCA_CHANNEL_DAC);
00303   
00304   // Initialize Generic Clock
00305   init_gclk();
00306   
00307   // do a loop
00308   for (;;)
00309   {
00310   }
00311 
00312 }

static void pdca_int_handler ( void   )  [static]

The PDCA interrupt handler.

The handler reload the PDCA settings with the correct ASCII animation address and size using the reload register. The interrupt will happen each time half of the animation is played. Let's use interrupt level 0 in the example.

Definition at line 159 of file dacifb_example2.c.

References EXAMPLE_PDCA_CHANNEL_DAC, sin_table, and SINUS_SAMPLES.

Referenced by pdca_set_irq().

00160 {
00161     // Set PDCA channel reload values with address where data to load are stored, and size of the data block to load.
00162     pdca_reload_channel(EXAMPLE_PDCA_CHANNEL_DAC, (void *)sin_table, SINUS_SAMPLES);
00163 }

void pdca_set_irq ( void   ) 

Init interrupt controller and register pdca_int_handler interrupt.

Definition at line 167 of file dacifb_example2.c.

References pdca_int_handler().

Referenced by main().

00168 {
00169 #if defined (__GNUC__)
00170   // Disable all interrupt/exception.
00171   Disable_global_interrupt();
00172 
00173   INTC_init_interrupts();
00174 
00175   // Register the compare interrupt handler to the interrupt controller
00176   // and enable the compare interrupt.
00177   // (__int_handler) &pdca_int_handler The handler function to register.
00178   // AVR32_PDCA_IRQ_0 The interrupt line to register to.
00179   // AVR32_INTC_INT0  The priority level to set for this interrupt line.
00180   // INTC_register_interrupt(__int_handler handler, int line, int priority);
00181   INTC_register_interrupt( (__int_handler) &pdca_int_handler, AVR32_PDCA_IRQ_0, AVR32_INTC_INT0);
00182 #endif
00183 
00184   // Enable all interrupt/exception.
00185   Enable_global_interrupt();
00186 }


Variable Documentation

U8 dac_channel_audio = EXAMPLE_DAC_AUDIO_CHANNEL

Definition at line 118 of file dacifb_example2.c.

Referenced by main().

S16 dac_value_audio = -1

Definition at line 113 of file dacifb_example2.c.

volatile avr32_dacifb_t* dacifb = &AVR32_DACIFB1

Definition at line 111 of file dacifb_example2.c.

Referenced by main().

Initial value:

 {
                                                .auto_refresh_mode    = FALSE,                      
                                                .trigger_mode         = DACIFB_TRIGGER_MODE_EVENT, 
                                                .left_adjustment      = FALSE,                      
                                                .data_shift           = 0,                          
                                                .data_round_enable    = FALSE                       
}

Definition at line 135 of file dacifb_example2.c.

Initial value:

 {
                            .reference                  = DACIFB_REFERENCE_VDDANA,        
                            .channel_selection          = DACIFB_CHANNEL_SELECTION_B,     
                            .low_power                  = FALSE,                          
                            .dual                       = FALSE,                          
                            .prescaler_clock_hz         = EXAMPLE_DAC_PRESCALER_CLOCK     
}

Definition at line 126 of file dacifb_example2.c.

volatile avr32_pevc_t* ppevc = &AVR32_PEVC

Definition at line 123 of file dacifb_example2.c.

Referenced by init_pevc().

U16 sin_table[SINUS_SAMPLES]

Definition at line 53 of file sinus.c.

Referenced by main(), and pdca_int_handler().


Generated on Fri Feb 19 02:24:31 2010 for AVR32 - DACIFB Driver Example 1 by  doxygen 1.5.5