58 lines
2.3 KiB
C
58 lines
2.3 KiB
C
|
|
#ifndef BOOT_SHARE_H
|
|||
|
|
#define BOOT_SHARE_H
|
|||
|
|
|
|||
|
|
#include <stdint.h>
|
|||
|
|
|
|||
|
|
/*==== BL ↔ APP 共享内存(热复位保持)====
|
|||
|
|
* 位于 SRAM 顶部,不属于任何段,启动代码不会清零;
|
|||
|
|
* 软件复位/看门狗复位后内容保持,断电后丢失。
|
|||
|
|
* 注意:若 APP 的 RAM 用量增长超过 0x2000BF00,需调整该地址 */
|
|||
|
|
#define BOOT_SHARE_ADDR 0x2000BF00u
|
|||
|
|
#define BOOT_SHARE_MAGIC 0x52534852u /* 'RSHR' */
|
|||
|
|
|
|||
|
|
typedef struct {
|
|||
|
|
uint32_t magic; /* BOOT_SHARE_MAGIC */
|
|||
|
|
uint32_t csr_flags; /* BL 开机时写入的 RCC->CSR(复位原因标志) */
|
|||
|
|
uint32_t uptime_sec; /* APP 每秒更新的本轮运行时长(热复位不丢) */
|
|||
|
|
uint32_t pending_reason; /* APP 主动复位前写入的细分原因码(RSN_x) */
|
|||
|
|
uint32_t checksum; /* 前 4 项累加和 */
|
|||
|
|
} boot_share_t;
|
|||
|
|
|
|||
|
|
#define BOOT_SHARE ((volatile boot_share_t *)BOOT_SHARE_ADDR)
|
|||
|
|
|
|||
|
|
/*==== 重启原因码 ====*/
|
|||
|
|
#define RSN_UNKNOWN 0 /* 未知 */
|
|||
|
|
#define RSN_POWER_ON 1 /* 上电/意外掉电 */
|
|||
|
|
#define RSN_PIN_RESET 2 /* 按键复位 */
|
|||
|
|
#define RSN_WATCHDOG 3 /* 卡死看门狗溢出 */
|
|||
|
|
#define RSN_KICKED 4 /* 平台/服务器踢下线 */
|
|||
|
|
#define RSN_PING_TIMEOUT 5 /* 心跳超时(服务器无响应/假在线) */
|
|||
|
|
#define RSN_NO_SERVICE 6 /* 4G 无网络服务 */
|
|||
|
|
#define RSN_NO_SIM 7 /* 无 SIM 卡(预留) */
|
|||
|
|
#define RSN_OTA_UPDATE 8 /* OTA 升级完成重启 */
|
|||
|
|
#define RSN_OTA_HEALTH 9 /* OTA 健康检查超时 */
|
|||
|
|
#define RSN_4G_FAIL 10 /* 4G 初始化失败 */
|
|||
|
|
#define RSN_CMD_RESET 11 /* 串口 RESET 命令 */
|
|||
|
|
#define RSN_CMD_OTA 12 /* 串口 OTA 命令 */
|
|||
|
|
#define RSN_CMD_RECOVERY 13 /* 串口 RECOVERY 命令 */
|
|||
|
|
#define RSN_POWER_LOSS 14 /* 外部 12V 断电(法拉电容续航中记录) */
|
|||
|
|
#define RSN_4G_MODULE 15 /* 4G 模组异常自重启(boot.rom) */
|
|||
|
|
|
|||
|
|
static inline uint32_t boot_share_sum(const volatile boot_share_t *s)
|
|||
|
|
{
|
|||
|
|
return s->magic + s->csr_flags + s->uptime_sec + s->pending_reason;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static inline int boot_share_valid(void)
|
|||
|
|
{
|
|||
|
|
return BOOT_SHARE->magic == BOOT_SHARE_MAGIC &&
|
|||
|
|
BOOT_SHARE->checksum == boot_share_sum(BOOT_SHARE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static inline void boot_share_store(void)
|
|||
|
|
{
|
|||
|
|
BOOT_SHARE->checksum = boot_share_sum(BOOT_SHARE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endif /* BOOT_SHARE_H */
|