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
#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 "xc_ptr.h"
@@ -36,6 +44,7 @@
static unsigned samplesOut[MAX(NUM_USB_CHAN_OUT, I2S_CHANS_DAC)];
/* TODO Rm me */
#ifndef ADAT_RX
#define ADAT_RX 0
#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)];
/* TODO Rm me */
#if defined(ADAT_RX) && (ADAT_RX ==0)
#undef ADAT_RX
#endif
@@ -57,10 +67,6 @@ static unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)];
#undef SPDIF_RX
#endif
#if (AUD_TO_USB_RATIO > 1)
#include "src.h"
#endif
#if (DSD_CHANS_DAC != 0)
extern buffered out port:32 p_dsd_dac[DSD_CHANS_DAC];
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 */
/* Note, marked unsafe since other cores may be using this mclk port */
unsafe
{
configure_clock_src(clk_audio_mclk, (port) p_mclk_in);
}
configure_clock_src(clk_audio_mclk, p_mclk_in);
start_clock(clk_audio_mclk);
@@ -1322,24 +1325,25 @@ void XUA_AudioHub(chanend ?c_mix_out
EnableBufferedPort(p_dsd_dac[i], 32);
}
#endif
#ifdef ADAT_TX
/* Share SPDIF clk blk */
unsafe
{
configure_clock_src(clk_mst_spd, (port)p_mclk_in);
}
configure_clock_src(clk_mst_spd, p_mclk_in);
configure_out_port_no_ready(p_adat_tx, clk_mst_spd, 0);
set_clock_fall_delay(clk_mst_spd, 7);
#if (XUA_SPDIF_TX_EN == 0)
start_clock(clk_mst_spd);
#endif
#endif
/* Configure ADAT/SPDIF tx ports */
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE == AUDIO_IO_TILE)
unsafe
{
SpdifTransmitPortConfig(p_spdif_tx, clk_mst_spd, (port)p_mclk_in);
}
SpdifTransmitPortConfig(p_spdif_tx, clk_mst_spd, p_mclk_in);
#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);
#endif
/* 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;
#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;
@@ -190,7 +182,7 @@ 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 */
/* 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
@@ -363,18 +355,12 @@ 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)
set_clock_src(clk_audio_mclk2, p_mclk_in2);
set_port_clock(p_for_mclk_count, clk_audio_mclk2);
start_clock(clk_audio_mclk2);
set_clock_src(clk_audio_mclk_usb, p_mclk_in_usb);
set_port_clock(p_for_mclk_count, clk_audio_mclk_usb);
start_clock(clk_audio_mclk_usb);
#else
/* Clock port from same clock-block as I2S */
/* TODO remove asm() */
@@ -626,11 +612,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
@@ -717,16 +698,12 @@ int main()
#endif
#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]:
{
/* 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_mclk_pdm);
xua_pdm_mic(c_ds_output);
}
#ifdef MIC_PROCESSING_USE_INTERFACE
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;
#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 */
extern clock clk_pdm;
@@ -46,11 +39,11 @@ mic_array_frame_time_domain mic_audio[2];
#ifdef MIC_PROCESSING_USE_INTERFACE
[[combinable]]
#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
#pragma unsafe arrays
[[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
{
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
#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 */
/* 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 +232,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])
{
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);

View File

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