
/******************** (C) COPYRIGHT 2021 SONiX *******************************
* COMPANY:	SONiX
* DATE:		2021/12/21
* AUTHOR:		Roger
* IC:			SN8F5754
*____________________________________________________________________________
* REVISION		Date				User		Description
* 1.0					2021/12/21	Roger		1. First release
*____________________________________________________________________________
*****************************************************************************/
#define __XRAM_SFR_H__
/*_____ I N C L U D E S _____________________________________________________*/
#include <SN8F5754.h>
#include "ISP.h"
#include "crc.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[0x20] _at_ 0x3B00;

uint8_t baryDEMO_Data[32] = {11, 22, 33, 44, 55, 66, 77, 88}; /* byte(unsined char) array */

/*_____ 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;
#define	IO_PORT3_OUTPUT_LOW		P3M |= 0xFF;	P3 &= 0x00;

/**
 *	@Brief		main: ISP Test Demo Function
 *	@param		None
 *	@retval		None
 */
void main(void)
{	
	uint8_t	bISPsuccess;
	/*	Initialize GPIO status	*/
	GPIO_Initialization();	
  /*	Initializes and configures the CRC function	*/	
	CRC_Initialization(mskCRCM_POLY_CRC16, mskCRCM_RANGE_3FDD);
	
	/*	ISP Program with checksum verification	*/
	bISPsuccess = ISP_WritePage_CRC16Verify(&btabDATA_StorePage[0], &baryDEMO_Data[0]);	
	
	while(1)
	{
		WDTR=0x5A;	/* Reset Watchdog timer */
		if(bISPsuccess == 0)
		{
			OB_IO_OUTPUT_HIGH 	/* ISP Failed condition	*/
		}		
	}
}


/**
 *	@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
	IO_PORT3_OUTPUT_LOW
}


