iLLD_TC29x  1.0
How to use the Stm driver?
Collaboration diagram for How to use the Stm driver?:

The Stm Standard driver provides APIs to initialize, configure and control the Stm.

In the following sections it will be described, how to integrate the driver into the application framework.

Preparation

Include Files

Include following header file into your C code:

#include <Stm/Std/IfxStm.h>

Variables

Declare STM variables :

Ifx_STM *stmSfr;

Interrupt Handler Installation

See also How to define Interrupts?

Define priorities for the Interrrupt handlers. This is normally done in the Ifx_IntPrioDef.h file:

// priorities are normally defined in Ifx_IntPrioDef.h
#define IFX_INTPRIO_STM0_SR0 10

Add the interrupt service routines to your C code. They have to call the Stm interrupt handlers: please take care in choosing number of ticks, the below example code will raise an interrupt evry time the specified number of ticks have been elapsed.

IFX_INTERRUPT(stm0Sr0ISR, 0, IFX_INTPRIO_STM0_SR0)
{
IfxStm_clearCompareFlag(stmSfr, stmConfig.comparator);
IfxStm_increaseCompare(stmSfr, stmConfig.comparator, stmConfig.ticks);
}

Finally install the interrupt handlers in your initialisation function:

// install interrupt handlers
IfxCpu_Irq_installInterruptHandler(&stm0Sr0ISR, IFX_INTPRIO_STM0_SR0);

Module Initialisation

The STM module can be configured to generate an interrupt at every compare match of the selected comaparator with the desired compare value, the interrupt can further be routed to other comparator.

The module initialisation can be done as followed.

stmSfr = &MODULE_STM0;
// configure to generate interrupt every 10 us
stmConfig.ticks = ticks;
stmConfig.triggerPriority = IFX_INTPRIO_STM0_SR0;
IfxStm_initCompare(stmSfr, &stmConfig);

Now the Stm shall generate interrupts regularly based on the configured time !