How to setup multiple ERU interrupts with multiple interrupt functions

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Joe_08
Level 2
Level 2
First solution authored 5 replies posted 5 questions asked

Hi,

I have a TC375 and have gotten the ERU interrupt example code to work but I'm trying to get multiple interrupts with different priorities to trigger different interrupt functions. What would need to be changed to my code in order to make this work. Currently only one of the interrupts is triggered but the other is ignored. My application is to determine the speed of 4 wheel speed sensors. Each sensor has 2 interrupts and I would need have a separate interrupt function for each sensor. For now I'm just trying to get 2 separate interrupt pins to work.

 

/*
* ERU_Interrupt.c
*
* Created on: Feb. 19, 2023
* Author: jcaru
*/


/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "ERU_Interrupt.h"

/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
#define ISR_PRIORITY_SCUERU_INTFLA 60 /* Define the SCU ERU interrupt priority */
#define ISR_PRIORITY_SCUERU_INTFLB 61 /* Define the SCU ERU interrupt priority */
#define FL_A_IN &IfxScu_REQ6D_P11_10_IN /* External request pin FL_A */
#define FL_B_IN &IfxScu_REQ6A_P20_0_IN /*External request pin FL_B*/

/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
ERUconfig g_ERUconfig_FL_A;
ERUconfig g_ERUconfig_FL_B;/* SCU_ERU global data */
float FL_Dir = 0.0;
float FL_pulseCnt = 0.0;
float FL_RPM = 0.0;
/*********************************************************************************************************************/
/*----------------------------------------------Function Implementations---------------------------------------------*/
/*********************************************************************************************************************/
/* Macro to define Interrupt Service Routine.
* This macro makes the following definitions:
* 1) Define linker section as .intvec_tc<vector number>_<interrupt priority>.
* 2) Define compiler specific attribute for the interrupt functions.
* 3) Define the Interrupt Service Routine as ISR function.
*
* IFX_INTERRUPT(isr, vectabNum, priority)
* - isr: Name of the ISR function.
* - vectabNum: Vector table number.
* - priority: Interrupt priority. Refer Usage of Interrupt Macro for more details.
*/
IFX_INTERRUPT(SCUERU_IntFLA_Handler, 0, ISR_PRIORITY_SCUERU_INTFLA);
IFX_INTERRUPT(SCUERU_IntFLB_Handler, 0, ISR_PRIORITY_SCUERU_INTFLB);

/* Interrupt Service Routine */
void SCUERU_IntFLA_Handler(void)
{
FL_pulseCnt ++;
boolean trigB = IfxPort_getPinState(&MODULE_P20, 0);
if(trigB)
{
FL_Dir = -1.0;
}
else
{
FL_Dir = 1.0;
}


}

void SCUERU_IntFLB_Handler(void)
{
FL_pulseCnt ++;
boolean trigA = IfxPort_getPinState(&MODULE_P11,10);
if(trigA)
{
FL_Dir = 1.0;
}
else
{
FL_Dir = -1.0;
}
}

