esp-idf/components/spiffs/spiffs_api.c

85 wiersze
2.5 KiB
C

/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "freertos/FreeRTOS.h"
#include "esp_log.h"
#include "esp_partition.h"
#include "esp_spiffs.h"
#include "spiffs_api.h"
2018-06-21 08:51:44 +00:00
static const char* TAG = "SPIFFS";
void spiffs_api_lock(spiffs *fs)
{
(void) xSemaphoreTake(((esp_spiffs_t *)(fs->user_data))->lock, portMAX_DELAY);
}
void spiffs_api_unlock(spiffs *fs)
{
xSemaphoreGive(((esp_spiffs_t *)(fs->user_data))->lock);
}
s32_t spiffs_api_read(spiffs *fs, uint32_t addr, uint32_t size, uint8_t *dst)
{
esp_err_t err = esp_partition_read(((esp_spiffs_t *)(fs->user_data))->partition,
addr, dst, size);
components/esp_common: added esp_macros.h that aims to hold useful macros esp_common/esp_compiler: renamed esp_macros file to a more specific one esp_common/esp_compiler: removed CONTAINER_OF macro, it was a duplicate components/freertos: placed likely macros around port and critical sections component/freertos: placed likely macros on lists module components/freertos: placed unlikely macros inside of assertion points, they likely wont fail components/freertos: added likely macros on queue modules FreeRTOS queues are one of most hot code path, because to queues itself tend to be used a lot by the applications, besides that, queues are the basic primitive to form both mutexes and semaphores, The focus here is to place likely macros inside lowest level send and receive routines, since they're common from all kobjects: semaphores, queues, mutexes and FR internals (like timer queue) components/lwip: placed likely/unlikey on net-interfaces code components/fatfs: added unlikely macros on disk drivers code components/spiffs: added unlikely macros on low level fs driver components/freertos: added likely/unlikely macros on timers and ticker freertos/event_group: placed likely/unlikely macros on hot event group code paths components/sdmmc: placed likely / unlikely macros on lower level path of sdmmc components/bt: placed unlikely macros around bt HCI functions calling components/lwip: added likely/unlikely macros on OS port code section components/freertos: fix code style on tick handler
2019-10-15 21:01:05 +00:00
if (unlikely(err)) {
ESP_LOGE(TAG, "failed to read addr 0x%08" PRIx32 ", size 0x%08" PRIx32 ", err %d", addr, size, err);
return -1;
}
return 0;
}
s32_t spiffs_api_write(spiffs *fs, uint32_t addr, uint32_t size, uint8_t *src)
{
esp_err_t err = esp_partition_write(((esp_spiffs_t *)(fs->user_data))->partition,
addr, src, size);
components/esp_common: added esp_macros.h that aims to hold useful macros esp_common/esp_compiler: renamed esp_macros file to a more specific one esp_common/esp_compiler: removed CONTAINER_OF macro, it was a duplicate components/freertos: placed likely macros around port and critical sections component/freertos: placed likely macros on lists module components/freertos: placed unlikely macros inside of assertion points, they likely wont fail components/freertos: added likely macros on queue modules FreeRTOS queues are one of most hot code path, because to queues itself tend to be used a lot by the applications, besides that, queues are the basic primitive to form both mutexes and semaphores, The focus here is to place likely macros inside lowest level send and receive routines, since they're common from all kobjects: semaphores, queues, mutexes and FR internals (like timer queue) components/lwip: placed likely/unlikey on net-interfaces code components/fatfs: added unlikely macros on disk drivers code components/spiffs: added unlikely macros on low level fs driver components/freertos: added likely/unlikely macros on timers and ticker freertos/event_group: placed likely/unlikely macros on hot event group code paths components/sdmmc: placed likely / unlikely macros on lower level path of sdmmc components/bt: placed unlikely macros around bt HCI functions calling components/lwip: added likely/unlikely macros on OS port code section components/freertos: fix code style on tick handler
2019-10-15 21:01:05 +00:00
if (unlikely(err)) {
ESP_LOGE(TAG, "failed to write addr 0x%08" PRIx32 ", size 0x%08" PRIx32 ", err %d", addr, size, err);
return -1;
}
return 0;
}
s32_t spiffs_api_erase(spiffs *fs, uint32_t addr, uint32_t size)
{
esp_err_t err = esp_partition_erase_range(((esp_spiffs_t *)(fs->user_data))->partition,
addr, size);
if (err) {
ESP_LOGE(TAG, "failed to erase addr 0x%08" PRIx32 ", size 0x%08" PRIx32 ", err %d", addr, size, err);
return -1;
}
return 0;
}
void spiffs_api_check(spiffs *fs, spiffs_check_type type,
spiffs_check_report report, uint32_t arg1, uint32_t arg2)
{
static const char * spiffs_check_type_str[3] = {
"LOOKUP",
"INDEX",
"PAGE"
};
static const char * spiffs_check_report_str[7] = {
"PROGRESS",
"ERROR",
"FIX INDEX",
"FIX LOOKUP",
"DELETE ORPHANED INDEX",
"DELETE PAGE",
"DELETE BAD FILE"
};
if (report != SPIFFS_CHECK_PROGRESS) {
ESP_LOGE(TAG, "CHECK: type:%s, report:%s, %" PRIx32 ":%" PRIx32, spiffs_check_type_str[type],
spiffs_check_report_str[report], arg1, arg2);
} else {
ESP_LOGV(TAG, "CHECK PROGRESS: report:%s, %" PRIx32 ":%" PRIx32,
spiffs_check_report_str[report], arg1, arg2);
}
}