hal_flash.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef __HAL_FLASH_H__
  2. #define __HAL_FLASH_H__
  3. //flash 1.0V
  4. /*************************************
  5. *INCLUDES
  6. */
  7. #include "bsp_flash.h"
  8. #include "app_step.h"
  9. #include "app_err.h"
  10. #include "app_power.h"
  11. #include "nrf_gpio.h"
  12. #include "nrf_delay.h"
  13. #include "nrf_sdm.h"
  14. /*************************************
  15. *DEFINITION
  16. */
  17. #define FLASH_FLAG 0xAA5555AA
  18. #define FLASH_ADDR_INFO FLASH_ZONE_ADDR_1
  19. #define FLASH_ADDR_STEP FLASH_ZONE_ADDR_2
  20. #define FLASH_ADDR_BACKUP FLASH_ZONE_ADDR_3
  21. #define MaxLength(a,b) a>b?a:b
  22. /*************************************
  23. *STRUCTIONS
  24. */
  25. //__attribute__((packed,aligned(4))) : 先按实际字节占位算,最后才4字节对齐。
  26. //size:20
  27. typedef struct __attribute__((packed,aligned(4))) _FlashBackup{
  28. uint8_t macAddr_L[6];
  29. uint8_t macAddr_R[6];
  30. uint16_t hardVersion;
  31. uint16_t sotfVersion;
  32. uint8_t isConfig;
  33. }FlashBackup_t;
  34. //size:36
  35. typedef struct __attribute__((packed,aligned(4))) _FlashStep{
  36. uint8_t startTime[8]; //记录时间
  37. uint8_t newStartTime[8]; //当前时间
  38. uint32_t stepCur[2]; //当前永久步数
  39. uint32_t step[2]; //每小时记录的左右鞋永久步数0左1右
  40. uint32_t num; //已经记录的每小时步数数量
  41. }FlashStep_t;
  42. //size:12
  43. typedef struct __attribute__((packed,aligned(4))) _FlashClient{
  44. uint8_t isConfig;
  45. uint16_t hardVersion;
  46. uint16_t sotfVersion;
  47. uint8_t macAddr[6];
  48. }FlashClient_t;
  49. //size:
  50. typedef struct __attribute__((packed,aligned(4))) _FlashLog{
  51. // uint32_t fault_id;
  52. // uint32_t pc;
  53. // uint32_t error_info;
  54. // assert_info_t * p_assert_info;
  55. // error_info_t * p_error_info;
  56. // ret_code_t err_code;
  57. // uint32_t line_num;
  58. // const uint8_t * p_file_name;
  59. uint8_t Errorflag;
  60. uint8_t logData[100];
  61. }FlashLog;
  62. //size:64
  63. typedef struct __attribute__((packed,aligned(4))) _Flash_Param{
  64. uint32_t flag;
  65. uint8_t isHost;
  66. uint8_t macHost[6];
  67. uint16_t basePress;
  68. FlashStep_t mStep;
  69. FlashClient_t mClient;
  70. FlashLog mFlashLog;
  71. }Flash_t;
  72. extern Flash_t mFlash;
  73. extern FlashBackup_t mBackup;
  74. /********************************************
  75. *API FUCTIONS
  76. */
  77. void Flash_Initialize(void);
  78. //存储步数
  79. uint32_t Flash_SaveStep(void);
  80. //删除所有步数
  81. uint32_t Flash_DeleteAllStep(void);
  82. //存储基本信息
  83. uint32_t Flash_SaveInfomation(void);
  84. //获取基本信息
  85. uint32_t Flash_GetInfomation(Flash_t *pflash);
  86. //存储备份信息
  87. uint32_t Flash_SaveBackup(void);
  88. //获取备份信息
  89. uint32_t Flash_GetBackup(FlashBackup_t *pbackup);
  90. //保存日志信息
  91. uint32_t Flash_SaveLog(uint32_t id, uint32_t pc, uint32_t info);
  92. //返回主机标志位
  93. uint8_t Get_isHost(void);
  94. //测试接口
  95. void TestHalFlashInterface(void);
  96. #endif