Simplified mclk port usage (no longer unsafe). pdm_mics() -> xua_pdm_mics()

This commit is contained in:
xross
2018-02-27 14:35:40 +00:00
parent 04b08c9213
commit a8562ad56a
4 changed files with 52 additions and 77 deletions

View File

@@ -29,6 +29,14 @@
#endif #endif
#endif #endif
#if (NUM_PDM_MICS > 0)
#include "xua_pdm_mic.h"
#endif
#if (AUD_TO_USB_RATIO > 1)
#include "src.h"
#endif
#include "xua_commands.h" #include "xua_commands.h"
#include "xc_ptr.h" #include "xc_ptr.h"
@@ -36,6 +44,7 @@
static unsigned samplesOut[MAX(NUM_USB_CHAN_OUT, I2S_CHANS_DAC)]; static unsigned samplesOut[MAX(NUM_USB_CHAN_OUT, I2S_CHANS_DAC)];
/* TODO Rm me */
#ifndef ADAT_RX #ifndef ADAT_RX
#define ADAT_RX 0 #define ADAT_RX 0
#endif #endif
@@ -49,6 +58,7 @@ static unsigned samplesOut[MAX(NUM_USB_CHAN_OUT, I2S_CHANS_DAC)];
static unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)]; static unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)];
/* TODO Rm me */
#if defined(ADAT_RX) && (ADAT_RX ==0) #if defined(ADAT_RX) && (ADAT_RX ==0)
#undef ADAT_RX #undef ADAT_RX
#endif #endif
@@ -57,10 +67,6 @@ static unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)];
#undef SPDIF_RX #undef SPDIF_RX
#endif #endif
#if (AUD_TO_USB_RATIO > 1)
#include "src.h"
#endif
#if (DSD_CHANS_DAC != 0) #if (DSD_CHANS_DAC != 0)
extern buffered out port:32 p_dsd_dac[DSD_CHANS_DAC]; extern buffered out port:32 p_dsd_dac[DSD_CHANS_DAC];
extern buffered out port:32 p_dsd_clk; extern buffered out port:32 p_dsd_clk;
@@ -1307,10 +1313,7 @@ void XUA_AudioHub(chanend ?c_mix_out
/* Clock master clock-block from master-clock port */ /* Clock master clock-block from master-clock port */
/* Note, marked unsafe since other cores may be using this mclk port */ /* Note, marked unsafe since other cores may be using this mclk port */
unsafe configure_clock_src(clk_audio_mclk, p_mclk_in);
{
configure_clock_src(clk_audio_mclk, (port) p_mclk_in);
}
start_clock(clk_audio_mclk); start_clock(clk_audio_mclk);
@@ -1322,24 +1325,25 @@ void XUA_AudioHub(chanend ?c_mix_out
EnableBufferedPort(p_dsd_dac[i], 32); EnableBufferedPort(p_dsd_dac[i], 32);
} }
#endif #endif
#ifdef ADAT_TX #ifdef ADAT_TX
/* Share SPDIF clk blk */ /* Share SPDIF clk blk */
unsafe configure_clock_src(clk_mst_spd, p_mclk_in);
{
configure_clock_src(clk_mst_spd, (port)p_mclk_in);
}
configure_out_port_no_ready(p_adat_tx, clk_mst_spd, 0); configure_out_port_no_ready(p_adat_tx, clk_mst_spd, 0);
set_clock_fall_delay(clk_mst_spd, 7); set_clock_fall_delay(clk_mst_spd, 7);
#if (XUA_SPDIF_TX_EN == 0) #if (XUA_SPDIF_TX_EN == 0)
start_clock(clk_mst_spd); start_clock(clk_mst_spd);
#endif #endif
#endif #endif
/* Configure ADAT/SPDIF tx ports */ /* Configure ADAT/SPDIF tx ports */
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE == AUDIO_IO_TILE) #if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE == AUDIO_IO_TILE)
unsafe SpdifTransmitPortConfig(p_spdif_tx, clk_mst_spd, p_mclk_in);
{ #endif
SpdifTransmitPortConfig(p_spdif_tx, clk_mst_spd, (port)p_mclk_in);
} #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);
#endif #endif
/* Perform required CODEC/ADC/DAC initialisation */ /* Perform required CODEC/ADC/DAC initialisation */

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;
@@ -190,7 +182,7 @@ in port p_pdm_clk = PORT_PDM_CLK;
in buffered port:32 p_pdm_mics = PORT_PDM_DATA; in buffered port:32 p_pdm_mics = PORT_PDM_DATA;
#if (PDM_TILE != AUDIO_IO_TILE) #if (PDM_TILE != AUDIO_IO_TILE)
/* If Mics and I2S are on the same tile we'll share an MCLK port */ /* If Mics and I2S are not the same tile we need a separate MCLK port */
in port p_pdm_mclk = PORT_PDM_MCLK; in port p_pdm_mclk = PORT_PDM_MCLK;
#endif #endif
#endif #endif
@@ -363,18 +355,12 @@ 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)
set_clock_src(clk_audio_mclk2, p_mclk_in2); set_clock_src(clk_audio_mclk_usb, p_mclk_in_usb);
set_port_clock(p_for_mclk_count, clk_audio_mclk2); set_port_clock(p_for_mclk_count, clk_audio_mclk_usb);
start_clock(clk_audio_mclk2); start_clock(clk_audio_mclk_usb);
#else #else
/* Clock port from same clock-block as I2S */ /* Clock port from same clock-block as I2S */
/* TODO remove asm() */ /* TODO remove asm() */
@@ -626,11 +612,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
@@ -717,16 +698,12 @@ int main()
#endif #endif
#ifndef PDM_RECORD #ifndef PDM_RECORD
#if (NUM_PDM_MICS > 0) #if (NUM_PDM_MICS > 0) && (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_mclk_pdm);
unsafe xua_pdm_mic(c_ds_output);
{
p_mclk_in = p_mclk_in_;
}
pdm_mic(c_ds_output);
} }
#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);

