11.07.2015 Views

Imagecraft c compiler and development environment for the atmel avr

Imagecraft c compiler and development environment for the atmel avr

Imagecraft c compiler and development environment for the atmel avr

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ICCV8 <strong>for</strong> AVR – C Compiler <strong>for</strong> Atmel AVR2. Insert _StackCheck(); in your code where you want to check <strong>the</strong> stacks <strong>for</strong>overflow. This may be anywhere in your code, e.g. inside your Watchdog Timerfunction.3. When _StackCheck() detects a stack overflow, it calls <strong>the</strong> function_StackOverflowed() with an integer argument with a value of 1 to indicatethat <strong>the</strong> hardware stack has overflowed, <strong>and</strong> a value of 0 to indicate that <strong>the</strong>software stack has overflowed.4. The default _StackOverflowed() library function jumps to location 0 <strong>and</strong>resets <strong>the</strong> program. To change this default behavior, write your own_StackOverflowed function in your source code. This will override <strong>the</strong> defaultone. For program debugging, your _StackOverflowed function should dosomething to indicate a catastrophic condition, perhaps by blinking a LED. If youare using a debugger, you can set a breakpoint at <strong>the</strong> _StackOverflowedfunction to see if it gets called.The prototypes <strong>for</strong> <strong>the</strong>se two functions are listed in <strong>the</strong> header file AVRdef.h.SentinelsThe startup code writes a sentinel byte at <strong>the</strong> address just above <strong>the</strong> data area <strong>and</strong> asimilar byte at <strong>the</strong> address just above <strong>the</strong> software stack. If <strong>the</strong> sentinel bytes getchanged, <strong>the</strong>n a stack overflow has occurred.Note that if you are using dynamic memory allocation, you must skip <strong>the</strong> sentinel byteat _bss_end <strong>for</strong> your heap allocation. See St<strong>and</strong>ard Library And Memory AllocationFunctions.107

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!