/******************** (C) COPYRIGHT 2021 SONiX *******************************
* COMPANY:	SONiX
* DATE:		2022/04/11
* IC:			SN8F5762
*____________________________________________________________________________
* REVISION		Date				Author		Description
* 1.0					2021/04/11	SONiX			1. First release
*____________________________________________________________________________
*****************************************************************************/
/*_____ I N C L U D E S _________________________________*/
#include <SN8F5762.h>
#include "int.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 _________________________*/
uint8_t bGPIO_ReadDataBuf;

/*_____ M A C R O S _____________________________________*/
#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 OB_IO_OUTPUT_LOW   		P10=0;  P1M |=0x01; 
#define OB_IO_OUTPUT_HIGH 		P10=1;  P1M |=0x01;

#define INT0_PIN_INPUT				P0M &= 0xFE;


/**
 *	@Brief		main: INT Test Demo Function
 *	@param		None
 *	@retval		None
 */

void main(void)
{
	/*	Initialize GPIO status	*/
	GPIO_Initialization();
	
	/*	Initializes and configures the INT0 function
			(1) Set INT0 IO to input mode for capture external signal
			(2) Set INT0 trigger edge to falling edge
	    (3) Set INT0 IO select pin
			(4)	Clear INT0 ISR flag	*/
	INT0_PIN_INPUT															/*	(1)	*/
	PEDGE |= mskPEDGE_INT0_FALLINGEDGE;				  /*	(2)	*/
  PEDGE |= mskPEDGE_INT0_IO;                  /*	(3)	*/
	TCON &=	~mskTCON_INT0_FLAG;									/*	(4)	*/
	
	/*	Enable INT0 interrupt and global interrupt	*/
	IEN0 |= mskIEN0_INT0_INT_ENABLE;
	EAL = 1;

	while(1)
  {
    /*  wait for external interrupt  */
		P01 ^= 1;
  }

}


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


/**
 *	@Brief		ISR_Int0
 *						External interrupt INT0 interrupt service routine
 */
void ISR_Int0(void) interrupt ISRInt0
{		
	 /*	Observe the IO toggle to represent INT0 interrupt was execute	*/
	OB_IO_OUTPUT_HIGH
	OB_IO_OUTPUT_LOW

}