cy_en_sysclk_status_t Cy_SysClk_FllEnable(uint32_t timeoutus)
{
/* first set the CCO enable bit */
SRSS->unCLK_FLL_CONFIG4.stcField.u1CCO_ENABLE = 1ul;
/* Wait until CCO is ready */
while(SRSS->unCLK_FLL_STATUS.stcField.u1CCO_READY == 0ul)
{
if(timeoutus == 0ul)
{
/* If cco ready doesn't occur, FLL is stopped. */
Cy_SysClk_FllDisable();
return(CY_SYSCLK_TIMEOUT);
}
Cy_SysLib_DelayUs(1u);
timeoutus--;
}
/* Set the FLL bypass mode to 2 */
SRSS->unCLK_FLL_CONFIG3.stcField.u2BYPASS_SEL = (uint32_t)CY_SYSCLK_FLLPLL_OUTPUT_INPUT;
/* Set the FLL enable bit, if CCO is ready */
SRSS->unCLK_FLL_CONFIG.stcField.u1FLL_ENABLE = 1ul;
/* now do the timeout wait for FLL_STATUS, bit LOCKED */
while(SRSS->unCLK_FLL_STATUS.stcField.u1LOCKED == 0ul)
{
if(timeoutus == 0ul)
{
/* If lock doesn't occur, FLL is stopped. */
Cy_SysClk_FllDisable();
return(CY_SYSCLK_TIMEOUT);
}
Cy_SysLib_DelayUs(1u);
timeoutus--;
}
/* Lock occurred; we need to clear the unlock occurred bit.
Do so by writing a 1 to it. */
SRSS->unCLK_FLL_STATUS.stcField.u1UNLOCK_OCCURRED = 1ul;
/* Set the FLL bypass mode to 3 */
SRSS->unCLK_FLL_CONFIG3.stcField.u2BYPASS_SEL = (uint32_t)CY_SYSCLK_FLLPLL_OUTPUT_OUTPUT;
return(CY_SYSCLK_SUCCESS);
}