bsp_flash.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef __BSP_FLASH_H__
  2. #define __BSP_FLASH_H__
  3. //flash 1.0V
  4. /*********************************************************************
  5. * INCLUDES
  6. */
  7. #include "nrf_fstorage.h"
  8. #include "nrf_fstorage_sd.h"
  9. #include "nrf_pwr_mgmt.h"
  10. #include "nrf_soc.h"
  11. #include "nrf_log.h"
  12. #include "app_error.h"
  13. #include "SEGGER_RTT.h"
  14. /*********************************************************************
  15. * DEFINITIONS
  16. */
  17. #define FSTORAGE_READ 0x00 //读标志位
  18. #define FSTORAGE_WRITE 0x01 //写标志位
  19. #define START_FSTORAGE_ADDR 0x00074000UL //FLASH起始地址
  20. #define END_FSTORAGE_ADDR 0x00078000UL //FLASH结束地址
  21. #define FLASH_PAGE_SIZE 4096 //页的长度
  22. #define FLASH_PAGE_NUM ((END_FSTORAGE_ADDR - START_FSTORAGE_ADDR)/FLASH_PAGE_SIZE) //页的个数
  23. #define PAGE_INT_SIZE (FLASH_PAGE_SIZE/4) //一页所包含的4字节个数
  24. #define FLASH_ZONE_ADDR_1 START_FSTORAGE_ADDR //页1首地址
  25. #define FLASH_ZONE_ADDR_2 (FLASH_ZONE_ADDR_1 +FLASH_PAGE_SIZE*2) //页2首地址
  26. #define FLASH_ZONE_ADDR_3 (FLASH_ZONE_ADDR_2 +FLASH_PAGE_SIZE) //页3首地址
  27. #define FLASH_ZONEADDR_CHECK(zone_addr) ((zone_addr==FLASH_ZONE_ADDR_1 || zone_addr==FLASH_ZONE_ADDR_2 || zone_addr==FLASH_ZONE_ADDR_3)?0:1) //验证是否在页x的范围内(1、2、3)
  28. //ERROR CODE
  29. #define FLASH_OP_SUCCESS 0x00 //flash操作成功
  30. #define FLASH_ERROR_ZONEADDR (FLASH_OP_SUCCESS+0x01) //区域地址错误
  31. #define FLASH_ERROR_ADDROVERBOUNDS (FLASH_OP_SUCCESS+0x02) //地址越界
  32. #define FLASH_ERROR_ADDRALIGN (FLASH_OP_SUCCESS+0x03) //地址不对齐
  33. #define FLASH_ERROR_DATAALIGN (FLASH_OP_SUCCESS+0x04) //4字节数据不对齐
  34. #define FLASH_ERROR_DATAEXIST (FLASH_OP_SUCCESS+0x05) //数据已存在
  35. #define FLASH_ERROR_PAGENUM (FLASH_OP_SUCCESS+0x06) //页号错误
  36. /*********************************************************************
  37. * API FUNCTIONS
  38. */
  39. //FLASH初始化
  40. void Fstorage_FlashInit(void);
  41. //连续读取N个字节
  42. uint32_t Read_N_Byte_flash(uint32_t addr , uint32_t *pData, uint32_t dataLen);
  43. //获取输入地址对应的页号
  44. uint32_t GetPageNum(uint32_t addr, uint16_t *PageNum);
  45. //根据页号擦除一整页
  46. uint32_t Erase_OnePage(uint16_t PageNum);
  47. //连续写入N个4字节(可跨页写,不影响其他数据)
  48. uint32_t Write_N_4Byte_flash(uint32_t addr , uint32_t *pdata, uint32_t len);
  49. //连续写入N个4字节(调用前FLASH预先已擦除)
  50. uint32_t Only_Write_N_4Byte_flash(uint32_t addr , uint32_t *pdata, uint32_t len, bool is_check);
  51. //查找一页中可写的空间
  52. uint32_t Find_FreeSpace_In_Page(uint16_t PageNum, uint32_t *start_addr, uint32_t *len);
  53. #endif