[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Probably a bug
From: |
Shahpour Moavenat |
Subject: |
[avr-gcc-list] Probably a bug |
Date: |
Tue, 8 Jun 2004 10:10:58 -0700 (PDT) |
Hi all,
Below the email is the source file which problem occurs in.
The problem is in function putchar1, the while loop is translated to
while (tx_counter1 == TX_BUFFER_SIZE1);
from .lst file:
153 .LM12:
154 006a 8091 0000 lds r24,tx_counter1
155 .L5:
156 006e 8830 cpi r24,lo8(8)
157 0070 F1F3 breq .L5
which is a never ending loop when tx_counter1 equals TX_BUFFER_SIZE1. But
in the main program if a SIG_UART1_TRANS interrupt occurs the tx_counter1
decrements one and the while loop in putchar1 should end. But the
generated assembly code, does not see this change (it only sees the
register value not the variable value).
I'm not sure if it is bug or not. But at least, it seems in some
situations the generated assembly code does not do what is meant by the
written C code.
I work in WinAVR 20040404 under Windows XP.
Thank you,
S. Moavenat
The source code:
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/sfr_defs.h>
void putchar1(char c);
#define DATA_REGISTER_EMPTY (1<<UDRE)
// USART1 Transmitter buffer
#define TX_BUFFER_SIZE1 8
char tx_buffer1[TX_BUFFER_SIZE1];
unsigned char tx_wr_index1,tx_rd_index1,tx_counter1;
// USART1 Transmitter interrupt service routine
//interrupt [USART1_TXC] void uart1_tx_isr(void)
INTERRUPT(SIG_UART1_TRANS)
{
cli();
if (tx_counter1)
{
UDR1='c';
--tx_counter1;
UDR1=tx_buffer1[tx_rd_index1];
++tx_rd_index1;
if (tx_rd_index1 == TX_BUFFER_SIZE1) tx_rd_index1=0;
};
sei();
}
// Write a character to the USART1 Transmitter buffer
void putchar1(char c)
{
while (tx_counter1 == TX_BUFFER_SIZE1);
//if(tx_counter1 == TX_BUFFER_SIZE1) return;
cli();
if (tx_counter1 || ((UCSR1A & DATA_REGISTER_EMPTY)==0))
{
tx_buffer1[tx_wr_index1]=c;
++tx_wr_index1;
if (tx_wr_index1 == TX_BUFFER_SIZE1) tx_wr_index1=0;
++tx_counter1;
}
else UDR1=c;
sei();
}
// Declare your global variables here
int main(void)
{
}
__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
- [avr-gcc-list] Probably a bug,
Shahpour Moavenat <=