📄 flash.h
字号:
#ifndef _FLASH_H_
#define _FLASH_H_
#include "fun_monitnum.h"
#include "uart485.h"
///For LPC213X
#define SCK1 (1<<17)
#define DI1 (1<<18)
#define DO1 (1<<19)
#define SE1 (1<<20)
#define INSERT (1<<24)
#define WP (1<<25)
#define HOLD (1<<24)
#define DO1H IO0SET|=DO1
#define DO1L IO0CLR|=DO1
#define SCK1H IO0SET|=SCK1
#define SCK1L IO0CLR|=SCK1
#define DI1H (IO0PIN&DI1)
#define SE_ENABLE IO0CLR|=SE1
#define SE_DISABLE IO0SET|=SE1
#define SEL IO0CLR|=SE1
#define SEH IO0SET|=SE1
#define HOLD_ENABLE IO0CLR|=HOLD
#define HOLD_DISABLE IO0SET|=HOLD
#define WP_ENABLE IO0CLR|=WP
#define WP_DISABLE IO0SET|=WP
#define WREN 0x06
#define WRDI 0x04
#define RDID 0x9f
#define RDSR 0x05
#define WRSR 0x01
#define READ 0x03
#define FAST_READ 0x0b
#define PP 0x02
#define SE 0xd8
#define BE 0xc7
#define RES 0xab
#define WIP 0x1 //Check the write in progress bit of the SPI status register
#define WEL 0x2 //Check the write enable bit of the SPI status register
#define TIMEOUT 35000*64
#define NUM_SECTORS 128 // number of sectors in the M25P20 flash device
#define USE_M25P64
#define USE_JEDEC_STANDARD_TWO_BYTE_SIGNATURE
#ifdef USE_M25P64 /* The USE_M25P64 device */
#define USE_JEDEC_STANDARD_TWO_BYTE_SIGNATURE /* undefine this macro to read One-Byte Signature*/
#ifdef USE_JEDEC_STANDARD_TWO_BYTE_SIGNATURE
#define EXPECTED_DEVICE (0x2017) /* Device Identification for the USE_M25P64 */
#else
#define EXPECTED_DEVICE (0x16) /* Device Identification for the USE_M25P64 */
#endif
#define FLASH_AVAILABLE (0x07f0000) /* Available device size in Bytes*/
#define FLASH_SIZE (0x0800000) /* Total device size in Bytes */
#define FLASH_PAGE_COUNT (0x08000) /* Total device size in Pages */
#define FLASH_SECTOR_COUNT (0x80) /* Total device size in Sectors */
#define FLASH_WRITE_BUFFER_SIZE 0x100 /* Write Buffer = 256 bytes */
#define FLASH_MWA 1 /* Minimum Write Access */
#define BE_TIMEOUT (0x160) /* Timeout in seconds suggested for Bulk Erase Operation*/
#define NO_DEEP_POWER_DOWN_SUPPORT /* No support for Deep Power-down feature*/
#endif /* USE_M25P64 */
#define FLASHAUTO (0xffffffff)
#define DO1_ENABLE PINSEL1 = ((PINSEL1 & (~(0x03<<6))) | (0x02<<6))
#define DO1_DISABLE PINSEL1 = (PINSEL1 & (~(0x03<<6)));IO0DIR &= (~(0x01<<19))
#define SE1_ENABKE PINSEL1 = ((PINSEL1 & (~(0x03<<8))) | (0x02<<8))
#define SE1_DISABLE PINSEL1 = (PINSEL1 & (~(0x03<<8)));IO0DIR |= (0x01<<20) ;IOSET |= (1<<20)
#define SSP_SOFT PINSEL1 &= (~(0xaaaa<<2))
#define SSP_HARD PINSEL1 = (PINSEL1 & (~(0xFF << 2))) | (0xAA << 2);
/*
*********************************************************************************************************
** 函数名称:SSP_Init()
** 函数功能:将SSP控制器设置为主机SPI。
** 入口参数:无
** 出口参数:无
*********************************************************************************************************
*/
void SSP_Init(void);
/*
*********************************************************************************************************
* 函数名称:SSP_SendData()
* 函数功能:SSP接口向SPI总线发送数据。
* 入口参数:data 待发送的数据
* 出口参数:返回值为读取的数据
*********************************************************************************************************
*/
uint8 SSP_SendData(uint8 data);
/*
*********************************************************************************************************
* 函数名称:FLASH_CMD()
* 函数功能:Flash 存储器读写函数
* 入口参数:cmd 读写命令
* 出口参数:返回值为读取的数据
*********************************************************************************************************
*/
uint8 FlashCmd(uint8 cmd);
uint8 CMD_WREN(void);
uint8 CMD_WRDI(void);
uint8 CMD_RDID(void);
uint8 CMD_RDSR(void);
uint8 CMD_WRSR(uint8 data);
uint8 CMD_READ(uint32 addr,uint8 *data,uint16 length);
uint8 CMD_FREAD(uint32 addr,uint8 length);
uint8 CMD_PP(uint32 addr,uint8 *data,uint16 length);
uint8 CMD_RES(void);
uint8 CMD_SE(uint32 saddr);
uint8 CMD_BE(void);
uint8 Wait_For_WEL(void);
uint8 Wait_For_Status( uint8 Statusbit );
void SSP_Soft_Init(void);
uint SSPS_SendData(uint8 data,uint8 dataen);
uint8 CMD_RDIDS(void);
uint8 FlashRead(uint32 FlashAddr,uint8 *RamAddr,uint8 length);
uint8 FlashWrite(uint32 FlashAddr,uint8 *RamAddr,uint8 length);
typedef struct _tagFlashRecord
{
uint32 RecordID;
uint32 RecordDistance;
uint16 RecordTrain; //*(2个字节)车次
uint16 RecordDriver; //*(2个字节)司机号
uint16 RecordSpeed;
uint8 RecordCarriageNum;
uint8 RecordSec;
uint8 RecordMin;
uint8 RecordHour;
uint8 RecordDate;
uint8 RecordMonth;
uint8 RecordHor1;
uint8 RecordVer1;
uint8 RecordHor2;
uint8 RecordVer2;
uint8 RecordHor3;
uint8 RecordVer3;
uint8 RecordHor4;
uint8 RecordVer4;
uint8 RecordForw;
uint8 RecordAlarmFlag;
uint8 RecordReserved0;
uint8 RecordReserved1;
}FlashRecord,*LPFlashRecord;
extern volatile uint8 ID[3];
extern volatile uint8 flash_buf[256];
extern volatile uint32 FlashCurrentWriteAddr,FlashCurrentReadAddr;
extern volatile FlashRecord AlarmDataRecord;
extern volatile uint8 FlashCurrentSector,FlashFormatEn;
uint8 RecordPackage( LPFlashRecord RData, LPUART485 UData, LPMONITDATA AData);
uint8 WriteRecord2Flash(LPFlashRecord RData);
uint8 ReadRecordFromFlash(LPFlashRecord RData);
uint8 SearchRecordIndex(void);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -