PSoC 4 Peripheral Driver Library - Alpha

General Description

Functions

cy_en_sysclk_status_t Cy_SysClk_PllSetSource (uint32_t pllNum, cy_en_sysclk_pll_src_t source)
 Selects the PLL reference clock of the selected ClkHf. More...
 
__STATIC_INLINE cy_en_sysclk_pll_src_t Cy_SysClk_PllGetSource (uint32_t pllNum)
 Returns the clock source of the specified PLL. More...
 
cy_en_sysclk_status_t Cy_SysClk_PllConfigure (uint32_t pllNum, const cy_stc_sysclk_pll_config_t *config)
 Configures a given PLL. More...
 
cy_en_sysclk_status_t Cy_SysClk_PllManualConfigure (uint32_t pllNum, const cy_stc_sysclk_pll_manual_config_t *config)
 Manually configures a PLL based on user inputs. More...
 
cy_en_sysclk_status_t Cy_SysClk_PllEnable (uint32_t pllNum, uint32_t timeoutUs)
 Enables the PLL. More...
 
void Cy_SysClk_PllGetConfiguration (uint32_t pllNum, cy_stc_sysclk_pll_manual_config_t *config)
 Reports configuration settings for a PLL. More...
 
uint32_t Cy_SysClk_PllGetFrequency (uint32_t pllNum)
 Reports the output frequency of the specified PLL. More...
 
__STATIC_INLINE bool Cy_SysClk_PllIsEnabled (uint32_t pllNum)
 Reports whether or not the selected PLL is enabled. More...
 
__STATIC_INLINE bool Cy_SysClk_PllIsLocked (uint32_t pllNum)
 Reports whether or not the selected PLL is locked. More...
 
__STATIC_INLINE void Cy_SysClk_PllBypass (uint32_t pllNum, cy_en_sysclk_pll_bypass_t mode)
 Sets PLL bypass mode. More...
 
__STATIC_INLINE cy_en_sysclk_pll_bypass_t Cy_SysClk_PllGetBypassState (uint32_t pllNum)
 Returns the PLL bypass state. More...
 
__STATIC_INLINE bool Cy_SysClk_PllLostLock (uint32_t pllNum)
 Reports whether or not the selected PLL lost its lock since the last time this function was called. More...
 
__STATIC_INLINE void Cy_SysClk_PllDisable (uint32_t pllNum)
 Disables the selected PLL. More...
 

Function Documentation

◆ Cy_SysClk_PllSetSource()

cy_en_sysclk_status_t Cy_SysClk_PllSetSource ( uint32_t  pllNum,
cy_en_sysclk_pll_src_t  source 
)

Selects the PLL reference clock of the selected ClkHf.

Parameters
pllNumthe number of PLL instance, starting from 0. If there is only one PLL in device - the 0 is the only valid number.
sourcecy_en_sysclk_pll_src_t
Returns
Error / status code cy_en_sysclk_status_t :
CY_SYSCLK_SUCCESS - the PLL reference clock source is selected
CY_SYSCLK_INVALID_STATE - the PLL reference clock source is not enabled
CY_SYSCLK_BAD_PARAM - some input parameter is invalid
Note
Call SystemCoreClockUpdate after this function calling if ClkSys frequency is affected.
Call Cy_SysLib_SetWaitStates before this function calling if ClkSys frequency is increasing.
Call Cy_SysLib_SetWaitStates after this function calling if ClkSys frequency is decreasing.
Function Usage
/* Scenario: PLL needs to source HFCLK0, which must operate at 100 MHz.
The IMO sources the PLL at 8MHz. Startup time is not an issue
and manual configuration of the PLL is not needed. */
{
/*.inputFreq =*/ 24000000UL, /* PLL input: 24 MHz IMO */
/*.outputFreq =*/ 36000000UL /* PLL output: 36 MHz */
};
{
/* Set the PLL source to be the IMO. */
{
/* Insert error handling */
}
}
/* Configure PLL0 with the settings in pllConfig struct */
if (CY_SYSCLK_SUCCESS != Cy_SysClk_PllConfigure(0UL, &pllConfig))
{
/* Insert error handling */
}
/* Enable the PLL0 with 2000 microsecond timeout */
{
/* Insert error handling */
}

