/******************** (C) COPYRIGHT 2021 SONiX *******************************
* COMPANY:	SONiX
* DATE:		2021/12/21
* AUTHOR:		SONiX
* IC:			SN8F5762
*____________________________________________________________________________
* REVISION		Date				User		Description
* 1.0					2022/04/11	SONiX		1. First release
*____________________________________________________________________________
*****************************************************************************/

/*_____ I N C L U D E S _________________________________*/
#include <SN8F5762.h>
#include "ISP.h"
/*_____ F U N C T I O N S _______________________________*/
void GPIO_Initialization(void);
/*_____ D E F I N I T I O N S ___________________________*/

/*_____ D E C L A R A T I O N S _________________________*/
code uint8_t btabDATA_StorePage[32] _at_ 0x3B00;

uint8_t baryDEMO_Data[32] = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 
                             0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF}; /* byte(unsined char) array */
uint8_t	bResultData[32] = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 
                             0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF};	/* the result for checking whether ISP worked success or not */



/*_____ M A C R O S _____________________________________*/
#define OB_IO_OUTPUT_LOW   		P00=0;  P0M |=0x01; 
#define OB_IO_OUTPUT_HIGH 		P00=1;  P0M |=0x01;

#define	IO_PORT0_OUTPUT_LOW		P0M |= 0xFF;	P0 &= 0x00;
#define	IO_PORT1_OUTPUT_LOW		P1M |= 0xFF;	P1 &= 0x00;
#define	IO_PORT2_OUTPUT_LOW		P2M |= 0xFF;	P2 &= 0x00;


/**
 *	@Brief		main: ISP Test Demo Function
 *	@param		None
 *	@retval		None
 */
void main(void)
{	
	uint8_t i;
	/*	Initialize GPIO status	*/
	GPIO_Initialization();	
	
	isp_page_write(&btabDATA_StorePage[0], &baryDEMO_Data[0]);	/*	ISP Main Function	*/
	
	//ISP_CompareRomData
	for(i=0; i<sizeof(bResultData); i++)
	{
		if(*(uint8_t*) (btabDATA_StorePage+i) != bResultData[i])
		{
			OB_IO_OUTPUT_HIGH /* Data compare failed	*/
		}
	}	
		

	while(1)
	{
		WDTR=0x5A;	/* Reset Watchdog timer */
	}
}


/**
 *	@Brief		Initialize GPIO status
 *	@param		None
 *	@retval		None
 */
void GPIO_Initialization(void)
{
	/*	Set whole IOs to output low	*/
	IO_PORT0_OUTPUT_LOW
	IO_PORT1_OUTPUT_LOW
	IO_PORT2_OUTPUT_LOW

}



