Skip to content

Commit

Permalink
Merge branch 'test/add_i2s_tdm_full_duplex_test_app' into 'master'
Browse files Browse the repository at this point in the history
test: add i2s tdm full duplex multi device test app

Closes IDFGH-8003

See merge request espressif/esp-idf!19904
  • Loading branch information
L-KAYA committed Sep 16, 2022
2 parents 03b25c6 + 7768905 commit 740a8b5
Show file tree
Hide file tree
Showing 13 changed files with 476 additions and 4 deletions.
32 changes: 32 additions & 0 deletions .gitlab/ci/target-test.yml
Expand Up @@ -228,6 +228,14 @@ component_ut_pytest_esp32_generic:
- build_pytest_components_esp32
tags: [ esp32, generic ]

component_ut_pytest_esp32_generic_multi_device:
extends:
- .pytest_components_dir_template
- .rules:test:component_ut-esp32
needs:
- build_pytest_components_esp32
tags: [ esp32, generic_multi_device ]

component_ut_pytest_esp32_adc:
extends:
- .pytest_components_dir_template
Expand Down Expand Up @@ -276,6 +284,14 @@ component_ut_pytest_esp32s2_generic:
- build_pytest_components_esp32s2
tags: [ esp32s2, generic ]

component_ut_pytest_esp32s2_generic_multi_device:
extends:
- .pytest_components_dir_template
- .rules:test:component_ut-esp32s2
needs:
- build_pytest_components_esp32s2
tags: [ esp32s2, generic_multi_device ]

component_ut_pytest_esp32s2_adc:
extends:
- .pytest_components_dir_template
Expand All @@ -300,6 +316,14 @@ component_ut_pytest_esp32s3_generic:
- build_pytest_components_esp32s3
tags: [ esp32s3, generic ]

component_ut_pytest_esp32s3_generic_multi_device:
extends:
- .pytest_components_dir_template
- .rules:test:component_ut-esp32s3
needs:
- build_pytest_components_esp32s3
tags: [ esp32s3, generic_multi_device ]

component_ut_pytest_esp32s3_adc:
extends:
- .pytest_components_dir_template
Expand Down Expand Up @@ -372,6 +396,14 @@ component_ut_pytest_esp32c3_generic:
- build_pytest_components_esp32c3
tags: [ esp32c3, generic ]

component_ut_pytest_esp32c3_generic_multi_device:
extends:
- .pytest_components_dir_template
- .rules:test:component_ut-esp32c3
needs:
- build_pytest_components_esp32c3
tags: [ esp32c3, generic_multi_device ]

component_ut_pytest_esp32c3_adc:
extends:
- .pytest_components_dir_template
Expand Down
4 changes: 4 additions & 0 deletions components/driver/.build-test-rules.yml
Expand Up @@ -4,6 +4,10 @@ components/driver/test_apps/i2s_test_apps:
disable:
- if: SOC_I2S_SUPPORTED != 1

components/driver/test_apps/i2s_test_apps/i2s_tdm:
disable:
- if: SOC_I2S_SUPPORTS_TDM != 1

components/driver/test_apps/i2s_test_apps/legacy_i2s_adc_dac:
disable:
- if: SOC_I2S_SUPPORTS_ADC_DAC != 1
Expand Down
8 changes: 6 additions & 2 deletions components/driver/i2s/i2s_tdm.c
Expand Up @@ -49,8 +49,12 @@ static esp_err_t i2s_tdm_calculate_clock(i2s_chan_handle_t handle, const i2s_tdm
}
} while (clk_info->bclk_div <= 2);
} else {
/* For slave mode, mclk >= bclk * 8, so fix bclk_div to 2 first */
clk_info->bclk_div = 8;
if (clk_cfg->bclk_div < 8) {
ESP_LOGW(TAG, "the current bclk division is too small, adjust the bclk division to 8");
clk_info->bclk_div = 8;
} else {
clk_info->bclk_div = clk_cfg->bclk_div;
}
clk_info->bclk = rate * handle->total_slot * slot_bits;
clk_info->mclk = clk_info->bclk * clk_info->bclk_div;
}
Expand Down
4 changes: 3 additions & 1 deletion components/driver/include/driver/i2s_tdm.h
Expand Up @@ -118,6 +118,7 @@ extern "C" {
.sample_rate_hz = rate, \
.clk_src = I2S_CLK_SRC_DEFAULT, \
.mclk_multiple = I2S_MCLK_MULTIPLE_256, \
.bclk_div = 8, \
}

/**
Expand Down Expand Up @@ -150,7 +151,8 @@ typedef struct {
/* General fields */
uint32_t sample_rate_hz; /*!< I2S sample rate */
i2s_clock_src_t clk_src; /*!< Choose clock source */
i2s_mclk_multiple_t mclk_multiple; /*!< The multiple of mclk to the sample rate */
i2s_mclk_multiple_t mclk_multiple; /*!< The multiple of mclk to the sample rate, only take effect for master role */
uint32_t bclk_div; /*!< The division from mclk to bclk, only take effect for slave role, it shouldn't be smaller than 8. Increase this field when data sent by slave lag behind */
} i2s_tdm_clk_config_t;

/**
Expand Down
@@ -0,0 +1,6 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(i2s_tdm_full_duplex_test)
3 changes: 3 additions & 0 deletions components/driver/test_apps/i2s_test_apps/i2s_tdm/README.md
@@ -0,0 +1,3 @@
| Supported Targets | ESP32-C3 | ESP32-S3 |
| ----------------- | -------- | -------- |

@@ -0,0 +1,4 @@
idf_component_register(SRCS "test_app_main.c" "test_i2s_tdm_full_duplex.c"
INCLUDE_DIRS "."
WHOLE_ARCHIVE
)
@@ -0,0 +1,41 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include "unity.h"
#include "unity_test_runner.h"
#include "esp_heap_caps.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#define TEST_MEMORY_LEAK_THRESHOLD (-300)

static size_t before_free_8bit;
static size_t before_free_32bit;

static void check_leak(size_t before_free, size_t after_free, const char *type)
{
ssize_t delta = after_free - before_free;
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak");
}

void setUp(void)
{
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
}

void tearDown(void)
{
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
check_leak(before_free_8bit, after_free_8bit, "8BIT");
check_leak(before_free_32bit, after_free_32bit, "32BIT");
}

void app_main(void)
{
unity_run_menu();
}

0 comments on commit 740a8b5

Please sign in to comment.