#ifndef _EKBOOSTLOAD_H_
#define _EKBOOSTLOAD_H_

//////////////////////////////
//  Supported Device Table //
//////////////////////////////
//  PART    FLASH    //
//**************************//
// 16F877      8 K         //
// 16F876      8 K         //
// 16F874      4 K         //
// 16F873      4 K         //
// 16F871      2 K         //
// 16F870      2 K         //
//////////////////////////////

//Adjust CLOCK_SPEED to match your target.
#define CLOCK_SPEED 20000000
//Set Part Type
#define _16F877   1

#if defined( _16F877 ) || defined( _16F876 )
#define BOOTLOAD_START  0x1E00   
#elif defined( _16F874 ) || defined( _16F873 )
#define BOOTLOAD_START  0x0E00   
#elif defined( _16F871 ) || defined( _16F870 )
#define BOOTLOAD_START  0x0600   
#endif

#define BOOTLOAD_JUMP   BOOTLOAD_START+1
#define BL_JUMP_HIBYTE  ( ( BOOTLOAD_JUMP >> 8 ) & 0x00FF )
#define BL_JUMP_LOBYTE  ( BOOTLOAD_JUMP & 0x00FF )

#if( CLOCK_SPEED == 20000000 )
#define  BR_CONST 129
#elif( CLOCK_SPEED == 10000000 )
#define BR_CONST  64
#elif( CLOCK_SPEED == 4000000 )
#define BR_CONST  25
#endif

//Software Flow Control Definitions
#define XON    17//Resume
#define XOFF   19//Pause 

void serial_init( );
void write_flash( unsigned char hiAddr, unsigned char loAddr, unsigned char hiData, unsigned char loData );
unsigned char read_flash( unsigned char hiAddr, unsigned char loAddr, unsigned char hiByte );
unsigned char ascii2byte(unsigned char hiNibble, unsigned char loNibble);
unsigned char serial_getbyte( );
void serial_putchar( unsigned char cByte );

unsigned char g_CommTimeOut;

#endif //_EKBOOSTLOAD_H_