app_flash.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #ifndef __APP_FLASH_H__
  2. #define __APP_FLASH_H__
  3. /*************************************
  4. *INCLUDES
  5. */
  6. #include "exception.h"
  7. #include "app_power.h"
  8. #include "nrf_gpio.h"
  9. #include "nrf_delay.h"
  10. #include "nrf_sdm.h"
  11. #define FLASH_HEAD 0xAA5555AA
  12. //ERROR CODE
  13. #define ZONE_OP_SUCCESS 0x00 //ZONE操作成功
  14. #define ZONE_ERROR_READ_FAIL (ZONE_OP_SUCCESS+0x01) //读取该区域失败
  15. #define ZONE_ERROR_WRITE_FAIL (ZONE_OP_SUCCESS+0x02) //写入该区域失败
  16. #define ZONE_ERROR_ERASE_FAIL (ZONE_OP_SUCCESS+0x03) //擦除该区域失败
  17. #define ZONE_ERROR_ADDRESS_FAIL (ZONE_OP_SUCCESS+0x04) //输入地址越界
  18. /********************************************
  19. *API FUCTIONS
  20. */
  21. #define RecordMacAddrL 6 //需要保存左右鞋的MAC地址
  22. #define LR_FLAG_VALUE 0x66
  23. typedef struct __attribute__((packed,aligned(4))) _FlashBackup{
  24. uint32_t head;
  25. uint8_t macAddr_L[RecordMacAddrL];
  26. uint8_t macAddr_R[RecordMacAddrL];
  27. uint32_t hardVersion;
  28. uint16_t sotfVersion;
  29. uint8_t isConfig;
  30. uint8_t isHost;
  31. uint8_t ErrStartCnt;
  32. uint8_t RestartCnt;
  33. uint8_t LR_FLAG;
  34. }FlashBackup_t;
  35. //size:36
  36. typedef struct _FlashStep{
  37. uint8_t startTime[8]; //当前时间
  38. uint32_t stepCur[2]; //当前永久步数
  39. uint32_t step[2]; //每小时记录的左右鞋永久步数0左1右
  40. uint32_t step_num; //已经记录的每小时步数数量
  41. }FlashStep_t;
  42. //size:12
  43. typedef struct _FlashClient{
  44. uint8_t isConfig;
  45. uint16_t LastsotfVersion;
  46. uint32_t hardVersion;
  47. uint16_t sotfVersion;
  48. uint8_t updateFlag;
  49. uint8_t macAddr[RecordMacAddrL];
  50. }FlashClient_t;
  51. //size:
  52. typedef struct _FlashLog{
  53. uint8_t Errorflag;
  54. uint8_t logData[50];
  55. }FlashLog;
  56. //size:64
  57. typedef struct _Flash_Param{
  58. uint32_t head;
  59. uint8_t isHost;
  60. uint8_t LR_FLAG;
  61. uint8_t macHost[RecordMacAddrL];
  62. FlashStep_t mStep;
  63. FlashClient_t mClient;
  64. FlashLog mFlashLog;
  65. battercb_t mbattercb_t;
  66. }Flash_t;
  67. extern Flash_t mFlash;
  68. extern FlashBackup_t mBackup;
  69. /*1.当新API读到旧的数据的时候,新API多的参数用默认值填充,写回的时候按照新API的格式写回。(向后兼容)
  70. 2.当旧API读到新数据,自己不认识的那段buff,要保存起来,写回的时候,将这段buff原样memcpy。(向前兼容,没实现)
  71. */
  72. /********************************************
  73. *API FUCTIONS
  74. */
  75. void Flash_Initialize(void);
  76. //存储步数
  77. uint32_t Flash_SaveStep(void);
  78. //获取步数区域首地址
  79. uint32_t Flash_GetStepZoneStartAddr(void);
  80. //删除所有步数
  81. uint32_t Flash_DeleteAllStep(void);
  82. //删除information的数据
  83. uint32_t Flash_DeleteAllInfor(void);
  84. uint32_t Flash_DeleteAllBackup(void);
  85. uint32_t Flash_GetBackup(FlashBackup_t *pbackup);
  86. uint32_t Flash_SaveBackup(void);
  87. //存储基本信息
  88. uint32_t Flash_SaveInfomation(void);
  89. //获取脚步的起始地址
  90. uint32_t flash_GetStep_StartAddress(void);
  91. //读取指定flash的内容
  92. uint32_t flash_Data_Read(uint32_t addr, uint32_t *pData, uint32_t dataLen);
  93. //保存日志信息
  94. uint32_t Flash_SaveLog(uint32_t id, uint32_t pc, uint32_t info);
  95. //测试接口
  96. //void TestHalFlashInterface(void);
  97. void flash_SetClearStepFlag(void);
  98. #endif