View File

@@ -25,13 +25,6 @@ extern in port p_pdm_clk;
extern in buffered port:32 p_pdm_mics; extern in buffered port:32 p_pdm_mics;
#if (PDM_TILE != AUDIO_IO_TILE)
/* If Mics and I2S are on the same tile we'll share an MCLK port */
extern in port p_pdm_mclk;
#else
extern unsafe port p_mclk_in;
#endif
/* Delcared in main.xc */ /* Delcared in main.xc */
extern clock clk_pdm; extern clock clk_pdm;
@@ -46,11 +39,11 @@ mic_array_frame_time_domain mic_audio[2];
#ifdef MIC_PROCESSING_USE_INTERFACE #ifdef MIC_PROCESSING_USE_INTERFACE
[[combinable]] [[combinable]]
#pragma unsafe arrays #pragma unsafe arrays
void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio, client mic_process_if i_mic_process) void xua_pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio, client mic_process_if i_mic_process)
#else #else
#pragma unsafe arrays #pragma unsafe arrays
[[combinable]] [[combinable]]
void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) void xua_pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio)
#endif #endif
{ {
unsigned buffer; unsigned buffer;
@@ -228,15 +221,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)
{ {
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 +232,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])
{
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
{ {

View File

@@ -1,7 +1,12 @@
// Copyright (c) 2015-2018, XMOS Ltd, All rights reserved // Copyright (c) 2015-2018, XMOS Ltd, All rights reserved
/* Included from lib_mic_array */
#include "mic_array.h" #include "mic_array.h"
/* Configures PDM ports/clocks */
void xua_pdm_mic_config(in port p_mclk_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
@@ -12,7 +17,7 @@ typedef interface mic_process_if
[[combinable]] [[combinable]]
void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio void xua_pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio
#ifdef MIC_PROCESSING_USE_INTERFACE #ifdef MIC_PROCESSING_USE_INTERFACE
, client mic_process_if i_mic_process , client mic_process_if i_mic_process
#endif #endif
@@ -22,7 +27,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]);
#else #else
@@ -33,10 +38,10 @@ void user_pdm_init();
/* PDM interface and decimation cores */ /* PDM interface and decimation cores */
[[combinable]] [[combinable]]
void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio); void xua_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]);
#endif #endif