iLLD_TC23x  1.0
How to define Interrupts?
Collaboration diagram for How to define Interrupts?:

This page describes how to use interrupts with application framework.

Interrupts Terminology:

Hardware Managed Interrupt Mechanism.

Hardware managed interrupts have static interrupt vector which are defined for each priority separately. These vectors have jump instruction to the interrupt handler.

Advantages:
This mechanism has less interrupt latency time.

Software Managed Interrupt Mechanism.

Software managed interrupts have single interrupt vector statically defined at vector position 255. This address is assigned to BIV during startup.
For Tricore, this vector position is important, because whenever an interrupt occurs, with whichever priority, the execution control jumps to this vector position. The code at this vector position will:
1) fetch the priority of the targetted interrupt.
2) fetch the interrupt handler defined for this priority (this is done by Interrupt handler installation. Refer Step4: How to install Interrupt Service routine/handler?
3) Then call the handler as notmal function call.

Advantages:
This kind of mechanism is useful when project wants to change the handler for an interrupt during runtime.

Disadvantages:
This mechanism has more interrupt latency time.

of the interrupt and in tand jumps to the function

Steps to use Interrupt Mechanism.

Dependency: Ifx_Compilers, Ifx_Cpu, Ifx_Src, IfxCpu_Irq
Following are the steps to use interrupt mechanism.

Step1: Define Interrupt priorities.

Define priorities of all interrupts with names corresponding to their functionality. It is recommended to define such priority definitions in single header file, because it is easy to detect if ISR priorities are conflicting. In Tricore architecture, two Isrs can't have same priority at same point of time.

Note
These defines shall be defined without brackets surrounding priority number. (eg. #define PRIO (10) is not allowed)

In a user defined file eg. Ifx_IntPrioDef.h, placed in folder: 0_AppSw/Tricore/DemoApp:

//file: Ifx_IntPrioDef.h.
#define IFX_INTPRIO_FUNCT1 1
#define IFX_INTPRIO_FUNCT2 2
#define IFX_INTPRIO_FUNCT3 5
#define IFX_INTPRIO_STM0 8
#define IFX_INTPRIO_ADC_FUNC1 10
//etc.
Note
!! IMPORTANT !!
As explained above, the definition with closing bracket around priority number as, #define IFX_INTPRIO_FUNCT1 (1) will cause compilation error. Because linker sections which are constructed using such information will also get these brackets included. Which look like ".intvec_tc0_(1)" instead of the expected ".intvec_tc0_1"
Linker sections' definitions are predefined statically in .lsl file, for all 255 interrupts, with the format ".intvec_tc<vector number>_<interrupt priority>".

Step2: Define Type of interrupt mechanism.

To use Hardware Managed Interrupt Mechanism.

Refer Hardware Managed Interrupt Mechanism. If project is designed for hardware managed interrupts, this feature is enabled at the file Ifx_Cfg.h, at path: 0_Src/0_AppSw/Config/Common/, as shown below. IFX_USE_SW_MANAGED_INT definition must be undefined (i.e. the statement "#define IFX_USE_SW_MANAGED_INT" shall be commented as below).

//file: Ifx_Cfg.h
//#define IFX_USE_SW_MANAGED_INT

To use Software Managed Interrupt Mechanism.

Refer Software Managed Interrupt Mechanism. If project is designed for software managed interrupts, this feature is enabled at the file Ifx_Cfg.h, at path: 0_Src/0_AppSw/Config/Common/, as shown below. IFX_USE_SW_MANAGED_INT definition must be defined.

//file: Ifx_Cfg.h
#define IFX_USE_SW_MANAGED_INT

Software managed interrupts must also install the "Interrupt Handlers" Refer Step4: How to install Interrupt Service routine/handler?

Step3: How to define an Interrupt Service routine?

Interrupt service routines or interrupt handlers are defined in driver specific files or application specific files.

//file usercode1.c
#include "Compilers.h" // to get the compiler abstracted macros for interrupt definition
#include "Ifx_IntPrioDef.h" // to get the priority numbers
//define an ISR with name Isr_Stm0 with priority defined by IFX_INTPRIO_STM0
IFX_INTERRUPT (Isr_Stm0, 0, IFX_INTPRIO_STM0)
{
//Isr code here
}
//file usercode2.c
#include "Compilers.h" // to get the compiler abstracted macros for interrupt definition
#include "Ifx_IntPrioDef.h" // to get the priority numbers
//define an ISR with name Isr_Adc_fun1 with priority defined by IFX_INTPRIO_ADC_FUNC1
IFX_INTERRUPT (Isr_Adc_fun1, 0, IFX_INTPRIO_ADC_FUNC1)
{
//Isr code here
}

Step4: How to install Interrupt Service routine/handler?

This step is not required for HW managed interrupts.
Interrupt service routines or interrupt handlers are installed in driver specific files or application specific files

//file usermain.c
#include "IfxCpu_Irq.h"
#include "Ifx_IntPrioDef.h" // to get the priority numbers
void userfunction_init(void)
{
//code for user function init
// :
// :
IfxCpu_Irq_installInterruptHandler (Isr_Stm0, IFX_INTPRIO_STM0);
IfxCpu_Irq_installInterruptHandler (Isr_Adc_fun1, IFX_INTPRIO_ADC_FUNC1);
// :
}

Step5: Managing the Service Request Node.

For the interrupt to get activated, interrupt triggers are needed. These triggers are activated by peripheral modules and corresponding service request node must be
1) Configured with correct priority number
2) The request node must be enabled
Refer to How to use Service Request Mechanism?