/*
* 文件名：w25qxx.h
* 功能  ：驱动 WINBOND W25N01GV
* 作者  ：LEVETOP
*/

#ifndef __W25N01_H
#define __W25N01_H

#include "stdint.h"
#include "flash_drv.h"
#include "ssi_reg.h"


//      W25N01GV  容量为 1G-Bit，1024 Block，33280 Page
#define  NandPageSize     (2048)          	//one Page =2KB (Program)
#define  NandBlockSize    (64*2048)         //one Block=128KB (Erase)

//----------------------------------------------------------------Instruction--------------------------------------------------------------------------- 
#define W25_DEVICE_ID     0XEFAA21
#define W25N01GV_ID             0x9f
#define W25N01GV_ReadStatusReg  0x0f//0x05
#define W25N01GV_WriteStatusReg 	0x1f//0x01  
#define W25N01GV_SR1  0xA0  
#define W25N01GV_SR2  0xB0
#define W25N01GV_SR3  0xC0
#define W25N01GV_PageDataRead   0x13
#define W25N01GV_ReadData  		0x03
#define W25N01GV_WriteEnable    0x06
#define W25N01GV_WriteDisable   0x04
#define W25N01GV_FastReadDual     	0x3b
#define W25N01GV_FastReadDualIO   	0xbb
#define W25N01GV_LoadProgramData 	0x02
#define W25N01GV_ProgramExecute  	0x10
#define W25X_BlockErase32KB			0x52
#define W25N01GV_128KBlockErase  	0xD8

/*************************************************************** winbond NandFlash **********************************************************************/
//status register
UINT8 LT_W25N01GV_ReadSR(UINT8 reg);
void  LT_W25N01GV_Write_SR(UINT8 reg, UINT8 val);
void LT_W25N01GV_Wait_Busy(void);
void LT_W25N01GV_Write_Enable(void);
void LT_W25N01GV_Write_Disable(void);
void W25N01GV_ContinuousRead_Mode(void);
void W25N01GV_BufferRead_Mode(void);
UINT32 LT_W25N01GV_ReadID(void);

//Init
void W25N01GV_Init(void);

//erase
void LT_W25N01GV_BlockErase128KB(UINT32 addr);

/*--------------------------BufferRead_Mode-----------------------------------*/
//STD_Read_Mode 
void LT_W25N01GV_PageDataRead(UINT32 PageNum);
void LT_W25N01GV_Read(UINT8* pBuffer,UINT32 ReadAddr,UINT16 NumByteToRead);					/*STD_Read_Mode*/
void Nand_LT_W25N01GV_DMA_PageRead(SSI_TypeDef *SSIx,UINT8* pread,UINT32 length);		/*STD_DMA_Read_Mode*/

//STD_Write_Mode 
void LT_W25N01GV_STD_DMA_Send(SSI_TypeDef *SSIx,UINT8* psend,UINT16 Column,UINT32 length);
void LT_W25N01GV_Write_Page(UINT8* pBuffer,UINT16 page,UINT16 column,UINT16 NumByteToWrite);
void LT_W25N01GV_Write(UINT8* pBuffer,UINT32 WriteAddr,UINT16 NumByteToWrite);

//-----------------Dual_Mode-----------
/*Dual_Read_Mode*/
void NandFlash_Read_Init(UINT8 command_num,UINT8 addr_bits_num, UINT8 waitCycles,UINT32 data_len);
void NandFlash_Read(u16 page, u16 column, UINT8 *buf, UINT32 num);             
/*Dual_DMA_Read_Mode*/
void NandFlash_DMA_Read_Init(UINT8 command_num,UINT8 addr_bits_num, UINT8 waitCycles,UINT32 data_len);
void NandFlash_DMA_Read(UINT16 page,UINT16 column,UINT8* buff,UINT16 data_len);
void NandFlash_DMA_Wait(void);


/*------------------------ContinuousRead_Mode--------------------------------*/
//None


#endif 
