spi_flash: Add spi_flash_cache_enabled() test function

pull/407/head
Angus Gratton 2017-03-02 15:21:03 +11:00
rodzic 6ee5a1e492
commit 3442d4d463
4 zmienionych plików z 66 dodań i 0 usunięć

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -233,6 +233,12 @@ size_t spi_flash_cache2phys(const void *cached);
*/
const void *spi_flash_phys2cache(size_t phys_offs, spi_flash_mmap_memory_t memory);
/** @brief Check at runtime if flash cache is enabled on both CPUs
*
* @return true if both CPUs have flash cache enabled, false otherwise.
*/
bool spi_flash_cache_enabled();
/**
* @brief SPI flash critical section enter function.
*/

Wyświetl plik

@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/semphr.h>
#include <unity.h>
#include <esp_spi_flash.h>
#include <esp_attr.h>
#include <esp_flash_encrypt.h>
#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);
}

Wyświetl plik

@ -62,6 +62,7 @@ Functions
.. 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