hal_flash.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. float cal[6];
  34. }FlashBackup_t;
  35. //size:36
  36. typedef struct __attribute__((packed,aligned(4))) _FlashStep{
  37. uint8_t startTime[8]; //记录时间
  38. uint32_t stepCur[2]; //当前永久步数
  39. uint32_t num; //已经记录的每小时步数数量
  40. }FlashStep_t;
  41. //size:12
  42. typedef struct __attribute__((packed,aligned(4))) _FlashClient{
  43. uint8_t isConfig;
  44. uint16_t hardVersion;
  45. uint16_t sotfVersion;
  46. uint8_t macAddr[6];
  47. }FlashClient_t;
  48. //size:
  49. typedef struct __attribute__((packed,aligned(4))) _FlashLog{
  50. // uint32_t fault_id;
  51. // uint32_t pc;
  52. // uint32_t error_info;
  53. // assert_info_t * p_assert_info;
  54. // error_info_t * p_error_info;
  55. // ret_code_t err_code;
  56. // uint32_t line_num;
  57. // const uint8_t * p_file_name;
  58. uint8_t Errorflag;
  59. uint8_t logData[100];
  60. }FlashLog;
  61. //size:64
  62. typedef struct __attribute__((packed,aligned(4))) _Flash_Param{
  63. uint32_t flag;
  64. uint8_t isHost;
  65. uint8_t macHost[6];
  66. uint16_t basePress;
  67. FlashStep_t mStep;
  68. FlashClient_t mClient;
  69. FlashLog mFlashLog;
  70. }Flash_t;
  71. extern Flash_t mFlash;
  72. extern FlashBackup_t mBackup;
  73. /********************************************
  74. *API FUCTIONS
  75. */
  76. void Flash_Initialize(void);
  77. //存储步数
  78. uint32_t Flash_SaveStep(void);
  79. //删除所有步数
  80. uint32_t Flash_DeleteAllStep(void);
  81. //存储基本信息
  82. uint32_t Flash_SaveInfomation(void);
  83. //获取基本信息
  84. uint32_t Flash_GetInfomation(Flash_t *pflash);
  85. //存储备份信息
  86. uint32_t Flash_SaveBackup(void);
  87. //获取备份信息
  88. uint32_t Flash_GetBackup(FlashBackup_t *pbackup);
  89. //保存日志信息
  90. uint32_t Flash_SaveLog(uint32_t id, uint32_t pc, uint32_t info);
  91. //返回主机标志位
  92. uint8_t Get_isHost(void);
  93. //测试接口
  94. void TestHalFlashInterface(void);
  95. #endif