Change version of lib_mic_array; Fix synchronous endpoint behaviour

The device now adjusts it's clock to the USB clock when host is not
pushing data to device.
This commit is contained in:
Oscar Bailey
2019-02-26 16:59:29 +00:00
parent a8fa274230
commit 86b4ab89ea
8 changed files with 62 additions and 18 deletions

View File

@@ -10,7 +10,7 @@ XCC_FLAGS = -fcomment-asm -Xmapper --map -Xmapper MAPFILE -Os -report \
# The USED_MODULES variable lists other module used by the application. These
# modules will extend the SOURCE_DIRS, INCLUDE_DIRS and LIB_DIRS variables.
# Modules are expected to be in the directory above the BASE_DIR directory.
USED_MODULES = lib_xua lib_i2s lib_xud lib_i2c lib_mic_array_ddr
USED_MODULES = lib_xua lib_i2s lib_xud lib_i2c lib_mic_array
#=============================================================================
# The following part of the Makefile includes the common build infrastructure

View File

@@ -11,7 +11,7 @@
#include "i2s.h"
#include "i2c.h"
#include "mic_array.h"
#include "XUA_Buffer_lite.h"
#include "xua_buffer_lite.h"
#include "xua_ep0_wrapper.h"
#include "pdm_mic.h"
#include "audio_config.h"
@@ -96,12 +96,11 @@ int main()
c_audio :> int _; //Now wait until i2c has finished mclk setup
const unsigned micDiv = MCLK_48/3072000;
if (XUA_ADAPTIVE) mic_array_setup_ddr_xcore(pdmclk, pdmclk6, p_pdm_clk, p_pdm_mics, micDiv);
else mic_array_setup_ddr(pdmclk, pdmclk6, p_mclk_in, p_pdm_clk, p_pdm_mics, micDiv);
mic_array_setup_ddr(pdmclk, pdmclk6, p_mclk_in, p_pdm_clk, p_pdm_mics, micDiv);
par {
i2s_frame_master(i_i2s, p_i2s_dac, 1, p_i2s_adc, 1, p_bclk, p_lrclk, p_mclk_in, clk_audio_bclk);
[[distribute]]AudioHub(i_i2s, c_audio, c_ds_output);
[[distribute]] AudioHub(i_i2s, c_audio, c_ds_output);
pdm_mic(c_ds_output[0], p_pdm_mics);
par (int i = 0; i < 5; i++) burn_normal_priority();

View File

@@ -1,3 +1,4 @@
#include <string.h>
#include "i2s.h"
#include "i2c.h"
#include "xua.h"
@@ -34,6 +35,8 @@ void AudioHub(server i2s_frame_callback_if i2s,
mic_array_decimator_configure(c_ds_output, decimatorCount, dc);
mic_array_init_time_domain_frame(c_ds_output, decimatorCount, buffer, mic_audio_frame, dc);
// Used for debug
//int saw = 0;
while (1) {
select {
@@ -57,7 +60,7 @@ void AudioHub(server i2s_frame_callback_if i2s,
case i2s.restart_check() -> i2s_restart_t restart:
restart = I2S_NO_RESTART; // Keep on looping
timer tmr; int t0, t1; tmr :> t0;
//Transfer samples. Takes about 25 ticks
for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio :> samples_out[i];
if (XUA_ADAPTIVE) c_audio :> clock_nudge;
@@ -70,6 +73,9 @@ void AudioHub(server i2s_frame_callback_if i2s,
for (int i = 0; i < XUA_NUM_PDM_MICS; i++) raw_mics[i] = current->data[i][0];
}
//memset(raw_mics, saw, sizeof(int) * XUA_NUM_PDM_MICS);
//saw += 500;
//Taking about 160 ticks when adjusting, 100 when not
tmr :> t0;
pll_nudge(clock_nudge);

View File

@@ -5,6 +5,8 @@
void mic_array_decimator_set_samprate(const unsigned samplerate, int mic_decimator_fir_data_array[], mic_array_decimator_conf_common_t *dcc, mic_array_decimator_config_t dc[]);
void pdm_mic(streaming chanend c_ds_output, in buffered port:32 p_pdm_mics);
void mic_array_setup_ddr_xcore(clock pdmclk, clock pdmclk6, out port p_pdm_clk, buffered in port:32 p_pdm_data, int divide);
void mic_array_setup_ddr(clock pdmclk, clock pdmclk6, in port p_mclk,
out port p_pdm_clk, buffered in port:32 p_pdm_data,
int divide);
#endif

View File

@@ -35,7 +35,7 @@ void mic_array_decimator_set_samprate(const unsigned samplerate, int mic_decimat
fir_coefs[6] = (int * unsafe)g_third_stage_div_12_fir;
//dcc = {MIC_ARRAY_MAX_FRAME_SIZE_LOG2, 1, 0, 0, decimationfactor, fir_coefs[decimationfactor/2], 0, 0, DECIMATOR_NO_FRAME_OVERLAP, 2};
dcc->frame_size_log2 = MIC_ARRAY_MAX_FRAME_SIZE_LOG2;
dcc->len = MIC_ARRAY_MAX_FRAME_SIZE_LOG2;
dcc->apply_dc_offset_removal = 1;
dcc->index_bit_reversal = 0;
dcc->windowing_function = null;
@@ -73,17 +73,24 @@ void pdm_mic(streaming chanend c_ds_output, in buffered port:32 p_pdm_mics)
}
}
void mic_array_setup_ddr_xcore(clock pdmclk,
void mic_array_setup_ddr(clock pdmclk,
clock pdmclk6,
in port p_mclk, /*used only in I2S slave case*/
out port p_pdm_clk,
buffered in port:32 p_pdm_data,
int divide) {
configure_clock_xcore(pdmclk, 80);
//configure_clock_src_divide(pdmclk, p_mclk, divide/2);
configure_clock_xcore(pdmclk6, 40);
//configure_clock_src_divide(pdmclk6, p_mclk, divide/4);
#if !XUA_ADAPTIVE //i2s slave
//p_mclk coming from the Pi is 24.576 MHz
configure_clock_src_divide(pdmclk, p_mclk, 4); //3.072 = 24.576 / 8
configure_clock_src_divide(pdmclk6, p_mclk, 2); //6.144 = 24.576 / 4
#else
configure_clock_xcore(pdmclk, 80); // 3.072
configure_clock_xcore(pdmclk6, 40); // 6.144
#endif
configure_port_clock_output(p_pdm_clk, pdmclk);
configure_in_port(p_pdm_data, pdmclk6);

View File

@@ -27,6 +27,7 @@ void XUD_GetSetupData_Select(chanend c, XUD_ep e_out, unsigned &length, XUD_Resu
extern XUD_ep ep0_out;
extern XUD_ep ep0_in;
#if 0
//Unsafe to allow us to use fifo API without local unsafe scope
unsafe void XUA_Buffer_lite(chanend c_ep0_out, chanend c_ep0_in, chanend c_aud_out, chanend ?c_feedback, chanend c_aud_in, chanend c_sof, in port p_for_mclk_count, streaming chanend c_audio_hub) {
@@ -197,6 +198,7 @@ unsafe void XUA_Buffer_lite(chanend c_ep0_out, chanend c_ep0_in, chanend c_aud_o
}
}
}
#endif
extern port p_sda;
[[combinable]]
@@ -336,7 +338,11 @@ unsafe void XUA_Buffer_lite2(server ep0_control_if i_ep0_ctl, chanend c_aud_out,
timer tmr; int t0, t1; tmr :> t0;
//If host is not streaming out, then send a fixed number of samples to host
if (output_interface_num == 0) num_samples_to_send_to_host = (DEFAULT_FREQ / SOF_FREQ_HZ) * NUM_USB_CHAN_IN;
if (output_interface_num == 0) {
num_samples_to_send_to_host = (DEFAULT_FREQ / SOF_FREQ_HZ) * NUM_USB_CHAN_IN;
int fill_level = fifo_get_fill_short(device_to_host_fifo_ptr);
if (isnull(c_feedback)) do_clock_nudge_pdm(-do_rate_control(fill_level, &pid_state), &clock_nudge);
}
fifo_ret_t ret = fifo_block_pop_short_fast(device_to_host_fifo_ptr, buffer_aud_in.short_words, num_samples_received_from_host);
if (ret != FIFO_SUCCESS) {
@@ -349,7 +355,7 @@ unsafe void XUA_Buffer_lite2(server ep0_control_if i_ep0_ctl, chanend c_aud_out,
//Use the number of samples we received last time so we are always balanced (assumes same in/out count)
unsigned input_buffer_size = num_samples_to_send_to_host * in_subslot_size;
XUD_SetReady_InPtr(ep_aud_in, (unsigned)buffer_aud_in.long_words, input_buffer_size); //loopback
XUD_SetReady_InPtr(ep_aud_in, (unsigned) buffer_aud_in.long_words, input_buffer_size); //loopback
num_samples_to_send_to_host = 0;
//tmr :> t1; debug_printf("i%d\n", t1 - t0);
break;
@@ -375,4 +381,4 @@ unsafe void XUA_Buffer_lite2(server ep0_control_if i_ep0_ctl, chanend c_aud_out,
break;
}
}
}
}

View File

@@ -0,0 +1,24 @@
def options(ctx):
ctx.add_option('--target', action='store', default='xua_lite_example.xe')
ctx.add_option('--debug', action='store_true')
def configure(conf):
conf.load('xwaf.compiler_xcc')
conf.env.PROJECT_ROOT = '../../..'
def build(bld):
target_path = 'bin/' + bld.options.target
bld.env.TARGET_ARCH ='src/RPI_HAT_60QFN.xn'
bld.env.XSCOPE = bld.path.find_resource('config.xscope')
depends_on = ['lib_xua','lib_i2s','lib_xud','lib_mic_array', 'lib_i2c']
#bld.env.XCC_FLAGS = ['-O2', '-g', '-Wall', '-fcmdline-buffer-bytes=512', '-report', '-DDISABLE_STAGE_C']
bld.env.XCC_FLAGS = ['-fcomment-asm','-Xmapper','--map','-Xmapper','MAPFILE',
'-Os','-report','-g','-Wno-unused-function','-Wno-timing',
'-DXUD_SERIES_SUPPORT=XUD_X200_SERIES','-DUSB_TILE=tile[1]',
'-DMIC_ARRAY_CH0=PIN0','-DMIC_ARRAY_CH1=PIN4', '-DDEBUG_PRINT_ENABLE=1']
if bld.options.debug:
bld.env.XCC_FLAGS.append('-DDEBUG')
source = bld.path.ant_glob(['src/**/*.xc', 'src/**/*.c'])
bld.program(source=source, depends_on=depends_on,target=target_path)

View File

@@ -88,7 +88,7 @@ void XUA_PdmBuffer(streaming chanend c_ds_output[2], chanend c_audio)
fir_coefs[6] = g_third_stage_div_12_fir;
//dcc = {MIC_ARRAY_MAX_FRAME_SIZE_LOG2, 1, 0, 0, decimationfactor, fir_coefs[decimationfactor/2], 0, 0, DECIMATOR_NO_FRAME_OVERLAP, 2};
dcc.frame_size_log2 = MIC_ARRAY_MAX_FRAME_SIZE_LOG2;
dcc.len = MIC_ARRAY_MAX_FRAME_SIZE_LOG2;
dcc.apply_dc_offset_removal = 1;
dcc.index_bit_reversal = 0;
dcc.windowing_function = null;