/* Waiting for clock source ready */
CLK_WaitClockReady(CLK_CLKSTATUS_OSC10K_STB_Msk|CLK_CLKSTATUS_OSC22M_STB_Msk|CLK_CLKSTATUS_XTL12M_STB_Msk);
/* Disable PLL first to avoid unstable when setting PLL */
CLK_DisablePLL();
/* Set PLL frequency */
CLK->PLLCON = (CLK->PLLCON & ~(0x000FFFFFul)) | 0x00004217ul;
/* Waiting for PLL ready */
CLK_WaitClockReady(CLK_CLKSTATUS_PLL_STB_Msk);
/* If the defines do not exist in your project, please refer to the related clk.h in the clk_h folder appended to the tool package. */
/* Set HCLK clock */
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_PLL, CLK_CLKDIV_HCLK(1));
/* Enable IP clock */
CLK_EnableModuleClock(ISP_MODULE);
CLK_EnableModuleClock(TMR0_MODULE);
//CLK_EnableModuleClock(UART0_MODULE);
CLK_EnableModuleClock(UART1_MODULE);
/* Set IP clock */
CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0_S_HXT, MODULE_NoMsk);
//CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_PLL, CLK_CLKDIV_UART(1));
CLK_SetModuleClock(UART1_MODULE, CLK_CLKSEL1_UART_S_PLL, CLK_CLKDIV_UART(1));
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */
SystemCoreClockUpdate();
/* Lock protected registers */
SYS_LockReg();
}
void IP_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init TIMER Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Open Timer0 frequency to 1 Hz in periodic mode, and enable interrupt */
TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 100);
TIMER_EnableInt(TIMER0);
/* Configure UART1 and set UART1 Baudrate */
UART_Open(UART1, 9600);
/* Set RS485-Master as AUD mode */
/* Enable AUD mode to HW control RTS pin automatically */
/* You also can use GPIO to control RTS pin for replacing AUD mode*/
UART_SelectRS485Mode(UART1, UART_ALT_CSR_RS485_AUD_Msk, 44);
/* Set RTS pin active level as high level active */
UART1->MCR &= ~UART_MCR_LEV_RTS_Msk;
UART1->MCR |= UART_RTS_IS_HIGH_LEV_ACTIVE;
/* Set UART parity as SPACE and ship baud rate setting */
UART_SetLine_Config(UART1, 0, UART_WORD_LEN_8, UART_PARITY_NONE, UART_STOP_BIT_1);