/*
 * SPI_Flash.h
 *
 *  Created on: Nov 8, 2011
 *      Author: RomanM
 */

#ifndef SPI_FLASH_H_
#define SPI_FLASH_H_

#define	FLASH_IS_BUSY()	(SPI_Flash_ReadStatus() & 0x01)

typedef struct {
	uint8_t ManufacturerID	: 8;
	uint8_t	DensityCode		: 5;
	uint8_t FamilyCode		: 3;
	uint8_t ProductVersion	: 5;
	uint8_t SubCode			: 3;
} SPI_Flash_InfoStruct_t;

void SPI_Flash_Init(void);

void SPI_Flash_WriteEnable(void);
void SPI_Flash_WriteDisable(void);
void SPI_Flash_ProtectSector(uint32_t address);
void SPI_Flash_UnprotectSector(uint32_t address);
uint8_t SPI_Flash_ReadProtectionRegister(uint32_t address);

uint8_t SPI_Flash_ReadStatus(void);
void SPI_Flash_WriteStatus(uint8_t data);

SPI_Flash_InfoStruct_t SPI_Flash_ReadInfo(void);

void SPI_Flash_BlockErase4kB(uint32_t address);
void SPI_Flash_BlockErase32kB(uint32_t address);
void SPI_Flash_BlockErase64kB(uint32_t address);
void SPI_Flash_ChipErase(void);

void SPI_Flash_ReadData(uint32_t address, uint8_t *inBuff, uint8_t n);
void SPI_Flash_ReadData_LowFreq(uint32_t address, uint8_t *inBuff, uint8_t n);
void SPI_Flash_WriteData(uint32_t address, uint8_t *outBuff, uint8_t n);

#endif /* SPI_FLASH_H_ */
