Skip to content

Commit

Permalink
Added bare minimum processing in the i2s_receive() callback and adjus…
Browse files Browse the repository at this point in the history
…ted the acceptable backpressure thresholds accordingly
  • Loading branch information
Shuchita Khare committed Feb 21, 2024
1 parent 1f843bd commit 99c48de
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
56 changes: 36 additions & 20 deletions test/lib_i2s/backpressure_test/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
{
Expand All @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions test/lib_i2s/test_backpressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 99c48de

Please sign in to comment.