◆ Cy_SysClk_PllGetSource()

__STATIC_INLINE cy_en_sysclk_pll_src_t Cy_SysClk_PllGetSource ( uint32_t  pllNum)

Returns the clock source of the specified PLL.

Parameters
pllNumthe number of PLL instance, starting from 0. If there is only one PLL in device - the 0 is the only valid number. For other pllNum values the default CY_SYSCLK_PLL_SRC_ECO value is returned.
Function Usage
/* Scenario: PLL needs to source HFCLK0, which must operate at 100 MHz.
The IMO sources the PLL at 8MHz. Startup time is not an issue
and manual configuration of the PLL is not needed. */
{
/*.inputFreq =*/ 24000000UL, /* PLL input: 24 MHz IMO */
/*.outputFreq =*/ 36000000UL /* PLL output: 36 MHz */
};
{
/* Set the PLL source to be the IMO. */
{
/* Insert error handling */
}
}
/* Configure PLL0 with the settings in pllConfig struct */
if (CY_SYSCLK_SUCCESS != Cy_SysClk_PllConfigure(0UL, &pllConfig))
{
/* Insert error handling */
}
/* Enable the PLL0 with 2000 microsecond timeout */
{
/* Insert error handling */
}

◆ Cy_SysClk_PllConfigure()

cy_en_sysclk_status_t Cy_SysClk_PllConfigure ( uint32_t  pllNum,
const cy_stc_sysclk_pll_config_t config 
)

Configures a given PLL.

The configuration formula used is: Fout = pll_clk * (P / Q / div_out), where: Fout is the desired output frequency pll_clk is the frequency of the input source P is the feedback divider. Its value is in bitfield FEEDBACK_DIV. Q is the reference divider. Its value is in bitfield REFERENCE_DIV. div_out is the reference divider. Its value is in bitfield OUTPUT_DIV.

Parameters
pllNumthe number of PLL instance, starting from 0. If there is only one PLL in device - the 0 is the only valid number.
configThe pointer to a configuration structure cy_stc_sysclk_pll_config_t
Returns
Error / status code cy_en_sysclk_status_t :
CY_SYSCLK_SUCCESS - PLL successfully configured
CY_SYSCLK_INVALID_STATE - PLL not configured because it is already enabled
CY_SYSCLK_BAD_PARAM - One or more invalid parameters.
Note
In case of returning CY_SYSCLK_BAD_PARAM the function does not write anything into the configuration register, so either the previous correct configuration or the default configuration remains in the register.
Call this function after changing the PLL input frequency, for example if Cy_SysClk_ImoSetFrequency() or Cy_SysClk_PllSetSource() is called.
Do not call this function when the PLL is enabled. If it is called, then this function returns immediately with an error return value and no register updates.
Call SystemCoreClockUpdate after this function calling if it affects the CLK_HF0 frequency.
Call Cy_SysLib_SetWaitStates before calling this function if the PLL is the source of CLK_HF0 and the PLL frequency is increasing.
Call Cy_SysLib_SetWaitStates after calling this function if the PLL is the source of CLK_HF0 and the PLL frequency is decreasing.
Function Usage
/* Scenario: PLL needs to source HFCLK0, which must operate at 100 MHz.
The IMO sources the PLL at 8MHz. Startup time is not an issue
and manual configuration of the PLL is not needed. */
{
/*.inputFreq =*/ 24000000UL, /* PLL input: 24 MHz IMO */
/*.outputFreq =*/ 36000000UL /* PLL output: 36 MHz */
};
{
/* Set the PLL source to be the IMO. */
{
/* Insert error handling */
}
}
/* Configure PLL0 with the settings in pllConfig struct */
if (CY_SYSCLK_SUCCESS != Cy_SysClk_PllConfigure(0UL, &pllConfig))
{
/* Insert error handling */
}
/* Enable the PLL0 with 2000 microsecond timeout */
{
/* Insert error handling */
}

