avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Problems with ATMEGA8 USART


From: David Kelly
Subject: Re: [avr-gcc-list] Problems with ATMEGA8 USART
Date: Tue, 16 Aug 2005 20:28:57 -0500


On Aug 16, 2005, at 2:48 AM, Nigel Winterbottom wrote:

-----Original Message-----

The one clumsy part of code was in my_putchar() which had to reach
directly into the hardware for the specific port to restart the Tx
IRQ if the buffer had been empty, which causes my Tx IRQ routine to
shut itself off. Also there was a possible race condition.

--
David Kelly N4HHE, address@hidden
====================================================================== ==
Whom computers would destroy, they must first drive mad.

You've missed a trick, restarting USART comms is a simple as re- enabling the interrupt which is safe to do as many times as you like and whenever
you like.

Thats not quite what I meant. I do enable the IRQ for each character. The issue was in finding which UART needed to be enabled without enabling one which would then serve an empty event. Here is the exact code I wrote back in December. Today I'd probably bracket the insertion and masking with cli()/sei().

int
uputc( int c, Uart *fp )
{
        //  We don't inc tx_head until after storing c and
        //  possibly wrapping tx_head to prevent the IRQ
        //  routine from seeing the character until after wrap.
        //  fp->tx_head++ is tempting.

        fp->tbuf[fp->tx_head] = c;

        //  Increment and wrap using a mask
        fp->tx_head = (fp->tx_head + 1) & (TX_MAX_SIZE-1);

        //  If the service routine delivers the char above and
        //  clears UDRIE before we make sure its set below then
        //  below will cause an IRQ with tbuf empty. The service
        //  routine will disable UDRIE again, no harm done.

        //  This is a tacky hack to find the right UART.
        if( fp == &UART0 )
                UCSR0B |= (1<<UDRIE);   // ensure IRQ is enabled
        else
                UCSR1B |= (1<<UDRIE1);  // ensure IRQ is enabled

        return(c);
}


--
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.





reply via email to

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