From a7f00f503ac72de8cd5769fc49acfd5e3a6c646e Mon Sep 17 00:00:00 2001 From: Armando Date: Mon, 26 Jun 2023 19:37:06 +0800 Subject: [PATCH] spi_flash: rename spi_flash_os_func_app: spi_start, spi_end spi_start -> s_acquire_spi_bus_lock spi_end -> s_release_spi_bus_lock --- components/spi_flash/spi_flash_os_func_app.c | 12 ++++----- .../test_flash_utils/CMakeLists.txt | 5 ++++ .../include/test_flash_utils.h | 27 +++++++++++++++++++ .../test_flash_utils/test_flash_utils.c | 17 ++++++++++++ .../test_apps/esp_flash_stress/CMakeLists.txt | 2 +- .../esp_flash_stress/main/CMakeLists.txt | 1 + .../esp_flash_stress/main/test_app_main.c | 2 +- .../main/test_esp_flash_stress.c | 17 +++--------- 8 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 components/spi_flash/test_apps/components/test_flash_utils/CMakeLists.txt create mode 100644 components/spi_flash/test_apps/components/test_flash_utils/include/test_flash_utils.h create mode 100644 components/spi_flash/test_apps/components/test_flash_utils/test_flash_utils.c diff --git a/components/spi_flash/spi_flash_os_func_app.c b/components/spi_flash/spi_flash_os_func_app.c index 352afee455..f242bb46b3 100644 --- a/components/spi_flash/spi_flash_os_func_app.c +++ b/components/spi_flash/spi_flash_os_func_app.c @@ -71,7 +71,7 @@ IRAM_ATTR static void cache_disable(void* arg) } #endif //#if !SPI_FLASH_CACHE_NO_DISABLE -static IRAM_ATTR esp_err_t spi_start(void *arg) +static IRAM_ATTR esp_err_t acquire_spi_bus_lock(void *arg) { spi_bus_lock_dev_handle_t dev_lock = ((app_func_arg_t *)arg)->dev_lock; @@ -84,19 +84,19 @@ static IRAM_ATTR esp_err_t spi_start(void *arg) return ESP_OK; } -static IRAM_ATTR esp_err_t spi_end(void *arg) +static IRAM_ATTR esp_err_t release_spi_bus_lock(void *arg) { return spi_bus_lock_acquire_end(((app_func_arg_t *)arg)->dev_lock); } static IRAM_ATTR esp_err_t spi23_start(void *arg){ - esp_err_t ret = spi_start(arg); + esp_err_t ret = acquire_spi_bus_lock(arg); on_spi_acquired((app_func_arg_t*)arg); return ret; } static IRAM_ATTR esp_err_t spi23_end(void *arg){ - esp_err_t ret = spi_end(arg); + esp_err_t ret = release_spi_bus_lock(arg); on_spi_released((app_func_arg_t*)arg); return ret; } @@ -114,7 +114,7 @@ static IRAM_ATTR esp_err_t spi1_start(void *arg) */ #if CONFIG_SPI_FLASH_SHARE_SPI1_BUS //use the lock to disable the cache and interrupts before using the SPI bus - ret = spi_start(arg); + ret = acquire_spi_bus_lock(arg); #elif SPI_FLASH_CACHE_NO_DISABLE _lock_acquire(&s_spi1_flash_mutex); #else @@ -133,7 +133,7 @@ static IRAM_ATTR esp_err_t spi1_end(void *arg) * There are three ways for ESP Flash API lock, see `spi1_start` */ #if CONFIG_SPI_FLASH_SHARE_SPI1_BUS - ret = spi_end(arg); + ret = release_spi_bus_lock(arg); #elif SPI_FLASH_CACHE_NO_DISABLE _lock_release(&s_spi1_flash_mutex); #else diff --git a/components/spi_flash/test_apps/components/test_flash_utils/CMakeLists.txt b/components/spi_flash/test_apps/components/test_flash_utils/CMakeLists.txt new file mode 100644 index 0000000000..b1e95cf41e --- /dev/null +++ b/components/spi_flash/test_apps/components/test_flash_utils/CMakeLists.txt @@ -0,0 +1,5 @@ +set(srcs "test_flash_utils.c") + +idf_component_register(SRCS ${srcs} + INCLUDE_DIRS include + REQUIRES esp_partition) diff --git a/components/spi_flash/test_apps/components/test_flash_utils/include/test_flash_utils.h b/components/spi_flash/test_apps/components/test_flash_utils/include/test_flash_utils.h new file mode 100644 index 0000000000..19162a77a2 --- /dev/null +++ b/components/spi_flash/test_apps/components/test_flash_utils/include/test_flash_utils.h @@ -0,0 +1,27 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include "esp_partition.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Return the 'flash_test' custom data partition + * defined in the custom partition table. + * + * @return partition handle + */ +const esp_partition_t *get_test_flash_partition(void); + +#ifdef __cplusplus +} +#endif diff --git a/components/spi_flash/test_apps/components/test_flash_utils/test_flash_utils.c b/components/spi_flash/test_apps/components/test_flash_utils/test_flash_utils.c new file mode 100644 index 0000000000..290f632a35 --- /dev/null +++ b/components/spi_flash/test_apps/components/test_flash_utils/test_flash_utils.c @@ -0,0 +1,17 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "test_flash_utils.h" + +const esp_partition_t *get_test_flash_partition(void) +{ + /* This finds "flash_test" partition defined in custom partitions.csv */ + const esp_partition_t *result = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, + ESP_PARTITION_SUBTYPE_ANY, "flash_test"); + assert(result != NULL); /* means partition table set wrong */ + return result; +} diff --git a/components/spi_flash/test_apps/esp_flash_stress/CMakeLists.txt b/components/spi_flash/test_apps/esp_flash_stress/CMakeLists.txt index 5565d0d2f6..e557291582 100644 --- a/components/spi_flash/test_apps/esp_flash_stress/CMakeLists.txt +++ b/components/spi_flash/test_apps/esp_flash_stress/CMakeLists.txt @@ -1,7 +1,7 @@ # This is the project CMakeLists.txt file for the test subproject cmake_minimum_required(VERSION 3.16) -set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components") +set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/components/spi_flash/test_apps/components") include($ENV{IDF_PATH}/tools/cmake/project.cmake) diff --git a/components/spi_flash/test_apps/esp_flash_stress/main/CMakeLists.txt b/components/spi_flash/test_apps/esp_flash_stress/main/CMakeLists.txt index 17e9f27daf..c202102665 100644 --- a/components/spi_flash/test_apps/esp_flash_stress/main/CMakeLists.txt +++ b/components/spi_flash/test_apps/esp_flash_stress/main/CMakeLists.txt @@ -4,4 +4,5 @@ set(srcs "test_app_main.c" # In order for the cases defined by `TEST_CASE` to be linked into the final elf, # the component can be registered as WHOLE_ARCHIVE idf_component_register(SRCS ${srcs} + PRIV_REQUIRES test_flash_utils spi_flash unity WHOLE_ARCHIVE) diff --git a/components/spi_flash/test_apps/esp_flash_stress/main/test_app_main.c b/components/spi_flash/test_apps/esp_flash_stress/main/test_app_main.c index 16da07c2ab..54d22dfd2d 100644 --- a/components/spi_flash/test_apps/esp_flash_stress/main/test_app_main.c +++ b/components/spi_flash/test_apps/esp_flash_stress/main/test_app_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/spi_flash/test_apps/esp_flash_stress/main/test_esp_flash_stress.c b/components/spi_flash/test_apps/esp_flash_stress/main/test_esp_flash_stress.c index 4ef8dec10c..e71f365a2e 100644 --- a/components/spi_flash/test_apps/esp_flash_stress/main/test_esp_flash_stress.c +++ b/components/spi_flash/test_apps/esp_flash_stress/main/test_esp_flash_stress.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -15,9 +15,9 @@ #include "esp_check.h" #include "esp_attr.h" #include "esp_flash.h" -#include "esp_partition.h" +#include "test_flash_utils.h" -portMUX_TYPE s_test_spinlock = portMUX_INITIALIZER_UNLOCKED; +portMUX_TYPE static s_test_spinlock = portMUX_INITIALIZER_UNLOCKED; /*--------------------------------------------------------------- ESP Flash API Concurrency Pressure Test @@ -33,17 +33,6 @@ typedef struct { const esp_partition_t *part; } test_concurrency_ctx_t; - -static const esp_partition_t *get_test_flash_partition(void) -{ - /* This finds "flash_test" partition defined in partition_table_unit_test_app.csv */ - const esp_partition_t *result = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, - ESP_PARTITION_SUBTYPE_ANY, "flash_test"); - assert(result != NULL); /* means partition table set wrong */ - return result; -} - - static void s_test_flash_ops_task(void *arg) { test_concurrency_ctx_t *test_ctx = (test_concurrency_ctx_t *)arg;