Core 0
Blink one single led using the three cores, core0 toggle flag variable each second, core1 set the led to low when flag == FALSE and core2 set the led high when flag == TRUE
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "IfxPort_Io.h"
#include "bsp.h"
IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
/*global value shared by the three cores, but only core 0
has awrite operation on this variable*/
uint8 flag;
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() );
/*since the port 00.5 is share resource ti must be configured before cpu suyncrhonization */
IfxPort_setPinMode( &MODULE_P00, 5, IfxPort_Mode_outputPushPullGeneral );
IfxPort_setPinPadDriver( &MODULE_P00, 5, IfxPort_PadDriver_cmosAutomotiveSpeed1 );
/* Wait for CPU sync event */
IfxCpu_emitEvent( &g_cpuSyncEvent );
IfxCpu_waitEvent( &g_cpuSyncEvent, 1u );
while(1)
{
/*toggle flag value every second*/
flag = !flag;
wait( IfxStm_getTicksFromMilliseconds(&MODULE_STM0, 1000 ) );
}
}
Core 1
Only core 0 write the variable every second, but core 1 write into the register to clear the pin
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "IfxPort_Io.h"
extern IfxCpu_syncEvent g_cpuSyncEvent;
extern uint8 flag;
void core1_main(void)
{
IfxCpu_enableInterrupts();
/* !!WATCHDOG1 IS DISABLED HERE!!
* Enable the watchdog and service it periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
while(1)
{
/*when global variable is reset*/
if( flag == FALSE )
{
IfxPort_setPinLow( &MODULE_P00, 5 );
}
}
}
Core 2
While core 2 write into the register again to set the pin, there is no risk of a race condition because the difference of one second between both writing operation in both cores,
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "IfxPort_Io.h"
extern IfxCpu_syncEvent g_cpuSyncEvent;
extern uint8 flag;
void core2_main(void)
{
IfxCpu_enableInterrupts();
/* !!WATCHDOG2 IS DISABLED HERE!!
* Enable the watchdog and service it periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
while(1)
{
/*when global variable is set*/
if( flag == TRUE )
{
IfxPort_setPinHigh( &MODULE_P00, 5 );
}
}
}