V1.4-Chinese:无秤模式不打印FEED初始化日志;重启记录序号显示固定1~10,且改为一记录一扇区实现真正滑动覆盖
This commit is contained in:
parent
bd4edea20d
commit
7597d095dc
|
|
@ -167,8 +167,10 @@ void feedScaleInit(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !FEED_SCALE_DISABLED
|
||||||
log_info("> FEED: 初始化, 去皮=%.1fKG, 单次投料=%.1fKG",
|
log_info("> FEED: 初始化, 去皮=%.1fKG, 单次投料=%.1fKG",
|
||||||
(float)zero_weight / 10.0f, (float)once_weight / 10.0f);
|
(float)zero_weight / 10.0f, (float)once_weight / 10.0f);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void feedScaleSetZero(uint16_t zero_100g)
|
void feedScaleSetZero(uint16_t zero_100g)
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@
|
||||||
#define RST_REC_MAGIC 0x5253544Cu /* 'RSTL' */
|
#define RST_REC_MAGIC 0x5253544Cu /* 'RSTL' */
|
||||||
#define RST_REC_SIZE 32u
|
#define RST_REC_SIZE 32u
|
||||||
|
|
||||||
|
/* 每条记录独占一个 4KB 扇区:NOR Flash 只能 1->0 翻位,同扇区覆写必须先整擦,
|
||||||
|
* 若 10 条挤一个扇区,回卷擦除会一次丢掉 9 条旧记录;
|
||||||
|
* 一条一扇区才能实现真正的"第 11 条只覆盖最旧那条"。W25Q64 有 8MB,用 10 个扇区无压力 */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t magic; /* RST_REC_MAGIC */
|
uint32_t magic; /* RST_REC_MAGIC */
|
||||||
uint32_t seq; /* 递增序号,大者新 */
|
uint32_t seq; /* 递增序号,大者新 */
|
||||||
|
|
@ -71,13 +75,15 @@ static int rec_valid(const rst_rec_t *r)
|
||||||
|
|
||||||
static void rec_read(uint8_t slot, rst_rec_t *r)
|
static void rec_read(uint8_t slot, rst_rec_t *r)
|
||||||
{
|
{
|
||||||
W25Q64_Read(RST_LOG_ADDR + slot * RST_REC_SIZE, (uint8_t *)r, RST_REC_SIZE);
|
W25Q64_Read(RST_LOG_ADDR + (uint32_t)slot * W25Q64_SECTOR_SIZE, (uint8_t *)r, RST_REC_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rec_write(uint8_t slot, rst_rec_t *r)
|
static void rec_write(uint8_t slot, rst_rec_t *r)
|
||||||
{
|
{
|
||||||
r->crc16 = rec_sum(r);
|
r->crc16 = rec_sum(r);
|
||||||
W25Q64_WriteBuffer(RST_LOG_ADDR + slot * RST_REC_SIZE, (const uint8_t *)r, RST_REC_SIZE);
|
/* 每条独占一扇区:覆写前先擦除该扇区(NOR 只能 1->0 翻位) */
|
||||||
|
W25Q64_EraseRegion(RST_LOG_ADDR + (uint32_t)slot * W25Q64_SECTOR_SIZE, W25Q64_SECTOR_SIZE);
|
||||||
|
W25Q64_WriteBuffer(RST_LOG_ADDR + (uint32_t)slot * W25Q64_SECTOR_SIZE, (const uint8_t *)r, RST_REC_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 找最新记录:返回槽位;无有效记录返回 -1 */
|
/* 找最新记录:返回槽位;无有效记录返回 -1 */
|
||||||
|
|
@ -103,10 +109,6 @@ static void append_record(uint8_t reason, uint32_t uptime_sec)
|
||||||
uint32_t seq = 0;
|
uint32_t seq = 0;
|
||||||
int newest = find_newest(&seq);
|
int newest = find_newest(&seq);
|
||||||
int slot = (newest < 0) ? 0 : (newest + 1) % RST_LOG_SLOTS;
|
int slot = (newest < 0) ? 0 : (newest + 1) % RST_LOG_SLOTS;
|
||||||
if (slot == 0) {
|
|
||||||
/* 回到起点:整扇区擦除重写 */
|
|
||||||
W25Q64_EraseRegion(RST_LOG_ADDR, W25Q64_SECTOR_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
rst_rec_t r;
|
rst_rec_t r;
|
||||||
memset(&r, 0xFF, sizeof(r));
|
memset(&r, 0xFF, sizeof(r));
|
||||||
|
|
@ -195,7 +197,7 @@ void reset_log_boot(void)
|
||||||
BOOT_SHARE->magic = BOOT_SHARE_MAGIC;
|
BOOT_SHARE->magic = BOOT_SHARE_MAGIC;
|
||||||
boot_share_store();
|
boot_share_store();
|
||||||
|
|
||||||
/* 打印最近 10 条(新→旧) */
|
/* 打印最近 10 条(新→旧),显示序号固定 1~10([1] 最新,写满后覆盖最旧) */
|
||||||
log_info("> 历史重启记录(新→旧):");
|
log_info("> 历史重启记录(新→旧):");
|
||||||
uint32_t newest_seq;
|
uint32_t newest_seq;
|
||||||
int newest = find_newest(&newest_seq);
|
int newest = find_newest(&newest_seq);
|
||||||
|
|
@ -209,12 +211,12 @@ void reset_log_boot(void)
|
||||||
rec_read((uint8_t)slot, &r);
|
rec_read((uint8_t)slot, &r);
|
||||||
if (!rec_valid(&r)) continue;
|
if (!rec_valid(&r)) continue;
|
||||||
if (r.uptime_sec == 0xFFFFFFFFu) {
|
if (r.uptime_sec == 0xFFFFFFFFu) {
|
||||||
log_info(" [%u] 重启原因: %s 运行时间: 未知",
|
log_info(" [%d] 重启原因: %s 运行时间: 未知",
|
||||||
(unsigned)r.seq, reason_str(r.reason));
|
i + 1, reason_str(r.reason));
|
||||||
} else {
|
} else {
|
||||||
uint32_t m = r.uptime_sec / 60;
|
uint32_t m = r.uptime_sec / 60;
|
||||||
log_info(" [%u] 重启原因: %s 运行时间: %u天%02u小时%02u分",
|
log_info(" [%d] 重启原因: %s 运行时间: %u天%02u小时%02u分",
|
||||||
(unsigned)r.seq, reason_str(r.reason),
|
i + 1, reason_str(r.reason),
|
||||||
(unsigned)(m / 1440), (unsigned)((m % 1440) / 60), (unsigned)(m % 60));
|
(unsigned)(m / 1440), (unsigned)((m % 1440) / 60), (unsigned)(m % 60));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue