Altera_Forum
Honored Contributor
12 years agoEclipse EDS optimizer ommitted delay loop?
Hello!
I was having this code for a simple LED blinking Nios II application based on a counter and some delays:
# include "sys/alt_stdio.h"# include "system.h"# include "altera_avalon_pio_regs.h"
int main()
{
int count = 140;
int delay1 = 0;
int delay2 = 0;
int delay3 = 0;
int delay4 = 0;
/* Event loop never exits. */
while (1) {
IOWR_ALTERA_AVALON_PIO_DATA(LEDS_BASE, count&0x02);
delay1 = 0;
while(delay1 < 900000) {
delay2=0;
while(delay2 < 900000) {
delay3=0;
while(delay3 < 900000) {
delay4=0;
while(delay4 < 900000) {
delay4++;
}
delay3++;
}
delay2++;
}
delay1++;
}
//alt_putstr("DELAY3\n");
count++;
}
return 0;
}
The optimizer was set at level 2 and I was trying to run the program but for some reason I had no delay!! The LEDs were constantly ON. Then I tried to debug the code using a debug configuration in Eclipse and I saw only the count variable but no delay variables. Then I saw a remark somewhere "Optimized out"! When I switched the optimizer option to Off. I finally could see the difference. My question is how can the optimizer change the functionality of the code like this? Doesn't the program become unreliable after this? Regards