app_flash.h 2.3 KB

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