Trigger the STM0 Comparator 0 manually using its corresponding Service Request Node
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "IfxPort.h"
#include "IfxStm.h"
/*interrupt priority number for STM0 comparator 0*/
#define IFX_INTPRIO_STM0_CMP0 10
/*STM0 module*/
#define STM0 0
/*STM comparator 0*/
#define CMP0 0
IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
void core0_main(void)
{
IfxCpu_enableInterrupts();
/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdogs and service them periodically if it is required */
IfxScuWdt_disableCpuWatchdog( IfxScuWdt_getCpuWatchdogPassword() );
IfxScuWdt_disableSafetyWatchdog( IfxScuWdt_getSafetyWatchdogPassword() );
/* Wait for CPU sync event */
IfxCpu_emitEvent( &g_cpuSyncEvent );
IfxCpu_waitEvent( &g_cpuSyncEvent, 1 );
/*configure the pin */
IfxPort_setPinMode( &MODULE_P00, 5, IfxPort_Mode_outputPushPullGeneral );
IfxPort_setPinPadDriver( &MODULE_P00, 5, IfxPort_PadDriver_cmosAutomotiveSpeed1 );
/* Call the function to route the trigger from for STM0 CMP0 to CPU0 and set
* priority specified as 10 in its corresponding Service Request Node (SRN)
* This is what will match with the vector interrupt */
IfxSrc_init( &MODULE_SRC.STM.STM[ STM0 ].SR[ CMP0 ], IfxSrc_Tos_cpu0, IFX_INTPRIO_STM0_CMP0 );
/* Enable the service request node, "&MODULE_SRC.STM.STM[ STM0 ].SR[ CMP0 ]" is the
address of the corresponding Service Request Node (SRN)*/
IfxSrc_enable( &MODULE_SRC.STM.STM[ STM0 ].SR[ CMP0 ] );
while(1)
{
/* Trigger the interrupt on STM0 CMP0, this is going to force the interrupt since
* is not cause by the STM peripheral itself */
IfxSrc_setRequest( &MODULE_SRC.STM.STM[ STM0 ].SR[ CMP0 ] );
/*delay 500ms before trigger the interrupt again*/
IfxStm_waitTicks( &MODULE_STM0, IfxStm_getTicksFromMilliseconds( &MODULE_STM0, 500u ) );
}
}
/*The program will jump here imediatly after the function IfxSrc_setRequest trigger the STM interrupt.
The interrupt service routine is declared using the macro IFX_INTERRUPT, a name Isr_function is given,
indicate the vector table is the number 0 corresponding to CPU0 and the priority number
vector table and priority is what will really match with the interrupt request*/
IFX_INTERRUPT( Isr_function, 0, IFX_INTPRIO_STM0_CMP0 )
{
/*we do something like flip a led */
IfxPort_togglePin( &MODULE_P00, 5 );
/*the is no need to clear any vector interrupt flag*/
}