Copy across from apps_usb_aud_shared

This commit is contained in:
Russell Gallop
2011-07-08 15:12:28 +01:00
parent 0235ee8dcc
commit 7bc53853c4
14 changed files with 248 additions and 305 deletions

View File

@@ -12,6 +12,7 @@
#include <xs1.h>
#include <xclib.h>
#include <print.h>
#include <assert.h>
#include "clocking.h"
#include "audioports.h"
@@ -63,27 +64,24 @@ extern void device_reboot(void);
unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_dig_rx)
{
unsigned sample;
#if NUM_USB_CHAN_OUT > 0
unsigned samplesOut[NUM_USB_CHAN_OUT];
#endif
#if NUM_USB_CHAN_IN > 0
unsigned samplesIn[NUM_USB_CHAN_IN];
unsigned samplesInPrev[NUM_USB_CHAN_IN];
#endif
unsigned tmp;
unsigned index;
#ifdef RAMP_CHECK
unsigned prev=0;
int started = 0;
#endif
#ifndef CODEC_SLAVE
int oldtime;
#endif
#if NUM_USB_CHAN_IN > 0
for (int i=0;i<NUM_USB_CHAN_IN;i++)
{
samplesIn[i] = 0;
samplesInPrev[i] = 0;
}
#endif
outuint(c_out, 0);
/* Check for sample freq change or new samples from mixer*/
@@ -98,21 +96,16 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d
#ifndef MIXER // Interfaces straight to decouple()
(void) inuint(c_out);
#if NUM_USB_CHAN_IN > 0
#pragma loop unroll
for(int i = 0; i < NUM_USB_CHAN_IN; i++)
{
outuint(c_out, samplesIn[i]);
}
#endif
#if NUM_USB_CHAN_OUT > 0
#pragma loop unroll
for(int i = 0; i < NUM_USB_CHAN_OUT; i++)
{
samplesOut[i] = inuint(c_out);
}
#endif
#else
#pragma loop unroll
for(int i = 0; i < NUM_USB_CHAN_OUT; i++)
@@ -208,7 +201,6 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d
tmp += 33;
#if (I2S_CHANS_DAC != 0)
#pragma loop unroll
for(int i = 0; i < I2S_WIRES_DAC; i++)
{
p_i2s_dac[i] @ tmp <: 0;
@@ -222,6 +214,7 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d
{
clearbuf(p_i2s_adc[i]);
}
oldtime = tmp-1+32;
/* TODO In master mode, the i/o loop assumes L/RCLK = 32bit clocks. We should check this every interation
* and resync if we got a bclk glitch */
@@ -244,22 +237,17 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d
{
#ifndef MIXER // Interfaces straight to decouple()
(void) inuint(c_out);
#if NUM_USB_CHAN_IN > 0
#pragma loop unroll
for(int i = 0; i < NUM_USB_CHAN_IN; i++)
{
outuint(c_out, samplesIn[i]);
}
#endif
#if NUM_USB_CHAN_OUT > 0
#pragma loop unroll
for(int i = 0; i < NUM_USB_CHAN_OUT; i++)
{
samplesOut[i] = inuint(c_out);
}
#endif
#else
#pragma loop unroll
for(int i = 0; i < NUM_USB_CHAN_OUT; i++)
@@ -309,7 +297,7 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d
#pragma xta endpoint "i2s_output_l"
#if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0)
#if (I2S_CHANS_DAC != 0)
#pragma loop unroll
for(int i = 0; i < I2S_CHANS_DAC; i+=2)
{
@@ -367,16 +355,14 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d
for(int i = 1; i < I2S_CHANS_ADC; i += 2)
{
p_i2s_adc[index++] :> sample;
#if NUM_USB_CHAN_IN > 0
samplesIn[i] = bitrev(sample);
/* Store the previous left in left */
samplesIn[i-1] = samplesInPrev[i];
#endif
}
#endif
#if defined(SPDIF) && (NUM_USB_CHAN_OUT > 0)
#ifdef SPDIF
outuint(c_spd_out, samplesOut[SPDIF_TX_INDEX]); /* Forward sample to SPDIF txt thread */
sample = samplesOut[SPDIF_TX_INDEX + 1];
outuint(c_spd_out, sample); /* Forward sample to SPDIF txt thread */
@@ -399,7 +385,7 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d
tmp = 0;
#pragma xta endpoint "i2s_output_r"
#if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0)
#if (I2S_CHANS_DAC != 0)
#pragma loop unroll
for(int i = 1; i < I2S_CHANS_DAC; i+=2)
{
@@ -454,10 +440,7 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d
for(int i = 1; i < I2S_CHANS_ADC; i += 2)
{
p_i2s_adc[index++] :> sample;
#if NUM_USB_CHAN_IN > 0
samplesInPrev[i] = bitrev(sample);
#endif
}
@@ -513,7 +496,7 @@ static unsigned dummy_deliver(chanend c_out) {
return 0;
}
void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config)
void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c_i2c)
{
chan c_spdif_out;
unsigned curSamFreq = DEFAULT_FREQ;
@@ -526,10 +509,10 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config)
#endif
/* Initialise master clock generation */
ClockingInit();
ClockingInit(c_i2c);
/* Perform required CODEC/ADC/DAC initialisation */
CodecInit(c_config);
CodecInit(c_config, c_i2c);
while(1)
{
@@ -548,7 +531,7 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config)
divide = mClk / ( curSamFreq * 64 );
/* Configure clocking for required master clock */
ClockingConfig(mClk);
ClockingConfig(mClk, c_i2c);
if(!firstRun)
{
@@ -568,7 +551,7 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config)
firstRun = 0;
/* Configure CODEC/DAC/ADC for SampleFreq/MClk */
CodecConfig(curSamFreq, mClk, c_config);
CodecConfig(curSamFreq, mClk, c_config, c_i2c);
/* Configure audio ports */
ConfigAudioPorts(divide);