Core one toggle the the bits in a variable that later will be send using a buffer to another core, the second core will turn on/off leds according to variable value, notice how a mutex is still in use to avoid both cores access the buffer at the same time and corrupt information when reading or writing
Core 0
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "IfxPort_Io.h"
#include "IfxStm.h"
#include "Ifx_CircularBuffer.h"
IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
IFX_ALIGN(4) IfxCpu_mutexLock resourceLock;
IFX_ALIGN(4) Ifx_CircularBuffer circBuffer;
IFX_ALIGN(4) uint16 buffer[10];
void core0_main( void )
{
uint64 Timeout_500ms;
uint64 SeedTick;
uint8 state = 0;
uint16 leds = 0x00AA;
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() );
/*configure the pin from 5 to 12 on port 00 as output pushpull and cmos speed of 1 */
IfxPort_setGroupModeOutput( &MODULE_P00, 5, 0xff, IfxPort_Mode_outputPushPullGeneral, IfxPort_OutputIdx_general );
IfxPort_setGroupPadDriver( &MODULE_P00, 5, 0xff, IfxPort_PadDriver_cmosAutomotiveSpeed1 );
/*set the initial value to zero, leds turned off*/
IfxPort_setGroupState( &MODULE_P00, 5, 0xff, 0x00 );
circBuffer.base = buffer;
circBuffer.index = 0;
circBuffer.length = 10;
/* Wait for CPU sync event */
IfxCpu_emitEvent( &g_cpuSyncEvent );
IfxCpu_waitEvent( &g_cpuSyncEvent, 10u );
/*get the number of ticks corresponding to 500ms*/
Timeout_500ms = (uint64)IfxStm_getTicksFromMilliseconds( &MODULE_STM0, 500 );
/*get the timer STM0 count for the first time*/
SeedTick = IfxStm_get( &MODULE_STM0 );
while(1)
{
switch(state)
{
case 0:
/* query if the timer count already is equal or bigger than the last count*/
if( ( IfxStm_get( &MODULE_STM0 ) - SeedTick ) >= Timeout_500ms )
{
/*get the timer STM0 count for again*/
SeedTick = IfxStm_get( &MODULE_STM0 );
state = 1;
}
break;
case 1:
/*try to acquire the mutex and remain in this state until then*/
if( IfxCpu_acquireMutex( &resourceLock ) == TRUE )
{
/*once the mutex is ours, write the new value in the less significant four bytes
* of the PORT00 starting at pin 5 */
leds = 0x00ff & ~leds;
Ifx_CircularBuffer_write8( &circBuffer, &leds, 2 );
/*release the mutex for some other core*/
IfxCpu_releaseMutex( &resourceLock );
state = 0;
}
break;
}
}
}
Core 1
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "IfxPort_Io.h"
#include "IfxStm.h"
#include "Ifx_CircularBuffer.h"
extern IfxCpu_syncEvent g_cpuSyncEvent;
extern IfxCpu_mutexLock resourceLock;
extern Ifx_CircularBuffer circBuffer;
void core1_main(void)
{
uint64 Timeout_500ms;
uint64 SeedTick;
uint8 state = 0;
uint16 leds = 0x0030;
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, we need to wait until ports have been initialized */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 10);
/*get the number of ticks corresponding to 500ms*/
Timeout_500ms = (uint64)IfxStm_getTicksFromMilliseconds( &MODULE_STM1, 500 );
/*get the timer STM1 count for the first time*/
SeedTick = IfxStm_get( &MODULE_STM1 );
while(1)
{
switch(state)
{
case 0:
/* query if the timer count already is equal or bigger than the last count*/
if( ( IfxStm_get( &MODULE_STM1 ) - SeedTick ) >= Timeout_500ms )
{
/*get the timer STM1 count for again*/
SeedTick = IfxStm_get( &MODULE_STM1 );
state = 1;
}
break;
case 1:
/*try to acquire the mutex and remain in this state until then*/
if( IfxCpu_acquireMutex( &resourceLock ) == TRUE )
{
/*once the mutex is ours, write the new value in the most significant four bytes
* of the PORT00 starting at pin 5 */
Ifx_CircularBuffer_read8( &circBuffer, &leds, 2 );
IfxPort_setGroupState( &MODULE_P00, 5, 0x00ff, leds );
/*release the mutex for some other core*/
IfxCpu_releaseMutex( &resourceLock );
state = 0;
}
break;
}
}
}