#ifndef __W25QXX_H
#define __W25QXX_H

#include "main.h"

//W25X系列/Q系列芯片列表	ID码   
#define W25Q80 	0xEF13 	
#define W25Q16 	0xEF14
#define W25Q32 	0xEF15
#define W25Q64 	0xEF16
#define W25Q128	0xEF17
#define W25Q256 0xEF18

#define 	W25Q128_FLASH_SIZE 			0x01000000
#define 	W25Q128_ADDR_BIT_NUM 		24

#define 	NOR_FLASH_SIZE 					W25Q128_FLASH_SIZE
#define 	NOR_PAGE_SIZE 					0x100

extern unsigned short W25QXX_TYPE;					//定义W25QXX芯片型号		   
 
////////////////////////////////////////////////////////////////////////////////// 
//指令表
#define W25Qx_CMD_Reset_Enble    		0x66
#define W25Qx_CMD_Reset_Memory   		0x99

#define W25Qx_CMD_ManufactDeviceID 	0x90

#define W25Qx_CMD_ReadStatusReg1 		0x05
#define W25Qx_CMD_ReadStatusReg2 		0x35
#define W25Qx_CMD_ReadStatusReg3 		0x15
#define W25Qx_CMD_WriteStatusReg1 	0x01
#define W25Qx_CMD_WriteStatusReg2 	0x31
#define W25Qx_CMD_WriteStatusReg3 	0x11

#define W25Qx_CMD_WriteEnable 			0x06
#define W25Qx_CMD_WriteDisable 			0x04

#define W25Qx_CMD_ChipErase 				0x60
#define W25Qx_CMD_SectorErase_4K 		0x20
#define W25Qx_CMD_SectorErase_32K		0x52
#define W25Qx_CMD_SectorErase_64K		0xD8
#define W25Qx_CMD_Quad_PageProgram	0x32
#define W25Qx_CMD_Quad_Read 				0x6B

/*
#define W25X_WriteEnable			0x06 
#define W25X_WriteDisable			0x04 

#define W25X_ReadStatusReg1		0x05 
#define W25X_ReadStatusReg2		0x35 
#define W25X_ReadStatusReg3		0x15 
#define W25X_WriteStatusReg1  0x01 
#define W25X_WriteStatusReg2  0x31 
#define W25X_WriteStatusReg3  0x11 

#define W25X_ReadData					0x03 
#define W25X_FastReadData			0x0B 
#define W25X_FastReadDual			0x3B 
#define W25X_FastReadQuad			0x6B 
#define W25X_PageProgram			0x32 
#define W25X_BlockErase				0xD8 
#define W25X_SectorErase			0x20 
#define W25X_ChipErase				0x60 
#define W25X_PowerDown				0xB9 
#define W25X_ReleasePowerDown	0xAB 
#define W25X_DeviceID					0xAB 
#define W25X_ManufactDeviceID	0x90 
#define W25X_JedecDeviceID		0x9F 
#define W25X_Enable4ByteAddr  0xB7
#define W25X_Exit4ByteAddr    0xE9
#define W25X_EnterQPIMode     0x38
#define W25X_ExitQPIMode      0xFF
*/

extern unsigned short norflash_get_busy_flag[2];
extern unsigned short norflash_err_flag[2];

extern void W25QXX_Init(void);
extern void W25QXX_Qspi_Enable(void);
extern void W25QXX_Qspi_Disable(void);
extern unsigned short  W25QXX_ReadID(void);
extern unsigned char W25QXX_ReadSR(unsigned char regno);
extern void W25QXX_Write_SR(unsigned char regno,unsigned char sr); 
extern void W25QXX_Write_Enable(void); 
extern void W25QXX_Write_Disable(void);
extern void W25QXX_Write_NoCheck(unsigned char* pBuffer,unsigned int WriteAddr,unsigned short NumByteToWrite);//写flash,不校验
extern void W25QXX_Read(unsigned char* pBuffer,unsigned int ReadAddr,unsigned short NumByteToRead); 
extern void W25QXX_Write(unsigned char* pBuffer,unsigned int WriteAddr,unsigned short NumByteToWrite);
extern void W25QXX_Write_Byte_no_wait(unsigned char* pBuffer,unsigned int WriteAddr,unsigned short NumByteToWrite);
extern void W25QXX_Erase_Chip(void);
extern void W25QXX_Erase_Chip_no_wait(void);
extern void W25QXX_Erase_Sector(unsigned int addr);
extern void W25QXX_Erase_Sector_4k_no_wait(unsigned int addr);
extern void W25QXX_Erase_Sector_32k_no_wait(unsigned int addr);
extern void W25QXX_Erase_Sector_64k_no_wait(unsigned int addr);
extern void W25QXX_Wait_Busy(void);   
extern void W25QXX_Reset(void);

#endif
