
/******************** (C) COPYRIGHT 2021 SONiX *******************************
* COMPANY:	SONiX
* DATE:		2021/12/21
* IC:			SN8F5754
*____________________________________________________________________________
* REVISION		Date				Author		Description
* 1.0					2021/12/21	Roger			1. First release
*____________________________________________________________________________
*****************************************************************************/



/*_____ I N C L U D E S _________________________________*/
#define __XRAM_SFR_H__
#include <SN8F5754.h>
#include "ilrc_calibration.h"
/*_____ F U N C T I O N S _______________________________*/

void ILRC_SetAutoCalibration(void);
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 _________________________*/

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

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

void main(void)
{
	/*
	 *	(1) GPIO Initial
	 *	(2) ILRC Auto-Trim	Function
	 *  (3) Clear Watchdog Timer
	 */
		GPIO_Initialization();     																				/*	(1)	*/			
		ILRC_SetAutoCalibration();																				/*	(2)	*/
		while(1)
		{
			WDTR = 0x5A;																										/*	(3)	*/	
		}	
}

/**
 *  @Brief    initial GPIO status
 *  @param    None
 *  @return   None
 */
void GPIO_Initialization(void)
{
    IO_PORT0_OUTPUT_LOW
    IO_PORT1_OUTPUT_LOW
    IO_PORT2_OUTPUT_LOW
    IO_PORT3_OUTPUT_LOW       
}

/**
 *	@Brief		ILRC_Setautocalibration: ILRCCalibration Auto Trim Function
 *	@param		None
 *	@return		None
 */

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


