app_flash.h 2.9 KB

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