app_flash.h 2.8 KB

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