#ifndef __HAL_FLASH_H__ #define __HAL_FLASH_H__ //flash 1.0V /************************************* *INCLUDES */ #include "bsp_flash.h" #include "app_step.h" #include "app_err.h" #include "app_power.h" #include "nrf_gpio.h" #include "nrf_delay.h" #include "nrf_sdm.h" /************************************* *DEFINITION */ #define FLASH_FLAG 0xAA5555AA #define FLASH_ADDR_INFO FLASH_ZONE_ADDR_1 #define FLASH_ADDR_STEP FLASH_ZONE_ADDR_2 #define FLASH_ADDR_BACKUP FLASH_ZONE_ADDR_3 #define MaxLength(a,b) a>b?a:b /************************************* *STRUCTIONS */ //__attribute__((packed,aligned(4))) : 先按实际字节占位算,最后才4字节对齐。 //size:20 typedef struct __attribute__((packed,aligned(4))) _FlashBackup{ uint8_t macAddr_L[6]; uint8_t macAddr_R[6]; uint16_t hardVersion; uint16_t sotfVersion; uint8_t isConfig; float cal[6]; }FlashBackup_t; //size:36 typedef struct __attribute__((packed,aligned(4))) _FlashStep{ uint8_t startTime[8]; //记录时间 uint32_t stepCur[2]; //当前永久步数 uint32_t num; //已经记录的每小时步数数量 }FlashStep_t; //size:12 typedef struct __attribute__((packed,aligned(4))) _FlashClient{ uint8_t isConfig; uint16_t hardVersion; uint16_t sotfVersion; uint8_t macAddr[6]; }FlashClient_t; //size: typedef struct __attribute__((packed,aligned(4))) _FlashLog{ // uint32_t fault_id; // uint32_t pc; // uint32_t error_info; // assert_info_t * p_assert_info; // error_info_t * p_error_info; // ret_code_t err_code; // uint32_t line_num; // const uint8_t * p_file_name; uint8_t Errorflag; uint8_t logData[100]; }FlashLog; //size:64 typedef struct __attribute__((packed,aligned(4))) _Flash_Param{ uint32_t flag; uint8_t isHost; uint8_t macHost[6]; uint16_t basePress; FlashStep_t mStep; FlashClient_t mClient; FlashLog mFlashLog; }Flash_t; extern Flash_t mFlash; extern FlashBackup_t mBackup; /******************************************** *API FUCTIONS */ void Flash_Initialize(void); //存储步数 uint32_t Flash_SaveStep(void); //删除所有步数 uint32_t Flash_DeleteAllStep(void); //存储基本信息 uint32_t Flash_SaveInfomation(void); //获取基本信息 uint32_t Flash_GetInfomation(Flash_t *pflash); //存储备份信息 uint32_t Flash_SaveBackup(void); //获取备份信息 uint32_t Flash_GetBackup(FlashBackup_t *pbackup); //保存日志信息 uint32_t Flash_SaveLog(uint32_t id, uint32_t pc, uint32_t info); //返回主机标志位 uint8_t Get_isHost(void); //测试接口 void TestHalFlashInterface(void); #endif