/******************** (C) COPYRIGHT 2021 SONiX *******************************
* COMPANY:	SONiX
* DATE:		2022/04/11
* IC:			SN8F5858
*____________________________________________________________________________
* REVISION		Date				AUTHOR		Description
* 1.0					2022/04/11	SONiX			1. First release
*____________________________________________________________________________
*****************************************************************************/
/*_____ I N C L U D E S _________________________________*/

#include <SN8F5762.h>
#include "timer.h"
/*_____ F U N C T I O N S _______________________________*/
void GPIO_Initialization(void);
void TIMER0_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 _________________________*/

/*_____ 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   		P00=0;  P0M |=0x01; 
#define OB_IO_OUTPUT_HIGH 		P00=1;  P0M |=0x01;

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

void main(void)
{
	/*	Initialize GPIO status	*/
	GPIO_Initialization();
	TIMER0_Initialization();  

		while(1)
		{	 
      //P01 = 0;          // TEST IO
			IDLE()            //** into IDLE mode  	
			//P01 = 1;          // TEST IO
		}

}

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

void TIMER0_Initialization(void)
{
	/*
	 *	(1) Set Timer0 Mode2 (8-bit Auto-Reload Timer) And IHRC As Timer0 Source
	 *	(2) Set	TL0 Overflow Value
	 *	(3)	Set	TH0 Overflow Value
	 *	  
	 */		
		TMOD |= (mskTMOD_T0_MODE2|mskTMOD_T0CT);			/*	(1)	*/
		TH0 = TH0_VALUE;            									/*	(2)	*/
    TL0 = TH0_VALUE;            									/*	(3)	*/	
		TCON0 |= mskTCON0_T0_DIV128; 
	  IEN0 |= mskIEN0_ET0;  									
		EAL =	1;																	
		TCON |=	mskTCON_TR0;										

}

void ISR_Timer0(void) interrupt ISRTimer0	using 3
{
	OB_TEST_PIN ^=  1;														/*	Timer0 ISR Test Pin	Toggle	*/ 
}
