MTB CAT1 Peripheral driver library
EVTGEN (Event Generator)

General Description

This driver provides API functions to configure and use the Event Generator.

The functions and other declarations used in this driver are in cy_evtgen.h. You can include cy_pdl.h to get access to all functions and declarations in the PDL.

Glossary

EVTGEN Solution

The Event Generator (EVTGEN) implements event generation - in Active mode, for interrupts and triggers and in Deep Sleep mode only for interrupts. The Active functionality interrupt is connected to the CPU interrupt controller. Active mode triggered events can be used to trigger a specific device functionality mode (for example, execution of an interrupt handler, a SAR ADC conversion, and so on) in Active power mode. The Deep Sleep functionality interrupts can be used to wake up the CPU from the Deep Sleep power mode. The event generator includes a single counter and a maximum of 16 comparator structures for each Active and Deep Sleep mode. EVTGEN reduces CPU involvement and thus overall power consumption and jitters.

evtgen_architecture.png

EVTGEN consists of two blocks: Active and Deep Sleep mode blocks. There are 16 comparator structures and one 32-bit counter for each of the modes which increment with each cycle CLK_REF. Each comparator structure has an Active and a Deep Sleep comparator. A comparator compares a programmed comparator value with the current counter value. When the counter value "passes" (equal) a comparator value, a comparator output is activated.

evtgen_clock_structure.png

The Event Generator implements synchronization between the Active counter and Deep Sleep counter through ratio control. The ratio value shows the number of clk_ref_div periods in one clk_lf periods. Event Generator uses Ratio value to synchronize active counter and Deep Sleep counter with hardware automatically.

Configuration Considerations

The EVTGEN driver configuration can be divided into a number of sequential steps:

Note
The EVTGEN driver is built on top of the EVTGEN hardware block. The EVTGEN0 instance is used as an example for all code snippets. Modify the code to match your design.

Configure EVTGEN

To set up the EVTGEN driver, provide the configuration parameters in the cy_stc_evtgen_config_t structure. To initialize the driver, call the Cy_EvtGen_Init function providing a pointer to the populated cy_stc_evtgen_config_t structure.

/* Populate the configuration structure */
cy_stc_evtgen_config_t configEvtGen =
{
.frequencyRef = 8000000u,
.frequencyLf = 32800u,
.frequencyTick = 1000000u,
.ratioControlMode = CY_EVTGEN_RATIO_CONTROL_SW,
.ratioValueDynamicMode = CY_EVTGEN_RATIO_DYNAMIC_MODE0,
};
/* Configure EVTGEN to operate */
(void) Cy_EvtGen_Init(EVTGEN0, &configEvtGen);

Enable Clock Path

A clock source must be connected to the EVTGEN block to control time. Enable High Frequency clock. Use the SysClk (System Clock) driver API to do.

#define CY_CFG_SYSCLK_CLKHF3_ENABLED 1UL
#define CY_CFG_SYSCLK_CLKHF3_DIVIDER CY_SYSCLK_CLKHF_NO_DIVIDE
#define CY_CFG_SYSCLK_CLKHF3 3UL
#define CY_CFG_SYSCLK_CLKHF3_FREQ_MHZ 8UL
#define CY_CFG_SYSCLK_CLKHF3_CLKPATH CY_SYSCLK_CLKHF_IN_CLKPATH6
#define CY_CFG_SYSCLK_CLKHF3_CLKPATH_NUM 6UL
/* Connect the assigned Clock Path to be a clock source for EVTGEN */
Cy_SysClk_ClkHfSetSource(CY_CFG_SYSCLK_CLKHF3, CY_CFG_SYSCLK_CLKHF3_CLKPATH);
Cy_SysClk_ClkHfDirectSel(CY_CFG_SYSCLK_CLKHF3, false);
Cy_SysClk_ClkHfEnable(CY_CFG_SYSCLK_CLKHF3);

Configure Comparator Structure

To set up the Comparator Structure of the EVTGEN driver, provide the configuration parameters in the cy_stc_evtgen_struct_config_t structure. To initialize the Comparator Structure, call the Cy_EvtGen_InitStruct function providing a pointer to the populated cy_stc_evtgen_struct_config_t structure.

/* Populate configuration structure */
cy_stc_evtgen_struct_config_t evtgen_configStruct0 =
{
.functionalitySelection = CY_EVTGEN_ACTIVE_FUNCTIONALITY,
.triggerOutEdge = CY_EVTGEN_EDGE_SENSITIVE,
.valueActiveComparator = 500000u,
.valueDeepSleepComparator = 80000u
};
/* Configure Comparator Structure to operate */
(void) Cy_EvtGen_InitStruct(EVTGEN0, 0u, &evtgen_configStruct0);

Configure Interrupt

The interrupt is the main operation of EVTGEN. Use it to configure an interrupt and create the interrupt handle for the selected EVTGEN instance. Also, enable this interrupt in the NVIC.

void EVTGEN_Isr(void)
{
{
Cy_EvtGen_UpdateActiveCompValue(EVTGEN0, 0u, 500000u);
/*
User's ISR for Comparator Structure 0
*/
}
}
void EVTGEN_Cfg_Isr(void)
{
/* Assign the EVTGEN interrupt number and priority */
#define EVTGEN_INTR_NUM (((NvicMux3_IRQn << CY_SYSINT_INTRSRC_MUXIRQ_SHIFT) | evtgen_0_interrupt_IRQn))
#define EVTGEN_INTR_PRIORITY (7u)
/* Populate configuration structure (code specific for CM4) */
const cy_stc_sysint_t evtgenIntrConfig =
{
.intrSrc = EVTGEN_INTR_NUM,
.intrPriority = EVTGEN_INTR_PRIORITY,
};
/* Hook the interrupt service routine and enable the interrupt */
(void) Cy_SysInt_Init(&evtgenIntrConfig, &EVTGEN_Isr);
Cy_EvtGen_ClearInterrupt(EVTGEN0, 0xFFu);
NVIC_ClearPendingIRQ(NvicMux3_IRQn);
NVIC_EnableIRQ((IRQn_Type)NvicMux3_IRQn);
#if (USE_EVTGEN_TRIGGER)
Cy_TrigMux_Connect(TRIG_IN_MUX_1_EVTGEN_TR_OUT0,
TRIG_OUT_MUX_1_PDMA0_TR_IN16,
0UL,
TRIGGER_TYPE_EDGE);
#endif
}

Enable EVTGEN

Finally, enable the EVTGEN operation by calling Cy_EvtGen_Enable.

/* Enable EVTGEN to operate */
#if (USE_HW_RATIO_CONTROL)
while(Cy_EvtGen_GetRatioStatus(EVTGEN0) != true)
{
__NOP();
}
#endif
/* Enable global interrupts */
__enable_irq();

Changelog

VersionChangesReason for Change
1.0 Initial version

API Reference

 Macro
 
 Functions
 
 Data structures
 
 Enumerated types