CAT2 Peripheral Driver Library

Functions

void Cy_LTC_Init (void)
 Initializes the lifetime counter to its default state. More...
 
bool Cy_LTC_IsEnabled (void)
 Returns the lifetime counter HW actual status. More...
 
void Cy_LTC_Enable (void)
 Enables the lifetime counter and the counter of the lifetime counter starts counting up. More...
 
void Cy_LTC_Disable (void)
 Disables the lifetime counter and the counter of the lifetime counter stops counting, but is not cleared to 0. More...
 
void Cy_LTC_SetDivider (cy_en_ltc_div_t divider)
 Configures the divide ratio for the pre-selector. More...
 
cy_en_ltc_div_t Cy_LTC_GetDivider (void)
 Returns the divide ratio for the pre-selector value. More...
 
void Cy_LTC_SetCounterValue (uint32_t count)
 Configures lifetime counter current value. More...
 
uint32_t Cy_LTC_GetCounterValue (void)
 Returns lifetime counter current value. More...
 
void Cy_LTC_SetWakeup (uint32_t wakeupValue)
 Configures the lifetime wakeup value. More...
 
uint32_t Cy_LTC_GetWakeup (void)
 Returns the lifetime wakeup value. More...
 
void Cy_LTC_SetInterrupt (void)
 Triggers an interrupt with software. More...
 
bool Cy_LTC_GetInterruptStatus (void)
 Returns the interrupt status. More...
 
void Cy_LTC_ClearInterrupt (void)
 Clears the lifetime counter interrupt factor. More...
 
void Cy_LTC_SetInterruptMask (bool enable)
 Enables or disables the lifetime counter interrupt handler triggering. More...
 
bool Cy_LTC_GetInterruptStatusMasked (void)
 Gets Bitwise "AND" between the interrupt request and mask configuration. More...
 

Detailed Description

Function Documentation

◆ Cy_LTC_Init()

void Cy_LTC_Init ( void  )

Initializes the lifetime counter to its default state.

  • The Lifetime counter disable.
  • The Lifetime counter value is set to 0.
  • The Lifetime wakeup value is set to default(CY_LTC_DEFAULT_WAKEUP_VALUE) value
  • Configure default(CY_LTC_PRESEL_DIV_2) divide ratio for preselector.
  • Clear mask and interrupt
  • The Lifetime counter enable.
Note
Applicable to PSOC4 HVMS/PA only.
Warning
A Low frequency clock source(Low-Frequency Clock) should be enabled before this driver usage.
Returns
none
Function Usage
/* The Watchdog timer should be unlocked before ILO being enabled. */
/* A Low frequency clock source should be enabled before this driver usage. */
/* Initialize the lifetime counter driver */
/* Disable lifetime counter. */
/* Configure custom divider ratio for preselector. */
/* Reset Counter value */
/* Set 1000 ticks */
/* Due to internal synchronization, it takes about one LFCLK cycle
to update the counters after divider configuration. */
uint16_t delay = (uint16_t) (1000000UL / Cy_SysClk_ClkLfGetFrequency());
/* Wait for LTC counter value changing. */
/* Enable lifetime counter. */
/* User can update the wakeup value without disabling the lifetime counter. */
/* It is recommended to wait for status enabled before entering deepsleep. */
while(!Cy_LTC_IsEnabled())
{
}
/* Put the device into Deep Sleep mode and wait for an interrupt to wake up. */
/* The wakeup value is compared against the hardware COUNT value.
If there is a match will deepsleep interrupt occur. */

◆ Cy_LTC_IsEnabled()

bool Cy_LTC_IsEnabled ( void  )

Returns the lifetime counter HW actual status.

Note
May lag by up to one Low-Frequency Clock cycle
Applicable to PSOC4 HVMS/PA only.
Returns
true - Lifetime counter actual status is enabled.
false - Lifetime counter actual status is disabled.
Function Usage
/* Check the lifetime counter current status */
{
/* Disable lifetime counter. */
}
/* Get current counter value. */
uint32_t curCounterVal = Cy_LTC_GetCounterValue();
/* Increase counter to 100 ticks */
Cy_LTC_SetCounterValue(curCounterVal + 100);
/* Enable lifetime counter. */

◆ Cy_LTC_Enable()

void Cy_LTC_Enable ( void  )

Enables the lifetime counter and the counter of the lifetime counter starts counting up.

The user does not need to wait for enable synchronization before entering Deep Sleep. This will occur within one Low-Frequency Clock cycle. But it is recommended to wait for the enabled status before entering Deep sleep ( Cy_SysPm_CpuEnterDeepSleep ).

Note
Due to internal synchronization, may take up to one Low-Frequency Clock cycle to take effect.
Applicable to PSOC4 HVMS/PA only.
Returns
none
Function Usage
/* Check the lifetime counter current status */
{
/* Disable lifetime counter. */
}
/* Get current counter value. */
uint32_t curCounterVal = Cy_LTC_GetCounterValue();
/* Increase counter to 100 ticks */
Cy_LTC_SetCounterValue(curCounterVal + 100);
/* Enable lifetime counter. */