◆ Cy_SysClk_PllManualConfigure()

cy_en_sysclk_status_t Cy_SysClk_PllManualConfigure ( uint32_t  pllNum,
const cy_stc_sysclk_pll_manual_config_t config 
)

Manually configures a PLL based on user inputs.

Parameters
pllNumthe number of PLL instance, starting from 0. If there is only one PLL in device - the 0 is the only valid number.
configcy_stc_sysclk_pll_manual_config_t
Returns
Error / status code cy_en_sysclk_status_t :
CY_SYSCLK_SUCCESS - PLL successfully configured
CY_SYSCLK_INVALID_STATE - PLL not configured because it is already enabled
CY_SYSCLK_BAD_PARAM - One or more invalid parameters.
Note
In case of returning CY_SYSCLK_BAD_PARAM the function does not write anything into the configuration register, so either the previous correct configuration or the default configuration remains in the register.
Call this function after changing the PLL input frequency, for example if Cy_SysClk_ImoSetFrequency() or Cy_SysClk_PllSetSource() is called.
Do not call this function when the PLL is enabled. If it is called, then this function returns immediately with an error return value and no register updates.
Call SystemCoreClockUpdate after this function calling if it affects the CLK_HF0 frequency.
Call Cy_SysLib_SetWaitStates before calling this function if the PLL is the source of CLK_HF0 and the PLL frequency is increasing.
Call Cy_SysLib_SetWaitStates after calling this function if the PLL is the source of CLK_HF0 and the PLL frequency is decreasing.
Function Usage
/* Scenario: PLL needs to be manually reconfigured:
* the reference divider should be changed to 10.
*/
{
Cy_SysClk_PllBypass(0UL, CY_SYSCLK_PLL_OUTPUT_INPUT); /* Bypass the PLL0 */
}
/* Refer to the TRM for the full set of equations used to calculate the PLL settings */
pllConfig.referenceDiv = 10U;
/* Configure PLL0 with the settings in pllConfig structure */
{
/* Insert error handling */
}
/* Call PllEnable with zero timeout */
(void) Cy_SysClk_PllEnable(0UL, 0UL); /* Ignore the status - it always is success in case of zero timeout */
/* Check the status of the lock */
while (Cy_SysClk_PllIsLocked(0UL))
{
/* Perform other actions while the PLL is locking */
}
Cy_SysClk_PllBypass(0UL, CY_SYSCLK_PLL_OUTPUT_AUTO); /* Set auto-bypass mode */
uint32_t pllFreq = Cy_SysClk_PllGetFrequency(0UL);

◆ Cy_SysClk_PllEnable()

cy_en_sysclk_status_t Cy_SysClk_PllEnable ( uint32_t  pllNum,
uint32_t  timeoutUs 
)

Enables the PLL.

The PLL should be configured before calling this function.

