/******************************************************************************
File: Flash_API_R8C.h

CPU Re-write functions for R8C.
Version 2.4

// doplnen typ R8C/33A							 
******************************************************************************/

#ifndef __FLASH_API_R8C_H
#define __FLASH_API_R8C_H


#include "../hwinit.h"					// pro definici f1_CLK_SPEED


void FlashEraseEW1( void );
void FlashWriteEW1(void);
tUInt FlashErase( void );
tUInt FlashWrite( void );
tUInt BootEraseDF(void);

// chybove kody pri flashovani
#define FLASH_WRITE_OK 		0x00
#define FLASH_WRITE_FAILED 	0x01
#define FLASH_UNCLEARED	  	0x02
#define FLASH_ERR_FWE 		0x03
#define FLASH_ERR_FLER 		0x04

// chybove kody pri mazani
#define FLASH_ERASE_OK 		0x05
#define FLASH_ERASE_FAILED	0x06
#define FLASH_ERR_CMD		0x07


// stav FLASH 
#define BLANK 				0x00
#define NOT_BLANK 			0x01

/******************************************************************************/
// definice pametovych bloku pro R8C/33
/******************************************************************************/

	//1KB x 4 Data Block Area 
	#define DF_BLOCK_A_START	0x3000	// oblast 1kB R/W - pro promene aplikaci - chova se jako EEPROM
	#define DF_BLOCK_A_END		0x33FF 

	#define DF_BLOCK_B_START	0x3400	// oblast 1kB pouze READ - pro ulozeni HW konstant - seriove cislo atd..
	#define DF_BLOCK_B_END		0x37FF 

	#define DF_BLOCK_C_START	0x3800	// tady se nahravaji flashovaci rutiny pro E8a-FDT
	#define DF_BLOCK_C_END		0x3BFF

	#define DF_BLOCK_D_START	0x3C00
	#define DF_BLOCK_D_END		0x3FFF 


	//32KB ROM Area 
	#define FLASH_BLOCK_0_START	0xF000
	#define FLASH_BLOCK_0_END	0xFFFF 		//4KB
    
	#define FLASH_BLOCK_1_START	0xE000		//4KB
	#define FLASH_BLOCK_1_END	0xEFFF 
    
	#define FLASH_BLOCK_2_START	0xC000		//8KB
	#define FLASH_BLOCK_2_END	0xDFFF
	
	#define FLASH_BLOCK_3_START	0x8000		//16KB
	#define FLASH_BLOCK_3_END	0xBFFF
	

    /* User Block Area */
    #define BLOCK_0 	0	/*   4KB: F000 - 0FFFF */
    #define BLOCK_1		1	/*   4KB: E000 - 0EFFF */
    #define BLOCK_2 	2	/*   8KB: C000 - 0DFFF */
    #define BLOCK_3 	3	/*  16KB: 8000 - 0BFFF */

	/* 1KB x 4 Data Block Area */
    #define BLOCK_A 	4	/* 1KB: 3000 - 33FF */
    #define BLOCK_B 	5	/* 1KB: 3400 - 37FF */
    #define BLOCK_C 	6	/* 1KB: 3800 - 3BFF */
    #define BLOCK_D 	7	/* 1KB: 3C00 - 3FFF */


#endif /* _FLASH_API_H (END OF FILE) */
