tpa6130_example.c File Reference


Detailed Description

Audio amplifier Example.

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

Definition in file tpa6130_example.c.

#include <avr32/io.h>
#include <stdio.h>
#include <string.h>
#include "compiler.h"
#include "preprocessor.h"
#include "print_funcs.h"
#include "flashc.h"
#include "pm.h"
#include "gpio.h"
#include "intc.h"
#include "tpa6130.h"
#include "abdac.h"
#include "conf_tpa6130.h"
#include "board.h"
#include "audio.h"
#include "sound.h"
#include "twi.h"

Go to the source code of this file.

Defines

#define FPBA_HZ   12000000
#define MSG_WELCOME   "\x1B[2J\x1B[H---------- Welcome to TPA6130 example ---------- \n"
 Welcome message to display.
#define SAMPLE_COUNT   (sizeof(sound_data))
#define SAMPLE_OFFSET   0x80
#define SAMPLE_RATE   46875
#define SOUND_SAMPLES   256
 Sample Count Value.
#define TPA6130_TWI_MASTER_SPEED   100000

Functions

void adc_reload_callback (void)
void adc_underrun_callback (void)
void dac_overrun_callback (void)
void dac_reload_callback (void)
void init_sys_clocks (void)
 Initializes the MCU system clocks.
int main (void)
void master_callback (U32 arg)
static void twi_init (void)

Variables

S16 samples [SOUND_SAMPLES]
U32 samples_count
static const S8 sound_data []


Define Documentation

#define FPBA_HZ   12000000

Definition at line 105 of file tpa6130_example.c.

Referenced by tpa6130_dac_setup(), and twi_init().

#define MSG_WELCOME   "\x1B[2J\x1B[H---------- Welcome to TPA6130 example ---------- \n"

Welcome message to display.

Definition at line 148 of file tpa6130_example.c.

Referenced by main().

#define SAMPLE_COUNT   (sizeof(sound_data))

Definition at line 121 of file tpa6130_example.c.

#define SAMPLE_OFFSET   0x80

Definition at line 119 of file tpa6130_example.c.

#define SAMPLE_RATE   46875

Definition at line 120 of file tpa6130_example.c.

#define SOUND_SAMPLES   256

Sample Count Value.

Definition at line 104 of file tpa6130_example.c.

Referenced by main().

#define TPA6130_TWI_MASTER_SPEED   100000

Definition at line 106 of file tpa6130_example.c.


Function Documentation

void adc_reload_callback ( void   ) 

Definition at line 190 of file tpa6130_example.c.

Referenced by master_callback().

00191 {
00192   // Nothing todo
00193 }

void adc_underrun_callback ( void   ) 

Definition at line 184 of file tpa6130_example.c.

Referenced by master_callback().

00185 {
00186   // Nothing todo
00187 }

void dac_overrun_callback ( void   ) 

Definition at line 178 of file tpa6130_example.c.

Referenced by master_callback().

00179 {
00180   // Nothing todo
00181 }

void dac_reload_callback ( void   ) 

Definition at line 173 of file tpa6130_example.c.

Referenced by master_callback().

00174 {
00175   // Nothing todo
00176 }

void init_sys_clocks ( void   ) 

Initializes the MCU system clocks.

Definition at line 221 of file tpa6130_example.c.

Referenced by main().

00222 {
00223   // Switch to OSC0 to speed up the booting
00224   pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);
00225 
00226   // Start oscillator1
00227   pm_enable_osc1_crystal(&AVR32_PM, FOSC1);
00228   pm_enable_clk1(&AVR32_PM, OSC1_STARTUP);
00229 
00230   // Set PLL0 (fed from OSC1 = 11.2896 MHz) to 124.1856 MHz
00231   // We use OSC1 since we need a correct master clock for the SSC module to generate
00232   // the correct sample rate
00233   pm_pll_setup(&AVR32_PM, 0,  // pll.
00234     10,  // mul.
00235     1,   // div.
00236     1,   // osc.
00237     16); // lockcount.
00238 
00239   // Set PLL operating range and divider (fpll = fvco/2)
00240   // -> PLL0 output = 62.0928 MHz
00241   pm_pll_set_option(&AVR32_PM, 0, // pll.
00242     1,  // pll_freq.
00243     1,  // pll_div2.
00244     0); // pll_wbwdisable.
00245 
00246   // start PLL0 and wait for the lock
00247   pm_pll_enable(&AVR32_PM, 0);
00248   pm_wait_for_pll0_locked(&AVR32_PM);
00249   // Set all peripheral clocks torun at master clock rate
00250   pm_cksel(&AVR32_PM,
00251     0,   // pbadiv.
00252     0,   // pbasel.
00253     0,   // pbbdiv.
00254     0,   // pbbsel.
00255     0,   // hsbdiv.
00256     0);  // hsbsel.
00257 
00258   // Set one waitstate for the flash
00259   flashc_set_wait_state(1);
00260 
00261   // Switch to PLL0 as the master clock
00262   pm_switch_to_clock(&AVR32_PM, AVR32_PM_MCCTRL_MCSEL_PLL0);
00263 
00264   // Use 12MHz from OSC0 and generate 96 MHz
00265   pm_pll_setup(&AVR32_PM, 1,  // pll.
00266     7,   // mul.
00267     1,   // div.
00268     0,   // osc.
00269     16); // lockcount.
00270 
00271   pm_pll_set_option(&AVR32_PM, 1, // pll.
00272     1,  // pll_freq: choose the range 80-180MHz.
00273     1,  // pll_div2.
00274     0); // pll_wbwdisable.
00275 
00276   // start PLL1 and wait forl lock
00277   pm_pll_enable(&AVR32_PM, 1);
00278 
00279   // Wait for PLL1 locked.
00280   pm_wait_for_pll1_locked(&AVR32_PM);
00281  
00282 }