Parameters
pllNumthe number of PLL instance, starting from 0. If there is only one PLL in device - the 0 is the only valid number.
timeoutUsamount of time in microseconds to wait for the PLL to lock. If the lock doesn't occur, PLL is stopped. To avoid waiting for lock, set this to 0 and manually check for lock using Cy_SysClk_PllIsLocked.
Returns
Error / status code cy_en_sysclk_status_t :
CY_SYSCLK_SUCCESS - PLL successfully enabled
CY_SYSCLK_TIMEOUT - Timeout waiting for PLL lock
CY_SYSCLK_BAD_PARAM - invalid clock path number
Note
Call SystemCoreClockUpdate after this function calling if it affects the CLK_HF0 frequency.
Call Cy_SysLib_SetWaitStates before calling this function if the PLL is the source of CLK_HF0 and the CLK_HF0 frequency is increasing.
Call Cy_SysLib_SetWaitStates after calling this function if the PLL is the source of CLK_HF0 and the CLK_HF0 frequency is decreasing.
Function Usage
/* Scenario: PLL needs to source HFCLK0, which must operate at 100 MHz.
The IMO sources the PLL at 8MHz. Startup time is not an issue
and manual configuration of the PLL is not needed. */
{
/*.inputFreq =*/ 24000000UL, /* PLL input: 24 MHz IMO */
/*.outputFreq =*/ 36000000UL /* PLL output: 36 MHz */
};
{
/* Set the PLL source to be the IMO. */
{
/* Insert error handling */
}
}
/* Configure PLL0 with the settings in pllConfig struct */
if (CY_SYSCLK_SUCCESS != Cy_SysClk_PllConfigure(0UL, &pllConfig))
{
/* Insert error handling */
}
/* Enable the PLL0 with 2000 microsecond timeout */
{
/* Insert error handling */
}

◆ Cy_SysClk_PllGetConfiguration()

void Cy_SysClk_PllGetConfiguration ( uint32_t  pllNum,
cy_stc_sysclk_pll_manual_config_t config 
)

Reports configuration settings for a PLL.

Parameters
pllNumthe number of PLL instance, starting from 0. If there is only one PLL in device - the 0 is the only valid number.
configcy_stc_sysclk_pll_manual_config_t
Returns
Error / status code cy_en_sysclk_status_t :
CY_SYSCLK_SUCCESS - PLL data successfully reported
CY_SYSCLK_BAD_PARAM - invalid clock path number
Function Usage
/* Scenario: PLL needs to be manually reconfigured:
* the reference divider should be changed to 10.
*/
{
Cy_SysClk_PllBypass(0UL, CY_SYSCLK_PLL_OUTPUT_INPUT); /* Bypass the PLL0 */
}
/* Refer to the TRM for the full set of equations used to calculate the PLL settings */
pllConfig.referenceDiv = 10U;
/* Configure PLL0 with the settings in pllConfig structure */
{
/* Insert error handling */
}
/* Call PllEnable with zero timeout */
(void) Cy_SysClk_PllEnable(0UL, 0UL); /* Ignore the status - it always is success in case of zero timeout */
/* Check the status of the lock */
while (Cy_SysClk_PllIsLocked(0UL))
{
/* Perform other actions while the PLL is locking */
}
Cy_SysClk_PllBypass(0UL, CY_SYSCLK_PLL_OUTPUT_AUTO); /* Set auto-bypass mode */
uint32_t pllFreq = Cy_SysClk_PllGetFrequency(0UL);

◆ Cy_SysClk_PllGetFrequency()

uint32_t Cy_SysClk_PllGetFrequency ( uint32_t  pllNum)

Reports the output frequency of the specified PLL.

Parameters
pllNumthe number of PLL instance, starting from 0. If there is only one PLL in device - the 0 is the only valid number.
Returns
The frequency, in Hz.
Function Usage
/* Scenario: PLL needs to be manually reconfigured:
* the reference divider should be changed to 10.
*/
{
Cy_SysClk_PllBypass(0UL, CY_SYSCLK_PLL_OUTPUT_INPUT); /* Bypass the PLL0 */
}
/* Refer to the TRM for the full set of equations used to calculate the PLL settings */
pllConfig.referenceDiv = 10U;
/* Configure PLL0 with the settings in pllConfig structure */
{
/* Insert error handling */
}
/* Call PllEnable with zero timeout */
(void) Cy_SysClk_PllEnable(0UL, 0UL); /* Ignore the status - it always is success in case of zero timeout */
/* Check the status of the lock */
while (Cy_SysClk_PllIsLocked(0UL))
{
/* Perform other actions while the PLL is locking */
}
Cy_SysClk_PllBypass(0UL, CY_SYSCLK_PLL_OUTPUT_AUTO); /* Set auto-bypass mode */
uint32_t pllFreq = Cy_SysClk_PllGetFrequency(0UL);

