00001
00075 #include <avr32/io.h>
00076 #include <stdio.h>
00077 #include <string.h>
00078 #include "compiler.h"
00079 #include "preprocessor.h"
00080
00081 #include "flashc.h"
00082 #include "pm.h"
00083 #include "gpio.h"
00084 #include "intc.h"
00085 #include "board.h"
00086 #include "spi.h"
00087
00088 #include "conf_tlv320aic23b.h"
00089 #include "tlv320aic23b.h"
00090 #include "audio.h"
00091
00093 #define SAMPLE_COUNT 2048
00094
00095 S16 sound_buffer1[SAMPLE_COUNT];
00096 S16 sound_buffer2[SAMPLE_COUNT];
00097
00098 void dac_reload_callback(void);
00099 void dac_overrun_callback(void);
00100 void adc_underrun_callback(void);
00101 void adc_reload_callback(void);
00102
00103 void master_callback(U32 arg)
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 }
00125
00126
00127 void dac_reload_callback(void)
00128 {
00129
00130 }
00131
00132 void dac_overrun_callback(void)
00133 {
00134
00135 }
00136
00137
00138 void adc_underrun_callback(void)
00139 {
00140
00141 }
00142
00143
00144 void adc_reload_callback(void)
00145 {
00146
00147 }
00148
00151 static void aic23b_resources_init(void)
00152 {
00153
00154 static const gpio_map_t AIC23B_SPI_GPIO_MAP =
00155 {
00156 {AIC23B_SPI_NPCS_PIN, AIC23B_SPI_NPCS_FUNCTION},
00157 {AIC23B_SPI_SCK_PIN, AIC23B_SPI_SCK_FUNCTION },
00158 {AIC23B_SPI_MISO_PIN, AIC23B_SPI_MISO_FUNCTION},
00159 {AIC23B_SPI_MOSI_PIN, AIC23B_SPI_MOSI_FUNCTION},
00160 };
00161
00162
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
00176 gpio_enable_module(AIC23B_SPI_GPIO_MAP,
00177 sizeof(AIC23B_SPI_GPIO_MAP) / sizeof(AIC23B_SPI_GPIO_MAP[0]));
00178
00179
00180 spi_initMaster(AIC23B_SPI, &AIC23B_SPI_OPTIONS);
00181
00182
00183 spi_selectionMode(AIC23B_SPI, 0, 0, 0);
00184
00185
00186 spi_enable(AIC23B_SPI);
00187
00188
00189 spi_setupChipReg(AIC23B_SPI, &AIC23B_SPI_OPTIONS, FOSC0);
00190
00191
00192 }
00193 int main(void)
00194 {
00195
00196 pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);
00197
00198
00199 INTC_init_interrupts();
00200
00201
00202 Enable_global_interrupt();
00203
00204
00205 aic23b_resources_init();
00206
00207
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
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
00227 while(!aic23b_adc_input(sound_buffer1,0));
00228
00229 aic23b_dac_output(sound_buffer1,(SAMPLE_COUNT/2));
00230
00231 while(!aic23b_dac_output(sound_buffer1,0));
00232
00233 aic23b_adc_input(sound_buffer2,(SAMPLE_COUNT/2));
00234 step = 1;
00235 break;
00236 case 1:
00237
00238 while(!aic23b_adc_input(sound_buffer2,0));
00239
00240 aic23b_dac_output(sound_buffer2,(SAMPLE_COUNT/2));
00241
00242 while(!aic23b_dac_output(sound_buffer2,0));
00243
00244 aic23b_adc_input(sound_buffer1,(SAMPLE_COUNT/2));
00245 step = 0;
00246 break;
00247 }
00248 }
00249 }