#ifndef _SPI_FLASH_H_
#define _SPI_FLASH_H_  1

#include "stm32f4xx.h"

//Dataflash指令表
#define Cmd_DF_PageRead      	0xD2
#define Cmd_DF_Buffer1Read      0xD1
#define Cmd_DF_Buffer2Read      0xD3
#define Cmd_DF_WriteBuffer1     0x84
#define Cmd_DF_WriteBuffer2     0x87
#define Cmd_DF_Buffer1ToPage  	0x83
#define Cmd_DF_Buffer2ToPage  	0x86
#define Cmd_DF_PageErase        0x81
#define Cmd_DF_BlockErase       0x50
#define Cmd_DF_SectorErase      0x7C
#define Cmd_DF_AllErase         0xC7
#define Cmd_DF_ReadState        0xD7
#define Cmd_DF_ReadID           0x9F

#define Dummy_Byte	 			0xA5

/* Select SPI FLASH: ChipSelect pin low  */
#define Select_Flash()      GPIO_ResetBits(GPIOB,GPIO_Pin_12)
/* Deselect SPI FLASH: ChipSelect pin high */
#define NotSelect_Flash()    GPIO_SetBits(GPIOB,GPIO_Pin_12)

typedef enum
{
	SPI_NONE=0,
	SPI_SUCCESS,
	SPI_ERROR,
	SPI_OVERTIME
}SPI_FLASH_DEFINED;

void sFlash_Init(void);	//SPI初始化
u8 sFlash_ReadByte(void);		//flash操作基本函数，读一个字节
u8 sFlash_SendByte(u8 byte);		//	FLASH操作基本函数，发送一个字节
void sFlashPageEarse(u16 page);	//擦除指定的页,页范围0-4095

void sFlashPageRead(u16 page,u8 *Data);		//读取整页，页范围0-4095
void sFlashPageWrite1(u16 page,u8 *Data);		//写一整页，页范围0-4095
void sFlashPageWrite2(u16 page, u8 * Data);

//void sFlashWaitBusy(void);			//Flash忙检测
u8 sFlashWaitBusy(void);			//Flash忙检测20140329
void sFlashReadID(u8 *ProdustID);		//读取flashID四个字节
u8 sFlashReadState(void);	
void sFlashModity512bytes(void);
void sFlashMultiRead(u8 *buf,u32 addr,u16 page_len);
#endif
