CAT2 Peripheral Driver Library

Functions

__STATIC_INLINE void Cy_SysClk_IloEnable (void)
 Enables the ILO. More...
 
__STATIC_INLINE bool Cy_SysClk_IloIsEnabled (void)
 Returns the ILO enable/disable state. More...
 
__STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_IloDisable (void)
 Disables the ILO. More...
 
void Cy_SysClk_IloStartMeasurement (void)
 Prepares the DFT hardware to perform the ILO accuracy measurement. More...
 
void Cy_SysClk_IloStopMeasurement (void)
 Cleans the DFT hardware registers, returning it to the default state. More...
 
cy_en_sysclk_status_t Cy_SysClk_IloCompensate (uint32_t desiredDelay, uint32_t *compensatedCycles)
 Measures the current ILO accuracy. More...
 

Detailed Description

Function Documentation

◆ Cy_SysClk_IloEnable()

__STATIC_INLINE void Cy_SysClk_IloEnable ( void  )

Enables the ILO.

Function Usage
/* Scenario: The WDC timers needs to be sourced by the ILO instead of the WCO.
*/
/* Enable the ILO */
/* Now switch the WDC timers clocking to ILO */
/* Disable the WCO */

◆ Cy_SysClk_IloIsEnabled()

__STATIC_INLINE bool Cy_SysClk_IloIsEnabled ( void  )

Returns the ILO enable/disable state.

Function Usage
/* Scenario: ILO is not needed and should be shut down to reduce power consumption. */
{
Cy_SysClk_IloDisable(); /* Disable the ILO */
}

◆ Cy_SysClk_IloDisable()

__STATIC_INLINE cy_en_sysclk_status_t Cy_SysClk_IloDisable ( void  )

Disables the ILO.

ILO can't be disabled if WDT is enabled.

Returns
Error / status code, cy_en_sysclk_status_t :
CY_SYSCLK_SUCCESS - ILO successfully disabled
CY_SYSCLK_INVALID_STATE - Cannot disable the ILO if the WDT is enabled.
Note
Do not call this function if the WDT is enabled, because the WDT is clocked by the ILO.
Function Usage
/* Scenario: ILO is not needed and should be shut down to reduce power consumption. */
{
Cy_SysClk_IloDisable(); /* Disable the ILO */
}

◆ Cy_SysClk_IloStartMeasurement()

void Cy_SysClk_IloStartMeasurement ( void  )

Prepares the DFT hardware to perform the ILO accuracy measurement.

This function is non-blocking and needs to be called before using the Cy_SysClk_IloCompensate() function.

This function configures measurement counters to be sourced by SysClk (Counter 1) and ILO (Counter 2).

Note
SysClk should be clocked by IMO, otherwise Cy_SysClk_IloCompensate() function can give incorrect results.
Function Usage
bool flag = false;
void Wdt_Isr(void)
{
flag = true;
}
/* Scenario: Configure and enable the WDT interrupt in the application code */
cy_stc_sysint_t Wdt_IrqCfg =
{
.intrSrc = srss_interrupt_wdt_IRQn, /* The interrupt source is the WDT interrupt */
.intrPriority = 3UL /* The interrupt priority is 3 */
};
/* Configure the interrupt with a vector at Wdt_Isr(). */
cy_en_sysint_status_t sysintStatus = Cy_SysInt_Init(&Wdt_IrqCfg, Wdt_Isr);
if (CY_SYSINT_SUCCESS != sysintStatus)
{
/* Insert the error handling here */
}
NVIC_EnableIRQ(Wdt_IrqCfg.intrSrc); /* Enable the interrupt. */
/* Scenario: Then somewhere in the main loop: */
uint32_t iloCycles = 0UL;
if (flag)
{
flag = false;
while (CY_SYSCLK_SUCCESS != Cy_SysClk_IloCompensate(500000, &iloCycles)); /* The desired WDT delay is 0.5 second */
Cy_SysClk_IloStopMeasurement(); /* Finish the procedure */
Cy_WDT_SetMatch((uint16_t)(iloCycles + Cy_WDT_GetMatch())); /* Program the next WDT event */
}

◆ Cy_SysClk_IloStopMeasurement()

void Cy_SysClk_IloStopMeasurement ( void  )

Cleans the DFT hardware registers, returning it to the default state.

Calling this function immediately stops the the ILO frequency measurement. Call this function before placing the device to deepsleep, if Cy_SysClk_IloStartMeasurement() API was called before.

