From a7288df94a33bdeaaee4d6edd8d5424f0bdae592 Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 11 May 2017 20:20:20 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E3=80=90=E5=AE=8C=E5=96=84=E3=80=91F?= =?UTF-8?q?lash=20=E6=8F=92=E4=BB=B6=EF=BC=8C=E5=A2=9E=E5=BC=BA=E5=8F=AF?= =?UTF-8?q?=E9=9D=A0=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: armink --- easylogger/plugins/flash/elog_flash.c | 32 +++++++++++++++------------ easylogger/plugins/flash/elog_flash.h | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/easylogger/plugins/flash/elog_flash.c b/easylogger/plugins/flash/elog_flash.c index 9e50171..f153b0d 100644 --- a/easylogger/plugins/flash/elog_flash.c +++ b/easylogger/plugins/flash/elog_flash.c @@ -79,7 +79,7 @@ ElogErrCode elog_flash_init(void) { /** * Read and output log which saved in flash. * - * @param index index for saved log. + * @param index index for saved log. @note It will auto word alignment. * Minimum index is 0. * Maximum index is log used flash total size - 1. * @param size @@ -88,35 +88,34 @@ void elog_flash_output(size_t index, size_t size) { /* 128 bytes buffer */ uint32_t buf[32] = { 0 }; size_t log_total_size = ef_log_get_used_size(); - size_t buf_szie = sizeof(buf); + size_t buf_size = sizeof(buf); size_t read_size = 0, read_overage_size = 0; + /* word alignment for index */ + index = index / 4 * 4; if (index + size > log_total_size) { log_i("The output position and size is out of bound. The max size is %d.", log_total_size); return; } - /* must be call this function after initialize OK */ ELOG_ASSERT(init_ok); /* lock flash log buffer */ log_buf_lock(); - /* Output all flash saved log. It will use filter */ + /* output all flash saved log. It will use filter */ while (true) { - if (index + read_size + buf_szie < log_total_size) { - ef_log_read(index + read_size, buf, buf_szie); - elog_flash_port_output((const char*)buf, buf_szie); - read_size += buf_szie; + if (read_size + buf_size < size) { + ef_log_read(index + read_size, buf, buf_size); + elog_flash_port_output((const char*)buf, buf_size); + read_size += buf_size; } else { /* flash read is word alignment */ - if ((log_total_size - index - read_size) % 4 == 0) { + if ((size - read_size) % 4 == 0) { read_overage_size = 0; } else { - read_overage_size = 4 - ((log_total_size - index - read_size) % 4); + read_overage_size = 4 - ((size - read_size) % 4); } - ef_log_read(index + read_size - read_overage_size, buf, - log_total_size - index - read_size + read_overage_size); - elog_flash_port_output((const char*) buf + read_overage_size, - log_total_size - index - read_size); + ef_log_read(index + read_size, buf, size - read_size + read_overage_size); + elog_flash_port_output((const char*) buf + read_overage_size, size - read_size); /* output newline sign */ elog_flash_port_output(ELOG_NEWLINE_SIGN, strlen(ELOG_NEWLINE_SIGN)); break; @@ -140,6 +139,11 @@ void elog_flash_output_all(void) { */ void elog_flash_output_recent(size_t size) { size_t max_size = ef_log_get_used_size(); + + if (size == 0) { + return; + } + if (size > max_size) { log_i("The output size is out of bound. The max size is %d.", max_size); } else { diff --git a/easylogger/plugins/flash/elog_flash.h b/easylogger/plugins/flash/elog_flash.h index 878fdcc..f4a171a 100644 --- a/easylogger/plugins/flash/elog_flash.h +++ b/easylogger/plugins/flash/elog_flash.h @@ -41,7 +41,7 @@ extern "C" { #endif /* EasyLogger flash log plugin's software version number */ -#define ELOG_FLASH_SW_VERSION "V2.0.0" +#define ELOG_FLASH_SW_VERSION "V2.0.1" /* elog_flash.c */ ElogErrCode elog_flash_init(void);