12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #ifndef __BSP_FLASH_H__
- #define __BSP_FLASH_H__
- //flash 1.0V
- /*********************************************************************
- * INCLUDES
- */
-
- #include "nrf_fstorage.h"
- #include "nrf_fstorage_sd.h"
- #include "nrf_pwr_mgmt.h"
- #include "nrf_soc.h"
- #include "nrf_log.h"
- #include "app_error.h"
- #include "SEGGER_RTT.h"
- /*********************************************************************
- * DEFINITIONS
- */
- #define FSTORAGE_READ 0x00 //读标志位
- #define FSTORAGE_WRITE 0x01 //写标志位
- #define START_FSTORAGE_ADDR 0x00074000UL //FLASH起始地址
- #define END_FSTORAGE_ADDR 0x00078000UL //FLASH结束地址
- #define FLASH_PAGE_SIZE 4096 //页的长度
- #define FLASH_PAGE_NUM ((END_FSTORAGE_ADDR - START_FSTORAGE_ADDR)/FLASH_PAGE_SIZE) //页的个数
- #define PAGE_INT_SIZE (FLASH_PAGE_SIZE/4) //一页所包含的4字节个数
- #define FLASH_ZONE_ADDR_1 START_FSTORAGE_ADDR //页1首地址
- #define FLASH_ZONE_ADDR_2 (FLASH_ZONE_ADDR_1 +FLASH_PAGE_SIZE*2) //页2首地址
- #define FLASH_ZONE_ADDR_3 (FLASH_ZONE_ADDR_2 +FLASH_PAGE_SIZE) //页3首地址
- #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)
- //ERROR CODE
- #define FLASH_OP_SUCCESS 0x00 //flash操作成功
- #define FLASH_ERROR_ZONEADDR (FLASH_OP_SUCCESS+0x01) //区域地址错误
- #define FLASH_ERROR_ADDROVERBOUNDS (FLASH_OP_SUCCESS+0x02) //地址越界
- #define FLASH_ERROR_ADDRALIGN (FLASH_OP_SUCCESS+0x03) //地址不对齐
- #define FLASH_ERROR_DATAALIGN (FLASH_OP_SUCCESS+0x04) //4字节数据不对齐
- #define FLASH_ERROR_DATAEXIST (FLASH_OP_SUCCESS+0x05) //数据已存在
- #define FLASH_ERROR_PAGENUM (FLASH_OP_SUCCESS+0x06) //页号错误
- /*********************************************************************
- * API FUNCTIONS
- */
- //FLASH初始化
- void Fstorage_FlashInit(void);
- //连续读取N个字节
- uint32_t Read_N_Byte_flash(uint32_t addr , uint32_t *pData, uint32_t dataLen);
- //获取输入地址对应的页号
- uint32_t GetPageNum(uint32_t addr, uint16_t *PageNum);
- //根据页号擦除一整页
- uint32_t Erase_OnePage(uint16_t PageNum);
- //连续写入N个4字节(可跨页写,不影响其他数据)
- uint32_t Write_N_4Byte_flash(uint32_t addr , uint32_t *pdata, uint32_t len);
- //连续写入N个4字节(调用前FLASH预先已擦除)
- uint32_t Only_Write_N_4Byte_flash(uint32_t addr , uint32_t *pdata, uint32_t len, bool is_check);
- //查找一页中可写的空间
- uint32_t Find_FreeSpace_In_Page(uint16_t PageNum, uint32_t *start_addr, uint32_t *len);
- #endif
|