tlv320aic23b_example.c File Reference


Detailed Description

Audio Codec Example.

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

Definition in file tlv320aic23b_example.c.

#include <avr32/io.h>
#include <stdio.h>
#include <string.h>
#include "compiler.h"
#include "preprocessor.h"
#include "flashc.h"
#include "pm.h"
#include "gpio.h"
#include "intc.h"
#include "board.h"
#include "spi.h"
#include "conf_tlv320aic23b.h"
#include "tlv320aic23b.h"
#include "audio.h"

Go to the source code of this file.

Defines

#define SAMPLE_COUNT   2048
 Sample Count Value.

Functions

void adc_reload_callback (void)
void adc_underrun_callback (void)
static void aic23b_resources_init (void)
 Initializes Audio Codec in SPI.
void dac_overrun_callback (void)
void dac_reload_callback (void)
int main (void)
void master_callback (U32 arg)

Variables

S16 sound_buffer1 [SAMPLE_COUNT]
S16 sound_buffer2 [SAMPLE_COUNT]


Define Documentation

#define SAMPLE_COUNT   2048

Sample Count Value.

Definition at line 93 of file tlv320aic23b_example.c.

Referenced by main().


Function Documentation

void adc_reload_callback ( void   ) 

Definition at line 144 of file tlv320aic23b_example.c.

Referenced by master_callback().

00145 {
00146   // Nothing todo
00147 }

void adc_underrun_callback ( void   ) 

Definition at line 138 of file tlv320aic23b_example.c.

Referenced by master_callback().

00139 {
00140   // Nothing todo
00141 }

static void aic23b_resources_init ( void   )  [static]

Initializes Audio Codec in SPI.

Definition at line 151 of file tlv320aic23b_example.c.

References AIC23B_CTRL_SIZE.

Referenced by main().

00152 {
00153 
00154   static const gpio_map_t AIC23B_SPI_GPIO_MAP =
00155   {
00156     {AIC23B_SPI_NPCS_PIN, AIC23B_SPI_NPCS_FUNCTION},  // Chip Select for DAC Audio NPCS.
00157     {AIC23B_SPI_SCK_PIN,  AIC23B_SPI_SCK_FUNCTION },  // SPI Clock.
00158     {AIC23B_SPI_MISO_PIN, AIC23B_SPI_MISO_FUNCTION},  // MISO.
00159     {AIC23B_SPI_MOSI_PIN, AIC23B_SPI_MOSI_FUNCTION},  // MOSI.
00160   };
00161 
00162   // SPI options.
00163   static const spi_options_t AIC23B_SPI_OPTIONS =
00164   {
00165     .reg          = AIC23B_SPI_NPCS,
00166     .baudrate     = AIC23B_SPI_MASTER_SPEED,
00167     .bits         = AIC23B_CTRL_SIZE,
00168     .spck_delay   = 0,
00169     .trans_delay  = 0,
00170     .stay_act     = 0,
00171     .spi_mode     = 3,
00172     .modfdis      = 1
00173   };
00174 
00175   // Assign I/Os to SPI.
00176   gpio_enable_module(AIC23B_SPI_GPIO_MAP,
00177                      sizeof(AIC23B_SPI_GPIO_MAP) / sizeof(AIC23B_SPI_GPIO_MAP[0]));
00178 
00179   // Initialize as master.
00180   spi_initMaster(AIC23B_SPI, &AIC23B_SPI_OPTIONS);
00181 
00182   // Set selection mode: variable_ps, pcs_decode, delay.
00183   spi_selectionMode(AIC23B_SPI, 0, 0, 0);
00184 
00185   // Enable SPI.
00186   spi_enable(AIC23B_SPI);
00187 
00188   // Initialize data flash with SPI clock Osc0.
00189   spi_setupChipReg(AIC23B_SPI, &AIC23B_SPI_OPTIONS, FOSC0);
00190 
00191   
00192 }

void dac_overrun_callback ( void   ) 

Definition at line 132 of file tlv320aic23b_example.c.

Referenced by master_callback().

00133 {
00134   // Nothing todo
00135 }

void dac_reload_callback ( void   ) 

Definition at line 127 of file tlv320aic23b_example.c.

