From 513761ef5b9262e0dca22f4caa920dbac56a2936 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Tue, 17 Jan 2023 11:33:52 +0000 Subject: [PATCH] Moved DoSampleTransfer to a header file so it can still be inlined (but also used in unit tests). Resolves fails in test_i2s_loopback --- lib_xua/api/xua_audiohub.h | 8 +-- lib_xua/src/core/audiohub/xua_audiohub.xc | 63 +-------------------- lib_xua/src/core/audiohub/xua_audiohub_st.h | 63 +++++++++++++++++++++ tests/test_mixer_routing_output/src/main.xc | 2 +- 4 files changed, 69 insertions(+), 67 deletions(-) create mode 100644 lib_xua/src/core/audiohub/xua_audiohub_st.h diff --git a/lib_xua/api/xua_audiohub.h b/lib_xua/api/xua_audiohub.h index 485abb0d..5f3e9ca2 100644 --- a/lib_xua/api/xua_audiohub.h +++ b/lib_xua/api/xua_audiohub.h @@ -1,9 +1,9 @@ // Copyright 2011-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. -#ifndef __XUA_AUDIOHUB_H__ -#define __XUA_AUDIOHUB_H__ +#ifndef _XUA_AUDIOHUB_H_ +#define _XUA_AUDIOHUB_H_ -#if __XC__ +#ifdef __XC__ #include "xccompat.h" #include "xs1.h" @@ -80,4 +80,4 @@ void UserBufferManagementInit(); void UserBufferManagement(unsigned sampsFromUsbToAudio[], unsigned sampsFromAudioToUsb[]); -#endif // __XUA_AUDIOHUB_H__ +#endif // _XUA_AUDIOHUB_H_ diff --git a/lib_xua/src/core/audiohub/xua_audiohub.xc b/lib_xua/src/core/audiohub/xua_audiohub.xc index c2e4b021..b10bc3d9 100755 --- a/lib_xua/src/core/audiohub/xua_audiohub.xc +++ b/lib_xua/src/core/audiohub/xua_audiohub.xc @@ -90,68 +90,7 @@ unsigned dsdMode = DSD_MODE_OFF; #include "audiohub_adat.h" #endif -#pragma unsafe arrays -unsigned DoSampleTransfer(chanend ?c_out, const int readBuffNo, const unsigned underflowWord) -{ - if(XUA_USB_EN) - { - outuint(c_out, underflowWord); - - /* Check for sample freq change (or other command) or new samples from mixer*/ - if(testct(c_out)) - { - unsigned command = inct(c_out); -#ifndef CODEC_MASTER - if(dsdMode == DSD_MODE_OFF) - { -#if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0) - /* Set clocks low */ - p_lrclk <: 0; - p_bclk <: 0; -#endif - } - else - { -#if(DSD_CHANS_DAC != 0) - /* DSD Clock might not be shared with lrclk or bclk... */ - p_dsd_clk <: 0; -#endif - } -#endif -#if (DSD_CHANS_DAC > 0) - if(dsdMode == DSD_MODE_DOP) - dsdMode = DSD_MODE_OFF; -#endif - return command; - } - else - { -#if NUM_USB_CHAN_OUT > 0 -#pragma loop unroll - for(int i = 0; i < NUM_USB_CHAN_OUT; i++) - { - int tmp = inuint(c_out); - samplesOut[i] = tmp; - } -#else - inuint(c_out); -#endif - UserBufferManagement(samplesOut, samplesIn[readBuffNo]); - -#if NUM_USB_CHAN_IN > 0 -#pragma loop unroll - for(int i = 0; i < NUM_USB_CHAN_IN; i++) - { - outuint(c_out, samplesIn[readBuffNo][i]); - } -#endif - } - } - else - UserBufferManagement(samplesOut, samplesIn[readBuffNo]); - - return 0; -} +#include "xua_audiohub_st.h" static inline int HandleSampleClock(int frameCount, buffered _XUA_CLK_DIR port:32 p_lrclk) { diff --git a/lib_xua/src/core/audiohub/xua_audiohub_st.h b/lib_xua/src/core/audiohub/xua_audiohub_st.h new file mode 100644 index 00000000..80c651fb --- /dev/null +++ b/lib_xua/src/core/audiohub/xua_audiohub_st.h @@ -0,0 +1,63 @@ +#pragma unsafe arrays +inline unsigned DoSampleTransfer(chanend ?c_out, const int readBuffNo, const unsigned underflowWord) +{ + if(XUA_USB_EN) + { + outuint(c_out, underflowWord); + + /* Check for sample freq change (or other command) or new samples from mixer*/ + if(testct(c_out)) + { + unsigned command = inct(c_out); +#ifndef CODEC_MASTER + if(dsdMode == DSD_MODE_OFF) + { +#if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0) + /* Set clocks low */ + p_lrclk <: 0; + p_bclk <: 0; +#endif + } + else + { +#if(DSD_CHANS_DAC != 0) + /* DSD Clock might not be shared with lrclk or bclk... */ + p_dsd_clk <: 0; +#endif + } +#endif +#if (DSD_CHANS_DAC > 0) + if(dsdMode == DSD_MODE_DOP) + dsdMode = DSD_MODE_OFF; +#endif + return command; + } + else + { +#if NUM_USB_CHAN_OUT > 0 +#pragma loop unroll + for(int i = 0; i < NUM_USB_CHAN_OUT; i++) + { + int tmp = inuint(c_out); + samplesOut[i] = tmp; + } +#else + inuint(c_out); +#endif + UserBufferManagement(samplesOut, samplesIn[readBuffNo]); + +#if NUM_USB_CHAN_IN > 0 +#pragma loop unroll + for(int i = 0; i < NUM_USB_CHAN_IN; i++) + { + outuint(c_out, samplesIn[readBuffNo][i]); + } +#endif + } + } + else + UserBufferManagement(samplesOut, samplesIn[readBuffNo]); + + return 0; +} + diff --git a/tests/test_mixer_routing_output/src/main.xc b/tests/test_mixer_routing_output/src/main.xc index fcd05ca7..f5afd627 100644 --- a/tests/test_mixer_routing_output/src/main.xc +++ b/tests/test_mixer_routing_output/src/main.xc @@ -356,9 +356,9 @@ void CheckBlock(unsigned samplesOut[], uint32_t expectedOut[], size_t len) } /* From xua_audiohub.xc */ -unsigned DoSampleTransfer(chanend ?c_out, const int readBuffNo, const unsigned underflowWord); extern unsigned samplesOut[NUM_USB_CHAN_OUT]; extern unsigned samplesIn[2][NUM_USB_CHAN_IN]; +#include "xua_audiohub_st.h" int Fake_XUA_AudioHub(chanend c_mix_aud, chanend c_stim) {