WL_Flash.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _WL_Flash_H_
  14. #define _WL_Flash_H_
  15. #include "esp_err.h"
  16. #include "Flash_Access.h"
  17. #include "WL_Config.h"
  18. #include "WL_State.h"
  19. /**
  20. * @brief This class is used to make wear levelling for flash devices. Class implements Flash_Access interface
  21. *
  22. */
  23. class WL_Flash : public Flash_Access
  24. {
  25. public :
  26. WL_Flash();
  27. ~WL_Flash() override;
  28. virtual esp_err_t config(wl_config_t *cfg, Flash_Access *flash_drv);
  29. virtual esp_err_t init();
  30. size_t chip_size() override;
  31. size_t sector_size() override;
  32. esp_err_t erase_sector(size_t sector) override;
  33. esp_err_t erase_range(size_t start_address, size_t size) override;
  34. esp_err_t write(size_t dest_addr, const void *src, size_t size) override;
  35. esp_err_t read(size_t src_addr, void *dest, size_t size) override;
  36. esp_err_t flush() override;
  37. Flash_Access *get_drv();
  38. wl_config_t *get_cfg();
  39. protected:
  40. bool configured = false;
  41. bool initialized = false;
  42. wl_state_t state;
  43. wl_config_t cfg;
  44. Flash_Access *flash_drv = NULL;
  45. size_t addr_cfg;
  46. size_t addr_state1;
  47. size_t addr_state2;
  48. size_t index_state1;
  49. size_t index_state2;
  50. size_t flash_size;
  51. uint32_t state_size;
  52. uint32_t cfg_size;
  53. uint8_t *temp_buff = NULL;
  54. size_t dummy_addr;
  55. uint32_t pos_data[4];
  56. esp_err_t initSections();
  57. esp_err_t updateWL();
  58. esp_err_t recoverPos();
  59. size_t calcAddr(size_t addr);
  60. esp_err_t updateVersion();
  61. esp_err_t updateV1_V2();
  62. void fillOkBuff(int n);
  63. bool OkBuffSet(int n);
  64. };
  65. #endif // _WL_Flash_H_