From 06370af0a2f8b7ff8e4cc038e6f4f5e91b6d0174 Mon Sep 17 00:00:00 2001 From: jaffer Date: Tue, 13 Dec 2022 23:32:16 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=E5=A2=9E=E5=8A=A0log=E6=80=BB=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E8=AE=A1=E7=AE=97=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jaffer --- easyflash/inc/easyflash.h | 1 + easyflash/src/ef_log.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/easyflash/inc/easyflash.h b/easyflash/inc/easyflash.h index 2aab0b1..dfaf4b3 100644 --- a/easyflash/inc/easyflash.h +++ b/easyflash/inc/easyflash.h @@ -85,6 +85,7 @@ EfErrCode ef_log_read(size_t index, uint32_t *log, size_t size); EfErrCode ef_log_write(const uint32_t *log, size_t size); EfErrCode ef_log_clean(void); size_t ef_log_get_used_size(void); +size_t ef_log_get_total_size(void); #endif /* ef_utils.c */ diff --git a/easyflash/src/ef_log.c b/easyflash/src/ef_log.c index 49e9d7c..7e4da13 100644 --- a/easyflash/src/ef_log.c +++ b/easyflash/src/ef_log.c @@ -410,6 +410,23 @@ size_t ef_log_get_used_size(void) { return physical_size - header_total_num * LOG_SECTOR_HEADER_SIZE; } +/** + * Get log flash total size. + * + * @return log flash total size. @note NOT contain sector headers + */ +size_t ef_log_get_total_size(void) { + size_t header_total_num = 0; + /* must be call this function after initialize OK */ + if (!init_ok) { + return 0; + } + + header_total_num = LOG_AREA_SIZE / EF_ERASE_MIN_SIZE; + + return LOG_AREA_SIZE - header_total_num * LOG_SECTOR_HEADER_SIZE; +} + /** * Sequential reading log data. It will ignore sector headers. *