/*******************************************************************************
* File Name          : md25d80.h
* Author             : frank
* Date               : 06/01/2017
* Description        : This file include micro and declare for md25d80.c
*******************************************************************************/
#ifndef MD25D80_H
#define MD25D80_H


#define CMD_WRITE_ENABLE 					(0x06)
#define CMD_WRITE_DISABLE 					(0x04)
#define CMD_READ_STATUS_REGISTER 			(0x05)
#define CMD_WRITE_STATUS_REGISTER 			(0x01)
#define CMD_READ_DATA_BYTES 				(0x03)
#define CMD_READ_DATA_BYTES_HIGH 			(0x0B)
#define CMD_DAUL_OUTPUT_FAST_READ 			(0x3B)
#define CMD_PAGE_PROGRAM					(0x02)
#define CMD_FAST_PAGE_PROGRAM				(0xF2)
#define CMD_SECTOR_ERASE					(0x20)
#define CMD_32K_BLOCK_ERASE					(0x52)
#define CMD_64K_BLOCK_ERASE					(0xD8)
#define CMD_CHIP_ERASE						(0x60)  // or 0xC7
#define CMD_DEEP_POWER_DOWN					(0xB9)
#define CMD_RELEASE_POWER_DOWN				(0xAB)
#define CMD_READ_DEVICE_ID					(0xAB)  // RES  - Old style of 8-bit Electronic Signature
#define CMD_READ_MANUFACTURE_ID				(0x90)  // REMS - (ManID, DevID)
#define CMD_READ_IDENTIFIACATION			(0x9F)  // RDID - jedic (ManID, MemType, MemDensity)


void MD25D80_ReadDeviceID(SPI_Typedef* SPIx, uint8_t *pBuf);
void MD25D80_ReadIdentification(SPI_Typedef* SPIx, uint8_t *pBuf);
void MD25D80_WriteEnable(SPI_Typedef* SPIx);
void MD25D80_WriteDisable(SPI_Typedef* SPIx);
void MD25D80_ReadStatusRegister(SPI_Typedef* SPIx, uint8_t *pBuf);
void MD25D80_WriteStatusRegister(SPI_Typedef* SPIx, uint8_t status);
void MD25D80_WriteData(SPI_Typedef* SPIx, uint32_t addr, uint8_t *pBuf, uint32_t len);
void MD25D80_ChipErase(SPI_Typedef* SPIx);
void MD25D80_4KB_SectorErase(SPI_Typedef* SPIx, uint32_t addr);
void MD25D80_64KB_BlockErase(SPI_Typedef* SPIx, uint32_t addr);
void MD25D80_32KB_BlockErase(SPI_Typedef* SPIx, uint32_t addr);
void MD25D80_ReadData(SPI_Typedef* SPIx, uint32_t addr, uint8_t *pBuf, uint32_t len);
void MD25D80_DebugWriteAndRead(SPI_Typedef* SPIx);
void Debug_WriteTestBinFileToMD25D80(SPI_Typedef* SPIx);
void Debug_LoadFlashToRam(SPI_Typedef* SPIx);
void MD25D80_ReadManufactureID(SPI_Typedef* SPIx, uint8_t *pBuf);
void MD25D80_PowerDown(SPI_Typedef* SPIx);
void MD25D80_ReleasePowerDown(SPI_Typedef* SPIx);
void MD25D80_SafeReadData(SPI_Typedef* SPIx, uint32_t addr, uint8_t *pBuf, uint32_t Length);
void MD25D80_SafeWriteData(SPI_Typedef* SPIx, uint32_t addr, uint8_t *pBuf, uint32_t Length);

extern char DebugTraceBuf[];
void ClearDebugTrace(void);
void AddDebugTrace(char *msg);
void PrintDebugTrace(void);

#endif //MD25D80_H
/*****************************END OF FILE****/
