Skip to content

Commit

Permalink
Merge pull request #273 from xross/feature/bringup_316
Browse files Browse the repository at this point in the history
Feature/bringup 316
  • Loading branch information
xross authored Jul 11, 2022
2 parents d6abd5d + f534537 commit 8157a76
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 212 deletions.
8 changes: 4 additions & 4 deletions legacy_tests/app_test_i2s_loopback/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ BUILD_FLAGS_i2s_slave_8in_8out_192khz = $(BUILD_FLAGS) \
-D DEFAULT_FREQ=192000 -DCODEC_MASTER=1 \
-O2 # optimisations to meet timing

BUILD_FLAGS_tdm_master_8in_8out_48khz = $(BUILD_FLAGS) -D I2S_MODE_TDM=1 \
BUILD_FLAGS_tdm_master_8in_8out_48khz = $(BUILD_FLAGS) -D XUA_PCM_FORMAT=XUA_PCM_FORMAT_TDM \
-D ADAT_RX=0 -D ADAT_TX=0 -D SPDIF_RX=0 -D SPDIF_TX=0 -D MIDI=0 \
-D NUM_USB_CHAN_IN=8 -D NUM_USB_CHAN_OUT=8 -D I2S_CHANS_ADC=8 -D I2S_CHANS_DAC=8 \
-D DEFAULT_FREQ=48000 \
-O2 # optimisations to meet timing

BUILD_FLAGS_tdm_slave_8in_8out_48khz = $(BUILD_FLAGS) -D I2S_MODE_TDM=1 \
BUILD_FLAGS_tdm_slave_8in_8out_48khz = $(BUILD_FLAGS) -D XUA_PCM_FORMAT=XUA_PCM_FORMAT_TDM \
-D ADAT_RX=0 -D ADAT_TX=0 -D SPDIF_RX=0 -D SPDIF_TX=0 -D MIDI=0 \
-D NUM_USB_CHAN_IN=8 -D NUM_USB_CHAN_OUT=8 -D I2S_CHANS_ADC=8 -D I2S_CHANS_DAC=8 \
-D DEFAULT_FREQ=48000 -DCODEC_MASTER=1 \
-O2 # optimisations to meet timing

BUILD_FLAGS_tdm_master_16in_16out_48khz = $(BUILD_FLAGS) -D I2S_MODE_TDM=1 \
BUILD_FLAGS_tdm_master_16in_16out_48khz = $(BUILD_FLAGS) -D XUA_PCM_FORMAT=XUA_PCM_FORMAT_TDM \
-D ADAT_RX=0 -D ADAT_TX=0 -D SPDIF_RX=0 -D SPDIF_TX=0 -D MIDI=0 \
-D NUM_USB_CHAN_IN=16 -D NUM_USB_CHAN_OUT=16 -D I2S_CHANS_ADC=16 -D I2S_CHANS_DAC=16 \
-D DEFAULT_FREQ=48000 \
-O2 # optimisations to meet timing

