Files
JBao_Heat_Lamp_FW/apps/usr_app/app_nvm.h
T

86 lines
3.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/******************************************************************************
* @file app_nvm.h
* @brief CBR0 VM 持久化(P1 起):灯泡开关 / linkage_config(20B) /
* time_en / time_config1~7(11B) / run_record(31×uint32+日期+寿命) /
* fault_en / alarm_en(规格书第 13 章)
* @author cyWu <1917507415@qq.com>
* @date 2026.09.04
* @version V1.1.0P0 = 空骨架(BOARD_NVM_ENABLE=0
*
* @note 存:灯泡开关(DP0)、linkage_config(20B, DP11)、time_en(DP12)、
* time_config1~7(11B, DP13~19)、run_record(DP2031×uint32 +
* slot0 日期 + 灯泡剩余寿命 DP3)、fault_en(DP22)、alarm_en(DP24)。
* 不存:DP1–6(温控/模式等易失)、DP9 当前温度(WO)、联动作废标志、
* 过零 pending、linkage_delete(DP10 脉冲)、BLE 三元组(出厂不清)。
* 写 VM 时机:APP 改配置后(500ms 防抖);运行记录每累计 600s 一次、
* 跨天旋转立刻写;寿命随 runrec 同写(到期/复位/写 DP3 边沿立刻)。
*
* ⚠ 写 flash 只能在任务上下文(app_nvm_flush / app_nvm_save /
* app_nvm_save_runrec),20ms 中断上下文只允许 app_nvm_tick 打脏。
******************************************************************************/
#ifndef __APP_NVM_H__
#define __APP_NVM_H__
#include <stdint.h>
/**
* @brief 初始化(校验 VM 有效性,仅日志;数据加载在 app_nvm_load
* @return 无
*/
void app_nvm_init(void);
/**
* @brief 立即保存全部业务字段到 VM
* @note syscfg 写入不能在裸中断里调用;只由 app_nvm_flush()(任务上下文)调用
* @return 无
*/
void app_nvm_save(void);
/**
* @brief 立即保存运行记录 item(跨天旋转时用,任务上下文)
* @note 与 app_nvm_save 的区别:只写 31 天记录这一项,避免跨天时把
* 状态/配置一起无谓擦写一遍
* @return 无
*/
void app_nvm_save_runrec(void);
/**
* @brief 从 VM 加载业务字段并应用(开机调用):
* 灯泡开关请求恢复(开则等过零吸合)、联动/定时/运行记录/剩余寿命
* 回填 gDevData
* @return 无
*/
void app_nvm_load(void);
/**
* @brief 业务节拍(中断上下文):变化检测 + 防抖计时,**不执行写入**
* @param dt 距上次调用的毫秒数
* @note ⚠ 跑在 usr_timer 20ms 回调 = 硬件定时器中断上下文,栈极小,
* 只允许轻量比较计时;禁止在此调 syscfg_write(会栈溢出复位)。
* @return 无
*/
void app_nvm_tick(uint16_t dt);
/**
* @brief 任务上下文落盘:防抖满后真正写 VM(由 usr_timer_loop 500ms 调用)
* @note 必须且只能在非中断上下文调用(VM 擦写 flash 栈用量大)
* @return 无
*/
void app_nvm_flush(void);
/**
* @brief 标记业务字段有变化,防抖计时归零(档位/模式/配置变化时调用)
* @return 无
*/
void app_nvm_mark_dirty(void);
/**
* @brief 出厂重置:清全部业务 VM(保留 BLE 配对,规格书第 14 章)
* @note 由 jb_product DP26 调用;RAM 复位由调用方完成(含寿命回额定)
* @return 无
*/
void app_nvm_reset(void);
#endif /* __APP_NVM_H__ */