app_flash.h 2.9 KB

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