From 91e9bdaf1351febd11f4fe2ebc33969b5f2e2d2b Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Mon, 4 Feb 2019 16:16:16 +0000 Subject: [PATCH 1/3] Test for 2-mic DDR array on XVF3510 m/board --- tests/test_mic_input/Makefile | 6 +-- tests/test_mic_input/src/test_mic_input.xc | 48 ++++++++++++++-------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/tests/test_mic_input/Makefile b/tests/test_mic_input/Makefile index 6e42627..92bcbcc 100644 --- a/tests/test_mic_input/Makefile +++ b/tests/test_mic_input/Makefile @@ -19,12 +19,12 @@ USED_MODULES = lib_mic_array lib_mic_array_board_support COMMON_FLAGS = -O2 -g -report XCC_FLAGS_8_MICS_DDR = $(COMMON_FLAGS) -DCOUNT=8 -DDDR=1 -XCC_FLAGS_7_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=7 -DDDR=0 +#XCC_FLAGS_7_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=7 -DDDR=0 #XCC_FLAGS_6_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=6 -DDDR=0 #XCC_FLAGS_5_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=5 -DDDR=0 -XCC_FLAGS_4_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=4 -DDDR=0 +#XCC_FLAGS_4_MICS_DDR = $(COMMON_FLAGS) -DCOUNT=4 -DDDR=1 #XCC_FLAGS_3_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=3 -DDDR=0 -#XCC_FLAGS_2_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=2 -DDDR=0 +XCC_FLAGS_2_MICS_DDR = $(COMMON_FLAGS) -DCOUNT=2 -DDDR=1 #XCC_FLAGS_1_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=1 -DDDR=0 # The XCORE_ARM_PROJECT variable, if set to 1, configures this diff --git a/tests/test_mic_input/src/test_mic_input.xc b/tests/test_mic_input/src/test_mic_input.xc index 3748190..826b8d4 100755 --- a/tests/test_mic_input/src/test_mic_input.xc +++ b/tests/test_mic_input/src/test_mic_input.xc @@ -26,14 +26,14 @@ #define FFT_CHANNELS ((COUNT+1)/2) #define ENABLE_PRECISION_MAXIMISATION 1 -on tile[0]: out port p_pdm_clk = XS1_PORT_1E; +on tile[0]: out port p_pdm_clk = XS1_PORT_1L; #if DDR -on tile[0]: in buffered port:32 p_pdm_mics = XS1_PORT_4D; +on tile[0]: in buffered port:32 p_pdm_mics = XS1_PORT_4E; on tile[0]: clock pdmclk6 = XS1_CLKBLK_3; #else on tile[0]: in buffered port:32 p_pdm_mics = XS1_PORT_8B; #endif -on tile[0]: in port p_mclk = XS1_PORT_1F; +on tile[0]: in port p_mclk_in = XS1_PORT_1K; on tile[0]: clock pdmclk = XS1_CLKBLK_2; int data[8][THIRD_STAGE_COEFS_PER_STAGE*DECIMATION_FACTOR]; @@ -278,26 +278,38 @@ void test(streaming chanend c_ds_output[DECIMATOR_COUNT]) { } } -port p_rst_shared = on tile[1]: XS1_PORT_4F; // Bit 0: DAC_RST_N, Bit 1: ETH_RST_N -port p_i2c = on tile[1]: XS1_PORT_4E; // Bit 0: SCLK, Bit 1: SDA +on tile[0] : clock mclk_internal = XS1_CLKBLK_5; + +void set_node_pll_reg(tileref tile_ref, unsigned reg_val){ + write_sswitch_reg(get_tile_id(tile_ref), XS1_SSWITCH_PLL_CTL_NUM, reg_val); +} + +void run_clock(void) { + configure_clock_xcore(mclk_internal, 10); // 24.576 MHz + configure_port_clock_output(p_mclk_in, mclk_internal); + start_clock(mclk_internal); +} + +// Nominal setting is ref div = 25, fb_div = 1024, op_div = 2 +// PCF Freq 0.96MHz + +#define PLL_NOM 0xC003FF18 // This is 3.072MHz + +void set_pll(void) { + set_node_pll_reg(tile[0], PLL_NOM); + run_clock(); +} + int main() { - chan c_sync; - i2c_master_if i_i2c[1]; + par { - on tile[1]: i2c_master_single_port(i_i2c, 1, p_i2c, 100, 0, 1, 0); - on tile[1]: { - p_rst_shared <: 0x00; - mabs_init_pll(i_i2c[0], SMART_MIC_BASE); - delay_seconds(5); - c_sync <: 1; - } - on tile[0]:{ - c_sync :> int; - stop_clock(pdmclk); + on tile[0]:{ + stop_clock(pdmclk); + set_pll(); #if DDR - mic_array_setup_ddr(pdmclk, pdmclk6, p_mclk, p_pdm_clk, p_pdm_mics, 8); + mic_array_setup_ddr(pdmclk, pdmclk6, p_mclk_in, p_pdm_clk, p_pdm_mics, 8); #else /* configure_clock_src_divide(pdmclk, p_mclk, 4); configure_port_clock_output(p_pdm_clk, pdmclk); From b486fafaf0f62d46d00ac6164a372393df7bbab2 Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Thu, 7 Feb 2019 10:22:21 +0000 Subject: [PATCH 2/3] Fix mic output to work for two mics array --- tests/test_mic_input/Makefile | 9 +++++---- tests/test_mic_input/src/mic_array_conf.h | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/test_mic_input/Makefile b/tests/test_mic_input/Makefile index 92bcbcc..466ab5e 100644 --- a/tests/test_mic_input/Makefile +++ b/tests/test_mic_input/Makefile @@ -18,13 +18,14 @@ USED_MODULES = lib_mic_array lib_mic_array_board_support # xcc for the final link (mapping) stage. COMMON_FLAGS = -O2 -g -report -XCC_FLAGS_8_MICS_DDR = $(COMMON_FLAGS) -DCOUNT=8 -DDDR=1 -#XCC_FLAGS_7_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=7 -DDDR=0 +#XCC_FLAGS_8_MICS_DDR = $(COMMON_FLAGS) -DCOUNT=8 -DDDR=1 +XCC_FLAGS_2_MICS_DDR = $(COMMON_FLAGS) -DCOUNT=2 -DDDR=1 +#XCC_FLAGS_7_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=7 -DDDR=0 #XCC_FLAGS_6_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=6 -DDDR=0 #XCC_FLAGS_5_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=5 -DDDR=0 -#XCC_FLAGS_4_MICS_DDR = $(COMMON_FLAGS) -DCOUNT=4 -DDDR=1 +#XCC_FLAGS_4_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=4 -DDDR=0 #XCC_FLAGS_3_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=3 -DDDR=0 -XCC_FLAGS_2_MICS_DDR = $(COMMON_FLAGS) -DCOUNT=2 -DDDR=1 +#XCC_FLAGS_2_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=2 -DDDR=0 #XCC_FLAGS_1_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=1 -DDDR=0 # The XCORE_ARM_PROJECT variable, if set to 1, configures this diff --git a/tests/test_mic_input/src/mic_array_conf.h b/tests/test_mic_input/src/mic_array_conf.h index cca8c12..b365e7e 100644 --- a/tests/test_mic_input/src/mic_array_conf.h +++ b/tests/test_mic_input/src/mic_array_conf.h @@ -5,5 +5,9 @@ #define MIC_ARRAY_MAX_FRAME_SIZE_LOG2 7 #define MIC_ARRAY_NUM_MICS 8 +#define MIC_ARRAY_CH0 PIN0 +#define MIC_ARRAY_CH1 PIN4 +#define MIC_ARRAY_CH2 PIN1 +#define MIC_ARRAY_CH3 PIN3 #endif /* MIC_ARRAY_CONF_H_ */ From 1985add1a2bdec25ac3aceeebcde89ec0ed2b2ef Mon Sep 17 00:00:00 2001 From: Ed Date: Mon, 19 Oct 2020 16:26:40 +0100 Subject: [PATCH 3/3] Add support for testing XCORE-AI boards (explorer and Osprey) --- tests/test_mic_input/Makefile | 13 ++- tests/test_mic_input/src/test_mic_input.xc | 125 +++++++++++++++++++-- 2 files changed, 124 insertions(+), 14 deletions(-) diff --git a/tests/test_mic_input/Makefile b/tests/test_mic_input/Makefile index 466ab5e..94940f6 100644 --- a/tests/test_mic_input/Makefile +++ b/tests/test_mic_input/Makefile @@ -1,7 +1,7 @@ # The TARGET variable determines what target system the application is # compiled for. It either refers to an XN file in the source directories # or a valid argument for the --target option when compiling -TARGET = SMART-MIC-BASE-1V0 + # The APP_NAME variable determines the name of the final .xe file. It should # not include the .xe postfix. If left blank the name will default to @@ -19,7 +19,7 @@ USED_MODULES = lib_mic_array lib_mic_array_board_support COMMON_FLAGS = -O2 -g -report #XCC_FLAGS_8_MICS_DDR = $(COMMON_FLAGS) -DCOUNT=8 -DDDR=1 -XCC_FLAGS_2_MICS_DDR = $(COMMON_FLAGS) -DCOUNT=2 -DDDR=1 +# XCC_FLAGS_2_MICS_DDR = $(COMMON_FLAGS) -DCOUNT=2 -DDDR=1 #XCC_FLAGS_7_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=7 -DDDR=0 #XCC_FLAGS_6_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=6 -DDDR=0 #XCC_FLAGS_5_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=5 -DDDR=0 @@ -28,6 +28,15 @@ XCC_FLAGS_2_MICS_DDR = $(COMMON_FLAGS) -DCOUNT=2 -DDDR=1 #XCC_FLAGS_2_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=2 -DDDR=0 #XCC_FLAGS_1_MICS_SDR = $(COMMON_FLAGS) -DCOUNT=1 -DDDR=0 +XCC_FLAGS_2_MICS_DDR_XS3 = $(COMMON_FLAGS) -DCOUNT=2 -DDDR=1 -DXCORE_AI=1 + +ifeq ($(findstring XS3, $(CONFIG)), XS3) + TARGET = XCORE-AI-EXPLORER +else + TARGET = SMART-MIC-BASE-1V0 +endif + + # The XCORE_ARM_PROJECT variable, if set to 1, configures this # project to create both xCORE and ARM binaries. XCORE_ARM_PROJECT = 0 diff --git a/tests/test_mic_input/src/test_mic_input.xc b/tests/test_mic_input/src/test_mic_input.xc index 826b8d4..327d5a7 100755 --- a/tests/test_mic_input/src/test_mic_input.xc +++ b/tests/test_mic_input/src/test_mic_input.xc @@ -8,6 +8,7 @@ #include "stdio.h" #include #include +#include #include "mic_array.h" #include "mic_array_board_support.h" @@ -26,15 +27,35 @@ #define FFT_CHANNELS ((COUNT+1)/2) #define ENABLE_PRECISION_MAXIMISATION 1 -on tile[0]: out port p_pdm_clk = XS1_PORT_1L; -#if DDR -on tile[0]: in buffered port:32 p_pdm_mics = XS1_PORT_4E; -on tile[0]: clock pdmclk6 = XS1_CLKBLK_3; +#ifdef XCORE_AI + #define PDM_TILE 1 +#else + #define PDM_TILE 0 +#endif + +// Nominal setting is ref div = 25, fb_div = 1024, op_div = 2 +// PCF Freq 0.96GHz +#define PLL_NOM 0xC003FF18 // This is 3.072MHz * 20 + +#ifdef XCORE_AI + on tile[1]: in buffered port:32 p_pdm_mics = PORT_PDM_DATA; + on tile[1]: in buffered port:32 p_pdm_mics_4b = XS1_PORT_4E; + on tile[1]: out port p_pdm_clk = PORT_PDM_CLK; + on tile[1]: clock pdmclk6 = XS1_CLKBLK_3; + on tile[1]: clock pdmclk = XS1_CLKBLK_2; + on tile[1]: in port p_mclk_in = PORT_MCLK_IN; #else -on tile[0]: in buffered port:32 p_pdm_mics = XS1_PORT_8B; + on tile[0]: out port p_pdm_clk = XS1_PORT_1L; + #if DDR + on tile[0]: in buffered port:32 p_pdm_mics = XS1_PORT_4E; + on tile[0]: clock pdmclk6 = XS1_CLKBLK_3; + #else + on tile[0]: in buffered port:32 p_pdm_mics = XS1_PORT_8B; + #endif + on tile[0]: in port p_mclk_in = XS1_PORT_1K; + on tile[0]: clock pdmclk = XS1_CLKBLK_2; #endif -on tile[0]: in port p_mclk_in = XS1_PORT_1K; -on tile[0]: clock pdmclk = XS1_CLKBLK_2; + int data[8][THIRD_STAGE_COEFS_PER_STAGE*DECIMATION_FACTOR]; @@ -46,6 +67,31 @@ int your_favourite_window_function(unsigned i, unsigned window_length){ void dsp_bfp_shl2( dsp_complex_t pts[], const uint32_t N, const int32_t shift_re, const int32_t shift_im ); +//Prints an ASCII art spectrum plot of the two mics. +//Linear X axis and Log Y axis +void print_spec(int64_t subband_rms_power[COUNT][FRAME_LENGTH/2]){ + int dbs[COUNT][FRAME_LENGTH/2] = {{0}}; + for (unsigned band=1;band < FRAME_LENGTH/2;band++){ + for(unsigned ch=0;ch<2;ch++){ + int64_t b = subband_rms_power[ch][band]; + double p = sqrt((double)b); + int db = 10 * log10(p) - 25; + dbs[ch][band] = db; + // printf("db %d: %d\n", band, db); + } + } + for(int dbp = 50; dbp >= 0; dbp--){ + for(unsigned ch=0;ch<2;ch++){ + for (unsigned band=1;band < FRAME_LENGTH/2;band++){ + printf("%s", dbs[ch][band] >= dbp ? "M" : "." ); + } + printf(" "); + } + printf("\n"); + } +} + + void test(streaming chanend c_ds_output[DECIMATOR_COUNT]) { unsafe{ unsigned buffer; @@ -140,6 +186,8 @@ void test(streaming chanend c_ds_output[DECIMATOR_COUNT]) { printf("\n"); #endif } + print_spec(subband_rms_power); + if(total_power < 10000.0){ for(unsigned i=0;i t0; + + #pragma loop unroll + #pragma unsafe arrays + for(int w = 0; w < 4; w++){ + unsigned o = 0; + + #pragma loop unroll + #pragma unsafe arrays + for(int i = 0; i < 32; i+=4){ + if(val & 0x1){ + o |= 0x1 << i; + } + val >>= 1; + } + outuint(c_out, o); + // printbinln(o); + + } + t :> t1; + // printf("%d\n", t1-t0); + } +} + + int main() { par { - on tile[0]:{ + on tile[PDM_TILE]:{ stop_clock(pdmclk); set_pll(); @@ -320,9 +415,15 @@ int main() { streaming chan c_4x_pdm_mic[DECIMATOR_COUNT]; streaming chan c_ds_output[DECIMATOR_COUNT]; + chan c_shim; par { +#ifdef XCORE_AI + port_shim_1b_4b(p_pdm_mics, c_shim); + call_mic_array_pdm_rx(c_shim, c_4x_pdm_mic[0], c_4x_pdm_mic[1]); +#else mic_array_pdm_rx(p_pdm_mics, c_4x_pdm_mic[0], c_4x_pdm_mic[1]); +#endif mic_array_decimate_to_pcm_4ch(c_4x_pdm_mic[0], c_ds_output[0], MIC_ARRAY_NO_INTERNAL_CHANS); mic_array_decimate_to_pcm_4ch(c_4x_pdm_mic[1], c_ds_output[1], MIC_ARRAY_NO_INTERNAL_CHANS); test(c_ds_output);