
/******************** (C) COPYRIGHT 2021 SONiX *******************************
* COMPANY:	SONiX
* DATE:		2022/04/12
* IC:			SN8F5762
*____________________________________________________________________________
* REVISION		Date				Author		Description
* 1.0					2022/04/12	SONiX			1. First release
*____________________________________________________________________________
*****************************************************************************/
/*_____ I N C L U D E S _________________________________*/
#include <SN8F5762.h>
#include "ilrc_calibration.h"

/*_____ F U N C T I O N S _______________________________*/
void GPIO_Initialization(void);
void ILRC_SetAutoCalibration(void);
/*_____ D E F I N I T I O N S ___________________________*/

/*_____ D E C L A R A T I O N 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;

/*_____ M A C R O S _____________________________________*/

/**
 *	@Brief		main: WDT Test Demo Function
 *	@param		None
 *	@return		None
 */

void main(void)
{  
		GPIO_Initialization();     										/*	GPIO	Initial	*/	
//	  P01 =1;                                      // TEST IO for ILRC calibration
	  ILRC_SetAutoCalibration();
//	  P01 =0;                                      // TEST IO for ILRC calibration
	  WDTR = 0x5A;
		while(1)
		{
			/*  Set OPTIONS_SN8F5858 -> Watchdog Reset as Enable 
					Clear Watchdog Timer	                          */		
			WDTR = 0x00;                                 //0x5A will clear watchdog timer, others will trigger WDT reset
//			P00 =1;                                    // TEST IO for WDT
//			P00 =0;                                    // TEST IO for WDT
		}
}

void GPIO_Initialization(void)
{
	/*	Set whole IOs to output low	*/
	IO_PORT0_OUTPUT_LOW
	IO_PORT1_OUTPUT_LOW
	IO_PORT2_OUTPUT_LOW
}

void ILRC_SetAutoCalibration(void)
{
	/*
   *	Auto-Calibration Command:
	 *	(1) Enable	ILRC Auto-Calibration Function
	 *	(2) Execute ILRC Calibration
	 *  (3) Waiting For ILRC Calibration Done 
	 */
		CLKCAL = mskCLKCAL_CALEN;																						/*	(1)	*/ 
		FRQCMD = mskFRQCMD_EXRCUTED_ILRC_AUTO_TRIM;													/*	(2)	*/  
		while(CLKCAL & mskCLKCAL_CALEN);														  			/*	(3)	*/

}
