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