Skip to content

Commit

Permalink
spi_flash: Move FLASH_PAGE_SIZE constant into esp_spi_flash.h
Browse files Browse the repository at this point in the history
  • Loading branch information
projectgus authored and igrr committed Jan 20, 2017
1 parent 14aa1d1 commit d446266
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
13 changes: 6 additions & 7 deletions components/spi_flash/flash_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@

#define REGIONS_COUNT 4
#define PAGES_PER_REGION 64
#define FLASH_PAGE_SIZE 0x10000
#define INVALID_ENTRY_VAL 0x100
#define VADDR0_START_ADDR 0x3F400000
#define VADDR1_START_ADDR 0x40000000
#define VADDR1_FIRST_USABLE_ADDR 0x400D0000
#define PRO_IRAM0_FIRST_USABLE_PAGE ((VADDR1_FIRST_USABLE_ADDR - VADDR1_START_ADDR) / FLASH_PAGE_SIZE + 64)
#define PRO_IRAM0_FIRST_USABLE_PAGE ((VADDR1_FIRST_USABLE_ADDR - VADDR1_START_ADDR) / SPI_FLASH_MMU_PAGE_SIZE + 64)

/* Ensure pages in a region haven't been marked as written via
spi_flash_mark_modified_region(). If the page has
Expand Down Expand Up @@ -124,8 +123,8 @@ esp_err_t IRAM_ATTR spi_flash_mmap(size_t src_addr, size_t size, spi_flash_mmap_
region_addr = VADDR1_FIRST_USABLE_ADDR;
}
// region which should be mapped
int phys_page = src_addr / FLASH_PAGE_SIZE;
int page_count = (size + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE;
int phys_page = src_addr / SPI_FLASH_MMU_PAGE_SIZE;
int page_count = (size + SPI_FLASH_MMU_PAGE_SIZE - 1) / SPI_FLASH_MMU_PAGE_SIZE;
// The following part searches for a range of MMU entries which can be used.
// Algorithm is essentially naïve strstr algorithm, except that unused MMU
// entries are treated as wildcards.
Expand Down Expand Up @@ -171,7 +170,7 @@ esp_err_t IRAM_ATTR spi_flash_mmap(size_t src_addr, size_t size, spi_flash_mmap_
new_entry->count = page_count;
new_entry->handle = ++s_mmap_last_handle;
*out_handle = new_entry->handle;
*out_ptr = (void*) (region_addr + start * FLASH_PAGE_SIZE);
*out_ptr = (void*) (region_addr + start * SPI_FLASH_MMU_PAGE_SIZE);
ret = ESP_OK;
}
spi_flash_enable_interrupts_caches_and_other_cpu();
Expand Down Expand Up @@ -256,8 +255,8 @@ static void IRAM_ATTR spi_flash_ensure_unmodified_region(size_t start_addr, size
/* generic implementation for the previous two functions */
static inline IRAM_ATTR void update_written_pages(size_t start_addr, size_t length, bool mark)
{
for (uint32_t addr = start_addr; addr < start_addr + length; addr += FLASH_PAGE_SIZE) {
int page = addr / FLASH_PAGE_SIZE;
for (uint32_t addr = start_addr; addr < start_addr + length; addr += SPI_FLASH_MMU_PAGE_SIZE) {
int page = addr / SPI_FLASH_MMU_PAGE_SIZE;
if (page >= 256) {
return; /* invalid address */
}
Expand Down
4 changes: 1 addition & 3 deletions components/spi_flash/flash_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,6 @@ esp_err_t IRAM_ATTR spi_flash_read(size_t src, void *dstv, size_t size)
return spi_flash_translate_rc(rc);
}

#define FLASH_PAGE_SIZE 0x10000

esp_err_t IRAM_ATTR spi_flash_read_encrypted(size_t src, void *dstv, size_t size)
{
if (src + size > g_rom_flashchip.chip_size) {
Expand All @@ -433,7 +431,7 @@ esp_err_t IRAM_ATTR spi_flash_read_encrypted(size_t src, void *dstv, size_t size
esp_err_t err;
const uint8_t *map;
spi_flash_mmap_handle_t map_handle;
size_t map_src = src & ~(FLASH_PAGE_SIZE-1);
size_t map_src = src & ~(SPI_FLASH_MMU_PAGE_SIZE-1);
size_t map_size = size + (src - map_src);

err = spi_flash_mmap(map_src, map_size, SPI_FLASH_MMAP_DATA, (const void **)&map, &map_handle);
Expand Down
5 changes: 4 additions & 1 deletion components/spi_flash/include/esp_spi_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ extern "C" {

#define SPI_FLASH_SEC_SIZE 4096 /**< SPI Flash sector size */

#define SPI_FLASH_MMU_PAGE_SIZE 0x10000 /**< Flash cache MMU mapping page size */

/**
* @brief Initialize SPI flash access driver
*
Expand Down Expand Up @@ -161,7 +163,8 @@ typedef uint32_t spi_flash_mmap_handle_t;
* page allocation, use spi_flash_mmap_dump function.
*
* @param src_addr Physical address in flash where requested region starts.
* This address *must* be aligned to 64kB boundary.
* This address *must* be aligned to 64kB boundary
* (SPI_FLASH_MMU_PAGE_SIZE).
* @param size Size of region which has to be mapped. This size will be rounded
* up to a 64k boundary.
* @param memory Memory space where the region should be mapped
Expand Down
1 change: 1 addition & 0 deletions docs/api/storage/spi_flash.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Macros
.. doxygendefine:: ESP_ERR_FLASH_OP_FAIL
.. doxygendefine:: ESP_ERR_FLASH_OP_TIMEOUT
.. doxygendefine:: SPI_FLASH_SEC_SIZE
.. doxygendefine:: SPI_FLASH_MMU_PAGE_SIZE
.. doxygendefine:: ESP_PARTITION_SUBTYPE_OTA

Type Definitions
Expand Down

0 comments on commit d446266

Please sign in to comment.