app_flash.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #ifndef __APP_FLASH_H__
  2. #define __APP_FLASH_H__
  3. /*************************************
  4. *INCLUDES
  5. */
  6. #include "hal_flash.h"
  7. #include "app_step.h"
  8. #include "app_err.h"
  9. #include "app_power.h"
  10. #include "nrf_gpio.h"
  11. #include "nrf_delay.h"
  12. #include "nrf_sdm.h"
  13. /*************************************
  14. *STRUCTIONS
  15. */
  16. //__attribute__((packed,aligned(4))) : 先按实际字节占位算,最后才4字节对齐。
  17. //size:20
  18. typedef struct __attribute__((packed,aligned(4))) _FlashBackup{
  19. uint32_t head;
  20. uint8_t macAddr_L[6];
  21. uint8_t macAddr_R[6];
  22. uint16_t hardVersion;
  23. uint16_t sotfVersion;
  24. uint8_t isConfig;
  25. /*此处加新的成员*/
  26. uint32_t m_struct_size; //结构体自身大小
  27. uint32_t tail_crc16; //crc16校准只能做成员 head ~ m_struct_size,因为未知的填充字节原因,tail_crc16和未知填充字节(默认为0)都为0好计算。
  28. }FlashBackup_t;
  29. //size:36
  30. typedef struct __attribute__((packed,aligned(4))) _FlashStep{
  31. uint8_t startTime[8]; //记录时间
  32. uint8_t newStartTime[8]; //当前时间
  33. uint32_t stepCur[2]; //当前永久步数
  34. uint32_t step[2]; //每小时记录的左右鞋永久步数0左1右
  35. uint32_t num; //已经记录的每小时步数数量
  36. }FlashStep_t;
  37. //size:12
  38. typedef struct __attribute__((packed,aligned(4))) _FlashClient{
  39. uint8_t isConfig;
  40. uint16_t hardVersion;
  41. uint16_t sotfVersion;
  42. uint8_t macAddr[6];
  43. }FlashClient_t;
  44. //size:
  45. typedef struct __attribute__((packed,aligned(4))) _FlashLog{
  46. uint8_t Errorflag;
  47. uint8_t logData[50];
  48. }FlashLog;
  49. //size:64
  50. typedef struct __attribute__((packed,aligned(4))) _Flash_Param{ //后期版本修改结构体,不能删除或修改现有成员,只能追加新的成员。
  51. uint32_t head;
  52. uint8_t isHost;
  53. uint8_t macHost[6];
  54. FlashStep_t mStep;
  55. FlashClient_t mClient;
  56. FlashLog mFlashLog;
  57. struct __attribute__((packed,aligned(4))){
  58. uint32_t except_data_back_mag : 1;
  59. uint32_t except_data_front_acc : 1;
  60. uint32_t except_data_front_gry : 1;
  61. uint32_t except_data_front_mag : 1;
  62. uint32_t except_data_charge : 1;
  63. uint32_t except_data_battery : 1;
  64. uint32_t except_mode_suspend_overflow : 1;
  65. uint32_t except_ant_damage : 1;
  66. uint32_t except_number_of_exist : 8;
  67. }exception;
  68. /*此处加新的成员*/
  69. // uint8_t add;
  70. // uint8_t add2;
  71. // uint8_t add3;
  72. // uint8_t add4;
  73. // uint32_t add5;
  74. ///////////
  75. uint32_t m_struct_size; //结构体自身大小
  76. uint32_t tail_crc16; //crc16校准只能做成员 head ~ m_struct_size,因为未知的填充字节原因,tail_crc16和未知填充字节(默认为0)都为0好计算。
  77. }Flash_t;
  78. extern Flash_t mFlash;
  79. extern FlashBackup_t mBackup;
  80. /*1.当新API读到旧的数据的时候,新API多的参数用默认值填充,写回的时候按照新API的格式写回。(向后兼容)
  81. 2.当旧API读到新数据,自己不认识的那段buff,要保存起来,写回的时候,将这段buff原样memcpy。(向前兼容,没实现)
  82. */
  83. /********************************************
  84. *API FUCTIONS
  85. */
  86. void Flash_Initialize(void);
  87. //存储步数
  88. uint32_t Flash_SaveStep(void);
  89. //获取步数区域首地址
  90. uint32_t Flash_GetStepZoneStartAddr(void);
  91. //获取步数区域数据
  92. uint32_t Flash_GetStep(uint32_t destination_addr, uint32_t *pData, uint32_t dataLen);
  93. //删除所有步数
  94. uint32_t Flash_DeleteAllStep(void);
  95. //存储基本信息
  96. uint32_t Flash_SaveInfomation(void);
  97. //获取基本信息
  98. uint32_t Flash_GetInfomation(Flash_t *pflash);
  99. //存储备份信息
  100. uint32_t Flash_SaveBackup(void);
  101. //获取备份信息
  102. uint32_t Flash_GetBackup(FlashBackup_t *pbackup);
  103. //保存日志信息
  104. uint32_t Flash_SaveLog(uint32_t id, uint32_t pc, uint32_t info);
  105. //返回主机标志位
  106. uint8_t Get_isHost(void);
  107. //测试接口
  108. void TestHalFlashInterface(void);
  109. #endif