[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

From: dlc
Subject: Re: [avr-gcc-list] About context saving in Vectors
Date: Wed, 14 Jan 2009 09:14:20 -0700
User-agent: Thunderbird (Macintosh/20081105)

Lin Nan wrote:
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 correctly where there is also a lot of USART1_TX_vect interrupts.

I compared the assembly code generated in two condition (Linux and Windows) and found that the ISR(USART1_TX_vect) function of Linux version save fewer registers than that of Windows Version, and so does ISR(USART1_RX_vect) function.

The ISR(USART1_TX_vect) function in Windows saves all call-used registers (r18-r27, r30-r31) while the Linux one neglects r21. Since there are function calls in the ISR function, I expected that all call-used registers should be saved.

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 from outside the ISR. I like to use ring buffers to store data from an ISR. When using the ring buffer the ISR modifies the "write" pointer, not the read pointer and the processing function outside the ISR modifies the read pointer and not the write pointer. This means that those pointers don't need "push/popped" in the ISR either.


I think this might be the cause of the strange bug. Does anyone have a comprehensive understanding on it?


AVR-GCC-list mailing list

Dennis Clark          TTT Enterprises

reply via email to

[Prev in Thread] Current Thread [Next in Thread]