diff --git a/lib_xua/api/xua_audiohub.h b/lib_xua/api/xua_audiohub.h index d4eee767..b09b6997 100644 --- a/lib_xua/api/xua_audiohub.h +++ b/lib_xua/api/xua_audiohub.h @@ -17,12 +17,14 @@ * * \param c_aud Audio sample channel connected to the mixer() thread or the * decouple() thread + * \param p_mclk_in Master clock port * \param c_dig channel connected to the clockGen() thread for * receiving/transmitting samples * \param c_config An optional channel that will be passed on to the * CODEC configuration functions. */ void XUA_AudioHub(chanend ?c_aud + , in port p_mclk_in #if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE) , chanend c_spdif_tx #endif diff --git a/lib_xua/src/core/audiohub/xua_audiohub.xc b/lib_xua/src/core/audiohub/xua_audiohub.xc index 296c8bad..e53aaf70 100755 --- a/lib_xua/src/core/audiohub/xua_audiohub.xc +++ b/lib_xua/src/core/audiohub/xua_audiohub.xc @@ -100,7 +100,6 @@ extern buffered out port:32 p_bclk; unsigned dsdMode = DSD_MODE_OFF; /* Master clock input */ -extern unsafe port p_mclk_in; extern in port p_mclk_in2; #if (XUA_SPDIF_TX_EN) @@ -1274,6 +1273,7 @@ static void dummy_deliver(chanend ?c_out, unsigned &command) #endif void XUA_AudioHub(chanend ?c_mix_out + , in port p_mclk_in #if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE) , chanend c_spdif_out #endif diff --git a/lib_xua/src/core/main.xc b/lib_xua/src/core/main.xc index 43e6b35e..d7b193f5 100755 --- a/lib_xua/src/core/main.xc +++ b/lib_xua/src/core/main.xc @@ -123,15 +123,7 @@ on tile[AUDIO_IO_TILE] : buffered out port:32 p_lrclk = PORT_I2S_LRCLK; on tile[AUDIO_IO_TILE] : buffered out port:32 p_bclk = PORT_I2S_BCLK; #endif -/* Note, declared unsafe as sometimes we want to share this port -e.g. PDM mics and I2S use same master clock IO */ -on tile[AUDIO_IO_TILE] : port p_mclk_in_ = PORT_MCLK_IN; - -/* TODO p_mclk_in should be delared as an unsafe resource */ -unsafe -{ - unsafe port p_mclk_in; -} +on tile[AUDIO_IO_TILE] : in port p_mclk_in = PORT_MCLK_IN; #ifndef NO_USB on tile[XUD_TILE] : in port p_for_mclk_count = PORT_MCLK_COUNT; @@ -185,6 +177,16 @@ on tile[SPDIF_TX_TILE] : clock clk_mst_spd = CLKBLK_SPDIF_TX; on tile[XUD_TILE] : clock clk_spd_rx = CLKBLK_SPDIF_RX; #endif +#if (NUM_PDM_MICS > 0) +in port p_pdm_clk = PORT_PDM_CLK; + + in buffered port:32 p_pdm_mics = PORT_PDM_DATA; +#if (PDM_TILE != AUDIO_IO_TILE) +/* If Mics and I2S are not the same tile we need a separate MCLK port */ +in port p_pdm_mclk = PORT_PDM_MCLK; +#endif +#endif + #if(XUD_SERIES_SUPPORT == XUD_L_SERIES) && defined(ADAT_RX) /* Cannot use default clock (CLKBLK_REF) for ADAT RX since it is tied to the 60MHz USB clock on G/L series parts. */ @@ -351,12 +353,6 @@ VENDOR_REQUESTS_PARAMS_DEC_ unsigned x; thread_speed(); - /* TODO p_mclk_in should be delared as an unsafe resource */ - unsafe - { - p_mclk_in = p_mclk_in_; - } - /* Attach mclk count port to mclk clock-block (for feedback) */ //set_port_clock(p_for_mclk_count, clk_audio_mclk); #if(AUDIO_IO_TILE != XUD_TILE) @@ -440,6 +436,9 @@ void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc, , server interface i_dfu ?dfuInterface #endif #if (NUM_PDM_MICS > 0) +#if (PDM_TILE == AUDIO_IO_TILE) + , streaming chanend c_ds_output[2] +#endif , chanend c_pdm_pcm #endif ) @@ -454,6 +453,11 @@ void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc, #define c_dig_rx null #endif +#if (NUM_PDM_MICS > 0) && (PDM_TILE == AUDIO_IO_TILE) + /* Configure clocks ports - sharing mclk port with I2S */ + xua_pdm_mic_config(p_mclk_in, p_pdm_clk, p_pdm_mics, clk_pdm); +#endif + par { #ifdef MIXER @@ -472,6 +476,7 @@ void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc, #define AUDIO_CHANNEL c_aud_in #endif XUA_AudioHub(AUDIO_CHANNEL + , p_mclk_in #if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE) , c_spdif_tx #endif @@ -486,6 +491,9 @@ void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc, #endif ); } +#if (NUM_PDM_MICS > 0) && (PDM_TILE == AUDIO_IO_TILE) + xua_pdm_mic(c_ds_output, p_pdm_mics); +#endif #if defined(SPDIF_RX) || defined(ADAT_RX) { @@ -614,11 +622,6 @@ int main() on tile[AUDIO_IO_TILE]: { - /* TODO p_mclk_in should be delared as an unsafe resource */ - unsafe - { - p_mclk_in = p_mclk_in_; - } usb_audio_io(c_mix_out, c_adc #if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE) , c_spdif_tx @@ -631,6 +634,9 @@ int main() , dfuInterface #endif #if (NUM_PDM_MICS > 0) +#if (PDM_TILE == AUDIO_IO_TILE) + , c_ds_output +#endif , c_pdm_pcm #endif ); @@ -706,16 +712,14 @@ int main() #ifndef PDM_RECORD #if (NUM_PDM_MICS > 0) - +#if (PDM_TILE != AUDIO_IO_TILE) + /* PDM Mics running on a separate to AudioHub */ on stdcore[PDM_TILE]: { - /* TODO p_mclk_in should be delared as an unsafe resource */ - unsafe - { - p_mclk_in = p_mclk_in_; - } - pdm_mic(c_ds_output); + xua_pdm_mic_config(p_pdm_mclk, p_pdm_clk, p_pdm_mics, clk_pdm); + xua_pdm_mic(c_ds_output, p_pdm_mics); } +#endif #ifdef MIC_PROCESSING_USE_INTERFACE on stdcore[PDM_TILE].core[0]: pdm_buffer(c_ds_output, c_pdm_pcm, i_mic_process); #else diff --git a/lib_xua/src/core/pdm_mics/pdm_mic.xc b/lib_xua/src/core/pdm_mics/pdm_mic.xc index 481187c8..e22658aa 100644 --- a/lib_xua/src/core/pdm_mics/pdm_mic.xc +++ b/lib_xua/src/core/pdm_mics/pdm_mic.xc @@ -20,21 +20,6 @@ #define MAX_DECIMATION_FACTOR (96000/(MIN_FREQ/AUD_TO_MICS_RATIO)) -/* Hardware resources */ -/* TODO these should be in main.xc with the rest of the resources */ -in port p_pdm_clk = PORT_PDM_CLK; - -in buffered port:32 p_pdm_mics = PORT_PDM_DATA; -#if (PDM_TILE != AUDIO_IO_TILE) -/* If Mics and I2S are on the same tile we'll share an MCLK port */ -in port p_pdm_mclk = PORT_PDM_MCLK; -#else -extern unsafe port p_mclk_in; -#endif - -/* Delcared in main.xc */ -extern clock clk_pdm; - #ifndef MIC_BUFFER_DEPTH #define MIC_BUFFER_DEPTH 1 #endif @@ -228,15 +213,8 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) #error MAX_FREQ > 48000 NOT CURRENTLY SUPPORTED #endif -void pdm_mic(streaming chanend c_ds_output[2]) +void xua_pdm_mic_config(in port p_pdm_mclk, in port p_pdm_clk, buffered in port:32 p_pdm_mics, clock clk_pdm) { - streaming chan c_4x_pdm_mic_0; -#if (NUM_PDM_MICS > 4) - streaming chan c_4x_pdm_mic_1; -#else - #define c_4x_pdm_mic_1 null -#endif - /* Mics expect a clock in the 3Mhz range, calculate the divide based on mclk */ /* e.g. For a 48kHz range mclk we expect a 3072000Hz mic clock */ /* e.g. For a 44.1kHz range mclk we expect a 2822400Hz mic clock */ @@ -246,19 +224,22 @@ void pdm_mic(streaming chanend c_ds_output[2]) unsigned micDiv = MCLK_48/3072000; -#if (PDM_TILE != AUDIO_IO_TILE) configure_clock_src_divide(clk_pdm, p_pdm_mclk, micDiv/2); -#else - /* Sharing mclk port with I2S */ - unsafe - { - configure_clock_src_divide(clk_pdm, (port) p_mclk_in, micDiv/2); - } -#endif + configure_port_clock_output(p_pdm_clk, clk_pdm); configure_in_port(p_pdm_mics, clk_pdm); start_clock(clk_pdm); +} +void xua_pdm_mic(streaming chanend c_ds_output[2], buffered in port:32 p_pdm_mics) +{ + streaming chan c_4x_pdm_mic_0; +#if (NUM_PDM_MICS > 4) + streaming chan c_4x_pdm_mic_1; +#else + #define c_4x_pdm_mic_1 null +#endif + par { mic_array_pdm_rx(p_pdm_mics, c_4x_pdm_mic_0, c_4x_pdm_mic_1); @@ -268,4 +249,5 @@ void pdm_mic(streaming chanend c_ds_output[2]) #endif } } + #endif diff --git a/lib_xua/src/core/pdm_mics/xua_pdm_mic.h b/lib_xua/src/core/pdm_mics/xua_pdm_mic.h index 1dcb983b..d56bff3a 100644 --- a/lib_xua/src/core/pdm_mics/xua_pdm_mic.h +++ b/lib_xua/src/core/pdm_mics/xua_pdm_mic.h @@ -2,6 +2,9 @@ #include "mic_array.h" +/* Configures PDM ports/clocks */ +void xua_pdm_mic_config(in port p_pdm_mclk, in port p_pdm_clk, buffered in port:32 p_pdm_mics, clock clk_pdm); + #ifdef MIC_PROCESSING_USE_INTERFACE /* Interface based user processing */ typedef interface mic_process_if @@ -22,7 +25,7 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio void user_pdm_process(server mic_process_if i_mic_data); /* PDM interface and decimation cores */ -void pdm_mic(streaming chanend c_ds_output[2]); +void xua_pdm_mic(streaming chanend c_ds_output[2], buffered in port:32 p_pdm_mics); #else @@ -36,7 +39,7 @@ void user_pdm_init(); void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio); /* PDM interface and decimation cores */ -void pdm_mic(streaming chanend c_ds_output[2]); +void xua_pdm_mic(streaming chanend c_ds_output[2], buffered in port:32 p_pdm_mics); #endif diff --git a/lib_xua/src/core/ports/audioports.xc b/lib_xua/src/core/ports/audioports.xc index 2f26b9af..80d2500a 100644 --- a/lib_xua/src/core/ports/audioports.xc +++ b/lib_xua/src/core/ports/audioports.xc @@ -7,7 +7,7 @@ -extern unsafe port p_mclk_in; +extern in port p_mclk_in; extern clock clk_audio_mclk; extern clock clk_audio_bclk;