int main ( void   ) 

Definition at line 284 of file tpa6130_example.c.

References DEFAULT_DAC_BITS_PER_SAMPLE, DEFAULT_DAC_NUM_CHANNELS, DEFAULT_DAC_SAMPLE_RATE_HZ, DEFAULT_DAC_SWAP_CHANNELS, init_sys_clocks(), master_callback(), MSG_WELCOME, samples, SOUND_SAMPLES, sound_table, tpa6130_dac_output(), tpa6130_dac_start(), tpa6130_get_volume(), tpa6130_init(), tpa6130_set_volume(), and twi_init().

00285 {
00286 
00287   init_sys_clocks();
00288 
00289   // Initialize RS232 debug text output.
00290   init_dbg_rs232(FOSC0);
00291 
00292   print_dbg(MSG_WELCOME);
00293 
00294   // Enbale LED0 and LED1
00295   gpio_enable_gpio_pin(LED0_GPIO);
00296   gpio_enable_gpio_pin(LED1_GPIO);
00297   
00298   /* Configure TWI as master */
00299   twi_init();
00300   
00301   // Initialize TPA6130
00302   tpa6130_init();
00303 
00304   // Initialize DAC that send audio to TPA6130
00305   tpa6130_dac_start(DEFAULT_DAC_SAMPLE_RATE_HZ,
00306                     DEFAULT_DAC_NUM_CHANNELS,
00307                     DEFAULT_DAC_BITS_PER_SAMPLE,
00308                     DEFAULT_DAC_SWAP_CHANNELS,
00309                     master_callback,
00310                       AUDIO_DAC_OUT_OF_SAMPLE_CB
00311                     | AUDIO_DAC_RELOAD_CB,
00312                     FOSC0);
00313 
00314   tpa6130_set_volume(0x2F);
00315   tpa6130_get_volume();
00316 
00317   int count = 0;
00318   int i=0;
00319 
00320   while(TRUE)
00321   {
00322     count = 0;
00323 
00324     // Store sample in sample for PDCA transfer
00325     while(count < (SOUND_SAMPLES)){
00326       samples[count++] = ((U8)sound_table[i]+0x80) << 8;
00327       samples[count++] = ((U8)sound_table[i]+0x80) << 8;
00328       i++;
00329       if (i >= sizeof(sound_table)) i = 0;
00330     }
00331 
00332     gpio_set_gpio_pin(LED0_GPIO);
00333     gpio_clr_gpio_pin(LED1_GPIO);
00334     // Play buffer
00335     tpa6130_dac_output((void *) samples,SOUND_SAMPLES/2);
00336     
00337     gpio_clr_gpio_pin(LED0_GPIO);
00338     gpio_set_gpio_pin(LED1_GPIO);
00339 
00340 
00341     /* Wait until the reload register is empty.
00342      * This means that one transmission is still ongoing
00343      * but we are already able to set up the next transmission
00344      */
00345      while(!tpa6130_dac_output(NULL, 0));
00346 
00347   }
00348 }

void master_callback ( U32  arg  ) 

Definition at line 150 of file tpa6130_example.c.

References adc_reload_callback(), adc_underrun_callback(), dac_overrun_callback(), and dac_reload_callback().

Referenced by main().