Function Usage
bool flag = false;
void Wdt_Isr(void)
{
flag = true;
}
/* Scenario: Configure and enable the WDT interrupt in the application code */
cy_stc_sysint_t Wdt_IrqCfg =
{
.intrSrc = srss_interrupt_wdt_IRQn, /* The interrupt source is the WDT interrupt */
.intrPriority = 3UL /* The interrupt priority is 3 */
};
/* Configure the interrupt with a vector at Wdt_Isr(). */
cy_en_sysint_status_t sysintStatus = Cy_SysInt_Init(&Wdt_IrqCfg, Wdt_Isr);
if (CY_SYSINT_SUCCESS != sysintStatus)
{
/* Insert the error handling here */
}
NVIC_EnableIRQ(Wdt_IrqCfg.intrSrc); /* Enable the interrupt. */
/* Scenario: Then somewhere in the main loop: */
uint32_t iloCycles = 0UL;
if (flag)
{
flag = false;
while (CY_SYSCLK_SUCCESS != Cy_SysClk_IloCompensate(500000, &iloCycles)); /* The desired WDT delay is 0.5 second */
Cy_SysClk_IloStopMeasurement(); /* Finish the procedure */
Cy_WDT_SetMatch((uint16_t)(iloCycles + Cy_WDT_GetMatch())); /* Program the next WDT event */
}

◆ Cy_SysClk_IloCompensate()

cy_en_sysclk_status_t Cy_SysClk_IloCompensate ( uint32_t  desiredDelay,
uint32_t *  compensatedCycles 
)

Measures the current ILO accuracy.

Basing on the measured frequency the required number of ILO cycles for a given delay (in microseconds) is obtained. The desired delay that needs to be compensated is passed through the desiredDelay parameter. The compensated cycle count is returned through the compesatedCycles pointer. The compensated ILO cycles can then be used to define the WDT period value, effectively compensating for the ILO inaccuracy and allowing a more accurate WDT interrupt generation. This function starts timers, and if they are already running, their status is checked. If the timer has reached 0, then it is considered that it has already measured and calculated, how many cycles are needed for DesiredDelay and returns "success". The Cy_SysClk_IloCompensate function execution time is always ~ 1ms.

Cy_SysClk_IloStartMeasurement() function should be called prior to calling this function.

Note
SysClk should be clocked by IMO, otherwise the Cy_SysClk_IloCompensate() function can give incorrect results.
If the System clock frequency is changed in runtime, the SystemCoreClockUpdate() should be called before calling a next Cy_SysClk_IloCompensate().
For a correct WDT or DeepSleep Timers functioning with ILO compensating the Cy_SysClk_IloCompensate() should be called before WDT or DeepSleep Timers enabling.
Warning
Do not enter Deep Sleep mode until the function returns CY_SYSCLK_SUCCESS.
Parameters
desiredDelayRequired delay in microseconds. Valid range is 100 ... 2 000 000 us.
Note
The desiredDelay range 100..2000000 is mathematically possible, but:
Physically, the longest WDT period is 65536 * ILO clock period,
which is nominally 25us, so the real maximum desiredDelay is 1.63s @40kHz ILO.
The 100us is about a four ILO clocks, so such a small desiredDelay may be imprecise (~25% of error or even more).
Therefore, the range 1ms..1s (1000...1000000) is recommended as practically applicable.
Parameters
*compensatedCyclesThe pointer to the variable in which the required number of ILO cycles for the given delay will be returned.

The value returned in *compensatedCycles pointer is not valid until the function returns CY_SYSCLK_SUCCESS.

Returns
The status cy_en_sysclk_status_t
  • CY_SYSCLK_SUCCESS - The compensation process is complete and the compensated cycles value is returned in the compensatedCycles pointer.
  • CY_SYSCLK_BAD_PARAM - One or more invalid parameters
  • CY_SYSCLK_STARTED - Indicates measurement is in progress. It is strongly recommended to do not make pauses between API calling. The function should be called repeatedly until the API returns CY_SYSCLK_SUCCESS.
  • CY_SYSCLK_INVALID_STATE - Indicates that measurement not started. The user should call Cy_SysClk_IloStartMeasurement() API before calling this function.
Function Usage
bool flag = false;
void Wdt_Isr(void)
{
flag = true;
}
/* Scenario: Configure and enable the WDT interrupt in the application code */
cy_stc_sysint_t Wdt_IrqCfg =
{
.intrSrc = srss_interrupt_wdt_IRQn, /* The interrupt source is the WDT interrupt */
.intrPriority = 3UL /* The interrupt priority is 3 */
};
/* Configure the interrupt with a vector at Wdt_Isr(). */
cy_en_sysint_status_t sysintStatus = Cy_SysInt_Init(&Wdt_IrqCfg, Wdt_Isr);
if (CY_SYSINT_SUCCESS != sysintStatus)
{
/* Insert the error handling here */
}
NVIC_EnableIRQ(Wdt_IrqCfg.intrSrc); /* Enable the interrupt. */
/* Scenario: Then somewhere in the main loop: */
uint32_t iloCycles = 0UL;
if (flag)
{
flag = false;
while (CY_SYSCLK_SUCCESS != Cy_SysClk_IloCompensate(500000, &iloCycles)); /* The desired WDT delay is 0.5 second */
Cy_SysClk_IloStopMeasurement(); /* Finish the procedure */
Cy_WDT_SetMatch((uint16_t)(iloCycles + Cy_WDT_GetMatch())); /* Program the next WDT event */
}