◆ Cy_SysClk_PllIsEnabled()

__STATIC_INLINE bool Cy_SysClk_PllIsEnabled ( uint32_t  pllNum)

Reports whether or not the selected PLL is enabled.

Parameters
pllNumthe number of PLL instance, starting from 0. If there is only one PLL in device - the 0 is the only valid number. For other pllNum values the false (disabled) is returned.
Returns
false = disabled
true = enabled
Function Usage
/* Scenario: PLL needs to be manually reconfigured:
* the reference divider should be changed to 10.
*/
{
Cy_SysClk_PllBypass(0UL, CY_SYSCLK_PLL_OUTPUT_INPUT); /* Bypass the PLL0 */
}
/* Refer to the TRM for the full set of equations used to calculate the PLL settings */
pllConfig.referenceDiv = 10U;
/* Configure PLL0 with the settings in pllConfig structure */
{
/* Insert error handling */
}
/* Call PllEnable with zero timeout */
(void) Cy_SysClk_PllEnable(0UL, 0UL); /* Ignore the status - it always is success in case of zero timeout */
/* Check the status of the lock */
while (Cy_SysClk_PllIsLocked(0UL))
{
/* Perform other actions while the PLL is locking */
}
Cy_SysClk_PllBypass(0UL, CY_SYSCLK_PLL_OUTPUT_AUTO); /* Set auto-bypass mode */
uint32_t pllFreq = Cy_SysClk_PllGetFrequency(0UL);

◆ Cy_SysClk_PllIsLocked()

__STATIC_INLINE bool Cy_SysClk_PllIsLocked ( uint32_t  pllNum)

Reports whether or not the selected PLL is locked.

Parameters
pllNumthe number of PLL instance, starting from 0. If there is only one PLL in device - the 0 is the only valid number. For other pllNum values the false (unlocked) is returned.
Returns
false = not locked
true = locked
Function Usage
/* Scenario: PLL needs to be manually reconfigured:
* the reference divider should be changed to 10.
*/
{
Cy_SysClk_PllBypass(0UL, CY_SYSCLK_PLL_OUTPUT_INPUT); /* Bypass the PLL0 */
}
/* Refer to the TRM for the full set of equations used to calculate the PLL settings */
pllConfig.referenceDiv = 10U;
/* Configure PLL0 with the settings in pllConfig structure */
{
/* Insert error handling */
}
/* Call PllEnable with zero timeout */
(void) Cy_SysClk_PllEnable(0UL, 0UL); /* Ignore the status - it always is success in case of zero timeout */
/* Check the status of the lock */
while (Cy_SysClk_PllIsLocked(0UL))
{
/* Perform other actions while the PLL is locking */
}
Cy_SysClk_PllBypass(0UL, CY_SYSCLK_PLL_OUTPUT_AUTO); /* Set auto-bypass mode */
uint32_t pllFreq = Cy_SysClk_PllGetFrequency(0UL);

◆ Cy_SysClk_PllBypass()

__STATIC_INLINE void Cy_SysClk_PllBypass ( uint32_t  pllNum,
cy_en_sysclk_pll_bypass_t  mode 
)

Sets PLL bypass mode.

