Partition.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "esp_log.h"
  14. #include "Partition.h"
  15. static const char *TAG = "wl_partition";
  16. Partition::Partition(const esp_partition_t *partition)
  17. {
  18. this->partition = partition;
  19. }
  20. size_t Partition::chip_size()
  21. {
  22. return this->partition->size;
  23. }
  24. esp_err_t Partition::erase_sector(size_t sector)
  25. {
  26. esp_err_t result = ESP_OK;
  27. result = erase_range(sector * SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE);
  28. return result;
  29. }
  30. esp_err_t Partition::erase_range(size_t start_address, size_t size)
  31. {
  32. esp_err_t result = esp_partition_erase_range(this->partition, start_address, size);
  33. if (result == ESP_OK) {
  34. ESP_LOGV(TAG, "erase_range - start_address=0x%08x, size=0x%08x, result=0x%08x", start_address, size, result);
  35. } else {
  36. ESP_LOGE(TAG, "erase_range - start_address=0x%08x, size=0x%08x, result=0x%08x", start_address, size, result);
  37. }
  38. return result;
  39. }
  40. esp_err_t Partition::write(size_t dest_addr, const void *src, size_t size)
  41. {
  42. esp_err_t result = ESP_OK;
  43. result = esp_partition_write(this->partition, dest_addr, src, size);
  44. return result;
  45. }
  46. esp_err_t Partition::read(size_t src_addr, void *dest, size_t size)
  47. {
  48. esp_err_t result = ESP_OK;
  49. result = esp_partition_read(this->partition, src_addr, dest, size);
  50. return result;
  51. }
  52. size_t Partition::sector_size()
  53. {
  54. return SPI_FLASH_SEC_SIZE;
  55. }
  56. Partition::~Partition()
  57. {
  58. }