00151 {
00152   if( arg == AUDIO_DAC_OUT_OF_SAMPLE_CB )
00153   {
00154     dac_overrun_callback();
00155   }
00156 
00157   else if( arg == AUDIO_DAC_RELOAD_CB )
00158   {
00159     dac_reload_callback();
00160   }
00161 
00162   else if( arg == AUDIO_ADC_OUT_OF_SAMPLE_CB )
00163   {
00164     adc_underrun_callback();;
00165   }
00166 
00167   else if( arg == AUDIO_ADC_RELOAD_CB )
00168   {
00169     adc_reload_callback();;
00170   }
00171 }

static void twi_init ( void   )  [static]

Definition at line 195 of file tpa6130_example.c.

References FPBA_HZ, TPA6130_TWI_ADDRESS, and TPA6130_TWI_MASTER_SPEED.

Referenced by main().

00196 {
00197   const gpio_map_t TPA6130_TWI_GPIO_MAP =
00198   {
00199   {TPA6130_TWI_SCL_PIN, TPA6130_TWI_SCL_FUNCTION},
00200   {TPA6130_TWI_SDA_PIN, TPA6130_TWI_SDA_FUNCTION}
00201   };
00202 
00203   const twi_options_t TPA6130_TWI_OPTIONS =
00204   {
00205     .pba_hz = FPBA_HZ,
00206     .speed  = TPA6130_TWI_MASTER_SPEED,
00207     .chip   = TPA6130_TWI_ADDRESS
00208   };
00209 
00210   // Assign I/Os to SPI.
00211   gpio_enable_module(TPA6130_TWI_GPIO_MAP,
00212     sizeof(TPA6130_TWI_GPIO_MAP) / sizeof(TPA6130_TWI_GPIO_MAP[0]));
00213   
00214   // Initialize as master.
00215   twi_master_init(TPA6130_TWI, &TPA6130_TWI_OPTIONS);
00216 
00217 }


Variable Documentation

S16 samples[SOUND_SAMPLES]

Definition at line 115 of file tpa6130_example.c.

Referenced by main().

Definition at line 116 of file tpa6130_example.c.

const S8 sound_data[] [static]

Initial value:

{
  0x00, 0x04, 0x08, 0x0C, 0x10, 0x14, 0x17, 0x1B, 0x1F, 0x23,
  0x27, 0x2B, 0x2F, 0x32, 0x36, 0x3A, 0x3D, 0x41, 0x44, 0x47,
  0x4B, 0x4E, 0x51, 0x54, 0x57, 0x5A, 0x5D, 0x60, 0x62, 0x65,
  0x67, 0x69, 0x6C, 0x6E, 0x70, 0x72, 0x73, 0x75, 0x77, 0x78,
  0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7E, 0x7F, 0x7F, 0x7F,
  0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7E, 0x7D, 0x7C, 0x7B, 0x7A,
  0x79, 0x78, 0x77, 0x75, 0x73, 0x72, 0x70, 0x6E, 0x6C, 0x69,
  0x67, 0x65, 0x62, 0x60, 0x5D, 0x5A, 0x57, 0x54, 0x51, 0x4E,
  0x4B, 0x47, 0x44, 0x41, 0x3D, 0x3A, 0x36, 0x32, 0x2F, 0x2B,
  0x27, 0x23, 0x1F, 0x1B, 0x17, 0x14, 0x10, 0x0C, 0x08, 0x04,
  0x00, 0xFC, 0xF8, 0xF4, 0xF0, 0xEC, 0xE9, 0xE5, 0xE1, 0xDD,
  0xD9, 0xD5, 0xD1, 0xCE, 0xCA, 0xC6, 0xC3, 0xBF, 0xBC, 0xB9,
  0xB5, 0xB2, 0xAF, 0xAC, 0xA9, 0xA6, 0xA3, 0xA0, 0x9E, 0x9B,
  0x99, 0x97, 0x94, 0x92, 0x90, 0x8E, 0x8D, 0x8B, 0x89, 0x88,
  0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x82, 0x81, 0x81, 0x81,
  0x80, 0x81, 0x81, 0x81, 0x82, 0x82, 0x83, 0x84, 0x85, 0x86,
  0x87, 0x88, 0x89, 0x8B, 0x8D, 0x8E, 0x90, 0x92, 0x94, 0x97,
  0x99, 0x9B, 0x9E, 0xA0, 0xA3, 0xA6, 0xA9, 0xAC, 0xAF, 0xB2,
  0xB5, 0xB9, 0xBC, 0xBF, 0xC3, 0xC6, 0xCA, 0xCE, 0xD1, 0xD5,
  0xD9, 0xDD, 0xE1, 0xE5, 0xE9, 0xEC, 0xF0, 0xF4, 0xF8, 0xFC
}

Definition at line 123 of file tpa6130_example.c.


Generated on Fri Feb 19 02:23:28 2010 for AVR32 UC3 - Example of using the TPA6130A2 by  doxygen 1.5.5