The example is quite similar to the previous one, but in this case, we utilize the 64-bit capability of the STM timer. The iLLD library provides a function to calculate the number of counts equivalent to milliseconds, thus avoiding the complexity of manual calculation.
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "IfxPort_Io.h"
#include "IfxStm.h"
IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
void core0_main(void)
{
sint32 Ticks;
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 );
/*get the number of ticks need it to count up to 500 milliseconds
* by default CPU0 frequency is set to 100MHz and the same frequency feeds the STM timer
* this fucntions use these values to calculate how many ticks are required to count up to
* 500ms
* Ticks = (100000 / 1000) * miliseconds = 50000 */
Ticks = IfxStm_getTicksFromMilliseconds( &MODULE_STM0, 500u );
while(1)
{
/*Flip the led on port 00 pin 5*/
IfxPort_togglePin( &MODULE_P00, 5 );
/*function internally will wait here reading the STM0 (for the CPU0), while
* the number of ticks reach its count, which in turns has to be for a period
* of time up to 500ms*/
IfxStm_waitTicks( &MODULE_STM0, Ticks );
}
}