#ifndef _XPERIPHSP6_LOADER_H
#define _XPERIPHSP6_LOADER_H

typedef union{
	unsigned int all;
	struct{
		unsigned int loader_on:1;
		unsigned int cs:1;
		unsigned int reserved0:2;
		unsigned int rw:1;
		unsigned int mode:1; 
		unsigned int reserved1:1;
		unsigned int data:1;
    	unsigned int reserved2:1;
		unsigned int clock:1;
		unsigned int reserved3:1;
		unsigned int plane_addr:4;
		unsigned int eeprom_read:1;
	}bit;
}ControlReg; 


typedef union{
	unsigned long all;
	struct{
		unsigned int addr0:8;
		unsigned int addr1:8;
		unsigned int addr2:8;
		unsigned int reserved:8;
	}bit;
}FlashAddr;

typedef union{
	unsigned long all;
	struct{
		unsigned int reserved:16;
		unsigned int reserved1:15;
		unsigned int data:1;
	}bit;
}AddrToSent;
 

typedef union{
	unsigned int all;
	struct{
		unsigned int reserved0:8;
		unsigned int dataReceived:1;
		unsigned int reserved1:6;
		unsigned int data:1;
	}bit;
}Byte;

typedef union{
	unsigned int all;
	struct{		
		unsigned int dataReceived:1;
		unsigned int reserved1:14;
		unsigned int data:1;
	}bit;
}Word;

typedef union{
	unsigned int all;
	struct{		
		unsigned int bit0:1;
		unsigned int bit1:1;
		unsigned int bit2:1;
		unsigned int bit3:1;

		unsigned int bit4:1;
		unsigned int bit5:1;
		unsigned int bit6:1;
		unsigned int bit7:1;

		unsigned int bit8:1;
		unsigned int bit9:1;
		unsigned int bit10:1;
		unsigned int bit11:1;

		unsigned int bit12:1;
		unsigned int bit13:1;
		unsigned int bit14:1;
		unsigned int bit15:1;

	}bit;
}WordToReverse;

typedef union{
	unsigned int all;
	struct{		
		unsigned int bit0:1;
		unsigned int bit1:1;
		unsigned int bit2:1;
		unsigned int bit3:1;

		unsigned int bit4:1;
		unsigned int bit5:1;
		unsigned int bit6:1;
		unsigned int bit7:1;

		unsigned int bit8:1;
		unsigned int bit9:1;
		unsigned int bit10:1;
		unsigned int bit11:1;

		unsigned int bit12:1;
		unsigned int bit13:1;
		unsigned int bit14:1;
		unsigned int bit15:1;
	}bit;
}WordReversed;



void memWrite (unsigned int adr_device, volatile unsigned long adr, 
               volatile unsigned long adr_eeprom, volatile unsigned long size, unsigned long *ok_write, 
               unsigned long *write_error, unsigned long *repeat_error );


void RDID(void);
void RDSR(void);
void WREN(void);
void WRDI(void);
void WRSR(void);
void RDSR(void);
void ERASE(void);
void READ(void);
void PROGRAM(void);



#endif

