2022-02-21 16:09:24 -05:00
|
|
|
/*
|
2023-09-07 09:59:47 -04:00
|
|
|
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
2022-02-21 16:09:24 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2018-07-04 19:01:03 -04:00
|
|
|
#ifndef _WL_Flash_H_
|
|
|
|
#define _WL_Flash_H_
|
|
|
|
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include "Flash_Access.h"
|
2023-09-07 09:59:47 -04:00
|
|
|
#include "Partition.h"
|
2018-07-04 19:01:03 -04:00
|
|
|
#include "WL_Config.h"
|
|
|
|
#include "WL_State.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This class is used to make wear levelling for flash devices. Class implements Flash_Access interface
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class WL_Flash : public Flash_Access
|
|
|
|
{
|
|
|
|
public :
|
|
|
|
WL_Flash();
|
|
|
|
~WL_Flash() override;
|
|
|
|
|
2023-07-17 05:59:28 -04:00
|
|
|
virtual esp_err_t config(wl_config_t *cfg, Partition *partition);
|
2018-07-04 19:01:03 -04:00
|
|
|
virtual esp_err_t init();
|
|
|
|
|
2023-03-30 10:15:43 -04:00
|
|
|
size_t get_flash_size() override;
|
|
|
|
size_t get_sector_size() override;
|
2018-07-04 19:01:03 -04:00
|
|
|
|
|
|
|
esp_err_t erase_sector(size_t sector) override;
|
|
|
|
esp_err_t erase_range(size_t start_address, size_t size) override;
|
|
|
|
|
|
|
|
esp_err_t write(size_t dest_addr, const void *src, size_t size) override;
|
|
|
|
esp_err_t read(size_t src_addr, void *dest, size_t size) override;
|
|
|
|
|
|
|
|
esp_err_t flush() override;
|
|
|
|
|
2023-09-07 09:59:47 -04:00
|
|
|
Partition *get_part();
|
2018-07-04 19:01:03 -04:00
|
|
|
wl_config_t *get_cfg();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool configured = false;
|
|
|
|
bool initialized = false;
|
|
|
|
wl_state_t state;
|
|
|
|
wl_config_t cfg;
|
2023-09-07 09:59:47 -04:00
|
|
|
Partition *partition = NULL;
|
2018-07-04 19:01:03 -04:00
|
|
|
|
|
|
|
size_t addr_cfg;
|
|
|
|
size_t addr_state1;
|
|
|
|
size_t addr_state2;
|
|
|
|
size_t index_state1;
|
|
|
|
size_t index_state2;
|
|
|
|
|
|
|
|
size_t flash_size;
|
|
|
|
uint32_t state_size;
|
|
|
|
uint32_t cfg_size;
|
|
|
|
uint8_t *temp_buff = NULL;
|
|
|
|
size_t dummy_addr;
|
2018-06-07 02:58:06 -04:00
|
|
|
uint32_t pos_data[4];
|
2018-07-04 19:01:03 -04:00
|
|
|
|
|
|
|
esp_err_t initSections();
|
|
|
|
esp_err_t updateWL();
|
|
|
|
esp_err_t recoverPos();
|
|
|
|
size_t calcAddr(size_t addr);
|
2018-06-07 02:58:06 -04:00
|
|
|
|
|
|
|
esp_err_t updateVersion();
|
|
|
|
esp_err_t updateV1_V2();
|
|
|
|
void fillOkBuff(int n);
|
|
|
|
bool OkBuffSet(int n);
|
2018-07-04 19:01:03 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _WL_Flash_H_
|