Merge branch 'bugfix/fix_legacy_i2s_clock_test_failure' into 'master'

i2s_legacy_test: fix the clock test failure

Closes IDFCI-1402 and IDFCI-1408

See merge request espressif/esp-idf!19319
This commit is contained in:
Kevin (Lao Kaiyao)
2022-08-03 17:13:43 +08:00
4 changed files with 161 additions and 97 deletions

View File

@@ -804,6 +804,8 @@ static esp_err_t i2s_calculate_clock(i2s_port_t i2s_num, i2s_hal_clock_info_t *c
/* Calculate clock for common mode */ /* Calculate clock for common mode */
ESP_RETURN_ON_ERROR(i2s_calculate_common_clock(i2s_num, clk_info), TAG, "Common clock calculate failed"); ESP_RETURN_ON_ERROR(i2s_calculate_common_clock(i2s_num, clk_info), TAG, "Common clock calculate failed");
ESP_LOGD(TAG, "[sclk] %d [mclk] %d [mclk_div] %d [bclk] %d [bclk_div] %d",
clk_info->sclk, clk_info->mclk, clk_info->mclk_div, clk_info->bclk, clk_info->bclk_div);
return ESP_OK; return ESP_OK;
} }

View File

@@ -364,18 +364,26 @@ TEST_CASE("I2S_thread_concurrent_safety_test", "[i2s]")
TEST_ESP_OK(i2s_del_channel(rx_handle)); TEST_ESP_OK(i2s_del_channel(rx_handle));
} }
static uint32_t get_start_index(uint16_t *buf, uint32_t len, uint32_t start_val) static bool whether_contains_exapected_data(uint16_t *src, uint32_t src_len, uint32_t src_step, uint32_t start_val, uint32_t val_step)
{ {
uint32_t i = 0; uint32_t val = start_val;
for (i = 0; i < len; i++) { uint32_t index_step = 1;
if (buf[i] == start_val) { for (int i = 0; val < 100 && i < src_len; i += index_step) {
printf("%d %d %d %d %d %d %d %d\n", if (src[i] == val) {
buf[i], buf[i+1], buf[i+2], buf[i+3], if (val == start_val && i < src_len - 8) {
buf[i+4], buf[i+5], buf[i+6], buf[i+7]); printf("start index: %d ---> \n%d %d %d %d %d %d %d %d\n", i,
break; src[i], src[i+1], src[i+2], src[i+3],
src[i+4], src[i+5], src[i+6], src[i+7]);
}
index_step = src_step;
val += val_step;
} else {
index_step = 1;
val = start_val;
} }
} }
return i;
return val >= 100;
} }
/** /**
@@ -394,6 +402,8 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s]")
i2s_chan_handle_t tx_handle; i2s_chan_handle_t tx_handle;
i2s_chan_handle_t rx_handle; i2s_chan_handle_t rx_handle;
bool is_failed = false;
i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER); i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER);
chan_cfg.dma_desc_num = 8; chan_cfg.dma_desc_num = 8;
chan_cfg.dma_frame_num = 128; chan_cfg.dma_frame_num = 128;
@@ -429,7 +439,6 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s]")
uint16_t *r_buf = calloc(1, READ_BUF_LEN); uint16_t *r_buf = calloc(1, READ_BUF_LEN);
size_t w_bytes = 0; size_t w_bytes = 0;
size_t r_bytes = 0; size_t r_bytes = 0;
uint32_t index = 0;
uint32_t retry = 0; uint32_t retry = 0;
for (int n = 0; n < WRITE_BUF_LEN / 2; n++) { for (int n = 0; n < WRITE_BUF_LEN / 2; n++) {
w_buf[n] = n%100; w_buf[n] = n%100;
@@ -439,7 +448,7 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s]")
* tx format: 0x00[L] 0x01[R] 0x02[L] 0x03[R] ... * tx format: 0x00[L] 0x01[R] 0x02[L] 0x03[R] ...
* rx receive: 0x01[R] 0x03[R] ... */ * rx receive: 0x01[R] 0x03[R] ... */
TEST_ESP_OK(i2s_channel_write(tx_handle, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_channel_write(tx_handle, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY));
for (retry = 0, index = READ_BUF_LEN / 2; (retry < RETEY_TIMES) && (index >= READ_BUF_LEN / 2 - 50); retry++) { for (retry = 0; retry < RETEY_TIMES; retry++) {
TEST_ESP_OK(i2s_channel_read(rx_handle, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_channel_read(rx_handle, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY));
#if CONFIG_IDF_TARGET_ESP32 #if CONFIG_IDF_TARGET_ESP32
/* The data of tx/rx channels are flipped on ESP32 */ /* The data of tx/rx channels are flipped on ESP32 */
@@ -449,12 +458,15 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s]")
r_buf[n+1] = temp; r_buf[n+1] = temp;
} }
#endif #endif
index = get_start_index(r_buf, READ_BUF_LEN / 2, 1); /* Expected: 1 3 5 7 9 ... 97 99 */
if (whether_contains_exapected_data(r_buf, READ_BUF_LEN / 2, 1, 1, 2)) {
break;
} }
printf("Data start index: %d\n", index); }
TEST_ASSERT(index < READ_BUF_LEN / 2 - 50); if (retry >= RETEY_TIMES) {
for (int16_t j = 1; j < 100; j += 2) { printf("rx right mono test failed\n");
TEST_ASSERT_EQUAL_INT16(r_buf[index++], j); is_failed = true;
goto err;
} }
printf("rx right mono test passed\n"); printf("rx right mono test passed\n");
@@ -468,7 +480,7 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s]")
TEST_ESP_OK(i2s_channel_enable(tx_handle)); TEST_ESP_OK(i2s_channel_enable(tx_handle));
TEST_ESP_OK(i2s_channel_enable(rx_handle)); TEST_ESP_OK(i2s_channel_enable(rx_handle));
TEST_ESP_OK(i2s_channel_write(tx_handle, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_channel_write(tx_handle, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY));
for (retry = 0, index = READ_BUF_LEN / 2; (retry < RETEY_TIMES) && (index >= READ_BUF_LEN / 2 - 50); retry++) { for (retry = 0; retry < RETEY_TIMES; retry++) {
TEST_ESP_OK(i2s_channel_read(rx_handle, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_channel_read(rx_handle, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY));
#if CONFIG_IDF_TARGET_ESP32 #if CONFIG_IDF_TARGET_ESP32
/* The data of tx/rx channels are flipped on ESP32 */ /* The data of tx/rx channels are flipped on ESP32 */
@@ -478,12 +490,15 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s]")
r_buf[n+1] = temp; r_buf[n+1] = temp;
} }
#endif #endif
index = get_start_index(r_buf, READ_BUF_LEN / 2, 2); /* Expected: 2 4 6 8 10 ... 96 98 */
if (whether_contains_exapected_data(r_buf, READ_BUF_LEN / 2, 1, 2, 2)) {
break;
} }
printf("Data start index: %d\n", index); }
TEST_ASSERT(index < READ_BUF_LEN / 2 - 50); if (retry >= RETEY_TIMES) {
for (int16_t j = 2; j < 100; j += 2) { printf("rx left mono test failed\n");
TEST_ASSERT_EQUAL_INT16(r_buf[index++], j); is_failed = true;
goto err;
} }
printf("rx left mono test passed\n"); printf("rx left mono test passed\n");
@@ -498,15 +513,17 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s]")
TEST_ESP_OK(i2s_channel_enable(tx_handle)); TEST_ESP_OK(i2s_channel_enable(tx_handle));
TEST_ESP_OK(i2s_channel_enable(rx_handle)); TEST_ESP_OK(i2s_channel_enable(rx_handle));
TEST_ESP_OK(i2s_channel_write(tx_handle, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_channel_write(tx_handle, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY));
for (retry = 0, index = READ_BUF_LEN / 2; (retry < RETEY_TIMES) && (index >= READ_BUF_LEN / 2 - 100); retry++) { for (retry = 0; retry < RETEY_TIMES; retry++) {
TEST_ESP_OK(i2s_channel_read(rx_handle, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_channel_read(rx_handle, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY));
index = get_start_index(r_buf, READ_BUF_LEN / 2, 1); /* Expected: 1 2 3 4 ... 98 99 */
if (whether_contains_exapected_data(r_buf, READ_BUF_LEN / 2, 1, 1, 1)) {
break;
} }
}
printf("Data start index: %d\n", index); if (retry >= RETEY_TIMES) {
TEST_ASSERT(index < READ_BUF_LEN / 2 - 100); printf("tx/rx stereo test failed\n");
for (int16_t j = 1; j < 100; j ++) { is_failed = true;
TEST_ASSERT_EQUAL_INT16(r_buf[index++], j); // receive all number goto err;
} }
printf("tx/rx stereo test passed\n"); printf("tx/rx stereo test passed\n");
@@ -522,25 +539,35 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s]")
TEST_ESP_OK(i2s_channel_enable(tx_handle)); TEST_ESP_OK(i2s_channel_enable(tx_handle));
TEST_ESP_OK(i2s_channel_enable(rx_handle)); TEST_ESP_OK(i2s_channel_enable(rx_handle));
TEST_ESP_OK(i2s_channel_write(tx_handle, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_channel_write(tx_handle, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY));
for (retry = 0, index = READ_BUF_LEN / 2; (retry < RETEY_TIMES) && (index >= READ_BUF_LEN / 2 - 100); retry++) { for (retry = 0; retry < RETEY_TIMES; retry++) {
TEST_ESP_OK(i2s_channel_read(rx_handle, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_channel_read(rx_handle, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY));
index = get_start_index(r_buf, READ_BUF_LEN / 2, 1); /* Expected: 1 x 2 x 3 x ... 98 x 99 */
if (whether_contains_exapected_data(r_buf, READ_BUF_LEN / 2, 2, 1, 1)) {
break;
} }
printf("Data start index: %d\n", index); }
TEST_ASSERT(index < READ_BUF_LEN / 2 - 200); if (retry >= RETEY_TIMES) {
for (int16_t j = 1; j < 100; j ++) { printf("tx mono rx stereo test failed\n");
TEST_ASSERT_EQUAL_INT16(r_buf[index], j); is_failed = true;
index += 2; goto err;
} }
printf("tx mono rx stereo test passed\n"); printf("tx mono rx stereo test passed\n");
#endif #endif
err:
if (is_failed) {
for (int i = 0; i < READ_BUF_LEN / 2; i++) {
printf("%x ", r_buf[i]);
}
printf("\n");
}
free(w_buf); free(w_buf);
free(r_buf); free(r_buf);
TEST_ESP_OK(i2s_channel_disable(tx_handle)); TEST_ESP_OK(i2s_channel_disable(tx_handle));
TEST_ESP_OK(i2s_channel_disable(rx_handle)); TEST_ESP_OK(i2s_channel_disable(rx_handle));
TEST_ESP_OK(i2s_del_channel(tx_handle)); TEST_ESP_OK(i2s_del_channel(tx_handle));
TEST_ESP_OK(i2s_del_channel(rx_handle)); TEST_ESP_OK(i2s_del_channel(rx_handle));
TEST_ASSERT_FALSE(is_failed);
} }
TEST_CASE("I2S_memory_leak_test", "[i2s]") TEST_CASE("I2S_memory_leak_test", "[i2s]")

View File

@@ -29,6 +29,9 @@
#include "driver/pulse_cnt.h" #include "driver/pulse_cnt.h"
#include "soc/pcnt_periph.h" #include "soc/pcnt_periph.h"
#endif #endif
#ifdef CONFIG_PM_ENABLE
#include "esp_pm.h"
#endif
#include "../../test_inc/test_i2s.h" #include "../../test_inc/test_i2s.h"
@@ -211,6 +214,28 @@ TEST_CASE("I2S_basic_driver_installation_uninstallation_and_settings_test", "[i2
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_STATE, i2s_driver_uninstall(I2S_NUM_0)); TEST_ASSERT_EQUAL(ESP_ERR_INVALID_STATE, i2s_driver_uninstall(I2S_NUM_0));
} }
static bool whether_contains_exapected_data(uint16_t *src, uint32_t src_len, uint32_t src_step, uint32_t start_val, uint32_t val_step)
{
uint32_t val = start_val;
uint32_t index_step = 1;
for (int i = 0; val < 100 && i < src_len; i += index_step) {
if (src[i] == val) {
if (val == start_val && i < src_len - 8) {
printf("start index: %d ---> \n%d %d %d %d %d %d %d %d\n", i,
src[i], src[i+1], src[i+2], src[i+3],
src[i+4], src[i+5], src[i+6], src[i+7]);
}
index_step = src_step;
val += val_step;
} else {
index_step = 1;
val = start_val;
}
}
return val >= 100;
}
/** /**
* @brief Test mono and stereo mode of I2S by loopback * @brief Test mono and stereo mode of I2S by loopback
* @note Only rx channel distinguish left mono and right mono, tx channel does not * @note Only rx channel distinguish left mono and right mono, tx channel does not
@@ -222,6 +247,7 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s_legacy]")
{ {
#define WRITE_BUF_LEN 2000 #define WRITE_BUF_LEN 2000
#define READ_BUF_LEN 4000 #define READ_BUF_LEN 4000
#define RETEY_TIMES 3
// master driver installed and send data // master driver installed and send data
i2s_config_t master_i2s_config = { i2s_config_t master_i2s_config = {
.mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX, .mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX,
@@ -269,6 +295,8 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s_legacy]")
uint16_t *r_buf = calloc(1, READ_BUF_LEN); uint16_t *r_buf = calloc(1, READ_BUF_LEN);
size_t w_bytes = 0; size_t w_bytes = 0;
size_t r_bytes = 0; size_t r_bytes = 0;
uint32_t retry = 0;
bool is_failed = false;
for (int n = 0; n < WRITE_BUF_LEN / 2; n++) { for (int n = 0; n < WRITE_BUF_LEN / 2; n++) {
w_buf[n] = n%100; w_buf[n] = n%100;
} }
@@ -276,6 +304,7 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s_legacy]")
* tx format: 0x00[L] 0x01[R] 0x02[L] 0x03[R] ... * tx format: 0x00[L] 0x01[R] 0x02[L] 0x03[R] ...
* rx receive: 0x01[R] 0x03[R] ... */ * rx receive: 0x01[R] 0x03[R] ... */
TEST_ESP_OK(i2s_write(I2S_NUM_0, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_write(I2S_NUM_0, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY));
for (retry = 0; retry < RETEY_TIMES; retry++) {
TEST_ESP_OK(i2s_read(I2S_NUM_0, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_read(I2S_NUM_0, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY));
#if CONFIG_IDF_TARGET_ESP32 #if CONFIG_IDF_TARGET_ESP32
/* The data of tx/rx channels are flipped on ESP32 */ /* The data of tx/rx channels are flipped on ESP32 */
@@ -285,19 +314,15 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s_legacy]")
r_buf[n+1] = temp; r_buf[n+1] = temp;
} }
#endif #endif
int i = 0; /* Expected: 1 3 5 7 9 ... 97 99 */
for (i = 0; (i < READ_BUF_LEN / 2); i++) { if (whether_contains_exapected_data(r_buf, READ_BUF_LEN / 2, 1, 1, 2)) {
if (r_buf[i] == 1) {
printf("%d %d %d %d\n%d %d %d %d\n",
r_buf[i], r_buf[i+1], r_buf[i+2], r_buf[i+3],
r_buf[i+4], r_buf[i+5], r_buf[i+6], r_buf[i+7]);
break; break;
} }
} }
printf("Data start index: %d\n", i); if (retry >= RETEY_TIMES) {
TEST_ASSERT(i < READ_BUF_LEN / 2 - 50); printf("rx right mono test failed\n");
for (int16_t j = 1; j < 100; j += 2) { is_failed = true;
TEST_ASSERT_EQUAL_INT16(r_buf[i++], j); goto err;
} }
printf("rx right mono test passed\n"); printf("rx right mono test passed\n");
@@ -306,21 +331,17 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s_legacy]")
* rx receive: 0x00[L] 0x01[R] 0x02[L] 0x03[R] ... */ * rx receive: 0x00[L] 0x01[R] 0x02[L] 0x03[R] ... */
TEST_ESP_OK(i2s_set_clk(I2S_NUM_0, SAMPLE_RATE, SAMPLE_BITS, I2S_CHANNEL_STEREO)); TEST_ESP_OK(i2s_set_clk(I2S_NUM_0, SAMPLE_RATE, SAMPLE_BITS, I2S_CHANNEL_STEREO));
TEST_ESP_OK(i2s_write(I2S_NUM_0, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_write(I2S_NUM_0, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY));
for (retry = 0; retry < RETEY_TIMES; retry++) {
TEST_ESP_OK(i2s_read(I2S_NUM_0, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_read(I2S_NUM_0, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY));
/* Expected: 1 2 3 4 ... 98 99 */
for (i = 0; (i < READ_BUF_LEN / 2); i++) { if (whether_contains_exapected_data(r_buf, READ_BUF_LEN / 2, 1, 1, 1)) {
if (r_buf[i] == 1) {
printf("%d %d %d %d\n%d %d %d %d\n",
r_buf[i], r_buf[i+1], r_buf[i+2], r_buf[i+3],
r_buf[i+4], r_buf[i+5], r_buf[i+6], r_buf[i+7]);
break; break;
} }
} }
printf("Data start index: %d\n", i); if (retry >= RETEY_TIMES) {
TEST_ASSERT(i < READ_BUF_LEN / 2 - 100); printf("tx/rx stereo test failed\n");
TEST_ASSERT(i % 2); is_failed = true;
for (int16_t j = 1; j < 100; j ++) { goto err;
TEST_ASSERT_EQUAL_INT16(r_buf[i++], j); // receive all number
} }
printf("tx/rx stereo test passed\n"); printf("tx/rx stereo test passed\n");
@@ -329,20 +350,17 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s_legacy]")
* rx receive: 0x01[R] 0x02[R] ... */ * rx receive: 0x01[R] 0x02[R] ... */
TEST_ESP_OK(i2s_set_clk(I2S_NUM_0, SAMPLE_RATE, I2S_BITS_PER_SAMPLE_32BIT, I2S_CHANNEL_MONO)); TEST_ESP_OK(i2s_set_clk(I2S_NUM_0, SAMPLE_RATE, I2S_BITS_PER_SAMPLE_32BIT, I2S_CHANNEL_MONO));
TEST_ESP_OK(i2s_write(I2S_NUM_0, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_write(I2S_NUM_0, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY));
for (retry = 0; retry < RETEY_TIMES; retry++) {
TEST_ESP_OK(i2s_read(I2S_NUM_0, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_read(I2S_NUM_0, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY));
/* Expected: 1 2 3 4 ... 98 99 */
for (i = 0; i < READ_BUF_LEN / 2; i++) { if (whether_contains_exapected_data(r_buf, READ_BUF_LEN / 2, 1, 1, 1)) {
if (r_buf[i] == 1) {
printf("%d %d %d %d\n%d %d %d %d\n",
r_buf[i], r_buf[i+1], r_buf[i+2], r_buf[i+3],
r_buf[i+4], r_buf[i+5], r_buf[i+6], r_buf[i+7]);
break; break;
} }
} }
printf("Data start index: %d\n", i); if (retry >= RETEY_TIMES) {
TEST_ASSERT(i < READ_BUF_LEN / 2 - 100); printf("tx/rx mono test failed\n");
for (int16_t j = 1; j < 100; j ++) { is_failed = true;
TEST_ASSERT_EQUAL_INT16(r_buf[i++], j); goto err;
} }
printf("tx/rx mono test passed\n"); printf("tx/rx mono test passed\n");
@@ -364,6 +382,7 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s_legacy]")
* tx format: 0x00[L] 0x01[R] 0x02[L] 0x03[R] ... * tx format: 0x00[L] 0x01[R] 0x02[L] 0x03[R] ...
* rx receive: 0x00[R] 0x02[R] ... */ * rx receive: 0x00[R] 0x02[R] ... */
TEST_ESP_OK(i2s_write(I2S_NUM_0, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_write(I2S_NUM_0, w_buf, WRITE_BUF_LEN, &w_bytes, portMAX_DELAY));
for (retry = 0; retry < RETEY_TIMES; retry++) {
TEST_ESP_OK(i2s_read(I2S_NUM_0, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY)); TEST_ESP_OK(i2s_read(I2S_NUM_0, r_buf, READ_BUF_LEN, &r_bytes, portMAX_DELAY));
#if CONFIG_IDF_TARGET_ESP32 #if CONFIG_IDF_TARGET_ESP32
/* The data of tx/rx channels are flipped on ESP32 */ /* The data of tx/rx channels are flipped on ESP32 */
@@ -373,24 +392,29 @@ TEST_CASE("I2S_mono_stereo_loopback_test", "[i2s_legacy]")
r_buf[n+1] = temp; r_buf[n+1] = temp;
} }
#endif #endif
for (i = 0; (i < READ_BUF_LEN / 2); i++) { /* Expected: 2 4 6 8 10 ... 96 98 */
if (r_buf[i] == 2) { if (whether_contains_exapected_data(r_buf, READ_BUF_LEN / 2, 1, 2, 2)) {
printf("%d %d %d %d\n%d %d %d %d\n",
r_buf[i], r_buf[i+1], r_buf[i+2], r_buf[i+3],
r_buf[i+4], r_buf[i+5], r_buf[i+6], r_buf[i+7]);
break; break;
} }
} }
printf("Data start index: %d\n", i); if (retry >= RETEY_TIMES) {
TEST_ASSERT(i < READ_BUF_LEN / 2 - 50); printf("rx left mono test failed\n");
for (int16_t j = 2; j < 100; j += 2) { is_failed = true;
TEST_ASSERT_EQUAL_INT16(r_buf[i++], j); goto err;
} }
printf("rx left mono test passed\n"); printf("rx left mono test passed\n");
err:
if (is_failed) {
for (int i = 0; i < READ_BUF_LEN / 2; i++) {
printf("%x ", r_buf[i]);
}
printf("\n");
}
free(w_buf); free(w_buf);
free(r_buf); free(r_buf);
TEST_ESP_OK(i2s_driver_uninstall(I2S_NUM_0)); TEST_ESP_OK(i2s_driver_uninstall(I2S_NUM_0));
TEST_ASSERT_FALSE(is_failed);
} }
#if SOC_I2S_SUPPORTS_TDM #if SOC_I2S_SUPPORTS_TDM
@@ -854,6 +878,14 @@ static void i2s_test_common_sample_rate(i2s_port_t id)
32000, 44100, 48000, 64000, 88200, 96000, 32000, 44100, 48000, 64000, 88200, 96000,
128000, 144000, 196000}; 128000, 144000, 196000};
int real_pulse = 0; int real_pulse = 0;
// Acquire the PM lock incase Dynamic Frequency Scaling(DFS) lower the frequency
#ifdef CONFIG_PM_ENABLE
esp_pm_lock_handle_t pm_lock;
esp_pm_lock_type_t pm_type = ESP_PM_APB_FREQ_MAX;
TEST_ESP_OK(esp_pm_lock_create(pm_type, 0, "legacy_i2s_test", &pm_lock));
esp_pm_lock_acquire(pm_lock);
#endif
for (int i = 0; i < 15; i++) { for (int i = 0; i < 15; i++) {
int expt_pulse = (int16_t)((float)test_freq[i] * (TEST_I2S_PERIOD_MS / 1000.0)); int expt_pulse = (int16_t)((float)test_freq[i] * (TEST_I2S_PERIOD_MS / 1000.0));
TEST_ESP_OK(i2s_set_clk(id, test_freq[i], SAMPLE_BITS, I2S_CHANNEL_STEREO)); TEST_ESP_OK(i2s_set_clk(id, test_freq[i], SAMPLE_BITS, I2S_CHANNEL_STEREO));
@@ -868,6 +900,10 @@ static void i2s_test_common_sample_rate(i2s_port_t id)
// Check if the error between real pulse number and expected pulse number is within 1% // Check if the error between real pulse number and expected pulse number is within 1%
TEST_ASSERT_INT_WITHIN(expt_pulse * 0.01, expt_pulse, real_pulse); TEST_ASSERT_INT_WITHIN(expt_pulse * 0.01, expt_pulse, real_pulse);
} }
#ifdef CONFIG_PM_ENABLE
esp_pm_lock_release(pm_lock);
esp_pm_lock_delete(pm_lock);
#endif
TEST_ESP_OK(pcnt_del_channel(pcnt_chan)); TEST_ESP_OK(pcnt_del_channel(pcnt_chan));
TEST_ESP_OK(pcnt_unit_stop(pcnt_unit)); TEST_ESP_OK(pcnt_unit_stop(pcnt_unit));
TEST_ESP_OK(pcnt_unit_disable(pcnt_unit)); TEST_ESP_OK(pcnt_unit_disable(pcnt_unit));

View File

@@ -3,4 +3,3 @@ CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_COMPILER_OPTIMIZATION_SIZE=y CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
CONFIG_I2S_ISR_IRAM_SAFE=y