Functions

group group_sysclk_pilo_funcs

Functions

void Cy_SysClk_PiloEnable(void)

Enables the PILO.

note

This function blocks for 1 millisecond between enabling the PILO and releasing the PILO reset.

Function Usage

    /* Scenario: PILO needs to source the LFCLK.  All peripherals clocked by
                 the LFCLK are disabled and the Watchdog timer (WDT) is unlocked. */

    /* Enable the PILO. Note: Blocks for 1 millisecond. */
    Cy_SysClk_PiloEnable();

    /* Set the LFCLK source to the PILO */
    Cy_SysClk_ClkLfSetSource(CY_SYSCLK_CLKLF_IN_PILO);

bool Cy_SysClk_PiloIsEnabled(void)

Reports the Enabled/Disabled status of the PILO.

note

This API is available for CAT1A devices.

Return

Boolean status of PILO: true - Enabled, false - Disabled.

Function Usage

    /* Scenario: LFCLK needs to be sourced by the ILO instead of the PILO. All
                 peripherals clocked by the LFCLK are disabled and the Watchdog
                 timer (WDT) is unlocked. */

    if (Cy_SysClk_PiloIsEnabled())
    {
        /* Disable the PILO */
        Cy_SysClk_PiloDisable();

        /* Enable the ILO */
        Cy_SysClk_IloEnable();

        /* Set the LFCLK source to the ILO */
        Cy_SysClk_ClkLfSetSource(CY_SYSCLK_CLKLF_IN_ILO);
    }

void Cy_SysClk_PiloDisable(void)

Disables the PILO.

Function Usage

    /* Scenario: LFCLK needs to be sourced by the ILO instead of the PILO. All
                 peripherals clocked by the LFCLK are disabled and the Watchdog
                 timer (WDT) is unlocked. */

    if (Cy_SysClk_PiloIsEnabled())
    {
        /* Disable the PILO */
        Cy_SysClk_PiloDisable();

        /* Enable the ILO */
        Cy_SysClk_IloEnable();

        /* Set the LFCLK source to the ILO */
        Cy_SysClk_ClkLfSetSource(CY_SYSCLK_CLKLF_IN_ILO);
    }

void Cy_SysClk_PiloSetTrim(uint32_t trimVal)

Sets the PILO trim bits, which adjusts the PILO frequency.

This is typically done after measuring the PILO frequency; see Cy_SysClk_StartClkMeasurementCounters().

Function Usage

    /* Scenario: PILO needs to be trimmed to +/- 2% of nominal 32.768 kHz using
                 the ECO as the source. */

    #define ECO_FREQ        24000000UL  /* 24 MHz ECO */
    #define PILO_NOMINAL    32768UL     /* 32.768 kHz PILO */
    #define PILO_ACCURACY   655UL       /* PILO_NOMINAL * 0.02 */

    bool trimStatus = false;

    while(!trimStatus)
    {
        /* Start the PILO clock measurement using the IMO */
        (void)Cy_SysClk_StartClkMeasurementCounters(CY_SYSCLK_MEAS_CLK_PILO,    /* Counter 1 clock      = PILO */
                                                    0x3FFUL,                    /* Counter 1 init value = 1024 */
                                                    CY_SYSCLK_MEAS_CLK_ECO);    /* Counter 2 clock      = ECO  */
        /* Wait for counter 1 to reach 0 */
        while (!Cy_SysClk_ClkMeasurementCountersDone()){}

        /* Measure clock 1 with the ECO clock cycles (counter 2) */
        uint32_t measuredFreq = Cy_SysClk_ClkMeasurementCountersGetFreq(false, ECO_FREQ);

        /* Increment/decrement the trim depending on the returned result */
        if ((PILO_NOMINAL + PILO_ACCURACY) < measuredFreq)
        {
            Cy_SysClk_PiloSetTrim(Cy_SysClk_PiloGetTrim() - 1UL);
        }
        else if (measuredFreq < (PILO_NOMINAL - PILO_ACCURACY))
        {
            Cy_SysClk_PiloSetTrim(Cy_SysClk_PiloGetTrim() + 1UL);
        }
        else
        {
            /* Trimmed within limits */
            trimStatus = true;
        }
    }

uint32_t Cy_SysClk_PiloGetTrim(void)

Reports the current PILO trim bits value.

Function Usage

    /* Scenario: PILO needs to be trimmed to +/- 2% of nominal 32.768 kHz using
                 the ECO as the source. */

    #define ECO_FREQ        24000000UL  /* 24 MHz ECO */
    #define PILO_NOMINAL    32768UL     /* 32.768 kHz PILO */
    #define PILO_ACCURACY   655UL       /* PILO_NOMINAL * 0.02 */

    bool trimStatus = false;

    while(!trimStatus)
    {
        /* Start the PILO clock measurement using the IMO */
        (void)Cy_SysClk_StartClkMeasurementCounters(CY_SYSCLK_MEAS_CLK_PILO,    /* Counter 1 clock      = PILO */
                                                    0x3FFUL,                    /* Counter 1 init value = 1024 */
                                                    CY_SYSCLK_MEAS_CLK_ECO);    /* Counter 2 clock      = ECO  */
        /* Wait for counter 1 to reach 0 */
        while (!Cy_SysClk_ClkMeasurementCountersDone()){}

        /* Measure clock 1 with the ECO clock cycles (counter 2) */
        uint32_t measuredFreq = Cy_SysClk_ClkMeasurementCountersGetFreq(false, ECO_FREQ);

        /* Increment/decrement the trim depending on the returned result */
        if ((PILO_NOMINAL + PILO_ACCURACY) < measuredFreq)
        {
            Cy_SysClk_PiloSetTrim(Cy_SysClk_PiloGetTrim() - 1UL);
        }
        else if (measuredFreq < (PILO_NOMINAL - PILO_ACCURACY))
        {
            Cy_SysClk_PiloSetTrim(Cy_SysClk_PiloGetTrim() + 1UL);
        }
        else
        {
            /* Trimmed within limits */
            trimStatus = true;
        }
    }