add api get valid mmu table pages number

This commit is contained in:
Tian Zhong Xing
2018-03-15 19:58:02 +08:00
parent 7e268adaf5
commit 7555031553
4 changed files with 89 additions and 21 deletions

View File

@@ -100,6 +100,21 @@ static void IRAM_ATTR spi_flash_mmap_init()
DPORT_STALL_OTHER_CPU_END();
}
static void IRAM_ATTR get_mmu_region(spi_flash_mmap_memory_t memory, int* out_begin, int* out_size,uint32_t* region_addr)
{
if (memory == SPI_FLASH_MMAP_DATA) {
// Vaddr0
*out_begin = 0;
*out_size = 64;
*region_addr = VADDR0_START_ADDR;
} else {
// only part of VAddr1 is usable, so adjust for that
*out_begin = PRO_IRAM0_FIRST_USABLE_PAGE;
*out_size = 3 * 64 - *out_begin;
*region_addr = VADDR1_FIRST_USABLE_ADDR;
}
}
esp_err_t IRAM_ATTR spi_flash_mmap(size_t src_addr, size_t size, spi_flash_mmap_memory_t memory,
const void** out_ptr, spi_flash_mmap_handle_t* out_handle)
{
@@ -157,17 +172,7 @@ esp_err_t IRAM_ATTR spi_flash_mmap_pages(int *pages, size_t page_count, spi_flas
int region_begin; // first page to check
int region_size; // number of pages to check
uint32_t region_addr; // base address of memory region
if (memory == SPI_FLASH_MMAP_DATA) {
// Vaddr0
region_begin = 0;
region_size = 64;
region_addr = VADDR0_START_ADDR;
} else {
// only part of VAddr1 is usable, so adjust for that
region_begin = PRO_IRAM0_FIRST_USABLE_PAGE;
region_size = 3 * 64 - region_begin;
region_addr = VADDR1_FIRST_USABLE_ADDR;
}
get_mmu_region(memory,&region_begin,&region_size,&region_addr);
if (region_size < page_count) {
return ESP_ERR_NO_MEM;
}
@@ -176,7 +181,7 @@ esp_err_t IRAM_ATTR spi_flash_mmap_pages(int *pages, size_t page_count, spi_flas
// entries are treated as wildcards.
int start;
int end = region_begin + region_size - page_count;
for (start = region_begin; start < end; ++start) {
for (start = region_begin; start <= end; ++start) {
int pageno = 0;
int pos;
DPORT_STALL_OTHER_CPU_START();
@@ -194,7 +199,7 @@ esp_err_t IRAM_ATTR spi_flash_mmap_pages(int *pages, size_t page_count, spi_flas
}
}
// checked all the region(s) and haven't found anything?
if (start == end) {
if (start > end) {
*out_handle = 0;
*out_ptr = NULL;
ret = ESP_ERR_NO_MEM;
@@ -292,6 +297,28 @@ void spi_flash_mmap_dump()
}
}
uint32_t spi_flash_mmap_get_free_pages(spi_flash_mmap_memory_t memory)
{
spi_flash_mmap_init();
int count = 0;
int region_begin; // first page to check
int region_size; // number of pages to check
uint32_t region_addr; // base address of memory region
get_mmu_region(memory,&region_begin,&region_size,&region_addr);
DPORT_STALL_OTHER_CPU_START();
for (int i = region_begin; i < region_begin + region_size; ++i) {
if (s_mmap_page_refcnt[i] == 0 && DPORT_PRO_FLASH_MMU_TABLE[i] == INVALID_ENTRY_VAL) {
count++;
}
}
DPORT_STALL_OTHER_CPU_END();
if(count >= 1) {
return count - 1; //don't sure mmap src_addr,if src_addr not align 64K bytes,max need one more pages
} else {
return 0;
}
}
/* 256-bit (up to 16MB of 64KB pages) bitset of all flash pages
that have been written to since last cache flush.