From b91b9469edd9538a9d9b0c5fb0620e99fa35244b Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Thu, 15 Feb 2024 10:57:02 +0000 Subject: [PATCH 01/16] Get test_i2s_basic_slave.py tests passing --- test/lib_i2s/i2s_slave_checker.py | 9 +++++++-- test/lib_i2s/i2s_slave_test/i2s_slave_test.cmake | 7 +++++++ test/lib_i2s/i2s_slave_test/src/main.c | 13 ++++++++++--- test/lib_i2s/test_i2s_basic_slave.py | 1 + 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/test/lib_i2s/i2s_slave_checker.py b/test/lib_i2s/i2s_slave_checker.py index 7369977..4cde037 100644 --- a/test/lib_i2s/i2s_slave_checker.py +++ b/test/lib_i2s/i2s_slave_checker.py @@ -92,7 +92,7 @@ def run(self): xsi, self._setup_strobe_port, self._setup_data_port ) xsi.drive_port_pins(self._bclk, bclk1) - xsi.drive_port_pins(self._lrclk, 1) + xsi.drive_port_pins(self._lrclk, 0) bclk_frequency = (bclk_frequency_u << 16) + bclk_frequency_l print( @@ -146,6 +146,9 @@ def run(self): # the range 32 - 63, lr_clock outputs 1, else it outputs 0. time = float(xsi.get_time()) + time = self.wait_until_ret(time + (clock_half_period*64)) + + lr_counter = data_bits + (data_bits // 2) + (is_i2s_justified) lr_count_max = (2 * data_bits) - 1 @@ -173,6 +176,8 @@ def run(self): xsi.drive_port_pins(self._bclk, bclk1) time = self.wait_until_ret(time + clock_half_period) + + error = False xsi.drive_port_pins(self._setup_resp_port, 0) @@ -213,7 +218,7 @@ def run(self): time = self.wait_until_ret( time + clock_half_period - din_sample_offset ) - + data_bit_mask = int("1" * data_bits, base=2) for p in range(0, num_outs): diff --git a/test/lib_i2s/i2s_slave_test/i2s_slave_test.cmake b/test/lib_i2s/i2s_slave_test/i2s_slave_test.cmake index 274af37..0dfb239 100644 --- a/test/lib_i2s/i2s_slave_test/i2s_slave_test.cmake +++ b/test/lib_i2s/i2s_slave_test/i2s_slave_test.cmake @@ -16,6 +16,13 @@ set(APP_LINK_OPTIONS -target=XCORE-AI-EXPLORER ) +set(APP_COMPILER_FLAGS_DATA_PLANE + -O3 +) + +# Compile main.c which contains the i2s_callback_group_t functions in O3 mode +set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/src/main.c PROPERTIES COMPILE_FLAGS "${APP_COMPILER_FLAGS_DATA_PLANE}") + #********************** # Tile Targets #********************** diff --git a/test/lib_i2s/i2s_slave_test/src/main.c b/test/lib_i2s/i2s_slave_test/src/main.c index 7fe32c0..6ea5511 100644 --- a/test/lib_i2s/i2s_slave_test/src/main.c +++ b/test/lib_i2s/i2s_slave_test/src/main.c @@ -26,7 +26,7 @@ xclock_t bclk = XS1_CLKBLK_1; #define NUM_BCLKS 1 #define NUM_BCLKS_TO_CHECK 1 static const unsigned bclk_freq_lut[NUM_BCLKS] = { - 1228800 + 12288000 }; #else #define NUM_BCLKS 12 @@ -150,8 +150,9 @@ i2s_restart_t i2s_restart_check(void *app_data) i2s_restart_t restart; frames_sent++; - if (frames_sent == 4) + if (frames_sent == 4) { restart = I2S_RESTART; + } else restart = I2S_NO_RESTART; @@ -196,7 +197,13 @@ void i2s_init(void *app_data, i2s_config_t *i2s_config) rx_data_counter[i] = 0; } - broadcast(bclk_freq_lut[bclk_freq_index], + unsigned bclk_freq = bclk_freq_lut[bclk_freq_index]; + if(DATA_BITS == 16) + { + bclk_freq = bclk_freq / 2; + } + + broadcast(bclk_freq, NUM_IN, NUM_OUT, DATA_BITS, i2s_config->mode == I2S_MODE_I2S); diff --git a/test/lib_i2s/test_i2s_basic_slave.py b/test/lib_i2s/test_i2s_basic_slave.py index 3ba6bb6..2ea7bd4 100644 --- a/test/lib_i2s/test_i2s_basic_slave.py +++ b/test/lib_i2s/test_i2s_basic_slave.py @@ -10,6 +10,7 @@ num_in_out_args = { "4ch_in,4ch_out": (4, 4), + "2ch_in,2ch_out": (2, 2), "1ch_in,1ch_out": (1, 1), "4ch_in,0ch_out": (4, 0), "0ch_in,4ch_out": (0, 4), From d9ab79416a080a3f321613e9890e5e6a8d23e1e2 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Thu, 15 Feb 2024 11:15:14 +0000 Subject: [PATCH 02/16] Store lrclk freq instead of bcl frequencies in the lut. Verify SMOKE=0 works --- test/lib_i2s/i2s_slave_test/src/main.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/test/lib_i2s/i2s_slave_test/src/main.c b/test/lib_i2s/i2s_slave_test/src/main.c index 6ea5511..345ae7d 100644 --- a/test/lib_i2s/i2s_slave_test/src/main.c +++ b/test/lib_i2s/i2s_slave_test/src/main.c @@ -25,15 +25,14 @@ xclock_t bclk = XS1_CLKBLK_1; #if SMOKE == 1 #define NUM_BCLKS 1 #define NUM_BCLKS_TO_CHECK 1 -static const unsigned bclk_freq_lut[NUM_BCLKS] = { - 12288000 +static const unsigned lr_freq_lut[NUM_BCLKS] = { + 192000 }; #else #define NUM_BCLKS 12 #define NUM_BCLKS_TO_CHECK 3 -static const unsigned bclk_freq_lut[NUM_BCLKS] = { - 1228800, 614400, 384000, 192000, 44100, - 22050, 96000, 176400, 88200, 48000, 24000, 352800 +static const unsigned lr_freq_lut[NUM_BCLKS] = { + 192000, 176400, 96000, 88200, 48000, 44100 }; #endif #ifndef DATA_BITS @@ -111,7 +110,7 @@ static int request_response( return r; } -static unsigned bclk_freq_index = 0; +static unsigned lr_freq_index = 0; static unsigned frames_sent = 0; static unsigned rx_data_counter[MAX_CHANNELS] = {0}; static unsigned tx_data_counter[MAX_CHANNELS] = {0}; @@ -174,15 +173,15 @@ void i2s_init(void *app_data, i2s_config_t *i2s_config) printf("Error\n"); } - if (bclk_freq_index == NUM_BCLKS_TO_CHECK - 1) { + if (lr_freq_index == NUM_BCLKS_TO_CHECK - 1) { if (current_mode == I2S_MODE_I2S) { current_mode = I2S_MODE_LEFT_JUSTIFIED; - bclk_freq_index = 0; + lr_freq_index = 0; } else { _Exit(1); } } else { - bclk_freq_index++; + lr_freq_index++; } } @@ -197,11 +196,7 @@ void i2s_init(void *app_data, i2s_config_t *i2s_config) rx_data_counter[i] = 0; } - unsigned bclk_freq = bclk_freq_lut[bclk_freq_index]; - if(DATA_BITS == 16) - { - bclk_freq = bclk_freq / 2; - } + unsigned bclk_freq = lr_freq_lut[lr_freq_index] * DATA_BITS * I2S_CHANS_PER_FRAME; broadcast(bclk_freq, NUM_IN, From d2a2babf7134bae5cae3f99434fe47fa072492a1 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Thu, 15 Feb 2024 11:28:14 +0000 Subject: [PATCH 03/16] Extend num_in_out_args for test_slave_bclk_invert.py --- test/lib_i2s/test_slave_bclk_invert.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/lib_i2s/test_slave_bclk_invert.py b/test/lib_i2s/test_slave_bclk_invert.py index 27c03a4..8948056 100644 --- a/test/lib_i2s/test_slave_bclk_invert.py +++ b/test/lib_i2s/test_slave_bclk_invert.py @@ -6,7 +6,13 @@ import pytest import Pyxsim as px -num_in_out_args = {"2ch_in,2ch_out": (2, 2)} +num_in_out_args = { + "4ch_in,4ch_out": (4, 4), + "2ch_in,2ch_out": (2, 2), + "1ch_in,1ch_out": (1, 1), + "4ch_in,0ch_out": (4, 0), + "0ch_in,4ch_out": (0, 4), +} bitdepth_args = {"16b": 16, "32b": 32} From 273666ef5802611aca6f4b1f0d9af19078bf52a6 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Thu, 15 Feb 2024 14:02:20 +0000 Subject: [PATCH 04/16] Add comments --- test/lib_i2s/i2s_slave_checker.py | 2 +- test/lib_i2s/i2s_slave_test/i2s_slave_test.cmake | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/test/lib_i2s/i2s_slave_checker.py b/test/lib_i2s/i2s_slave_checker.py index 4cde037..8000f8c 100644 --- a/test/lib_i2s/i2s_slave_checker.py +++ b/test/lib_i2s/i2s_slave_checker.py @@ -146,7 +146,7 @@ def run(self): # the range 32 - 63, lr_clock outputs 1, else it outputs 0. time = float(xsi.get_time()) - time = self.wait_until_ret(time + (clock_half_period*64)) + time = self.wait_until_ret(time + (clock_half_period*64)) # Add extra delay to ensure that the i2s_slave device sees the LRCLK transitions in the first for loop below lr_counter = data_bits + (data_bits // 2) + (is_i2s_justified) diff --git a/test/lib_i2s/i2s_slave_test/i2s_slave_test.cmake b/test/lib_i2s/i2s_slave_test/i2s_slave_test.cmake index 0dfb239..a7b1539 100644 --- a/test/lib_i2s/i2s_slave_test/i2s_slave_test.cmake +++ b/test/lib_i2s/i2s_slave_test/i2s_slave_test.cmake @@ -16,12 +16,9 @@ set(APP_LINK_OPTIONS -target=XCORE-AI-EXPLORER ) -set(APP_COMPILER_FLAGS_DATA_PLANE - -O3 -) - -# Compile main.c which contains the i2s_callback_group_t functions in O3 mode -set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/src/main.c PROPERTIES COMPILE_FLAGS "${APP_COMPILER_FLAGS_DATA_PLANE}") +# Compile main.c which contains the i2s_callback_group_t functions in O3 mode. Needed for passing the +# test_i2s_basic_slave[4ch_in,4ch_out-32b] and test_i2s_basic_slave[4ch_in,4ch_out-16b] tests +set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/src/main.c PROPERTIES COMPILE_FLAGS "-O3") #********************** # Tile Targets From be5cfc27af417e732ae63383ad73fb4188997b11 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Thu, 15 Feb 2024 15:26:49 +0000 Subject: [PATCH 05/16] Change macro names --- test/lib_i2s/i2s_slave_test/src/main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/lib_i2s/i2s_slave_test/src/main.c b/test/lib_i2s/i2s_slave_test/src/main.c index 345ae7d..c986fc5 100644 --- a/test/lib_i2s/i2s_slave_test/src/main.c +++ b/test/lib_i2s/i2s_slave_test/src/main.c @@ -23,15 +23,15 @@ xclock_t bclk = XS1_CLKBLK_1; #define I2S_LOOPBACK_LATENCY 1 #if SMOKE == 1 -#define NUM_BCLKS 1 -#define NUM_BCLKS_TO_CHECK 1 -static const unsigned lr_freq_lut[NUM_BCLKS] = { +#define NUM_LRCLKS 1 +#define NUM_LRCLKS_TO_CHECK 1 +static const unsigned lr_freq_lut[NUM_LRCLKS] = { 192000 }; #else -#define NUM_BCLKS 12 -#define NUM_BCLKS_TO_CHECK 3 -static const unsigned lr_freq_lut[NUM_BCLKS] = { +#define NUM_LRCLKS 12 +#define NUM_LRCLKS_TO_CHECK 3 +static const unsigned lr_freq_lut[NUM_LRCLKS] = { 192000, 176400, 96000, 88200, 48000, 44100 }; #endif @@ -173,7 +173,7 @@ void i2s_init(void *app_data, i2s_config_t *i2s_config) printf("Error\n"); } - if (lr_freq_index == NUM_BCLKS_TO_CHECK - 1) { + if (lr_freq_index == NUM_LRCLKS_TO_CHECK - 1) { if (current_mode == I2S_MODE_I2S) { current_mode = I2S_MODE_LEFT_JUSTIFIED; lr_freq_index = 0; From 1af7fbd38a676b980db413b42ffbb3dc7aafb340 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Thu, 15 Feb 2024 15:28:41 +0000 Subject: [PATCH 06/16] format python file --- test/lib_i2s/i2s_slave_checker.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/lib_i2s/i2s_slave_checker.py b/test/lib_i2s/i2s_slave_checker.py index 8000f8c..0a48ce1 100644 --- a/test/lib_i2s/i2s_slave_checker.py +++ b/test/lib_i2s/i2s_slave_checker.py @@ -146,8 +146,9 @@ def run(self): # the range 32 - 63, lr_clock outputs 1, else it outputs 0. time = float(xsi.get_time()) - time = self.wait_until_ret(time + (clock_half_period*64)) # Add extra delay to ensure that the i2s_slave device sees the LRCLK transitions in the first for loop below - + time = self.wait_until_ret( + time + (clock_half_period * 64) + ) # Add extra delay to ensure that the i2s_slave device sees the LRCLK transitions in the first for loop below lr_counter = data_bits + (data_bits // 2) + (is_i2s_justified) lr_count_max = (2 * data_bits) - 1 @@ -176,8 +177,6 @@ def run(self): xsi.drive_port_pins(self._bclk, bclk1) time = self.wait_until_ret(time + clock_half_period) - - error = False xsi.drive_port_pins(self._setup_resp_port, 0) From bca2034f0d43b799ebb45d28921b33336320d942 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Fri, 16 Feb 2024 16:04:23 +0000 Subject: [PATCH 07/16] Run all 6 lr frequencies for the test_i2s_basic_slave nightly test --- test/lib_i2s/i2s_slave_test/src/main.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/lib_i2s/i2s_slave_test/src/main.c b/test/lib_i2s/i2s_slave_test/src/main.c index c986fc5..979fdd4 100644 --- a/test/lib_i2s/i2s_slave_test/src/main.c +++ b/test/lib_i2s/i2s_slave_test/src/main.c @@ -23,15 +23,13 @@ xclock_t bclk = XS1_CLKBLK_1; #define I2S_LOOPBACK_LATENCY 1 #if SMOKE == 1 -#define NUM_LRCLKS 1 #define NUM_LRCLKS_TO_CHECK 1 -static const unsigned lr_freq_lut[NUM_LRCLKS] = { +static const unsigned lr_freq_lut[] = { 192000 }; #else -#define NUM_LRCLKS 12 -#define NUM_LRCLKS_TO_CHECK 3 -static const unsigned lr_freq_lut[NUM_LRCLKS] = { +#define NUM_LRCLKS_TO_CHECK 6 +static const unsigned lr_freq_lut[] = { 192000, 176400, 96000, 88200, 48000, 44100 }; #endif From 8e440d2f03ad8a91d82080b746b5c0d0d3a69e45 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Fri, 16 Feb 2024 16:15:06 +0000 Subject: [PATCH 08/16] Get test_i2s_basic_master.py test passing --- .../i2s_master_test/i2s_master_test.cmake | 3 + test/lib_i2s/i2s_master_test/src/main.c | 55 +++++++------------ test/lib_i2s/test_i2s_basic_master.py | 2 +- 3 files changed, 23 insertions(+), 37 deletions(-) diff --git a/test/lib_i2s/i2s_master_test/i2s_master_test.cmake b/test/lib_i2s/i2s_master_test/i2s_master_test.cmake index ece0872..1f70361 100644 --- a/test/lib_i2s/i2s_master_test/i2s_master_test.cmake +++ b/test/lib_i2s/i2s_master_test/i2s_master_test.cmake @@ -16,6 +16,9 @@ set(APP_LINK_OPTIONS -target=XCORE-AI-EXPLORER ) +# Compile main.c which contains the i2s_callback_group_t functions in O3 mode +set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/src/main.c PROPERTIES COMPILE_FLAGS "-O3") + #********************** # Tile Targets #********************** diff --git a/test/lib_i2s/i2s_master_test/src/main.c b/test/lib_i2s/i2s_master_test/src/main.c index 6c032bf..29b20e2 100644 --- a/test/lib_i2s/i2s_master_test/src/main.c +++ b/test/lib_i2s/i2s_master_test/src/main.c @@ -24,38 +24,38 @@ port_t setup_resp_port = XS1_PORT_1M; #define MAX_CHANNELS 8 #if defined(SMOKE) -#if NUM_OUT > 1 || NUM_IN > 1 #define NUM_MCLKS 1 -static const unsigned mclock_freq[NUM_MCLKS] = { - 12288000, -}; -#else -#define NUM_MCLKS 1 -static const unsigned mclock_freq[NUM_MCLKS] = { +// Choose mclk freq such that mclk_bclk_ratio is atleast 2 for the worst case sampling freq (192KHz), since +// mclk_bclk_ratio = 1 doesn't seem to be supported. +static const unsigned mclock_freq_32[NUM_MCLKS] = { 24576000, }; -#endif -#else -#if NUM_OUT > 1 || NUM_IN > 1 -#define NUM_MCLKS 2 -static const unsigned mclock_freq[NUM_MCLKS] = { +static const unsigned mclock_freq_16[NUM_MCLKS] = { 12288000, - 11289600, }; #else -#define NUM_MCLKS 4 -static const unsigned mclock_freq[NUM_MCLKS] = { +#define NUM_MCLKS 2 +static const unsigned mclock_freq_32[NUM_MCLKS] = { 24576000, 22579200, +}; +static const unsigned mclock_freq_16[NUM_MCLKS] = { 12288000, 11289600, }; #endif -#endif #ifndef DATA_BITS #define DATA_BITS 32 #endif +#if DATA_BITS == 32 + unsigned const *mclock_freq_ptr = mclock_freq_32; +#elif DATA_BITS == 16 + unsigned const *mclock_freq_ptr = mclock_freq_16; +#else + #error "Invalid DATA_BITS define" +#endif + // Applications are expected to define this macro if they want non-32b I2S width #define I2S_DATA_BITS DATA_BITS @@ -173,17 +173,6 @@ i2s_restart_t i2s_restart_check(void *app_data) void i2s_init(void *app_data, i2s_config_t *i2s_config) { - /* - * We're going to manually disable the 16b 192 kHz 8i8o test as it does not - * pass in this implementation (but does in lib_i2s!). This is the first - * thing tested in this sequence, so must first advance ratio_log2 - * by one to start with. - */ - if (DATA_BITS == 16 && NUM_IN == 4 && NUM_OUT == 4 && first_time) - { - ratio_log2++; - } - if (!first_time) { unsigned x = request_response(setup_strobe_port, setup_resp_port); error |= x; @@ -208,19 +197,13 @@ void i2s_init(void *app_data, i2s_config_t *i2s_config) } else { ratio_log2++; } - - uint32_t new_sample_rate = mclock_freq[mclock_freq_index] / ((1 << ratio_log2) * (2 * DATA_BITS)); + + uint32_t new_sample_rate = mclock_freq_ptr[mclock_freq_index] / ((1 << ratio_log2) * (2 * DATA_BITS)); if (new_sample_rate >= 48000) { s = 1; } - - // And then we need to skip the second time it comes up in testing - if (new_sample_rate == 192000 && DATA_BITS == 16 && NUM_IN == 4 && NUM_OUT == 4) - { - s = 0; - } } } @@ -237,7 +220,7 @@ void i2s_init(void *app_data, i2s_config_t *i2s_config) rx_data_counter[i] = 0; } - broadcast(mclock_freq[mclock_freq_index], + broadcast(mclock_freq_ptr[mclock_freq_index], i2s_config->mclk_bclk_ratio, NUM_IN, NUM_OUT, DATA_BITS, i2s_config->mode == I2S_MODE_I2S); diff --git a/test/lib_i2s/test_i2s_basic_master.py b/test/lib_i2s/test_i2s_basic_master.py index 6861b40..51ab1f0 100644 --- a/test/lib_i2s/test_i2s_basic_master.py +++ b/test/lib_i2s/test_i2s_basic_master.py @@ -76,7 +76,7 @@ def test_i2s_basic_master(build, capfd, nightly, request, bitdepth, num_in, num_ simthreads=[clk, checker], simargs=[ "--vcd-tracing", - f"-o i2s_trace_{num_in}_{num_out}.vcd -tile tile[0] -cycles -ports -ports-detailed -cores -instructions", + f"-o i2s_trace_{num_in}_{num_out}.vcd -tile tile[0] -cycles -ports -ports-detailed -cores -instructions -clock-blocks", "--trace-to", f"i2s_trace_{num_in}_{num_out}.txt", ], From 671b6f5d6401bc38cdccf63494564371fcca0ef7 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Sun, 18 Feb 2024 13:09:50 +0000 Subject: [PATCH 09/16] Fix test_basic_master_external_clock.py --- .../i2s_master_external_clock_test.cmake | 2 + .../i2s_master_external_clock_test/src/main.c | 100 +++++++++--------- test/lib_i2s/i2s_master_test/src/main.c | 66 ++++++------ .../test_basic_master_external_clock.py | 2 +- 4 files changed, 84 insertions(+), 86 deletions(-) diff --git a/test/lib_i2s/i2s_master_external_clock_test/i2s_master_external_clock_test.cmake b/test/lib_i2s/i2s_master_external_clock_test/i2s_master_external_clock_test.cmake index 057a339..7644ab0 100644 --- a/test/lib_i2s/i2s_master_external_clock_test/i2s_master_external_clock_test.cmake +++ b/test/lib_i2s/i2s_master_external_clock_test/i2s_master_external_clock_test.cmake @@ -15,6 +15,8 @@ set(APP_LINK_OPTIONS -report -target=XCORE-AI-EXPLORER ) +# Compile main.c which contains the i2s_callback_group_t functions in O3 mode +set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/src/main.c PROPERTIES COMPILE_FLAGS "-O3") #********************** # Tile Targets diff --git a/test/lib_i2s/i2s_master_external_clock_test/src/main.c b/test/lib_i2s/i2s_master_external_clock_test/src/main.c index 51a26f8..2c7309c 100644 --- a/test/lib_i2s/i2s_master_external_clock_test/src/main.c +++ b/test/lib_i2s/i2s_master_external_clock_test/src/main.c @@ -19,41 +19,49 @@ port_t setup_strobe_port = XS1_PORT_1L; port_t setup_data_port = XS1_PORT_16A; port_t setup_resp_port = XS1_PORT_1M; -#define MAX_RATIO 4 +#define MAX_RATIO 3 // 192, 96 and 48KHz #define MAX_CHANNELS 8 #define MAX_NUM_RESTARTS (4) -#if defined(SMOKE) -#if NUM_OUT > 1 || NUM_IN > 1 +#ifndef DATA_BITS +#define DATA_BITS 32 +#endif + +#if SMOKE #define NUM_MCLKS 1 +#if DATA_BITS == 32 +// Choose mclk freq such that mclk_bclk_ratio is atleast 2 for the worst case sampling freq (192KHz), since +// mclk_bclk_ratio = 1 doesn't seem to be supported. +static const unsigned mclock_freq[NUM_MCLKS] = { + 24576000, +}; +#elif DATA_BITS == 16 static const unsigned mclock_freq[NUM_MCLKS] = { 12288000, }; #else -#define NUM_MCLKS 1 + #error "Invalid DATA_BITS define" +#endif +#else // SMOKE = 0 +#define NUM_MCLKS 2 +#if DATA_BITS == 32 static const unsigned mclock_freq[NUM_MCLKS] = { 24576000, + 22579200, }; -#endif -#else -#if NUM_OUT > 1 || NUM_IN > 1 -#define NUM_MCLKS 1 +#elif DATA_BITS == 16 static const unsigned mclock_freq[NUM_MCLKS] = { 12288000, + 11289600, }; #else -#define NUM_MCLKS 1 -static const unsigned mclock_freq[NUM_MCLKS] = { - 24576000, -}; -#endif + #error "Invalid DATA_BITS define" #endif -#ifndef DATA_BITS -#define DATA_BITS 32 #endif + // Applications are expected to define this macro if they want non-32b I2S width #define I2S_DATA_BITS DATA_BITS @@ -177,26 +185,42 @@ i2s_restart_t i2s_restart_check(void *app_data) return restart; } -void i2s_init(void *app_data, i2s_config_t *i2s_config) +void setup_bclock() { - //bclock frequency is not changed in restart when using i2s_frame_master_external_clock. - //The clock needs to be set externally once, before starting i2s_frame_master_external_clock. + mclk_bclk_ratio = (1 << ratio_log2); + + broadcast(mclock_freq[mclock_freq_index], + mclk_bclk_ratio, + NUM_IN, NUM_OUT, DATA_BITS, + current_mode == I2S_MODE_I2S); + + clock_enable(bclk); + clock_set_source_port(bclk, p_mclk); + clock_set_divide(bclk, mclk_bclk_ratio >> 1); +} +void i2s_init(void *app_data, i2s_config_t *i2s_config) +{ if (!first_time) { unsigned x = request_response(setup_strobe_port, setup_resp_port); error |= x; if (error) { printf("Error: test fail\n"); } - - if (current_mode == I2S_MODE_I2S) { - current_mode = I2S_MODE_LEFT_JUSTIFIED; + if (ratio_log2 == MAX_RATIO) { + ratio_log2 = 1; + if (mclock_freq_index == NUM_MCLKS - 1) { + mclock_freq_index = 0; + if (current_mode == I2S_MODE_I2S) { + current_mode = I2S_MODE_LEFT_JUSTIFIED; + } else { + _Exit(1); + } + } else { + mclock_freq_index++; + } } else { - current_mode = I2S_MODE_I2S; - } - - if (num_restarts >= MAX_NUM_RESTARTS) { - _Exit(1); + ratio_log2++; } } @@ -211,27 +235,7 @@ void i2s_init(void *app_data, i2s_config_t *i2s_config) rx_data_counter[i] = 0; } - broadcast(mclock_freq[mclock_freq_index], - mclk_bclk_ratio, - NUM_IN, NUM_OUT, DATA_BITS, - i2s_config->mode == I2S_MODE_I2S); -} - -void setup_bclock() -{ - mclock_freq_index = 0; - ratio_log2 = 1; - mclk_bclk_ratio = (1 << ratio_log2); - current_mode = I2S_MODE_I2S; - - broadcast(mclock_freq[mclock_freq_index], - mclk_bclk_ratio, - NUM_IN, NUM_OUT, DATA_BITS, - current_mode == I2S_MODE_I2S); - - clock_enable(bclk); - clock_set_source_port(bclk, p_mclk); - clock_set_divide(bclk, mclk_bclk_ratio >> 1); + setup_bclock(); } DECLARE_JOB(spin, (void)); @@ -256,8 +260,6 @@ int main(){ port_enable(p_mclk); port_enable(p_bclk); - setup_bclock(); - PAR_JOBS ( PJOB(i2s_master_external_clock, ( &i_i2s, diff --git a/test/lib_i2s/i2s_master_test/src/main.c b/test/lib_i2s/i2s_master_test/src/main.c index 29b20e2..6a6e525 100644 --- a/test/lib_i2s/i2s_master_test/src/main.c +++ b/test/lib_i2s/i2s_master_test/src/main.c @@ -19,42 +19,46 @@ port_t setup_strobe_port = XS1_PORT_1L; port_t setup_data_port = XS1_PORT_16A; port_t setup_resp_port = XS1_PORT_1M; -#define MAX_RATIO 4 +#define MAX_RATIO 3 // 192, 96 and 48KHz #define MAX_CHANNELS 8 -#if defined(SMOKE) +#ifndef DATA_BITS +#define DATA_BITS 32 +#endif + +#if SMOKE #define NUM_MCLKS 1 +#if DATA_BITS == 32 // Choose mclk freq such that mclk_bclk_ratio is atleast 2 for the worst case sampling freq (192KHz), since // mclk_bclk_ratio = 1 doesn't seem to be supported. -static const unsigned mclock_freq_32[NUM_MCLKS] = { +static const unsigned mclock_freq[NUM_MCLKS] = { 24576000, }; -static const unsigned mclock_freq_16[NUM_MCLKS] = { +#elif DATA_BITS == 16 +static const unsigned mclock_freq[NUM_MCLKS] = { 12288000, }; #else + #error "Invalid DATA_BITS define" +#endif +#else // SMOKE = 0 #define NUM_MCLKS 2 -static const unsigned mclock_freq_32[NUM_MCLKS] = { +#if DATA_BITS == 32 +static const unsigned mclock_freq[NUM_MCLKS] = { 24576000, 22579200, }; -static const unsigned mclock_freq_16[NUM_MCLKS] = { +#elif DATA_BITS == 16 +static const unsigned mclock_freq[NUM_MCLKS] = { 12288000, 11289600, }; -#endif -#ifndef DATA_BITS -#define DATA_BITS 32 -#endif - -#if DATA_BITS == 32 - unsigned const *mclock_freq_ptr = mclock_freq_32; -#elif DATA_BITS == 16 - unsigned const *mclock_freq_ptr = mclock_freq_16; #else #error "Invalid DATA_BITS define" #endif +#endif + // Applications are expected to define this macro if they want non-32b I2S width #define I2S_DATA_BITS DATA_BITS @@ -180,30 +184,20 @@ void i2s_init(void *app_data, i2s_config_t *i2s_config) printf("Error: test fail\n"); } - int s = 0; - while (!s) { - if (ratio_log2 == MAX_RATIO) { - ratio_log2 = 1; - if (mclock_freq_index == NUM_MCLKS - 1) { - mclock_freq_index = 0; - if (current_mode == I2S_MODE_I2S) { - current_mode = I2S_MODE_LEFT_JUSTIFIED; - } else { - _Exit(1); - } + if (ratio_log2 == MAX_RATIO) { + ratio_log2 = 1; + if (mclock_freq_index == NUM_MCLKS - 1) { + mclock_freq_index = 0; + if (current_mode == I2S_MODE_I2S) { + current_mode = I2S_MODE_LEFT_JUSTIFIED; } else { - mclock_freq_index++; + _Exit(1); } } else { - ratio_log2++; - } - - uint32_t new_sample_rate = mclock_freq_ptr[mclock_freq_index] / ((1 << ratio_log2) * (2 * DATA_BITS)); - - if (new_sample_rate >= 48000) - { - s = 1; + mclock_freq_index++; } + } else { + ratio_log2++; } } @@ -220,7 +214,7 @@ void i2s_init(void *app_data, i2s_config_t *i2s_config) rx_data_counter[i] = 0; } - broadcast(mclock_freq_ptr[mclock_freq_index], + broadcast(mclock_freq[mclock_freq_index], i2s_config->mclk_bclk_ratio, NUM_IN, NUM_OUT, DATA_BITS, i2s_config->mode == I2S_MODE_I2S); diff --git a/test/lib_i2s/test_basic_master_external_clock.py b/test/lib_i2s/test_basic_master_external_clock.py index 8d779a2..53f31fe 100644 --- a/test/lib_i2s/test_basic_master_external_clock.py +++ b/test/lib_i2s/test_basic_master_external_clock.py @@ -21,7 +21,7 @@ def uncollect_if(bitdepth, num_in, num_out): if bitdepth == 16 and num_in == 4 and num_out == 4: return True -@pytest.mark.uncollect_if(func=uncollect_if) +#@pytest.mark.uncollect_if(func=uncollect_if) @pytest.mark.parametrize("bitdepth", bitdepth_args.values(), ids=bitdepth_args.keys()) @pytest.mark.parametrize( ("num_in", "num_out"), num_in_out_args.values(), ids=num_in_out_args.keys() From 218c87649f9eb8a1bbbd6b2e4551587663141da1 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Tue, 20 Feb 2024 09:45:40 +0000 Subject: [PATCH 10/16] Remove uncollect_if for the test_basic_master_external_clock 16b 4i4o case --- test/lib_i2s/test_basic_master_external_clock.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/lib_i2s/test_basic_master_external_clock.py b/test/lib_i2s/test_basic_master_external_clock.py index 53f31fe..a7ef151 100644 --- a/test/lib_i2s/test_basic_master_external_clock.py +++ b/test/lib_i2s/test_basic_master_external_clock.py @@ -16,12 +16,6 @@ bitdepth_args = {"16b": 16, "32b": 32} -# 16b 4i4o (8ch in/8ch out) currently does not pass -def uncollect_if(bitdepth, num_in, num_out): - if bitdepth == 16 and num_in == 4 and num_out == 4: - return True - -#@pytest.mark.uncollect_if(func=uncollect_if) @pytest.mark.parametrize("bitdepth", bitdepth_args.values(), ids=bitdepth_args.keys()) @pytest.mark.parametrize( ("num_in", "num_out"), num_in_out_args.values(), ids=num_in_out_args.keys() From 1f843bd4b040fb3988ba4f18fdc2d0421a82726d Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Wed, 21 Feb 2024 14:00:36 +0000 Subject: [PATCH 11/16] Modify backpressure test to something sensible --- test/build_lib_i2s_tests.sh | 24 --- .../backpressure_test/backpressure_test.cmake | 2 +- test/lib_i2s/backpressure_test/src/main.c | 163 +++++++++++++++--- test/lib_i2s/test_backpressure.py | 5 +- 4 files changed, 143 insertions(+), 51 deletions(-) diff --git a/test/build_lib_i2s_tests.sh b/test/build_lib_i2s_tests.sh index ecc5678..de3aa19 100755 --- a/test/build_lib_i2s_tests.sh +++ b/test/build_lib_i2s_tests.sh @@ -9,18 +9,6 @@ source ${FRAMEWORK_IO_ROOT}/tools/ci/helper_functions.sh # row format is: "make_target BOARD toolchain" declare -a applications=( - "test_hil_backpressure_test_32_768000_4_5_5" - "test_hil_backpressure_test_32_768000_4_0_10" - "test_hil_backpressure_test_32_768000_4_10_0" - "test_hil_backpressure_test_32_768000_3_5_5" - "test_hil_backpressure_test_32_768000_3_0_10" - "test_hil_backpressure_test_32_768000_3_10_0" - "test_hil_backpressure_test_32_768000_2_5_5" - "test_hil_backpressure_test_32_768000_2_0_10" - "test_hil_backpressure_test_32_768000_2_10_0" - "test_hil_backpressure_test_32_768000_1_5_5" - "test_hil_backpressure_test_32_768000_1_0_10" - "test_hil_backpressure_test_32_768000_1_10_0" "test_hil_backpressure_test_32_384000_4_5_5" "test_hil_backpressure_test_32_384000_4_0_10" "test_hil_backpressure_test_32_384000_4_10_0" @@ -81,18 +69,6 @@ declare -a applications=( "test_hil_i2s_slave_test_32_1_4_0_inv" "test_hil_i2s_slave_test_32_1_0_4_inv" "test_hil_i2s_slave_test_32_1_2_2_inv" - "test_hil_backpressure_test_16_768000_4_5_5" - "test_hil_backpressure_test_16_768000_4_0_10" - "test_hil_backpressure_test_16_768000_4_10_0" - "test_hil_backpressure_test_16_768000_3_5_5" - "test_hil_backpressure_test_16_768000_3_0_10" - "test_hil_backpressure_test_16_768000_3_10_0" - "test_hil_backpressure_test_16_768000_2_5_5" - "test_hil_backpressure_test_16_768000_2_0_10" - "test_hil_backpressure_test_16_768000_2_10_0" - "test_hil_backpressure_test_16_768000_1_5_5" - "test_hil_backpressure_test_16_768000_1_0_10" - "test_hil_backpressure_test_16_768000_1_10_0" "test_hil_backpressure_test_16_384000_4_5_5" "test_hil_backpressure_test_16_384000_4_0_10" "test_hil_backpressure_test_16_384000_4_10_0" diff --git a/test/lib_i2s/backpressure_test/backpressure_test.cmake b/test/lib_i2s/backpressure_test/backpressure_test.cmake index 554780d..4a14538 100644 --- a/test/lib_i2s/backpressure_test/backpressure_test.cmake +++ b/test/lib_i2s/backpressure_test/backpressure_test.cmake @@ -24,7 +24,7 @@ set(APP_LINK_OPTIONS # Tile Targets #********************** if(NOT DEFINED ENV{SAMPLE_RATES}) - set(SAMPLE_RATES 768000 384000 192000) + set(SAMPLE_RATES 384000 192000) else() set(SAMPLE_RATES $ENV{SAMPLE_RATES}) endif() diff --git a/test/lib_i2s/backpressure_test/src/main.c b/test/lib_i2s/backpressure_test/src/main.c index d28db53..70e350a 100644 --- a/test/lib_i2s/backpressure_test/src/main.c +++ b/test/lib_i2s/backpressure_test/src/main.c @@ -14,7 +14,7 @@ #define BURN_THREADS 6 #endif #ifndef SAMPLE_FREQUENCY -#define SAMPLE_FREQUENCY 768000 +#define SAMPLE_FREQUENCY 192000 #endif #ifndef TEST_LEN #define TEST_LEN 1000 @@ -44,6 +44,115 @@ #define SETSR(c) asm volatile("setsr %0" : : "n"(c)); +enum { + SAMPLE_RATE_192000, + SAMPLE_RATE_384000, + NUM_SAMPLE_RATES +}e_sample_rates; + +enum { + BITDEPTH_16, + BITDEPTH_32, + NUM_BIT_DEPTHS +}e_bit_depth; + +enum { + NUM_I2S_LINES_1, + NUM_I2S_LINES_2, + NUM_I2S_LINES_3, + NUM_I2S_LINES_4, +}e_channel_config; + +static int acceptable_receive_delay = 0, acceptable_send_delay = 0; +static int acceptable_delay_ticks[NUM_SAMPLE_RATES][NUM_I2S_LINES_4+1][NUM_BIT_DEPTHS]; + +static inline void populate_acceptable_delay_ticks() +{ + // These numbers are logged by running the test and logging the delay at the point at which the + // backpressure test starts failing. + + // 192 KHz + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_1][BITDEPTH_16] = 185; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_1][BITDEPTH_32] = 200; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_2][BITDEPTH_16] = 155; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_2][BITDEPTH_32] = 170; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_3][BITDEPTH_16] = 130; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_3][BITDEPTH_32] = 150; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_4][BITDEPTH_16] = 100; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_4][BITDEPTH_32] = 125; + + // 384 KHz + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_1][BITDEPTH_16] = 60; + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_1][BITDEPTH_32] = 70; + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_2][BITDEPTH_16] = 35; + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_2][BITDEPTH_32] = 45; + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_3][BITDEPTH_16] = 5; + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_3][BITDEPTH_32] = 20; + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_4][BITDEPTH_16] = 0; + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_4][BITDEPTH_32] = 0; +} + +void get_acceptable_delay() +{ + int sample_rate; + if(SAMPLE_FREQUENCY == 192000) + { + sample_rate = SAMPLE_RATE_192000; + } + else if(SAMPLE_FREQUENCY == 384000) + { + sample_rate = SAMPLE_RATE_384000; + } + else + { + printf("ERROR: Invalid sample rate %d\n", SAMPLE_FREQUENCY); + _Exit(1); + } + + int bit_depth; + if(DATA_BITS == 16) + { + bit_depth = BITDEPTH_16; + } + else if(DATA_BITS == 32) + { + bit_depth = BITDEPTH_32; + } + else + { + printf("ERROR: Invalid bit_depth %d\n", DATA_BITS); + _Exit(1); + } + if((NUM_I2S_LINES < 1) || (NUM_I2S_LINES > 4)) + { + printf("ERROR: Invalid NUM_I2S_LINES %d\n", NUM_I2S_LINES); + _Exit(1); + } + int delay = acceptable_delay_ticks[sample_rate][NUM_I2S_LINES-1][bit_depth]; + + // get the send and receive delay based on the + if((RECEIVE_DELAY_INCREMENT == 5) && (SEND_DELAY_INCREMENT == 5)) + { + acceptable_receive_delay = delay; + acceptable_send_delay = delay; + } + else if((RECEIVE_DELAY_INCREMENT == 0) && (SEND_DELAY_INCREMENT == 10)) + { + acceptable_receive_delay = 0; + acceptable_send_delay = 2*delay; + } + else if((RECEIVE_DELAY_INCREMENT == 10) && (SEND_DELAY_INCREMENT == 0)) + { + acceptable_receive_delay = 2*delay; + acceptable_send_delay = 0; + } + else + { + printf("ERROR: Unsupported receive (%d) and send (%d) delay increment combination\n", RECEIVE_DELAY_INCREMENT, SEND_DELAY_INCREMENT); + _Exit(1); + } +} + /* Ports and clocks used by the application */ port_t p_lrclk = XS1_PORT_1G; port_t p_bclk = XS1_PORT_1H; @@ -54,7 +163,7 @@ port_t p_din [4] = {XS1_PORT_1I, XS1_PORT_1J, XS1_PORT_1K, XS1_PORT_1L}; xclock_t mclk = XS1_CLKBLK_1; xclock_t bclk = XS1_CLKBLK_2; -static volatile int receive_delay = 5000; +static volatile int receive_delay = 0; static volatile int send_delay = 0; void i2s_init(void *app_data, i2s_config_t *i2s_config) @@ -85,11 +194,6 @@ i2s_restart_t i2s_restart_check(void *app_data) return I2S_NO_RESTART; } -#if DATA_BITS == 32 -#define OVERHEAD_TICKS 185 // Some of the period needs to be allowed for the callbacks -#else -#define OVERHEAD_TICKS 185 // Non-32b data widths take longer to process -#endif #define JITTER 1 //Allow for rounding so does not break when diff = period + 1 #define N_CYCLES_AT_DELAY 1 //How many LR clock cycles to measure at each backpressure delay value #define DIFF_WRAP_16(new, old) (new > old ? new - old : new + 0x10000 - old) @@ -121,28 +225,40 @@ void test_lr_period() { port_set_trigger_in_equal(p_lr_test, 0); (void) port_in(p_lr_test); counter++; - if (counter == N_CYCLES_AT_DELAY) { - receive_delay += RECEIVE_DELAY_INCREMENT; - send_delay += SEND_DELAY_INCREMENT; - if ((receive_delay + send_delay) > (period - OVERHEAD_TICKS)) { - printf("PASS\n"); - _Exit(0); - } - counter = 0; - } + port_set_trigger_in_equal(p_lr_test, 1); (void) port_in(p_lr_test); time = port_get_trigger_time(p_lr_test); int diff = DIFF_WRAP_16(time, time_old); if (diff > (period + JITTER)) { - printf("Backpressure breaks at receive delay ticks=%d, send delay ticks=%d\n", - receive_delay, send_delay); - printf("actual diff: %d, maximum (period + Jitter): %d\n", - diff, (period + JITTER)); - _Exit(1); + // The delay we're able to add in the i2s_receive() function should be acceptable_receive_delay ticks or more + if(receive_delay < acceptable_receive_delay) + { + printf("Backpressure breaks at receive delay ticks = %d, acceptable receive delay = %d\n", + receive_delay, acceptable_receive_delay); + printf("actual diff: %d, maximum (period + Jitter): %d\n", diff, (period + JITTER)); + _Exit(1); + } + + // The delay we're able to add in the i2s_send() function should be acceptable_send_delay ticks or more + if(send_delay < acceptable_send_delay) + { + printf("Backpressure breaks at send delay ticks = %d, acceptable send delay = %d\n", + send_delay, acceptable_send_delay); + printf("actual diff: %d, maximum (period + Jitter): %d\n", diff, (period + JITTER)); + _Exit(1); + } + printf("PASS\n"); + _Exit(0); } - time_old = time; + + if (counter == N_CYCLES_AT_DELAY) { + receive_delay += RECEIVE_DELAY_INCREMENT; + send_delay += SEND_DELAY_INCREMENT; + counter = 0; + } + time_old = time; } } @@ -153,6 +269,9 @@ void burn(void) { } int main() { + populate_acceptable_delay_ticks(); + get_acceptable_delay(); + i2s_callback_group_t i_i2s = { .init = (i2s_init_t) i2s_init, .restart_check = (i2s_restart_check_t) i2s_restart_check, diff --git a/test/lib_i2s/test_backpressure.py b/test/lib_i2s/test_backpressure.py index 020da02..d54599f 100644 --- a/test/lib_i2s/test_backpressure.py +++ b/test/lib_i2s/test_backpressure.py @@ -5,7 +5,7 @@ import subprocess from pathlib import Path -sample_rate_args = {"768kbps": 768000, "384kbps": 384000, "192kbps": 192000} +sample_rate_args = {"384kbps": 384000, "192kbps": 192000} num_channels_args = {"1ch": 1, "2ch": 2, "3ch": 3, "4ch": 4} @@ -41,9 +41,6 @@ def test_i2s_backpressure( send_increment, bitdepth, ): - if (num_channels != 4) and not nightly: - pytest.skip("Only run 4 channel tests unless it is a nightly") - id_string = ( f"{bitdepth}_{sample_rate}_{num_channels}_{receive_increment}_{send_increment}" ) From 99c48de214a74e9c98b302f8fd655e060b4deb19 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Wed, 21 Feb 2024 16:32:51 +0000 Subject: [PATCH 12/16] Added bare minimum processing in the i2s_receive() callback and adjusted the acceptable backpressure thresholds accordingly --- test/lib_i2s/backpressure_test/src/main.c | 56 +++++++++++++++-------- test/lib_i2s/test_backpressure.py | 5 ++ 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/test/lib_i2s/backpressure_test/src/main.c b/test/lib_i2s/backpressure_test/src/main.c index 70e350a..d53e8d9 100644 --- a/test/lib_i2s/backpressure_test/src/main.c +++ b/test/lib_i2s/backpressure_test/src/main.c @@ -68,26 +68,29 @@ static int acceptable_delay_ticks[NUM_SAMPLE_RATES][NUM_I2S_LINES_4+1][NUM_BIT_D static inline void populate_acceptable_delay_ticks() { - // These numbers are logged by running the test and logging the delay at the point at which the - // backpressure test starts failing. + // These numbers are logged by running the test and logging the delay at the last passing iteration + // before the backpressure test starts failing. So, on top of the bare minimum code in the i2s_send() + // and i2s_receive() functions in this file plus their calling overheads, we have acceptable_delay_ticks number + // of cycles per send and receive callback function call to add any extra processing. // 192 KHz - acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_1][BITDEPTH_16] = 185; - acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_1][BITDEPTH_32] = 200; - acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_2][BITDEPTH_16] = 155; - acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_2][BITDEPTH_32] = 170; - acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_3][BITDEPTH_16] = 130; - acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_3][BITDEPTH_32] = 150; - acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_4][BITDEPTH_16] = 100; - acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_4][BITDEPTH_32] = 125; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_1][BITDEPTH_16] = 170; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_1][BITDEPTH_32] = 185; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_2][BITDEPTH_16] = 140; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_2][BITDEPTH_32] = 155; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_3][BITDEPTH_16] = 105; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_3][BITDEPTH_32] = 125; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_4][BITDEPTH_16] = 70; + acceptable_delay_ticks[SAMPLE_RATE_192000][NUM_I2S_LINES_4][BITDEPTH_32] = 90; // 384 KHz - acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_1][BITDEPTH_16] = 60; - acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_1][BITDEPTH_32] = 70; - acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_2][BITDEPTH_16] = 35; - acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_2][BITDEPTH_32] = 45; - acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_3][BITDEPTH_16] = 5; - acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_3][BITDEPTH_32] = 20; + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_1][BITDEPTH_16] = 50; + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_1][BITDEPTH_32] = 55; + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_2][BITDEPTH_16] = 15; + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_2][BITDEPTH_32] = 25; + // For 384 KHz, we have non-zero backpressure only up to 2 channels + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_3][BITDEPTH_16] = 0; + acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_3][BITDEPTH_32] = 0; acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_4][BITDEPTH_16] = 0; acceptable_delay_ticks[SAMPLE_RATE_384000][NUM_I2S_LINES_4][BITDEPTH_32] = 0; } @@ -130,20 +133,29 @@ void get_acceptable_delay() } int delay = acceptable_delay_ticks[sample_rate][NUM_I2S_LINES-1][bit_depth]; + if(delay <= 0) + { + printf("ERROR: Invalid delay %d. Check if testing an unsupported configuration\n", delay); + _Exit(1); + } + // get the send and receive delay based on the if((RECEIVE_DELAY_INCREMENT == 5) && (SEND_DELAY_INCREMENT == 5)) { - acceptable_receive_delay = delay; - acceptable_send_delay = delay; + // Backpressure passes at delay, so add another increment number of ticks to get to the first fail instance + acceptable_receive_delay = delay + 5; + acceptable_send_delay = delay + 5; } else if((RECEIVE_DELAY_INCREMENT == 0) && (SEND_DELAY_INCREMENT == 10)) { + // Backpressure passes at 2*delay, so add another increment number of ticks to get to the first fail instance acceptable_receive_delay = 0; - acceptable_send_delay = 2*delay; + acceptable_send_delay = 2*delay + 10; } else if((RECEIVE_DELAY_INCREMENT == 10) && (SEND_DELAY_INCREMENT == 0)) { - acceptable_receive_delay = 2*delay; + // Backpressure passes at 2*delay, so add another increment number of ticks to get to the first fail instance + acceptable_receive_delay = 2*delay + 10; acceptable_send_delay = 0; } else @@ -165,6 +177,7 @@ xclock_t bclk = XS1_CLKBLK_2; static volatile int receive_delay = 0; static volatile int send_delay = 0; +static volatile int32_t receive_data_store[8]; void i2s_init(void *app_data, i2s_config_t *i2s_config) { @@ -184,6 +197,9 @@ void i2s_send(void *app_data, size_t n, int32_t *send_data) void i2s_receive(void *app_data, size_t n, int32_t *receive_data) { + for (size_t c = 0; c < n; c++) { + receive_data_store[c] = receive_data[c]; + } if (receive_delay) { delay_ticks(receive_delay); } diff --git a/test/lib_i2s/test_backpressure.py b/test/lib_i2s/test_backpressure.py index d54599f..e31ceab 100644 --- a/test/lib_i2s/test_backpressure.py +++ b/test/lib_i2s/test_backpressure.py @@ -17,7 +17,12 @@ bitdepth_args = {"16b": 16, "32b": 32} +# 384000 has a non-zero backpressure only upto 2 channels +def uncollect_if(bitdepth, sample_rate, num_channels, receive_increment, send_increment): + if sample_rate == 384000 and num_channels > 2: + return True +@pytest.mark.uncollect_if(func=uncollect_if) @pytest.mark.parametrize("bitdepth", bitdepth_args.values(), ids=bitdepth_args.keys()) @pytest.mark.parametrize( "sample_rate", sample_rate_args.values(), ids=sample_rate_args.keys() From c03005260d548aebb4ef5b13ecc8d38991cd5f79 Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Thu, 1 Aug 2024 13:38:33 +0100 Subject: [PATCH 13/16] Update lib_mic_array to v5.3.0 --- modules/mic_array | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mic_array b/modules/mic_array index 28cc9b1..e4996bd 160000 --- a/modules/mic_array +++ b/modules/mic_array @@ -1 +1 @@ -Subproject commit 28cc9b13ea73c9301ee6c786cb64218d773bc43e +Subproject commit e4996bdd66d825ff7ea33e0611e748c48be20d10 From 1e4d047a170a498a932601cba7db9173ec4c6924 Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Thu, 1 Aug 2024 13:39:13 +0100 Subject: [PATCH 14/16] Update changelog --- CHANGELOG.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bde7532..846c4d9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ IO Framework change log ======================= +3.5.1 +----- + + * CHANGE: Updated lib_mic_array to v5.3.0 + 3.5.0 ----- From dccdfe96ac996972eeff2c8e97372aff50863804 Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Thu, 1 Aug 2024 13:41:09 +0100 Subject: [PATCH 15/16] Update copyright dates --- test/lib_i2s/backpressure_test/src/main.c | 2 +- test/lib_i2s/i2s_master_external_clock_test/src/main.c | 2 +- test/lib_i2s/i2s_master_test/src/main.c | 2 +- test/lib_i2s/i2s_slave_test/src/main.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/lib_i2s/backpressure_test/src/main.c b/test/lib_i2s/backpressure_test/src/main.c index d53e8d9..0f14b9f 100644 --- a/test/lib_i2s/backpressure_test/src/main.c +++ b/test/lib_i2s/backpressure_test/src/main.c @@ -1,4 +1,4 @@ -// Copyright 2016-2022 XMOS LIMITED. +// Copyright 2016-2024 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include diff --git a/test/lib_i2s/i2s_master_external_clock_test/src/main.c b/test/lib_i2s/i2s_master_external_clock_test/src/main.c index 2c7309c..03f8923 100644 --- a/test/lib_i2s/i2s_master_external_clock_test/src/main.c +++ b/test/lib_i2s/i2s_master_external_clock_test/src/main.c @@ -1,4 +1,4 @@ -// Copyright 2015-2022 XMOS LIMITED. +// Copyright 2015-2024 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include diff --git a/test/lib_i2s/i2s_master_test/src/main.c b/test/lib_i2s/i2s_master_test/src/main.c index 6a6e525..2e1698e 100644 --- a/test/lib_i2s/i2s_master_test/src/main.c +++ b/test/lib_i2s/i2s_master_test/src/main.c @@ -1,4 +1,4 @@ -// Copyright 2015-2022 XMOS LIMITED. +// Copyright 2015-2024 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include diff --git a/test/lib_i2s/i2s_slave_test/src/main.c b/test/lib_i2s/i2s_slave_test/src/main.c index 979fdd4..0b7ccb9 100644 --- a/test/lib_i2s/i2s_slave_test/src/main.c +++ b/test/lib_i2s/i2s_slave_test/src/main.c @@ -1,4 +1,4 @@ -// Copyright 2015-2022 XMOS LIMITED. +// Copyright 2015-2024 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include From 30ee6fffdad4f6067e33337fba5c5485a3c3a68a Mon Sep 17 00:00:00 2001 From: Angel Cascarino Date: Thu, 1 Aug 2024 14:40:50 +0100 Subject: [PATCH 16/16] Add scope --- test/lib_i2s/i2s_slave_test/src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lib_i2s/i2s_slave_test/src/main.c b/test/lib_i2s/i2s_slave_test/src/main.c index 0b7ccb9..fd520fd 100644 --- a/test/lib_i2s/i2s_slave_test/src/main.c +++ b/test/lib_i2s/i2s_slave_test/src/main.c @@ -150,9 +150,9 @@ i2s_restart_t i2s_restart_check(void *app_data) if (frames_sent == 4) { restart = I2S_RESTART; } - else + else { restart = I2S_NO_RESTART; - + } return restart; }