forked from PAWPAW-Mirror/lib_xua
DSD ports now only enabled once - avoids issue with stop_clock and un-driven clock. ConfigAudioPortsWrapper() also simplified.
This commit is contained in:
@@ -26,8 +26,8 @@ unsigned testsamples[100];
|
|||||||
int p = 0;
|
int p = 0;
|
||||||
unsigned lastSample = 0;
|
unsigned lastSample = 0;
|
||||||
#if (DSD_CHANS_DAC != 0)
|
#if (DSD_CHANS_DAC != 0)
|
||||||
extern unsigned p_dsd_dac[DSD_CHANS_DAC];
|
extern buffered out port:32 p_dsd_dac[DSD_CHANS_DAC];
|
||||||
extern port p_dsd_clk;
|
extern buffered out port:32 p_dsd_clk;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned g_adcVal = 0;
|
unsigned g_adcVal = 0;
|
||||||
@@ -832,6 +832,15 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c)
|
|||||||
|
|
||||||
start_clock(clk_audio_mclk);
|
start_clock(clk_audio_mclk);
|
||||||
|
|
||||||
|
#if (DSD_CHANS_DAC > 0)
|
||||||
|
/* Make sure the DSD ports are on and buffered - just in case they are not shared with I2S */
|
||||||
|
EnableBufferedPort(p_dsd_clk, 32);
|
||||||
|
for(int i = 0; i< DSD_CHANS_DAC; i++)
|
||||||
|
{
|
||||||
|
EnableBufferedPort(p_dsd_dac[i], 32);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef SPDIF
|
#ifdef SPDIF
|
||||||
SpdifTransmitPortConfig(p_spdif_tx, clk_mst_spd, p_mclk_in);
|
SpdifTransmitPortConfig(p_spdif_tx, clk_mst_spd, p_mclk_in);
|
||||||
#endif
|
#endif
|
||||||
@@ -872,28 +881,31 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c)
|
|||||||
divide = mClk / ( curSamFreq * numBits );
|
divide = mClk / ( curSamFreq * numBits );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (DSD_CHANS_DAC != 0)
|
|
||||||
|
#if (DSD_CHANS_DAC > 0)
|
||||||
|
if(dsdMode)
|
||||||
|
{
|
||||||
/* Configure audio ports */
|
/* Configure audio ports */
|
||||||
ConfigAudioPortsWrapper(
|
ConfigAudioPortsWrapper(
|
||||||
#if (I2S_CHANS_DAC != 0)
|
#if (I2S_CHANS_DAC != 0)
|
||||||
p_i2s_dac,
|
p_dsd_dac,
|
||||||
|
DSD_CHANS_DAC,
|
||||||
#endif
|
#endif
|
||||||
#if (I2S_CHANS_ADC != 0)
|
#if (I2S_CHANS_ADC != 0)
|
||||||
p_i2s_adc,
|
p_i2s_adc,
|
||||||
|
I2S_WIRES_ADC,
|
||||||
#endif
|
#endif
|
||||||
#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0)
|
#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0)
|
||||||
#ifndef CODEC_MASTER
|
null,
|
||||||
p_lrclk,
|
p_dsd_clk,
|
||||||
p_bclk,
|
|
||||||
#else
|
|
||||||
p_lrclk,
|
|
||||||
p_bclk,
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
divide, dsdMode);
|
divide, dsdMode);
|
||||||
#else
|
}
|
||||||
/* Configure audio ports */
|
else
|
||||||
ConfigAudioPorts(
|
#endif
|
||||||
|
{
|
||||||
|
|
||||||
|
ConfigAudioPortsWrapper(
|
||||||
#if (I2S_CHANS_DAC != 0)
|
#if (I2S_CHANS_DAC != 0)
|
||||||
p_i2s_dac,
|
p_i2s_dac,
|
||||||
I2S_WIRES_DAC,
|
I2S_WIRES_DAC,
|
||||||
@@ -911,9 +923,9 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c)
|
|||||||
p_bclk,
|
p_bclk,
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
divide);
|
divide, dsdMode);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
{
|
{
|
||||||
unsigned curFreq = curSamFreq;
|
unsigned curFreq = curSamFreq;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include "devicedefines.h"
|
#include "devicedefines.h"
|
||||||
#include "audioports.h"
|
#include "audioports.h"
|
||||||
|
|
||||||
#if (DSD_CHANS_DAC != 0)
|
|
||||||
/* Note since DSD ports could be reused for I2S ports we do all the setup manually in C */
|
/* Note since DSD ports could be reused for I2S ports we do all the setup manually in C */
|
||||||
#if DSD_CHANS_DAC > 0
|
#if DSD_CHANS_DAC > 0
|
||||||
port p_dsd_dac[DSD_CHANS_DAC] = {
|
port p_dsd_dac[DSD_CHANS_DAC] = {
|
||||||
@@ -23,23 +22,21 @@ port p_dsd_dac[DSD_CHANS_DAC] = {
|
|||||||
port p_dsd_clk = PORT_DSD_CLK;
|
port p_dsd_clk = PORT_DSD_CLK;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline void EnableBufferedPort(port p, unsigned transferWidth)
|
void EnableBufferedPort(port p, unsigned transferWidth)
|
||||||
{
|
{
|
||||||
//set_port_use_on(p_dsd_dac[i]);
|
|
||||||
asm volatile("setc res[%0], %1"::"r"(p), "r"(XS1_SETC_INUSE_ON));
|
asm volatile("setc res[%0], %1"::"r"(p), "r"(XS1_SETC_INUSE_ON));
|
||||||
asm volatile("setc res[%0], %1"::"r"(p), "r"(XS1_SETC_BUF_BUFFERS));
|
asm volatile("setc res[%0], %1"::"r"(p), "r"(XS1_SETC_BUF_BUFFERS));
|
||||||
asm volatile("settw res[%0], %1"::"r"(p),"r"(transferWidth));
|
asm volatile("settw res[%0], %1"::"r"(p),"r"(transferWidth));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* C wrapper for ConfigAudioPorts() to handle DSD ports */
|
||||||
/* C wrapper for ConfigAudioPorts() such that we can mess around with arrays of ports */
|
|
||||||
void ConfigAudioPortsWrapper(
|
void ConfigAudioPortsWrapper(
|
||||||
#if (I2S_CHANS_DAC != 0)
|
#if (I2S_CHANS_DAC != 0)
|
||||||
port p_i2s_dac[I2S_WIRES_DAC],
|
port p_dac[], int numPortsDac,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (I2S_CHANS_ADC != 0)
|
#if (I2S_CHANS_ADC != 0)
|
||||||
port p_i2s_adc[I2S_WIRES_ADC],
|
port p_adc[], int numPortsAdc,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0)
|
#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0)
|
||||||
@@ -52,64 +49,17 @@ void ConfigAudioPortsWrapper(
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
unsigned int divide, unsigned int dsdMode)
|
unsigned int divide, unsigned int dsdMode)
|
||||||
{
|
|
||||||
/* Ensure dsd clock is on in all modes since I2S mode sets it low on exit
|
|
||||||
* to avoid stop_clock() potentially pausing forever. If this is not done
|
|
||||||
* an exception will be raised with audio() attempts to set this port low
|
|
||||||
*/
|
|
||||||
/* TODO Do we really need to do this on every SF change? Once is probably enough */
|
|
||||||
EnableBufferedPort(p_dsd_clk, 32);
|
|
||||||
|
|
||||||
if(dsdMode)
|
|
||||||
{
|
|
||||||
/* Make sure the ports are on and buffered - just in case they are not shared with I2S */
|
|
||||||
for(int i = 0; i< DSD_CHANS_DAC; i++)
|
|
||||||
{
|
|
||||||
EnableBufferedPort(p_dsd_dac[i], 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigAudioPorts(
|
|
||||||
#if (DSD_CHANS_DAC != 0)
|
|
||||||
p_dsd_dac,
|
|
||||||
DSD_CHANS_DAC,
|
|
||||||
#endif
|
|
||||||
#if (I2S_CHANS_ADC != 0)
|
|
||||||
p_i2s_adc,
|
|
||||||
I2S_WIRES_ADC,
|
|
||||||
#endif
|
|
||||||
#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0)
|
|
||||||
#ifndef CODEC_MASTER
|
|
||||||
0, /* NULL */
|
|
||||||
p_dsd_clk,
|
|
||||||
#else
|
|
||||||
0, /* NULL */
|
|
||||||
p_dsd_clk,
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
divide);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
ConfigAudioPorts(
|
ConfigAudioPorts(
|
||||||
#if (I2S_CHANS_DAC != 0)
|
#if (I2S_CHANS_DAC != 0)
|
||||||
p_i2s_dac,
|
p_dac,
|
||||||
I2S_WIRES_DAC,
|
numPortsDac,
|
||||||
#endif
|
#endif
|
||||||
#if (I2S_CHANS_ADC != 0)
|
#if (I2S_CHANS_ADC != 0)
|
||||||
p_i2s_adc,
|
p_adc,
|
||||||
I2S_WIRES_ADC,
|
numPortsAdc,
|
||||||
#endif
|
#endif
|
||||||
#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0)
|
|
||||||
#ifndef CODEC_MASTER
|
|
||||||
p_lrclk,
|
p_lrclk,
|
||||||
p_bclk,
|
p_bclk,
|
||||||
#else
|
|
||||||
p_lrclk,
|
|
||||||
p_bclk,
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
divide);
|
divide);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -4,9 +4,6 @@
|
|||||||
#include <xccompat.h>
|
#include <xccompat.h>
|
||||||
#include "devicedefines.h"
|
#include "devicedefines.h"
|
||||||
|
|
||||||
void ConfigAudioPorts_dsd(unsigned int divide);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __XC__
|
#ifdef __XC__
|
||||||
void ConfigAudioPorts(
|
void ConfigAudioPorts(
|
||||||
#if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0)
|
#if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0)
|
||||||
@@ -61,19 +58,19 @@ void ConfigAudioPorts(
|
|||||||
#ifdef __XC__
|
#ifdef __XC__
|
||||||
void ConfigAudioPortsWrapper(
|
void ConfigAudioPortsWrapper(
|
||||||
#if (I2S_CHANS_DAC != 0)
|
#if (I2S_CHANS_DAC != 0)
|
||||||
buffered out port:32 p_i2s_dac[I2S_WIRES_DAC],
|
buffered out port:32 p_i2s_dac[], int numPortsDAC,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (I2S_CHANS_ADC != 0)
|
#if (I2S_CHANS_ADC != 0)
|
||||||
buffered in port:32 p_i2s_adc[I2S_WIRES_ADC],
|
buffered in port:32 p_i2s_adc[], int numPortsADC,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0)
|
#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0)
|
||||||
#ifndef CODEC_MASTER
|
#ifndef CODEC_MASTER
|
||||||
buffered out port:32 p_lrclk,
|
buffered out port:32 ?p_lrclk,
|
||||||
buffered out port:32 p_bclk,
|
buffered out port:32 p_bclk,
|
||||||
#else
|
#else
|
||||||
in port p_lrclk,
|
in port ?p_lrclk,
|
||||||
in port p_bclk,
|
in port p_bclk,
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@@ -82,28 +79,26 @@ void ConfigAudioPortsWrapper(
|
|||||||
|
|
||||||
void ConfigAudioPortsWrapper(
|
void ConfigAudioPortsWrapper(
|
||||||
#if (I2S_CHANS_DAC != 0)
|
#if (I2S_CHANS_DAC != 0)
|
||||||
port p_i2s_dac[I2S_WIRES_DAC],
|
port p_i2s_dac[], int numPortsDAC,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (I2S_CHANS_ADC != 0)
|
#if (I2S_CHANS_ADC != 0)
|
||||||
port p_i2s_adc[I2S_WIRES_ADC],
|
port p_i2s_adc[], int numPortsADC,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0)
|
#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0)
|
||||||
#ifndef CODEC_MASTER
|
|
||||||
port p_lrclk,
|
port p_lrclk,
|
||||||
port p_bclk,
|
port p_bclk,
|
||||||
#else
|
|
||||||
port p_lrclk,
|
|
||||||
port p_bclk,
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
unsigned int divide, unsigned int dsdMode);
|
unsigned int divide, unsigned int dsdMode);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __XC__*/
|
#endif /* __XC__*/
|
||||||
|
|
||||||
|
#ifdef __XC__
|
||||||
|
void EnableBufferedPort(buffered out port:32 p, unsigned transferWidth);
|
||||||
|
#else
|
||||||
|
void EnableBufferedPort(port p, unsigned transferWidth);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _AUDIOPORTS_H_ */
|
#endif /* _AUDIOPORTS_H_ */
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ unsigned int divide)
|
|||||||
#ifndef CODEC_MASTER
|
#ifndef CODEC_MASTER
|
||||||
/* Note this call to stop_clock() will pause forever if the port clocking the clock-block is not low.
|
/* Note this call to stop_clock() will pause forever if the port clocking the clock-block is not low.
|
||||||
* deliver() should return with this being the case */
|
* deliver() should return with this being the case */
|
||||||
|
|
||||||
stop_clock(clk_audio_bclk);
|
stop_clock(clk_audio_bclk);
|
||||||
|
|
||||||
if(!isnull(p_lrclk))
|
if(!isnull(p_lrclk))
|
||||||
|
|||||||
Reference in New Issue
Block a user