Remove global variable for p_mclk_in

This commit is contained in:
Luciano Martin
2019-05-29 16:33:46 +01:00
committed by Larry Snizek
parent 156bf61b62
commit 2aab72a817
6 changed files with 53 additions and 62 deletions

View File

@@ -17,12 +17,14 @@
* *
* \param c_aud Audio sample channel connected to the mixer() thread or the * \param c_aud Audio sample channel connected to the mixer() thread or the
* decouple() thread * decouple() thread
* \param p_mclk_in Master clock port
* \param c_dig channel connected to the clockGen() thread for * \param c_dig channel connected to the clockGen() thread for
* receiving/transmitting samples * receiving/transmitting samples
* \param c_config An optional channel that will be passed on to the * \param c_config An optional channel that will be passed on to the
* CODEC configuration functions. * CODEC configuration functions.
*/ */
void XUA_AudioHub(chanend ?c_aud void XUA_AudioHub(chanend ?c_aud
, in port p_mclk_in
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE) #if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
, chanend c_spdif_tx , chanend c_spdif_tx
#endif #endif

View File

@@ -100,7 +100,6 @@ extern buffered out port:32 p_bclk;
unsigned dsdMode = DSD_MODE_OFF; unsigned dsdMode = DSD_MODE_OFF;
/* Master clock input */ /* Master clock input */
extern unsafe port p_mclk_in;
extern in port p_mclk_in2; extern in port p_mclk_in2;
#if (XUA_SPDIF_TX_EN) #if (XUA_SPDIF_TX_EN)
@@ -1274,6 +1273,7 @@ static void dummy_deliver(chanend ?c_out, unsigned &command)
#endif #endif
void XUA_AudioHub(chanend ?c_mix_out void XUA_AudioHub(chanend ?c_mix_out
, in port p_mclk_in
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE) #if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
, chanend c_spdif_out , chanend c_spdif_out
#endif #endif

View File

@@ -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; on tile[AUDIO_IO_TILE] : buffered out port:32 p_bclk = PORT_I2S_BCLK;
#endif #endif
/* Note, declared unsafe as sometimes we want to share this port on tile[AUDIO_IO_TILE] : in port p_mclk_in = PORT_MCLK_IN;
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;
}
#ifndef NO_USB #ifndef NO_USB
on tile[XUD_TILE] : in port p_for_mclk_count = PORT_MCLK_COUNT; 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; on tile[XUD_TILE] : clock clk_spd_rx = CLKBLK_SPDIF_RX;
#endif #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) #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 /* Cannot use default clock (CLKBLK_REF) for ADAT RX since it is tied to the
60MHz USB clock on G/L series parts. */ 60MHz USB clock on G/L series parts. */
@@ -351,12 +353,6 @@ VENDOR_REQUESTS_PARAMS_DEC_
unsigned x; unsigned x;
thread_speed(); 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) */ /* Attach mclk count port to mclk clock-block (for feedback) */
//set_port_clock(p_for_mclk_count, clk_audio_mclk); //set_port_clock(p_for_mclk_count, clk_audio_mclk);
#if(AUDIO_IO_TILE != XUD_TILE) #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 , server interface i_dfu ?dfuInterface
#endif #endif
#if (NUM_PDM_MICS > 0) #if (NUM_PDM_MICS > 0)
#if (PDM_TILE == AUDIO_IO_TILE)
, streaming chanend c_ds_output[2]
#endif
, chanend c_pdm_pcm , chanend c_pdm_pcm
#endif #endif
) )
@@ -454,6 +453,11 @@ void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc,
#define c_dig_rx null #define c_dig_rx null
#endif #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 par
{ {
#ifdef MIXER #ifdef MIXER
@@ -472,6 +476,7 @@ void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc,
#define AUDIO_CHANNEL c_aud_in #define AUDIO_CHANNEL c_aud_in
#endif #endif
XUA_AudioHub(AUDIO_CHANNEL XUA_AudioHub(AUDIO_CHANNEL
, p_mclk_in
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE) #if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
, c_spdif_tx , c_spdif_tx
#endif #endif
@@ -486,6 +491,9 @@ void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc,
#endif #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) #if defined(SPDIF_RX) || defined(ADAT_RX)
{ {
@@ -614,11 +622,6 @@ int main()
on tile[AUDIO_IO_TILE]: 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 usb_audio_io(c_mix_out, c_adc
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE) #if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
, c_spdif_tx , c_spdif_tx
@@ -631,6 +634,9 @@ int main()
, dfuInterface , dfuInterface
#endif #endif
#if (NUM_PDM_MICS > 0) #if (NUM_PDM_MICS > 0)
#if (PDM_TILE == AUDIO_IO_TILE)
, c_ds_output
#endif
, c_pdm_pcm , c_pdm_pcm
#endif #endif
); );
@@ -706,16 +712,14 @@ int main()
#ifndef PDM_RECORD #ifndef PDM_RECORD
#if (NUM_PDM_MICS > 0) #if (NUM_PDM_MICS > 0)
#if (PDM_TILE != AUDIO_IO_TILE)
/* PDM Mics running on a separate to AudioHub */
on stdcore[PDM_TILE]: on stdcore[PDM_TILE]:
{ {
/* TODO p_mclk_in should be delared as an unsafe resource */ xua_pdm_mic_config(p_pdm_mclk, p_pdm_clk, p_pdm_mics, clk_pdm);
unsafe xua_pdm_mic(c_ds_output, p_pdm_mics);
{
p_mclk_in = p_mclk_in_;
}
pdm_mic(c_ds_output);
} }
#endif
#ifdef MIC_PROCESSING_USE_INTERFACE #ifdef MIC_PROCESSING_USE_INTERFACE
on stdcore[PDM_TILE].core[0]: pdm_buffer(c_ds_output, c_pdm_pcm, i_mic_process); on stdcore[PDM_TILE].core[0]: pdm_buffer(c_ds_output, c_pdm_pcm, i_mic_process);
#else #else

View File

@@ -20,21 +20,6 @@
#define MAX_DECIMATION_FACTOR (96000/(MIN_FREQ/AUD_TO_MICS_RATIO)) #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 #ifndef MIC_BUFFER_DEPTH
#define MIC_BUFFER_DEPTH 1 #define MIC_BUFFER_DEPTH 1
#endif #endif
@@ -228,15 +213,8 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio)
#error MAX_FREQ > 48000 NOT CURRENTLY SUPPORTED #error MAX_FREQ > 48000 NOT CURRENTLY SUPPORTED
#endif #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 */ /* 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 48kHz range mclk we expect a 3072000Hz mic clock */
/* e.g. For a 44.1kHz range mclk we expect a 2822400Hz mic clock */ /* e.g. For a 44.1kHz range mclk we expect a 2822400Hz mic clock */
@@ -246,18 +224,21 @@ void pdm_mic(streaming chanend c_ds_output[2])
unsigned micDiv = MCLK_48/3072000; unsigned micDiv = MCLK_48/3072000;
#if (PDM_TILE != AUDIO_IO_TILE)
configure_clock_src_divide(clk_pdm, p_pdm_mclk, micDiv/2); 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_port_clock_output(p_pdm_clk, clk_pdm);
configure_in_port(p_pdm_mics, clk_pdm); configure_in_port(p_pdm_mics, clk_pdm);
start_clock(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 par
{ {
@@ -268,4 +249,5 @@ void pdm_mic(streaming chanend c_ds_output[2])
#endif #endif
} }
} }
#endif #endif

View File

@@ -2,6 +2,9 @@
#include "mic_array.h" #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 #ifdef MIC_PROCESSING_USE_INTERFACE
/* Interface based user processing */ /* Interface based user processing */
typedef interface mic_process_if 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); void user_pdm_process(server mic_process_if i_mic_data);
/* PDM interface and decimation cores */ /* 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 #else
@@ -36,7 +39,7 @@ void user_pdm_init();
void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio); void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio);
/* PDM interface and decimation cores */ /* 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 #endif

View File

@@ -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_mclk;
extern clock clk_audio_bclk; extern clock clk_audio_bclk;