Parameters
pllNumthe number of PLL instance, starting from 0. If there is only one PLL in device - the 0 is the only valid number.
modethe bypass mode cy_en_sysclk_pll_bypass_t.
Returns
Error / status code:
CY_SYSCLK_SUCCESS - PLL successfully disabled
CY_SYSCLK_BAD_PARAM - invalid clock path number
Note
Call SystemCoreClockUpdate after this function calling if it affects the CLK_HF0 frequency.
Call Cy_SysLib_SetWaitStates before calling this function if the PLL is the source of CLK_HF0 and the CLK_HF0 frequency is increasing.
Call Cy_SysLib_SetWaitStates after calling this function if the PLL is the source of CLK_HF0 and the CLK_HF0 frequency is decreasing.
Function Usage
/* Scenario: The PLL0 is no longer used and hence needs to be disabled. */
{
}
/* The clocks that relied on the PLL will now run off of the clock that
was used to source the FLL (e.g. IMO or ECO). */

◆ Cy_SysClk_PllGetBypassState()

__STATIC_INLINE cy_en_sysclk_pll_bypass_t Cy_SysClk_PllGetBypassState ( uint32_t  pllNum)

Returns the PLL bypass state.

Parameters
pllNumthe number of PLL instance, starting from 0. If there is only one PLL in device - the 0 is the only valid number.
Returns
The bypass state cy_en_sysclk_pll_bypass_t.
Function Usage
/* Scenario: The PLL0 is no longer used and hence needs to be disabled. */
{
}
/* The clocks that relied on the PLL will now run off of the clock that
was used to source the FLL (e.g. IMO or ECO). */

◆ Cy_SysClk_PllLostLock()

__STATIC_INLINE bool Cy_SysClk_PllLostLock ( uint32_t  pllNum)

Reports whether or not the selected PLL lost its lock since the last time this function was called.

Clears the lost lock indicator.

Parameters
pllNumthe number of PLL instance, starting from 0. If there is only one PLL in device - the 0 is the only valid number. For other pllNum values the false (did not lose lock) is returned.
Returns
false = did not lose lock
true = lost lock
Function Usage
/* Scenario: Suspicious change in PLL source clock frequency was encountered
in the application. Check if the PLL0 have lost the lock. */
{
/* Review the design work flow and eliminate the PLL source clock
* sudden change during PLL work (unless it is done intended or unavoidable).
*/
}

◆ Cy_SysClk_PllDisable()

__STATIC_INLINE void Cy_SysClk_PllDisable ( uint32_t  pllNum)

Disables the selected PLL.

Parameters
pllNumthe number of PLL instance, starting from 0. If there is only one PLL in device - the 0 is the only valid number.
Returns
Error / status code:
CY_SYSCLK_SUCCESS - PLL successfully disabled
CY_SYSCLK_BAD_PARAM - invalid clock path number
Note
Call SystemCoreClockUpdate after this function calling if it affects the CLK_HF0 frequency.
Call Cy_SysLib_SetWaitStates before calling this function if the PLL is the source of CLK_HF0 and the CLK_HF0 frequency is increasing.
Call Cy_SysLib_SetWaitStates after calling this function if the PLL is the source of CLK_HF0 and the CLK_HF0 frequency is decreasing.
Function Usage
/* Scenario: PLL needs to be manually reconfigured:
* the reference divider should be changed to 10.
*/
{
Cy_SysClk_PllBypass(0UL, CY_SYSCLK_PLL_OUTPUT_INPUT); /* Bypass the PLL0 */
}
/* Refer to the TRM for the full set of equations used to calculate the PLL settings */
pllConfig.referenceDiv = 10U;
/* Configure PLL0 with the settings in pllConfig structure */
{
/* Insert error handling */
}
/* Call PllEnable with zero timeout */
(void) Cy_SysClk_PllEnable(0UL, 0UL); /* Ignore the status - it always is success in case of zero timeout */
/* Check the status of the lock */
while (Cy_SysClk_PllIsLocked(0UL))
{
/* Perform other actions while the PLL is locking */
}
Cy_SysClk_PllBypass(0UL, CY_SYSCLK_PLL_OUTPUT_AUTO); /* Set auto-bypass mode */
uint32_t pllFreq = Cy_SysClk_PllGetFrequency(0UL);