ShipCentralControl/Anjiehui7_DTU/User/spi_Flash.h

70 lines
2.1 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
*********************************************************************************************************
* IAR Development Kits
* on the
*
* M451
*
* Filename : spi_flash.h
* Version : V1.00
* Programmer(s) : Qian Xianghong
*********************************************************************************************************
*/
#ifndef USER_SPI_FLASH_PRESENT
#define USER_SPI_FLASH_PRESENT
#include "type.h"
// Flash存储规划如下
// 0~7K: boot-loader解压程序由LDROM调入内存执行
// 8~11K: 配置数据2K+2K双份存储
// 12~14K保留
// 15K: SFLASH和FRAM一致性标识记录含标志位、CRC等
// 16~255K: 保留以后可能用于存放16点阵的字库现为了烧录方便是放在程序里面
// 256~511K升级包
// 512K~8189K: 历史记录 (64 x (122847 + 1) = 7678K
// 8190K~8191K: 保留2K)
// 配置数据起始地址8K大小为4K
#define SFLASH_CONFIG_BASE 0x2000
#define SFLASH_FRAM_VALID_INFO_BASE 0x3C00
// 升级包起始地址256K大小为256K
#define SFLASH_UPGRADE_BASE 0x40000ul
// 历史数据起始地址512K
#define SFLASH_DATA_BASE 0x80000ul
// 数据记录条数最多可122847+1条
#define SFLASH_DATA_COUNT 122847ul
// Flash存储容量: 8M bytes
#define SFLASH_SIZE 0x800000ul
#define SFLASH_PAGE_SIZE 256
#define SFLASH_ERASE_SIZE 256 // Page erase size
// 初始化引脚
// 打开设备和允许中断
void SFlash_Open();
void SFlash_ReadID();
uint8_t SFlash_UnlockBPR();
uint8_t SFlash_WriteEN();
void SFlash_ChipErase();
void SFlash_SectorErase(uint32_t Addr);
void SFlash_PageErase(uint32_t Addr);
uint32_t SFlash_BufferWrite(uint32_t Addr, uint8_t *buf, uint32_t nbytes);
uint32_t SFlash_BufferRead(uint32_t Addr, uint8_t *buf, uint32_t nbytes);
uint32_t SFlash_BufferVerify(uint32_t Addr, uint8_t *buf, uint32_t nbytes);
uint16_t do_sflash_crc(unsigned long base_addr, long len);
// 从SFlash读取记录前面2个字节为标志0x55AA最后两个字节为crc
uint32_t SFlash_LoadInfo(uint32_t Addr, uint8_t *buf, uint32_t nbytes);
// 保存记录到SFlash中前面2个字节为标志0x55AA最后两个字节为crc
uint32_t SFlash_SaveInfo(uint32_t Addr, uint8_t *buf, uint32_t nbytes);
#endif