iLLD_TC27xC  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 IfxLld_Cpu_Interrupt_Usage

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 100

Add the interrupt service routines to your C code. They have to call the Stm interrupt handlers:

IFX_INTERRUPT(stm0Sr0ISR, 0, IFX_INTPRIO_STM0_SR0)
{
IfxStm_clearCompareFlag(stmSfr, stmConfig.comparator);
IfxStm_updateCompare(stmSfr, stmConfig.comparator, IfxStm_getLower(stmSfr) + 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 module initialisation can be done in the same function.

stmSfr = &MODULE_STM0;
stmConfig.triggerInterruptEnabled = IFX_INTPRIO_STM0_SR0;
sint32 Fsys = IfxStm_getFrequency(stmSfr);
TimeConst_10ms = Fsys / (1000 / 10);
// configure to generate interrupt every 10 ms
stmConfig.ticks = IfxStm_getLower(stmSfr) + TimeConst_10ms;
IfxStm_initCompare(stmSfr, &stmConfig);

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