From 50f414f54cf459d6b5875d2b0a2a4b92adb79920 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 2 Mar 2017 15:21:03 +1100 Subject: [PATCH] spi_flash: Add spi_flash_cache_enabled() test function --- components/spi_flash/cache_utils.c | 6 +++ components/spi_flash/include/esp_spi_flash.h | 41 ++++++++++++++ .../spi_flash/test/test_cache_disabled.c | 53 +++++++++++++++++++ docs/api/storage/spi_flash.rst | 3 ++ 4 files changed, 103 insertions(+) create mode 100644 components/spi_flash/test/test_cache_disabled.c diff --git a/components/spi_flash/cache_utils.c b/components/spi_flash/cache_utils.c index 5e880ab493..6d0dd91845 100644 --- a/components/spi_flash/cache_utils.c +++ b/components/spi_flash/cache_utils.c @@ -275,3 +275,9 @@ static void IRAM_ATTR spi_flash_restore_cache(uint32_t cpuid, uint32_t saved_sta } } + +IRAM_ATTR bool spi_flash_cache_enabled() +{ + return REG_GET_BIT(DPORT_PRO_CACHE_CTRL_REG, DPORT_PRO_CACHE_ENABLE) + && REG_GET_BIT(DPORT_APP_CACHE_CTRL_REG, DPORT_APP_CACHE_ENABLE); +} diff --git a/components/spi_flash/include/esp_spi_flash.h b/components/spi_flash/include/esp_spi_flash.h index 060d598ec0..5cf0dc2d6e 100644 --- a/components/spi_flash/include/esp_spi_flash.h +++ b/components/spi_flash/include/esp_spi_flash.h @@ -197,6 +197,47 @@ void spi_flash_munmap(spi_flash_mmap_handle_t handle); */ void spi_flash_mmap_dump(); +#define SPI_FLASH_CACHE2PHYS_FAIL UINT32_MAX /* +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "../cache_utils.h" + +static QueueHandle_t result_queue; + +static IRAM_ATTR void cache_test_task(void *arg) +{ + bool do_disable = (bool)arg; + bool result; + if(do_disable) { + spi_flash_disable_interrupts_caches_and_other_cpu(); + } + result = spi_flash_cache_enabled(); + if (do_disable) { + spi_flash_enable_interrupts_caches_and_other_cpu(); + } + + TEST_ASSERT( xQueueSendToBack(result_queue, &result, 0) ); + vTaskDelete(NULL); +} + +TEST_CASE("spi_flash_cache_enabled() works on both CPUs", "[spi_flash]") +{ + result_queue = xQueueCreate(1, sizeof(bool)); + + for(int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) { + for(int disable = 0; disable <= 1; disable++) { + bool do_disable = disable; + bool result; + printf("Testing cpu %d disabled %d\n", cpu, do_disable); + + xTaskCreatePinnedToCore(cache_test_task, "cache_check_task", + 2048, (void *)do_disable, configMAX_PRIORITIES-1, NULL, cpu); + + TEST_ASSERT( xQueueReceive(result_queue, &result, 2) ); + TEST_ASSERT_EQUAL(!do_disable, result); + } + } + + vQueueDelete(result_queue); +} + diff --git a/docs/api/storage/spi_flash.rst b/docs/api/storage/spi_flash.rst index 5725ceb0c9..417e759103 100644 --- a/docs/api/storage/spi_flash.rst +++ b/docs/api/storage/spi_flash.rst @@ -52,6 +52,9 @@ Functions .. doxygenfunction:: spi_flash_mmap .. doxygenfunction:: spi_flash_munmap .. doxygenfunction:: spi_flash_mmap_dump +.. doxygenfunction:: spi_flash_cache2phys +.. doxygenfunction:: spi_flash_phys2cache +.. doxygenfunction:: spi_flash_cache_enabled .. doxygenfunction:: esp_partition_find .. doxygenfunction:: esp_partition_find_first .. doxygenfunction:: esp_partition_get -- 2.40.0