70 lines
2.1 KiB
C
70 lines
2.1 KiB
C
/*
|
||
*********************************************************************************************************
|
||
* 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
|