diff --git a/components/sdmmc/test_apps/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_common.c b/components/sdmmc/test_apps/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_common.c index 8bed8e394f..2cbd16d13a 100644 --- a/components/sdmmc/test_apps/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_common.c +++ b/components/sdmmc/test_apps/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_common.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,6 +8,7 @@ #include #include #include +#include "esp_timer.h" #include "test_utils.h" #include "sdkconfig.h" #include "soc/soc_caps.h" @@ -154,3 +155,43 @@ void sdmmc_test_rw_with_offset(sdmmc_card_t* card) do_single_rw_perf_test(card, card->csd.capacity/2, 8, 1, NULL); do_single_rw_perf_test(card, card->csd.capacity/2, 128, 1, NULL); } + +typedef struct { + SemaphoreHandle_t stop; + SemaphoreHandle_t done; + uint32_t busy_time_us; +} highprio_busy_task_args_t; + +static void highprio_busy_task(void* varg) +{ + highprio_busy_task_args_t* args = (highprio_busy_task_args_t*) varg; + while (xSemaphoreTake(args->stop, 0) != pdTRUE) { + vTaskDelay(1); + int64_t start = esp_timer_get_time(); + while (esp_timer_get_time() - start < args->busy_time_us) { + usleep(100); + } + } + xSemaphoreGive(args->done); + vTaskDelete(NULL); +} + +void sdmmc_test_rw_highprio_task(sdmmc_card_t* card) +{ + highprio_busy_task_args_t args = { + .stop = xSemaphoreCreateBinary(), + .done = xSemaphoreCreateBinary(), + .busy_time_us = 250000, + }; + + TEST_ASSERT(xTaskCreate(highprio_busy_task, "highprio_busy_task", 4096, &args, 20, NULL)); + + for (int i = 0; i < 4; ++i) { + do_single_rw_perf_test(card, 0, 64, 0, NULL); + } + + xSemaphoreGive(args.stop); + xSemaphoreTake(args.done, portMAX_DELAY); + vSemaphoreDelete(args.stop); + vSemaphoreDelete(args.done); +} diff --git a/components/sdmmc/test_apps/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_common.h b/components/sdmmc/test_apps/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_common.h index 3ca55aeb12..bb1f40717e 100644 --- a/components/sdmmc/test_apps/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_common.h +++ b/components/sdmmc/test_apps/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_common.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -50,6 +50,12 @@ void sdmmc_test_rw_unaligned_buffer(sdmmc_card_t* card); */ void sdmmc_test_rw_with_offset(sdmmc_card_t* card); +/** + * @brief Test read/write with higher priority tasks running concurrently + * @param card Pointer to the card object, must be initialized before calling this function. + */ +void sdmmc_test_rw_highprio_task(sdmmc_card_t* card); + #ifdef __cplusplus }; #endif diff --git a/components/sdmmc/test_apps/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_sd.c b/components/sdmmc/test_apps/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_sd.c index 9ed0c245ef..bea1df47f2 100644 --- a/components/sdmmc/test_apps/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_sd.c +++ b/components/sdmmc/test_apps/sdmmc_console/components/sdmmc_tests/sdmmc_test_rw_sd.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -101,3 +101,25 @@ TEST_CASE("sdmmc read/write using unaligned buffer, slot 1, 4-bit", "[sdmmc]") { do_one_sdmmc_rw_test_unaligned_buffer(SLOT_1, 4, SDMMC_FREQ_DEFAULT, 0); } + +/* ========== Read/write tests with higher priority tasks running concurrently ========== */ + +static void do_one_sdmmc_rw_test_highprio_task(int slot, int width) +{ + sdmmc_card_t card; + sdmmc_test_sd_skip_if_board_incompatible(slot, width, SDMMC_FREQ_DEFAULT, NO_DDR); + sdmmc_test_sd_begin(slot, width, SDMMC_FREQ_DEFAULT, NO_DDR, &card); + sdmmc_card_print_info(stdout, &card); + sdmmc_test_rw_highprio_task(&card); + sdmmc_test_sd_end(&card); +} + +TEST_CASE("sdmmc read/write with concurrent high-prio task, slot 0, 4-bit", "[sdmmc]") +{ + do_one_sdmmc_rw_test_highprio_task(0, 4); +} + +TEST_CASE("sdmmc read/write with concurrent high-prio task, slot 1, 4-bit", "[sdmmc]") +{ + do_one_sdmmc_rw_test_highprio_task(1, 4); +}