Referenced by master_callback().

00128 {
00129   // Nothing todo
00130 }

int main ( void   ) 

Definition at line 193 of file tlv320aic23b_example.c.

References aic23b_adc_input(), aic23b_codec_start(), aic23b_dac_output(), aic23b_resources_init(), DEFAULT_DAC_BITS_PER_SAMPLE, DEFAULT_DAC_NUM_CHANNELS, DEFAULT_DAC_SAMPLE_RATE_HZ, DEFAULT_DAC_SWAP_CHANNELS, master_callback(), SAMPLE_COUNT, sound_buffer1, and sound_buffer2.

00194 {
00195   // Switch to OSC0 as source of main clock.
00196   pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);
00197 
00198   // Initialize interrupt handling.
00199   INTC_init_interrupts();
00200 
00201   // Enable interrupts globally.
00202   Enable_global_interrupt();
00203   
00204   // Audio Codec Ressource Init
00205   aic23b_resources_init();
00206    
00207   // Codec Start
00208   aic23b_codec_start(DEFAULT_DAC_SAMPLE_RATE_HZ,
00209                     DEFAULT_DAC_NUM_CHANNELS,
00210                     DEFAULT_DAC_BITS_PER_SAMPLE,
00211                     DEFAULT_DAC_SWAP_CHANNELS,
00212                     master_callback,
00213                       AUDIO_DAC_OUT_OF_SAMPLE_CB
00214                     | AUDIO_DAC_RELOAD_CB,
00215                     FOSC0);
00216 
00217   // Record of buffer 1
00218   aic23b_adc_input(sound_buffer1,(SAMPLE_COUNT/2));
00219   unsigned char step = 1;
00220   while (1)
00221   {    
00222     LED_Toggle(LED0);
00223     switch(step)
00224     {
00225     case 0:
00226         // Wait until the end of reception of buffer 1 
00227         while(!aic23b_adc_input(sound_buffer1,0));
00228         // Play buffer 1 after complete reception
00229         aic23b_dac_output(sound_buffer1,(SAMPLE_COUNT/2));        
00230         // Wait until the end of transmission of buffer 1
00231         while(!aic23b_dac_output(sound_buffer1,0));
00232         // Record of buffer 2        
00233         aic23b_adc_input(sound_buffer2,(SAMPLE_COUNT/2)); 
00234         step = 1;
00235         break;
00236     case 1:
00237         // Wait until the end of reception of buffer 2       
00238         while(!aic23b_adc_input(sound_buffer2,0));
00239         // Play buffer 2 after complete reception
00240         aic23b_dac_output(sound_buffer2,(SAMPLE_COUNT/2));
00241         // Wait until the end of transmission of buffer 2
00242         while(!aic23b_dac_output(sound_buffer2,0));        
00243         // Record of buffer 2        
00244         aic23b_adc_input(sound_buffer1,(SAMPLE_COUNT/2));        
00245         step = 0;
00246         break;        
00247     }
00248   } 
00249 }

void master_callback ( U32  arg  ) 

Definition at line 103 of file tlv320aic23b_example.c.

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

Referenced by main().

00104 {
00105   if( arg == AUDIO_DAC_OUT_OF_SAMPLE_CB )
00106   {
00107     dac_overrun_callback();
00108   }
00109 
00110   else if( arg == AUDIO_DAC_RELOAD_CB )
00111   {
00112     dac_reload_callback();
00113   }
00114 
00115   else if( arg == AUDIO_ADC_OUT_OF_SAMPLE_CB )
00116   {
00117     adc_underrun_callback();;
00118   }
00119 
00120   else if( arg == AUDIO_ADC_RELOAD_CB )
00121   {
00122     adc_reload_callback();;
00123   }
00124 }


Variable Documentation

S16 sound_buffer1[SAMPLE_COUNT]

Definition at line 95 of file tlv320aic23b_example.c.

Referenced by main().

S16 sound_buffer2[SAMPLE_COUNT]

Definition at line 96 of file tlv320aic23b_example.c.

Referenced by main().


Generated on Fri Nov 27 14:08:36 2009 for AVR32 UC3 - Example of using an external Audio Codec TLV320AIC23B by  doxygen 1.5.5