Hi;
sorry for poor english, but;
It seems to be so stupid to write something about a
problem which seems to be solved. but remember one
important thing:
registers r2,..,r15 are saved and restored in some
internal functions in C runtime library source codes.
So if your interrupt routine called when r2 register
used by some other functions, it may corrupt its
functionality or even use bad value in this register.
The better way which could be suggested is to use a
temporary register in interrupt service routine
instead of global register allocation which only is
helpfull to be used in special codes which dont call
some specific methods which uses r2 register or
something.
for example:
there are some multiplication and division methods in
CRTL which use r2 register:
register foo char asm("r2");
ISR()
{
foo++;
}
void an_internal_function_which_uses_r2()
{
push r2
// CRITICAL AREA
do something with r2
pop r2
}
main()
{
for(;;)
an_internal_function_which_uses_r2();
}
in this source code if ISR called when CRTL method
uses
r2, foo will not be incremented, and at the other hand
CRTL function works wrong.
but consider to following source code:
int global_var;
ISR()
{
int fast_local_copy = global_var;
do something on fast_local_copy....
global_var = fast_local_copy;
}
overhead for this kind of code is only 4x2 or 8 cycles
(1us on 8MHz)
reza;
____________________________________________________________________________________
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
http://sims.yahoo.com/Message
Re: [AVR-Chat] Re: Claiming global registers in WinAVR / assembly
2007-07-19 by Reza
Attachments
- No local attachments were found for this message.