Files
JBao_Temp_Humi_Fan_FW/apps/usr_app/app_nvm.h
T

84 lines
3.1 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 CBR3 VM 持久化(P1 起):mode/fan_gear/联动/定时/运行记录/使能
* @author cyWu <1917507415@qq.com>
* @date 2026.09.02
* @version V2.0.0(规格书 V3.0.0):删除 CFG_USER_CBR3_COND(49B 条件配置)
* 与 cond_en;新增 linkage 20B + run_record 124B**VM 版本升到 2**
* 旧条件数据**不迁移**(当新设备,走首次上电默认值)
*
* @note 存:mode、fan_gear、linkage_config(20B)、time_en、time_config1~7、
* run_record(31×uint32 + slot0 日期)、fault_en、alarm_en。
* 不存:DP0、联动作废标志、模式已运行秒数、原始采样、
* linkage_delete(脉冲,RAM 瞬态)、BLE 三元组。
* 写 VM 时机:APP 改配置后、单次定时自毁、档位/模式稳定变化
* (500ms 防抖);运行记录每累计 10 分钟一次、跨天旋转立刻写。
*
* ⚠ 写 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 加载业务字段并应用(开机调用):
* mode/fan_gear 恢复、联动/定时/运行记录回填 gDevData;mode 从周期头开跑
* @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 DP27 调用;RAM 复位由调用方完成
* @return 无
*/
void app_nvm_reset(void);
#endif /* __APP_NVM_H__ */