From: SourceForge.net <no...@so...> - 2009-01-08 22:12:09
|
Bugs item #2492893, was opened at 2009-01-07 17:47 Message generated for change (Comment added) made by nategoos You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=520074&aid=2492893&group_id=68108 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: GCC Group: None Status: Open Resolution: Fixed Priority: 5 Private: No Submitted By: Aleksey V (pro8229) Assigned to: Nobody/Anonymous (nobody) Summary: WinAVR 20081205 - optimization bug Initial Comment: // next line skipping, if I use optimization posudomoyka.sost=WORK; while (newEvent!=TIME_END) // it's give forever loop wdt_reset(); //next line newer start posudomoyka.sost=SLEEP; ---------------------------------------------------------------------- Comment By: Nathan Moore (nategoos) Date: 2009-01-08 16:31 Message: You should not be declaring variables in header files (*.h). If you include example.h within 2 different source files (*.c) each of these may (and should) end up with their own copy of those variables. Within the data.h files you should have stuff like: extern bool savePoint; extern volatile sPosudomoyka posudomoyka; extern volatile signed char newEvent; And in one (and only one) *.c file you should have stuff like: bool savePoint=false; volatile sPosudomoyka posudomoyka = {0,0,0,0,0,SLEEP,SLEEP,NO_EVENT,NO_EVENT,false,false,NO_ERROR,true}; volatile signed char newEvent=-1; Since you only had one *.c file here that's not your problem, but it's going to bite you and it's basic C. You should notice however that there's crazy issues with declaring variables volatile that are bigger than what can be loaded in one cpu operation (like your struct or even an int on AVR). ---------------------------------------------------------------------- Comment By: Aleksey V (pro8229) Date: 2009-01-08 14:11 Message: //next line does not help me volatile signed char newEvent=-1; //next line has helped me volatile sPosudomoyka posudomoyka = {0,0,0,0,0, ... it's not like in FAQ, I think, isn't it? FAQ #1: http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_volatile thanks for help. ---------------------------------------------------------------------- Comment By: Eric Weddington (arcanum) Date: 2009-01-07 18:31 Message: You have your variable newEvent defined in data.h as this: signed char newEvent=-1; You are changing the value of newEvent in an interrupt service routine, and you are reading it in the mainline code in main(). You need to declare this variable as volatile. See the avr-libc user manual, FAQ #1: http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_volatile If it is not declared as volatile, the compiler will never read the value from memory and it will generate an infinite loop. Since it knows that it is in an infinite loop, the compiler correctly determines that the line "posudomoyka.sost=WORK;" can be optimized away as it does nothing and has no valid side effects. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=520074&aid=2492893&group_id=68108 |