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 "twim.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 107 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 150 of file tpa6130_example.c.

Referenced by main().

#define SAMPLE_COUNT   (sizeof(sound_data))

Definition at line 123 of file tpa6130_example.c.

#define SAMPLE_OFFSET   0x80

Definition at line 121 of file tpa6130_example.c.

#define SAMPLE_RATE   46875

Definition at line 122 of file tpa6130_example.c.

#define SOUND_SAMPLES   256

Sample Count Value.

Definition at line 106 of file tpa6130_example.c.

Referenced by main().

#define TPA6130_TWI_MASTER_SPEED   100000

Definition at line 108 of file tpa6130_example.c.


Function Documentation

void adc_reload_callback ( void   ) 

Definition at line 192 of file tpa6130_example.c.

Referenced by master_callback().

00193 {
00194   // Nothing todo
00195 }

void adc_underrun_callback ( void   ) 

Definition at line 186 of file tpa6130_example.c.

Referenced by master_callback().

00187 {
00188   // Nothing todo
00189 }

void dac_overrun_callback ( void   ) 

Definition at line 180 of file tpa6130_example.c.

Referenced by master_callback().

00181 {
00182   // Nothing todo
00183 }

void dac_reload_callback ( void   ) 

Definition at line 175 of file tpa6130_example.c.

Referenced by master_callback().

00176 {
00177   // Nothing todo
00178 }

void init_sys_clocks ( void   ) 

Initializes the MCU system clocks.

Definition at line 223 of file tpa6130_example.c.

Referenced by main().

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

int main ( void   ) 

Definition at line 286 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().

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

void master_callback ( U32  arg  ) 

Definition at line 152 of file tpa6130_example.c.

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

Referenced by main().

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

static void twi_init ( void   )  [static]

Definition at line 197 of file tpa6130_example.c.

References FPBA_HZ, TPA6130_TWI_ADDRESS, and TPA6130_TWI_MASTER_SPEED.

Referenced by main().

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


Variable Documentation

S16 samples[SOUND_SAMPLES]

Definition at line 117 of file tpa6130_example.c.

Referenced by main().

Definition at line 118 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 125 of file tpa6130_example.c.


Generated on Thu Dec 17 19:57:29 2009 for AVR32 UC3 - Example of using the TPA6130A2 by  doxygen 1.5.5