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

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

@ -67,7 +67,7 @@ if (!(EXPR)) \
while (1); \
}
/* EasyFlash software version number */
#define EF_SW_VERSION "2.07.28"
#define EF_SW_VERSION "2.08.26"
typedef struct _ef_env{
char *key;
@ -86,10 +86,10 @@ typedef enum {
/* the flash sector current status */
typedef enum {
FLASH_SECTOR_EMPTY,
FLASH_SECTOR_USING,
FLASH_SECTOR_FULL,
}FlashSecrorStatus;
EF_SECTOR_EMPTY,
EF_SECTOR_USING,
EF_SECTOR_FULL,
}EfSecrorStatus;
/* easyflash.c */
EfErrCode easyflash_init(void);
@ -127,7 +127,7 @@ size_t ef_log_get_used_size(void);
/* ef_utils.c */
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);
/* 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
*/
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);
/* get current status by current using address */
if (cur_using_addr == addr) {
return FLASH_SECTOR_EMPTY;
} else if (cur_using_addr < addr + sec_size - 4) {
return FLASH_SECTOR_USING;
if (cur_using_addr == 0 || cur_using_addr == addr - 4) {
return EF_SECTOR_EMPTY;
} else if (cur_using_addr == addr + sec_size - 4) {
return EF_SECTOR_FULL;
} 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
*/
uint32_t ef_find_sec_using_end_addr(uint32_t addr, size_t sec_size) {
size_t start, continue_ff;
/* counts continuous 0xFF */
for (start = 0; start < sec_size; start++) {
if (*(uint8_t *) (addr + start) == 0xFF) {
/* make sure it is not the last byte */
if (start < sec_size - 1) {
/* start counts */
for (continue_ff = 1; continue_ff < sec_size - start; continue_ff++) {
if (*(uint8_t *) (addr + start + continue_ff) != 0xFF) {
start += continue_ff;
break;
}
}
/* all sector counts finish */
if (continue_ff == sec_size - start) {
/* must be word alignment */
if (start % 4 != 0) {
start = (start / 4 + 1) * 4;
}
break;
}
/* read section data buffer size */
#define READ_BUF_SIZE 32
uint32_t start = addr, continue_ff = 0, read_buf_size = 0, i;
uint8_t buf[READ_BUF_SIZE];
EF_ASSERT(READ_BUF_SIZE % 4 == 0);
/* counts continuous 0xFF which is end of sector */
while (start < addr + sec_size) {
if (start + READ_BUF_SIZE < addr + sec_size) {
read_buf_size = READ_BUF_SIZE;
} else {
read_buf_size = addr + sec_size - start;
}
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 */
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 */
return addr;
} else if (start < sec_size) {
/* form start to sec_size all area is 0xFF, so it's used part of the sector */
return addr + start;
return addr >= 4 ? addr - 4 : 0;
} else if (continue_ff >= 4) {
/* form end_addr - 4 to sec_size length all area is 0xFF, so it's used part of the sector.
* the address must be word alignment. */
return (addr + sec_size - continue_ff) * 4 / 4 - 4;
} else {
/* all sector not has continuous 0xFF, alignment by word */
return addr + sec_size - 4;

Loading…
Cancel
Save