/* This functions initializes the output pin for the LED and the pin which toggles the state for generating
* the falling and rising edges which are used to trigger the interrupt.
* Additionally this function is configuring the ERU module including the service request configuration */
void initPeripheralsAndERU(void)
{
/* Turn off LED (LED is low-active) */

/* Trigger pin */
g_ERUconfig_FL_A.reqPin = FL_A_IN; /* Select external request pin */

/* Initialize this pin with pull-down enabled
* This function will also configure the input multiplexers of the ERU (Register EXISx)
*/
IfxScuEru_initReqPin(g_ERUconfig_FL_A.reqPin, IfxPort_InputMode_pullUp);

/* Determine input channel depending on input pin */
g_ERUconfig_FL_A.inputChannel = (IfxScuEru_InputChannel) g_ERUconfig_FL_A.reqPin->channelId;

/* Input channel configuration */
IfxScuEru_enableRisingEdgeDetection(g_ERUconfig_FL_A.inputChannel); /* Interrupt triggers on
rising edge (Register RENx) and */
// IfxScuEru_enableFallingEdgeDetection(g_ERUconfig_FL_A.inputChannel); /* on falling edge (Register FENx) */

/* Signal destination */
g_ERUconfig_FL_A.outputChannel = IfxScuEru_OutputChannel_0; /* OGU channel 0 */
/* Event from input ETL0 triggers output OGU0 (signal TRx0) */
g_ERUconfig_FL_A.triggerSelect = IfxScuEru_InputNodePointer_0;

/* Connecting Matrix, Event Trigger Logic ETL block */
/* Enable generation of trigger event (Register EIENx) */
IfxScuEru_enableTriggerPulse(g_ERUconfig_FL_A.inputChannel);
/* Determination of output channel for trigger event (Register INPx) */
IfxScuEru_connectTrigger(g_ERUconfig_FL_A.inputChannel, g_ERUconfig_FL_A.triggerSelect);

/* Configure Output channels, OutputGating Unit OGU (Register IGPy) */
IfxScuEru_setInterruptGatingPattern(g_ERUconfig_FL_A.outputChannel, IfxScuEru_InterruptGatingPattern_alwaysActive);

/* Service request configuration */
/* Get source pointer depending on outputChannel (SRC_SCUERU0 for outputChannel0) */
g_ERUconfig_FL_A.src=&MODULE_SRC.SCU.SCUERU[(int) g_ERUconfig_FL_A.outputChannel % 4];
IfxSrc_init(g_ERUconfig_FL_A.src, IfxSrc_Tos_cpu0, ISR_PRIORITY_SCUERU_INTFLA);
IfxSrc_enable(g_ERUconfig_FL_A.src);

 

g_ERUconfig_FL_B.reqPin = FL_B_IN; /* Select external request pin */

/* Initialize this pin with pull-down enabled
* This function will also configure the input multiplexers of the ERU (Register EXISx)
*/
IfxScuEru_initReqPin(g_ERUconfig_FL_B.reqPin, IfxPort_InputMode_pullUp);

/* Determine input channel depending on input pin */
g_ERUconfig_FL_B.inputChannel = (IfxScuEru_InputChannel) g_ERUconfig_FL_B.reqPin->channelId;

/* Input channel configuration */
IfxScuEru_enableRisingEdgeDetection(g_ERUconfig_FL_B.inputChannel); /* Interrupt triggers on
rising edge (Register RENx) and */
// IfxScuEru_enableFallingEdgeDetection(g_ERUconfig_FL_B.inputChannel); /* on falling edge (Register FENx) */

/* Signal destination */
g_ERUconfig_FL_B.outputChannel = IfxScuEru_OutputChannel_0; /* OGU channel 0 */
/* Event from input ETL0 triggers output OGU0 (signal TRx0) */
g_ERUconfig_FL_B.triggerSelect = IfxScuEru_InputNodePointer_0;

/* Connecting Matrix, Event Trigger Logic ETL block */
/* Enable generation of trigger event (Register EIENx) */
IfxScuEru_enableTriggerPulse(g_ERUconfig_FL_B.inputChannel);
/* Determination of output channel for trigger event (Register INPx) */
IfxScuEru_connectTrigger(g_ERUconfig_FL_B.inputChannel, g_ERUconfig_FL_B.triggerSelect);

/* Configure Output channels, OutputGating Unit OGU (Register IGPy) */
IfxScuEru_setInterruptGatingPattern(g_ERUconfig_FL_B.outputChannel, IfxScuEru_InterruptGatingPattern_alwaysActive);

/* Service request configuration */
/* Get source pointer depending on outputChannel (SRC_SCUERU0 for outputChannel0) */
g_ERUconfig_FL_B.src=&MODULE_SRC.SCU.SCUERU[(int) g_ERUconfig_FL_B.outputChannel % 4];
IfxSrc_init(g_ERUconfig_FL_B.src, IfxSrc_Tos_cpu0, ISR_PRIORITY_SCUERU_INTFLB);
IfxSrc_enable(g_ERUconfig_FL_B.src);
}


void RPMCntr(void)
{
float pulsePerRev = (float)(FL_pulseCnt/120.0);
float dir = (float)(FL_Dir * 1.0);
FL_RPM = (float)(dir * pulsePerRev * 600.0);
FL_pulseCnt = 0.0;
}

 

0 Likes
1 Solution
MoD
Employee
Employee
50 likes received 500 replies posted 100 solutions authored

As you can see in the name of your used pins (IfxScu_REQ6...) they are using the same ERU channel (6). You can select only 1 input on each ERU channel. For multiple interrupts you must use pins which are using different ERU channels.

View solution in original post

0 Likes
2 Replies
MoD
Employee
Employee
50 likes received 500 replies posted 100 solutions authored

As you can see in the name of your used pins (IfxScu_REQ6...) they are using the same ERU channel (6). You can select only 1 input on each ERU channel. For multiple interrupts you must use pins which are using different ERU channels.

0 Likes
Joe_08
Level 2
Level 2
First solution authored 5 replies posted 5 questions asked

Perfect, thank you clearing this up, this makes a lot more sense, and when I tried it, it worked.

0 Likes