RE: [avr-gcc-list] About context saving in Vectors

2009-01-15 Thread Stu Bell
Jim Brain wrote: Which is why there is the util/atomic.h macros. Check out: ATOMIC_BLOCK( ATOMIC_RESTORESTATE ) Can someone clarify why these macros are preferred over doing cli()/sei()/SREG=sreg in code? I'm not trying to troll, but wonder if there is something I am missing. Jim:

Re: [avr-gcc-list] About context saving in Vectors

2009-01-15 Thread Paulo Marques
Stu Bell wrote: Jim Brain wrote: [...] Can someone clarify why these macros are preferred over doing cli()/sei()/SREG=sreg in code? I'm not trying to troll, but wonder if there is something I am missing. [...] More important, in my mind, is that the macros are written in such a way that

[avr-gcc-list] About context saving in Vectors

2009-01-14 Thread Lin Nan
Hi all, I have been focused on a problem for three days. My program does not work if compiled with -Os in Ubuntu Linux 8.10 (Avr Gcc 4.3.0), but works if compiled with -Os in Windows+WinAVR(20080512). After quite a long time of digging, I found that a piece of code does not work

Re: [avr-gcc-list] About context saving in Vectors

2009-01-14 Thread Preston Wilson
Weddington, Eric wrote: I have been focused on a problem for three days. My program does not work if compiled with -Os in Ubuntu Linux 8.10 (Avr Gcc 4.3.0), but works if compiled with -Os in Windows+WinAVR(20080512). Version 4.3.0 of AVR GCC has known code generation problems that

Re: [avr-gcc-list] About context saving in Vectors

2009-01-14 Thread David Kelly
On Wed, Jan 14, 2009 at 09:14:20AM -0700, dlc wrote: The solution is to NOT call functions from within your ISR. That is just evil. Get your data in the ISR, put it in a mailbox or buffer and have a regularly scheduled function handle the details from outside the ISR. I like to use

RE: [avr-gcc-list] About context saving in Vectors

2009-01-14 Thread Stu Bell
The solution is to NOT call functions from within your ISR. That is just evil. Perhaps. And yet, there are occasions when even the reviled goto is useful, and even correct. All generalizations fail at some point. Including this one. Get your data in the ISR, put it in a mailbox or

Re: [avr-gcc-list] About context saving in Vectors

2009-01-14 Thread Dave Hylands
Hi Lin (and Dennis), And the function ISR(USART1_RX_vect) in Linux saves even fewer registers. The solution is to NOT call functions from within your ISR. That is just evil. Get your data in the ISR, put it in a mailbox or buffer and have a regularly scheduled function handle the details

Re: [avr-gcc-list] About context saving in Vectors

2009-01-14 Thread David Kelly
On Wed, Jan 14, 2009 at 10:02:48AM -0700, Stu Bell wrote: Don't quite understand the push/popped reference, but if a variable is accessed in both interrupt space and user space it needs to be protected so that its uses atomically. Which is why there is the util/atomic.h macros. Check

Re: [avr-gcc-list] About context saving in Vectors

2009-01-14 Thread dlc
David Kelly wrote: On Wed, Jan 14, 2009 at 09:14:20AM -0700, dlc wrote: The solution is to NOT call functions from within your ISR. That is just evil. Get your data in the ISR, put it in a mailbox or buffer and have a regularly scheduled function handle the details from outside the ISR.

Re: [avr-gcc-list] About context saving in Vectors

2009-01-14 Thread dlc
I guess that we agree. :) My biggest problem was getting variables established that gcc wouldn't try to save when the ISR started. I've tried REGISTER, but I couldn't guarantee that the register I'd fixed an index to was really not being used elsewhere, I had one instance where it clearly

Re: [avr-gcc-list] About context saving in Vectors

2009-01-14 Thread Preston Wilson
The solution is to NOT call functions from within your ISR. That is just evil. Get your data in the ISR, put it in a mailbox or buffer and have a regularly scheduled function handle the details from outside the ISR. I like to use ring buffers to store data from an ISR. When using the

Re: [avr-gcc-list] About context saving in Vectors

2009-01-14 Thread David Kelly
On Wed, Jan 14, 2009 at 01:41:33PM -0700, dlc wrote: I guess that we agree. :) My biggest problem was getting variables established that gcc wouldn't try to save when the ISR started. I've tried REGISTER, but I couldn't guarantee that the register I'd fixed an index to was really not

Re: [avr-gcc-list] About context saving in Vectors

2009-01-14 Thread Daniel O'Connor
On Thursday 15 January 2009 04:15:14 Dave Hylands wrote: Hi Lin (and Dennis), And the function ISR(USART1_RX_vect) in Linux saves even fewer registers. The solution is to NOT call functions from within your ISR. That is just evil. Get your data in the ISR, put it in a mailbox or

Re: [avr-gcc-list] About context saving in Vectors

2009-01-14 Thread David Kelly
On Jan 14, 2009, at 5:58 PM, Daniel O'Connor wrote: On Thursday 15 January 2009 04:15:14 Dave Hylands wrote: And here's some code that implements such a ring buffer. As David Kelly points out, as long as the index type is uint8_t, then nothing special is required (which for this particular

Re: [avr-gcc-list] About context saving in Vectors

2009-01-14 Thread Dave Hylands
Hi Daniel, And here's some code that implements such a ring buffer. As David Kelly points out, as long as the index type is uint8_t, then nothing special is required (which for this particular implementation means that buffers upto 128 entries would be supported)

Re: [avr-gcc-list] About context saving in Vectors

2009-01-14 Thread Dave Hylands
Hi David, You will notice Dave Hyland's code is C++. It's actually got a C portion, which is the macros, and it has a template, which is only compiled in if you're using C++. Personally, I don't use the C++ stuff very much. I just posted a couple links to my C based UART code which uses the