diff --git a/tests/test_mic_input/Makefile b/tests/test_mic_input/Makefile index 6e42627..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 @@ -18,15 +18,25 @@ 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_SDR = $(COMMON_FLAGS) -DCOUNT=4 -DDDR=0 +#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_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/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_ */ diff --git a/tests/test_mic_input/src/test_mic_input.xc b/tests/test_mic_input/src/test_mic_input.xc index 3748190..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_1E; -#if DDR -on tile[0]: in buffered port:32 p_pdm_mics = XS1_PORT_4D; -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 = XS1_PORT_1F; -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() { - 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[PDM_TILE]:{ + 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); @@ -308,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);