1、【修复】Flash 存储日志不支持外部 Flash 的问题。感谢网友 @Teddy_Le 的反馈。

Signed-off-by: armink <armink.ztl@gmail.com>
pull/7/merge
armink 10 years ago
parent 26053c0a94
commit 2883158fd0

@ -67,7 +67,7 @@ if (!(EXPR)) \
while (1); \ while (1); \
} }
/* EasyFlash software version number */ /* EasyFlash software version number */
#define EF_SW_VERSION "2.07.28" #define EF_SW_VERSION "2.08.26"
typedef struct _ef_env{ typedef struct _ef_env{
char *key; char *key;
@ -86,10 +86,10 @@ typedef enum {
/* the flash sector current status */ /* the flash sector current status */
typedef enum { typedef enum {
FLASH_SECTOR_EMPTY, EF_SECTOR_EMPTY,
FLASH_SECTOR_USING, EF_SECTOR_USING,
FLASH_SECTOR_FULL, EF_SECTOR_FULL,
}FlashSecrorStatus; }EfSecrorStatus;
/* easyflash.c */ /* easyflash.c */
EfErrCode easyflash_init(void); EfErrCode easyflash_init(void);
@ -127,7 +127,7 @@ size_t ef_log_get_used_size(void);
/* ef_utils.c */ /* ef_utils.c */
uint32_t ef_calc_crc32(uint32_t crc, const void *buf, size_t size); uint32_t ef_calc_crc32(uint32_t crc, const void *buf, size_t size);
FlashSecrorStatus ef_get_sector_status(uint32_t addr, size_t sec_size); EfSecrorStatus ef_get_sector_status(uint32_t addr, size_t sec_size);
uint32_t ef_find_sec_using_end_addr(uint32_t addr, size_t sec_size); uint32_t ef_find_sec_using_end_addr(uint32_t addr, size_t sec_size);
/* ef_port.c */ /* ef_port.c */

@ -106,15 +106,15 @@ uint32_t ef_calc_crc32(uint32_t crc, const void *buf, size_t size)
* *
* @return the flash sector current status * @return the flash sector current status
*/ */
FlashSecrorStatus ef_get_sector_status(uint32_t addr, size_t sec_size) { EfSecrorStatus ef_get_sector_status(uint32_t addr, size_t sec_size) {
uint32_t cur_using_addr = ef_find_sec_using_end_addr(addr, sec_size); uint32_t cur_using_addr = ef_find_sec_using_end_addr(addr, sec_size);
/* get current status by current using address */ /* get current status by current using address */
if (cur_using_addr == addr) { if (cur_using_addr == 0 || cur_using_addr == addr - 4) {
return FLASH_SECTOR_EMPTY; return EF_SECTOR_EMPTY;
} else if (cur_using_addr < addr + sec_size - 4) { } else if (cur_using_addr == addr + sec_size - 4) {
return FLASH_SECTOR_USING; return EF_SECTOR_FULL;
} else { } else {
return FLASH_SECTOR_FULL; return EF_SECTOR_USING;
} }
} }
@ -127,37 +127,38 @@ FlashSecrorStatus ef_get_sector_status(uint32_t addr, size_t sec_size) {
* @return current flash sector using end address * @return current flash sector using end address
*/ */
uint32_t ef_find_sec_using_end_addr(uint32_t addr, size_t sec_size) { uint32_t ef_find_sec_using_end_addr(uint32_t addr, size_t sec_size) {
size_t start, continue_ff; /* read section data buffer size */
/* counts continuous 0xFF */ #define READ_BUF_SIZE 32
for (start = 0; start < sec_size; start++) {
if (*(uint8_t *) (addr + start) == 0xFF) { uint32_t start = addr, continue_ff = 0, read_buf_size = 0, i;
/* make sure it is not the last byte */ uint8_t buf[READ_BUF_SIZE];
if (start < sec_size - 1) {
/* start counts */ EF_ASSERT(READ_BUF_SIZE % 4 == 0);
for (continue_ff = 1; continue_ff < sec_size - start; continue_ff++) { /* counts continuous 0xFF which is end of sector */
if (*(uint8_t *) (addr + start + continue_ff) != 0xFF) { while (start < addr + sec_size) {
start += continue_ff; if (start + READ_BUF_SIZE < addr + sec_size) {
break; read_buf_size = READ_BUF_SIZE;
} } else {
} read_buf_size = addr + sec_size - start;
/* all sector counts finish */
if (continue_ff == sec_size - start) {
/* must be word alignment */
if (start % 4 != 0) {
start = (start / 4 + 1) * 4;
}
break;
} }
ef_port_read(start, (uint32_t *)buf, read_buf_size);
for (i = 0; i < read_buf_size; i++) {
if (buf[i] == 0xFF) {
continue_ff++;
} else {
continue_ff = 0;
} }
} }
start += read_buf_size;
} }
/* calculate current flash sector using end address */ /* calculate current flash sector using end address */
if ((start == 0) && (continue_ff == sec_size)) { if (continue_ff == sec_size) {
/* from 0 to sec_size all sector is 0xFF, so the sector is empty */ /* from 0 to sec_size all sector is 0xFF, so the sector is empty */
return addr; return addr >= 4 ? addr - 4 : 0;
} else if (start < sec_size) { } else if (continue_ff >= 4) {
/* form start to sec_size all area is 0xFF, so it's used part of the sector */ /* form end_addr - 4 to sec_size length all area is 0xFF, so it's used part of the sector.
return addr + start; * the address must be word alignment. */
return (addr + sec_size - continue_ff) * 4 / 4 - 4;
} else { } else {
/* all sector not has continuous 0xFF, alignment by word */ /* all sector not has continuous 0xFF, alignment by word */
return addr + sec_size - 4; return addr + sec_size - 4;

Loading…
Cancel
Save