BUILD_FLAGS_tdm_slave_16in_16out_48khz = $(BUILD_FLAGS) -D I2S_MODE_TDM=1 \
BUILD_FLAGS_tdm_slave_16in_16out_48khz = $(BUILD_FLAGS) -D XUA_PCM_FORMAT=XUA_PCM_FORMAT_TDM \
-D ADAT_RX=0 -D ADAT_TX=0 -D SPDIF_RX=0 -D SPDIF_TX=0 -D MIDI=0 \
-D NUM_USB_CHAN_IN=16 -D NUM_USB_CHAN_OUT=16 -D I2S_CHANS_ADC=16 -D I2S_CHANS_DAC=16 \
-D DEFAULT_FREQ=48000 -DCODEC_MASTER=1 \
Expand Down
2 changes: 1 addition & 1 deletion legacy_tests/app_test_i2s_loopback/main.xc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void slave_mode_clk_setup(const unsigned samFreq, const unsigned chans_per_frame

#endif

#if I2S_MODE_TDM
#if (XUA_PCM_FORMAT == XUA_PCM_FORMAT_TDM)
const int i2s_tdm_mode = 8;
#else
const int i2s_tdm_mode = 2;
Expand Down
2 changes: 1 addition & 1 deletion lib_xua/api/xua_audiohub.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void XUA_AudioHub(chanend ?c_aud,
#if (XUA_SPDIF_TX_EN) //&& (SPDIF_TX_TILE != AUDIO_IO_TILE)
, chanend c_spdif_tx
#endif
#if((SPDIF_RX) || (ADAT_RX))
#if (XUA_SPDIF_RX_EN || ADAT_RX)
, chanend c_dig
#endif
#if (XUD_TILE != 0) && (AUDIO_IO_TILE == 0) && (XUA_DFU_EN == 1)
Expand Down
8 changes: 4 additions & 4 deletions lib_xua/api/xua_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void XUA_Buffer(
chanend c_midi_to_host,
chanend c_midi,
#endif
#if (SPDIF_RX) || (ADAT_RX)
#if (XUA_SPDIF_RX_EN) || (ADAT_RX)
chanend ?c_int,
chanend ?c_clk_int,
#endif
Expand All @@ -51,7 +51,7 @@ void XUA_Buffer(
#endif
, chanend c_aud
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
, client interface sync_if i_sync
, client interface pll_ref_if i_pll_ref
#endif
);

Expand All @@ -67,7 +67,7 @@ void XUA_Buffer_Ep(chanend c_aud_out,
chanend c_midi_to_host,
chanend c_midi,
#endif
#if (SPDIF_RX) || (ADAT_RX)
#if (XUA_SPDIF_RX_EN) || (ADAT_RX)
chanend ?c_int,
chanend ?c_clk_int,
#endif
Expand All @@ -81,7 +81,7 @@ void XUA_Buffer_Ep(chanend c_aud_out,
, chanend c_buff_ctrl
#endif
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
, client interface sync_if i_sync
, client interface pll_ref_if i_pll_ref
#endif
);

Expand Down
33 changes: 19 additions & 14 deletions lib_xua/api/xua_conf_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,25 @@
#define DSD_CHANS_DAC 0
#endif

#define XUA_PCM_FORMAT_I2S (0)
#define XUA_PCM_FORMAT_TDM (1)

/* TODO not required */
#ifndef I2S_MODE_TDM
#define I2S_MODE_TDM 0
#ifdef XUA_PCM_FORMAT
#if (XUA_PCM_FORMAT != XUA_PCM_FORMAT_I2S) && (XUA_PCM_FORMAT != XUA_PCM_FORMAT_TDM)
#error Bad value for XUA_PCM_FORMAT
#endif
#else
#define XUA_PCM_FORMAT XUA_PCM_FORMAT_I2S
#endif

/**
* @brief Channels per I2S frame. *
*
* Default: 2 i.e standard stereo I2S (8 if using TDM i.e. I2S_MODE_TDM).
* Default: 2 i.e standard stereo I2S (8 if using TDM i.e. XUA_PCM_FORMAT_TDM).
*
**/
#ifndef I2S_CHANS_PER_FRAME
#if (I2S_MODE_TDM == 1)
#if (XUA_PCM_FORMAT == XUA_PCM_FORMAT_TDM)
#define I2S_CHANS_PER_FRAME 8
#else
#define I2S_CHANS_PER_FRAME 2
Expand Down Expand Up @@ -188,7 +193,7 @@
*/
#if (I2S_DOWNSAMPLE_MONO_IN == 1)
#define I2S_DOWNSAMPLE_CHANS_IN (I2S_CHANS_ADC / 2)
#if ((I2S_DOWNSAMPLE_FACTOR_IN > 1) && (I2S_MODE_TDM == 1))
#if ((I2S_DOWNSAMPLE_FACTOR_IN > 1) && (XUA_PCM_FORMAT == XUA_PCM_FORMAT_TDM))
#error Mono I2S input downsampling is not avaliable in TDM mode
#endif
#else
Expand Down Expand Up @@ -359,8 +364,8 @@
/**
* @brief Enables SPDIF Rx. Default: 0 (Disabled)
*/
#ifndef SPDIF_RX
#define SPDIF_RX (0)
#ifndef XUA_SPDIF_RX_EN
#define XUA_SPDIF_RX_EN (0)
#endif

/**
Expand All @@ -376,9 +381,9 @@
*
* Default: NONE (Must be defined by app when SPDIF_RX enabled)
*/
#if (SPDIF_RX) || defined (__DOXYGEN__)
#if (XUA_SPDIF_RX_EN) || defined (__DOXYGEN__)
#ifndef SPDIF_RX_INDEX
#error SPDIF_RX_INDEX not defined and SPDIF_RX defined
#error SPDIF_RX_INDEX not defined and XUA_SPDIF_RX_EN defined
#define SPDIF_RX_INDEX 0 /* Default define for doxygen */
#endif
#endif
Expand Down Expand Up @@ -1163,7 +1168,7 @@ enum USBEndpointNumber_In
ENDPOINT_NUMBER_IN_FEEDBACK,
#endif
ENDPOINT_NUMBER_IN_AUDIO,
#if (SPDIF_RX) || (ADAT_RX)
#if (XUA_SPDIF_RX_EN) || (ADAT_RX)
ENDPOINT_NUMBER_IN_INTERRUPT, /* Audio interrupt/status EP */
#endif
#ifdef MIDI
Expand Down Expand Up @@ -1237,9 +1242,9 @@ enum USBEndpointNumber_Out
#endif

/* Length of clock unit/clock-selector units */
#if (SPDIF_RX) && (ADAT_RX)
#if (XUA_SPDIF_RX_EN) && (ADAT_RX)
#define NUM_CLOCKS (3)
#elif (SPDIF_RX) || (ADAT_RX)
#elif (XUA_SPDIF_RX_EN) || (ADAT_RX)
#define NUM_CLOCKS (2)
#else
#define NUM_CLOCKS (1)
Expand Down Expand Up @@ -1467,7 +1472,7 @@ enum USBEndpointNumber_Out
#endif

#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
#if (SPDIF_RX || ADAT_RX)
#if (XUA_SPDIF_RX_EN|| ADAT_RX)
#error "Digital input streams not supported in Sync mode"
#endif
#endif
2 changes: 1 addition & 1 deletion lib_xua/src/core/audiohub/audiohub_initport.xc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void InitPorts_slave(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, buf
p_lrclk when pinseq(1) :> void;
p_lrclk when pinseq(0) :> void;
p_lrclk when pinseq(1) :> void;
#if I2S_MODE_TDM
#if (XUA_PCM_FORMAT == XUA_PCM_FORMAT_TDM)
p_lrclk when pinseq(0) :> void;
p_lrclk when pinseq(1) :> void @ tmp;
#else
Expand Down
28 changes: 14 additions & 14 deletions lib_xua/src/core/audiohub/xua_audiohub.xc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
static unsigned samplesOut[MAX(NUM_USB_CHAN_OUT, I2S_CHANS_DAC)];

/* Two buffers for ADC data to allow for DAC and ADC I2S ports being offset */
#define IN_CHAN_COUNT (I2S_CHANS_ADC + XUA_NUM_PDM_MICS + (8*ADAT_RX) + (2*SPDIF_RX))
#define IN_CHAN_COUNT (I2S_CHANS_ADC + XUA_NUM_PDM_MICS + (8*ADAT_RX) + (2*XUA_SPDIF_RX_EN))

static unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)];

Expand Down Expand Up @@ -161,7 +161,7 @@ static inline int HandleSampleClock(int frameCount, buffered _XUA_CLK_DIR port:3
unsigned lrval = 0;
p_lrclk :> lrval;

if(I2S_MODE_TDM)
if(XUA_PCM_FORMAT == XUA_PCM_FORMAT_TDM)
{
/* Only check for the rising edge of frame sync being in the right place because falling edge timing not specified */
if (frameCount == 1)
Expand All @@ -186,7 +186,7 @@ static inline int HandleSampleClock(int frameCount, buffered _XUA_CLK_DIR port:3
return syncError;

#else
if(I2S_MODE_TDM)
if(XUA_PCM_FORMAT == XUA_PCM_FORMAT_TDM)
{
if(frameCount == (I2S_CHANS_PER_FRAME-1))
p_lrclk <: 0x80000000;
Expand All @@ -213,7 +213,7 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
, unsigned adatSmuxMode
#endif
, unsigned divide, unsigned curSamFreq
#if( (SPDIF_RX==1) || (ADAT_RX == 1))
#if (XUA_SPDIF_RX_EN || ADAT_RX)
, chanend c_dig_rx
#endif
#if (XUA_NUM_PDM_MICS > 0)
Expand Down Expand Up @@ -418,17 +418,17 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
if(frameCount == 0)
{

#if (SPDIF_RX == 1) || (ADAT_RX == 1)
#if (XUA_SPDIF_RX_EN || ADAT_RX)
/* Sync with clockgen */
inuint(c_dig_rx);

/* Note, digi-data we just store in samplesIn[readBuffNo] - we only double buffer the I2S input data */
#endif
#if (SPDIF_RX == 1)
#if (XUA_SPDIF_RX_EN)
asm("ldw %0, dp[g_digData]" :"=r"(samplesIn[readBuffNo][SPDIF_RX_INDEX + 0]));
asm("ldw %0, dp[g_digData+4]":"=r"(samplesIn[readBuffNo][SPDIF_RX_INDEX + 1]));
#endif
#if (ADAT_RX == 1)
#if (ADAT_RX)
asm("ldw %0, dp[g_digData+8]" :"=r"(samplesIn[readBuffNo][ADAT_RX_INDEX]));
asm("ldw %0, dp[g_digData+12]":"=r"(samplesIn[readBuffNo][ADAT_RX_INDEX + 1]));
asm("ldw %0, dp[g_digData+16]":"=r"(samplesIn[readBuffNo][ADAT_RX_INDEX + 2]));
Expand All @@ -439,7 +439,7 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
asm("ldw %0, dp[g_digData+36]":"=r"(samplesIn[readBuffNo][ADAT_RX_INDEX + 7]));
#endif

#if (SPDIF_RX == 1) || (ADAT_RX == 1)
#if (XUA_SPDIF_RX_EN || ADAT_RX)
/* Request digital data (with prefill) */
outuint(c_dig_rx, 0);
#endif
Expand Down Expand Up @@ -553,7 +553,7 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
}
#endif

#if I2S_MODE_TDM
#if (XUA_PCM_FORMAT == XUA_PCM_FORMAT_TDM)
/* Increase frameCount by 2 since we have output two channels (per data line) */
frameCount+=1;
if(frameCount == I2S_CHANS_PER_FRAME)
Expand Down Expand Up @@ -668,7 +668,7 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
#if (XUA_SPDIF_TX_EN) //&& (SPDIF_TX_TILE != AUDIO_IO_TILE)
, chanend c_spdif_out
#endif
#if ((ADAT_RX == 1) || (SPDIF_RX == 1))
#if (ADAT_RX || XUA_SPDIF_RX_EN)
, chanend c_dig_rx
#endif
#if (XUD_TILE != 0) && (AUDIO_IO_TILE == 0) && (XUA_DFU_EN == 1)
Expand Down Expand Up @@ -724,7 +724,7 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
while(1)
{
/* Calculate what master clock we should be using */
if ((MCLK_441 % curSamFreq) == 0)
if (((MCLK_441) % curSamFreq) == 0)
{
mClk = MCLK_441;
#ifdef ADAT_TX
Expand All @@ -733,7 +733,7 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
adatMultiple = mClk / 44100;
#endif
}
else if ((MCLK_48 % curSamFreq) == 0)
else if (((MCLK_48) % curSamFreq) == 0)
{
mClk = MCLK_48;
#ifdef ADAT_TX
Expand All @@ -746,7 +746,7 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
/* Calculate master clock to bit clock (or DSD clock) divide for current sample freq
* e.g. 11.289600 / (176400 * 64) = 1 */
{
#if I2S_MODE_TDM
#if (XUA_PCM_FORMAT == XUA_PCM_FORMAT_TDM)
/* I2S has 32 bits per sample. *8 as 8 channels */
unsigned numBits = 256;
#else
Expand Down Expand Up @@ -905,7 +905,7 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
, adatSmuxMode
#endif
, divide, curSamFreq
#if (ADAT_RX == 1) || (SPDIF_RX == 1)
#if (ADAT_RX || XUA_SPDIF_RX_EN)
, c_dig_rx
#endif
#if (XUA_NUM_PDM_MICS > 0)
Expand Down
20 changes: 10 additions & 10 deletions lib_xua/src/core/buffer/ep/ep_buffer.xc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ unsigned g_speed = (AUDIO_CLASS == 2) ? (DEFAULT_FREQ/8000) << 16 : (DEFAULT_FRE
unsigned g_freqChange = 0;
unsigned feedbackValid = 0;

#if defined (SPDIF_RX) || defined (ADAT_RX)
#if (XUA_SPDIF_RX_EN || ADAT_RX)
/* When digital Rx enabled we enable an interrupt EP to inform host about changes in clock validity */
/* Interrupt EP report data */
unsigned char g_intData[8] =
Expand Down Expand Up @@ -103,7 +103,7 @@ void XUA_Buffer(
chanend c_midi_to_host,
chanend c_midi,
#endif
#if (SPDIF_RX) || (ADAT_RX)
#if (XUA_SPDIF_RX_EN) || (ADAT_RX)
chanend ?c_ep_int,
chanend ?c_clk_int,
#endif
Expand All @@ -115,7 +115,7 @@ void XUA_Buffer(
#endif
, chanend c_aud
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
, client interface sync_if i_sync
, client interface pll_ref_if i_pll_ref
#endif
)
{
Expand All @@ -137,7 +137,7 @@ void XUA_Buffer(
c_midi_to_host, /* MIDI In */ // 4
c_midi,
#endif
#if (SPDIF_RX) || (ADAT_RX)
#if (XUA_SPDIF_RX_EN || ADAT_RX)
/* Audio Interrupt - only used for interrupts on external clock change */
c_ep_int,
c_clk_int,
Expand All @@ -150,7 +150,7 @@ void XUA_Buffer(
, c_buff_ctrl
#endif
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
, i_sync
, i_pll_ref
#endif
);

Expand Down Expand Up @@ -186,7 +186,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
chanend c_midi_to_host,
chanend c_midi,
#endif
#if (SPDIF_RX) || (ADAT_RX)
#if (XUA_SPDIF_RX_EN || ADAT_RX)
chanend ?c_ep_int,
chanend ?c_clk_int,
#endif
Expand All @@ -200,7 +200,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
, chanend c_buff_ctrl
#endif
#if XUA_SYNCMODE == XUA_SYNCMODE_SYNC
, client interface sync_if i_sync
, client interface pll_ref_if i_pll_ref
#endif
)
{
Expand Down Expand Up @@ -229,7 +229,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
XUD_ep ep_iap_ea_native_in = XUD_InitEp(c_iap_ea_native_in);
#endif
#endif
#if (SPDIF_RX) || (ADAT_RX)
#if (XUA_SPDIF_RX_EN || ADAT_RX)
XUD_ep ep_int = XUD_InitEp(c_ep_int);
#endif

Expand Down Expand Up @@ -367,7 +367,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
/* Wait for response from XUD and service relevant EP */
select
{
#if (SPDIF_RX) || (ADAT_RX)
#if (XUA_SPDIF_RX_EN || ADAT_RX)
/* Clocking thread wants to produce an interrupt... */
case inuint_byref(c_clk_int, u_tmp):
chkct(c_clk_int, XS1_CT_END);
Expand Down Expand Up @@ -529,7 +529,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
if (sofCount == framesPerSec)
{
/* Port is accessed via interface to allow flexibilty with location */
i_sync.toggle();
i_pll_ref.toggle();
sofCount = 0;
}
#else
Expand Down
Loading

0 comments on commit 8157a76

Please sign in to comment.