Skip to content

Commit

Permalink
1、【完善】Flash 插件,增强可靠性。
Browse files Browse the repository at this point in the history
Signed-off-by: armink <[email protected]>
  • Loading branch information
armink committed May 11, 2017
1 parent 96a2555 commit a7288df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 18 additions & 14 deletions easylogger/plugins/flash/elog_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion easylogger/plugins/flash/elog_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a7288df

Please sign in to comment.