I pulled up a pin level and set a idle loop(1200 times) and then pull down the pin level. The pin level is measured by a scope. I found a problem of code running time which might be relevant to S32 optimation options.
Here are the code:
SIU.GPDO.R=1; //pull up the pin 73
} //idle loop for 1200 times
SIU.GPDO.R=0; //pull down the pin 73
The system clock was set to 120MHz, so I thought the high level should be longer than 10us. However, when the optimization was chosed to None(-o0) the high level time of pin73 is about 330us! And when the optimization was chosed to Optimize(-o1) the high level time of pin73 is about 36us which I think is rational. And when the optimization was chosed to Optimize most(-o3) the high level time of pin73 is about 50ns which I think the idle is totally ignored by the compiler.
Question: The same code was also tested by CodeWarrior and the result is OK. So I think it might be relevant to the S32 compiler.
I don't know which MCU you are using - MPC5744P?
Anyway - use idle loop for timing is not good idea. There is for example PIT module for this purpose - we have example code in S32DS - pit_periodic_interrupt_mpc5744p. To your questions - please check disassembly code for your idle loop. For no optimization It looks like this:
01002db6: se_li r7,0
01002db8: se_stw r7,8(r31)
01002dba: e_b 0x1002dc4 <main+140>
01002dbe: se_lwz r7,8(r31)
01002dc0: se_addi r7,1
01002dc2: se_stw r7,8(r31)
01002dc4: se_lwz r6,8(r31)
01002dc6: e_li r7,65534
01002dca: cmplw cr7,r6,r7
01002dce: mfcr r7
01002dd2: e_rlwinm r7,r7,28,0,3
01002dd6: mtcrf 128,r7
01002dda: e_ble 0x1002dbe <main+134>
which means bunch of instructions. Some optimization levels completely remove idle loop - because technically it does nothing (it is dead code).