◆ Cy_LTC_Disable()

void Cy_LTC_Disable ( void  )

Disables the lifetime counter and the counter of the lifetime counter stops counting, but is not cleared to 0.

Note
Due to internal synchronization, may take up to one Low-Frequency Clock cycle to take effect.
Applicable to PSOC4 HVMS/PA only.
Returns
none
Function Usage
/* Check the lifetime counter current status */
{
/* Disable lifetime counter. */
}
/* Get current counter value. */
uint32_t curCounterVal = Cy_LTC_GetCounterValue();
/* Increase counter to 100 ticks */
Cy_LTC_SetCounterValue(curCounterVal + 100);
/* Enable lifetime counter. */

◆ Cy_LTC_SetDivider()

void Cy_LTC_SetDivider ( cy_en_ltc_div_t  divider)

Configures the divide ratio for the pre-selector.

Warning
Writes will be ignored when lifetime counter is enabled by Cy_LTC_Enable function.
Note
Due to internal synchronization, it takes about 1 Low-Frequency Clock cycle to update the counters after configuration.
Applicable to PSOC4 HVMS/PA only.
Parameters
dividercy_en_ltc_div_t
Returns
none
Function Usage
/* Disable lifetime counter. */
/* Configure custom divider ratio for preselector. */
/* Counter will start from 100 value */
/* Set wakeup on 1000 ticks */
/* Due to internal synchronization, it takes about one LFCLK cycle
to update the counters after divider configuration. */
uint16_t delay = (uint16_t) (1000000UL / Cy_SysClk_ClkLfGetFrequency());
/* Wait for LTC counter value changing. */
/* Enable lifetime counter. */

◆ Cy_LTC_GetDivider()

cy_en_ltc_div_t Cy_LTC_GetDivider ( void  )

Returns the divide ratio for the pre-selector value.

Note
Applicable to PSOC4 HVMS/PA only.
Returns
cy_en_ltc_div_t :
CY_LTC_PRESEL_DIV_2 - Divide Low-Frequency Clock by 2.
CY_LTC_PRESEL_DIV_4 - Divide Low-Frequency Clock by 4.
CY_LTC_PRESEL_DIV_8 - Divide Low-Frequency Clock by 8.
CY_LTC_PRESEL_DIV_16 - Divide Low-Frequency Clock by 16.
CY_LTC_PRESEL_DIV_32 - Divide Low-Frequency Clock by 32.
Function Usage
/* Disable lifetime counter. */
/* Configure custom divider ratio for preselector. */
switch(curDiv)
{
/* handle current value */
break;
/* handle current value */
break;
/* handle current value */
break;
/* handle current value */
break;
/* handle current value */
break;
default:
/* handle current value */
break;
}

◆ Cy_LTC_SetCounterValue()

void Cy_LTC_SetCounterValue ( uint32_t  count)

Configures lifetime counter current value.

Note
This function configuration is ignored when lifetime counter enabled.
The counter doesn't increment unless enabled(Cy_LTC_Enable).
The counter doesn't increment unless enabled(Cy_LTC_Enable).
Due to internal synchronization, it takes about one Low-Frequency Clock cycle to update the counters after divider configuration and counter needs to be disabled one Low-Frequency Clock cycle for the internal synchronization of this counter to take place.
Warning
Do not change this setting when lifetime counter is enabled.
Note
Applicable to PSOC4 HVMS/PA only.
Parameters
countLifetime counter current value.
Returns
none
Function Usage
/* Check the lifetime counter current status */
{
/* Disable lifetime counter. */
}
/* Get current counter value. */
uint32_t curCounterVal = Cy_LTC_GetCounterValue();
/* Increase counter to 100 ticks */
Cy_LTC_SetCounterValue(curCounterVal + 100);
/* Enable lifetime counter. */

◆ Cy_LTC_GetCounterValue()

uint32_t Cy_LTC_GetCounterValue ( void  )

Returns lifetime counter current value.

Note
The counter doesn't increment unless enabled(Cy_LTC_Enable).
Applicable to PSOC4 HVMS/PA only.
Returns
The lifetime current counter value.
Function Usage
/* Check the lifetime counter current status */
{
/* Disable lifetime counter. */
}
/* Get current counter value. */
uint32_t curCounterVal = Cy_LTC_GetCounterValue();
/* Increase counter to 100 ticks */
Cy_LTC_SetCounterValue(curCounterVal + 100);
/* Enable lifetime counter. */

◆ Cy_LTC_SetWakeup()

void Cy_LTC_SetWakeup ( uint32_t  wakeupValue)

Configures the lifetime wakeup value.

The user can change the WAKEUP value without disabling the lifetime counter.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
wakeupValueLifetime wakeup value.
Returns
none
Function Usage
/* Get current wakeup value. */
uint32_t curWakeupVal = Cy_LTC_GetWakeup();
/* Increase wakeup to 100 ticks */
Cy_LTC_SetWakeup(curWakeupVal + 100);

◆ Cy_LTC_GetWakeup()

uint32_t Cy_LTC_GetWakeup ( void  )

