esp-idf/components/spi_flash/sim/SpiFlash.h

74 lines
1.6 KiB
C
Raw Normal View History

/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _SpiFlash_H_
#define _SpiFlash_H_
2018-06-21 04:51:44 -04:00
#include <stdbool.h>
#include "esp_err.h"
#include "esp_rom_spiflash.h"
/**
* @brief This class is used to emulate flash devices.
*
*/
class SpiFlash
{
public:
SpiFlash();
~SpiFlash();
2018-06-21 04:51:44 -04:00
void init(uint32_t chip_size, uint32_t block_size, uint32_t sector_size, uint32_t page_size, const char* partitions_bin);
uint32_t get_chip_size();
uint32_t get_block_size();
uint32_t get_sector_size();
uint32_t get_page_size();
esp_rom_spiflash_result_t erase_block(uint32_t block);
esp_rom_spiflash_result_t erase_sector(uint32_t sector);
esp_rom_spiflash_result_t erase_page(uint32_t page);
2018-06-21 04:51:44 -04:00
esp_rom_spiflash_result_t write(uint32_t dest_addr, const void *src, uint32_t size);
esp_rom_spiflash_result_t read(uint32_t src_addr, void *dest, uint32_t size);
2018-06-21 04:51:44 -04:00
uint32_t get_erase_cycles(uint32_t sector);
uint32_t get_total_erase_cycles();
2018-06-21 04:51:44 -04:00
void set_erase_cycles_limit(uint32_t limit);
void set_total_erase_cycles_limit(uint32_t limit);
void reset_erase_cycles();
void reset_total_erase_cycles();
uint8_t* get_memory_ptr(uint32_t src_address);
private:
2018-06-21 04:51:44 -04:00
uint32_t chip_size;
uint32_t block_size;
uint32_t sector_size;
uint32_t page_size;
2018-06-21 04:51:44 -04:00
uint32_t blocks;
uint32_t sectors;
uint32_t pages;
uint8_t* memory;
2018-06-21 04:51:44 -04:00
bool* erase_states;
uint32_t* erase_cycles;
uint32_t erase_cycles_limit;
uint32_t total_erase_cycles;
uint32_t total_erase_cycles_limit;
void deinit();
};
#endif // _SpiFlash_H_