dacifb_example1.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_example1.c.

#include "board.h"
#include "print_funcs.h"
#include "gpio.h"
#include "power_clocks_lib.h"
#include "dacifb.h"
#include "intc.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

int main (void)
 main function
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
U16 sin_table [SINUS_SAMPLES]


Define Documentation

#define AVR32_PDCA_PID_DAC_TX   AVR32_PDCA_PID_DACIFB1_CHB_TX

Definition at line 105 of file dacifb_example1.c.

Referenced by main().

#define EXAMPLE_DAC_AUDIO_CHANNEL   DACIFB_CHANNEL_SELECTION_B

Definition at line 101 of file dacifb_example1.c.

#define EXAMPLE_DAC_AUDIO_FUNCTION   AVR32_DAC1B_PIN

Definition at line 103 of file dacifb_example1.c.

Referenced by main().

#define EXAMPLE_DAC_AUDIO_INSTANCE   1

Definition at line 100 of file dacifb_example1.c.

Referenced by main().

#define EXAMPLE_DAC_AUDIO_PIN   AVR32_DAC1B_PIN

Definition at line 102 of file dacifb_example1.c.

Referenced by main().

#define EXAMPLE_DAC_PRESCALER_CLOCK   FOSC0/2

Definition at line 106 of file dacifb_example1.c.

Referenced by main().

#define EXAMPLE_PDCA_CHANNEL_DAC   0

Definition at line 104 of file dacifb_example1.c.

Referenced by main(), and pdca_int_handler().


Function Documentation

int main ( void   ) 

main function

Definition at line 187 of file dacifb_example1.c.

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

00188 {
00189   // GPIO pin/dac-function map.
00190   static const gpio_map_t DACIFB_GPIO_MAP =
00191   {
00192     {AVR32_DACREF_PIN,AVR32_DACREF_FUNCTION},
00193     {AVR32_ADCREFP_PIN,AVR32_ADCREFP_FUNCTION},
00194     {AVR32_ADCREFN_PIN,AVR32_ADCREFN_FUNCTION},
00195 #if BOARD == UC3C_EK
00196     {EXAMPLE_DAC_AUDIO_PIN, EXAMPLE_DAC_AUDIO_FUNCTION}
00197 #endif
00198   };
00199 
00200   // switch to oscillator 0
00201   pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
00202   
00203   // init debug serial line
00204   init_dbg_rs232(FOSC0);
00205 
00206   // Assign and enable GPIO pins to the DAC function.
00207   gpio_enable_module(DACIFB_GPIO_MAP, sizeof(DACIFB_GPIO_MAP) / sizeof(DACIFB_GPIO_MAP[0]));
00208 
00209   // Get DACIFB Factory Configuration
00210   dacifb_get_calibration_data(dacifb, 
00211                               &dacifb_opt,
00212                               EXAMPLE_DAC_AUDIO_INSTANCE);
00213   
00214   // configure DACIFB
00215   dacifb_configure(dacifb,
00216                    &dacifb_opt,
00217                    FOSC0);
00218   
00219   // Enable the DACIFB channels.
00220 #if BOARD == UC3C_EK
00221   // configure channel DACIFB
00222   dacifb_configure_channel(dacifb,
00223                            dac_channel_audio,
00224                            &dacifb_channel_opt,
00225                            EXAMPLE_DAC_PRESCALER_CLOCK);
00226   
00227   dacifb_start_channel(dacifb,
00228                        dac_channel_audio,
00229                        FOSC0);
00230   
00231 #endif
00232 
00233   dacifb_reload_timer(dacifb,
00234                       dac_channel_audio,
00235                       8,
00236                       EXAMPLE_DAC_PRESCALER_CLOCK);
00237 
00238   // PDCA channel options
00239   static const pdca_channel_options_t PDCA_OPTIONS =
00240   {
00241     .addr = (void *)sin_table,                   // memory address
00242     .pid = AVR32_PDCA_PID_DAC_TX,                  // select peripheral - data are transmit on USART TX line.
00243     .size = SINUS_SAMPLES,                         // transfer counter
00244     .r_addr = NULL,                                // next memory address
00245     .r_size = 0,                                   // next transfer counter
00246     .transfer_size = PDCA_TRANSFER_SIZE_HALF_WORD       // select size of the transfer
00247   };
00248 
00249   // Init PDCA channel with the pdca_options.
00250   pdca_init_channel(EXAMPLE_PDCA_CHANNEL_DAC, &PDCA_OPTIONS); // init PDCA channel with options.
00251 
00252   // Register PDCA IRQ interrupt.
00253   pdca_set_irq();
00254 
00255   // Enable pdca interrupt each time the reload counter reaches zero.
00256   pdca_enable_interrupt_reload_counter_zero(EXAMPLE_PDCA_CHANNEL_DAC);
00257 
00258   // Enable now the transfer.
00259   pdca_enable(EXAMPLE_PDCA_CHANNEL_DAC);
00260   
00261   // do a loop
00262   for (;;)
00263   {
00264   }
00265 }

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 155 of file dacifb_example1.c.

References EXAMPLE_PDCA_CHANNEL_DAC, sin_table, and SINUS_SAMPLES.

Referenced by pdca_set_irq().

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

void pdca_set_irq ( void   ) 

Init interrupt controller and register pdca_int_handler interrupt.

Definition at line 163 of file dacifb_example1.c.

References pdca_int_handler().

Referenced by main().

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


Variable Documentation

U8 dac_channel_audio = EXAMPLE_DAC_AUDIO_CHANNEL

Definition at line 117 of file dacifb_example1.c.

Referenced by main().

S16 dac_value_audio = -1

Definition at line 112 of file dacifb_example1.c.

volatile avr32_dacifb_t* dacifb = &AVR32_DACIFB1

Definition at line 110 of file dacifb_example1.c.

Referenced by main().

Initial value:

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

Definition at line 131 of file dacifb_example1.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 122 of file dacifb_example1.c.

U16 sin_table[SINUS_SAMPLES]

Definition at line 46 of file sinus.c.

Referenced by main(), and pdca_int_handler().


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