Returns the lifetime wakeup value.

Note
Applicable to PSOC4 HVMS/PA only.
Returns
The lifetime wakeup value.
Function Usage
/* Get current wakeup value. */
uint32_t curWakeupVal = Cy_LTC_GetWakeup();
/* Increase wakeup to 100 ticks */
Cy_LTC_SetWakeup(curWakeupVal + 100);

◆ Cy_LTC_SetInterrupt()

void Cy_LTC_SetInterrupt ( void  )

Triggers an interrupt with software.

Can be used to set interrupts for firmware testing.

Note
Applicable to PSOC4 HVMS/PA only.
Returns
none

◆ Cy_LTC_GetInterruptStatus()

bool Cy_LTC_GetInterruptStatus ( void  )

Returns the interrupt status.

Note
Applicable to PSOC4 HVMS/PA only.
Returns
True - Interrupt occurred.
False - Interrupt did not occur.
Function Usage
#define SYSCLK_INTR_NUM ((IRQn_Type) srss_interrupt_srss_IRQn)
#define SYSCLK_INTR_PRIORITY (3U)
/* Configuration structure */
static cy_stc_sysint_t sysClkIntrConfig =
{
.intrSrc = SYSCLK_INTR_NUM,
.intrPriority = SYSCLK_INTR_PRIORITY,
};
static bool wakeupTiggered = false;
static void LTC_Isr(void)
{
/* Check interrupt happening. */
{
/* Clear the lifetime counter interrupt. */
wakeupTiggered = true;
}
}
void LTC_Example_Main(void)
{
/* Hook interrupt service routine */
(void) Cy_SysInt_Init(&sysClkIntrConfig, &LTC_Isr);
/* enable interrupt for interrupt controller */
NVIC_EnableIRQ(SYSCLK_INTR_NUM);
/* The Watchdog timer should be unlocked before ILO being enabled. */
/* A Low frequency clock source should be enabled before this driver usage. */
/* Initialize the lifetime counter driver */
/* Set wakeup on 1000 ticks */
/* It is recommended to wait for status enabled before entering deepsleep. */
while(!Cy_LTC_IsEnabled())
{
}
/* Put the device into Deep Sleep mode and wait for an interrupt to wake up. */
/* Check interrupt happening. */
if(wakeupTiggered)
{
/* handle wakeup */
}
}

◆ Cy_LTC_ClearInterrupt()

void Cy_LTC_ClearInterrupt ( void  )

Clears the lifetime counter interrupt factor.

Note
Applicable to PSOC4 HVMS/PA only.
Returns
none
Function Usage
#define SYSCLK_INTR_NUM ((IRQn_Type) srss_interrupt_srss_IRQn)
#define SYSCLK_INTR_PRIORITY (3U)
/* Configuration structure */
static cy_stc_sysint_t sysClkIntrConfig =
{
.intrSrc = SYSCLK_INTR_NUM,
.intrPriority = SYSCLK_INTR_PRIORITY,
};
static bool wakeupTiggered = false;
static void LTC_Isr(void)
{
/* Check interrupt happening. */
{
/* Clear the lifetime counter interrupt. */
wakeupTiggered = true;
}
}
void LTC_Example_Main(void)
{
/* Hook interrupt service routine */
(void) Cy_SysInt_Init(&sysClkIntrConfig, &LTC_Isr);
/* enable interrupt for interrupt controller */
NVIC_EnableIRQ(SYSCLK_INTR_NUM);
/* The Watchdog timer should be unlocked before ILO being enabled. */
/* A Low frequency clock source should be enabled before this driver usage. */
/* Initialize the lifetime counter driver */
/* Set wakeup on 1000 ticks */
/* It is recommended to wait for status enabled before entering deepsleep. */
while(!Cy_LTC_IsEnabled())
{
}
/* Put the device into Deep Sleep mode and wait for an interrupt to wake up. */
/* Check interrupt happening. */
if(wakeupTiggered)
{
/* handle wakeup */
}
}

◆ Cy_LTC_SetInterruptMask()

void Cy_LTC_SetInterruptMask ( bool  enable)

Enables or disables the lifetime counter interrupt handler triggering.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
enabletrue : to masking interrupt. After masking the interrupt, it is not passed to the CPU.
false : to reset masking. After unmasking the interrupt, it is passed to CPU.
Returns
none
Function Usage
/* Unmask interrupts if interrupts were masked */
{
/* Configure interrupt mask */
}
/* Clear the lifetime counter interrupt. */

◆ Cy_LTC_GetInterruptStatusMasked()

bool Cy_LTC_GetInterruptStatusMasked ( void  )

Gets Bitwise "AND" between the interrupt request and mask configuration.

Note
Applicable to PSOC4 HVMS/PA only.
Returns
true : There is Lifetime Counter interrupt factor and mask bit is set
false : There is no Lifetime Counter interrupt factor or mask bit is cleared
Function Usage
/* Unmask interrupts if interrupts were masked */
{
/* Configure interrupt mask */
}
/* Clear the lifetime counter interrupt. */