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

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

Re: [avr-gcc-list] interrupt-driven buffered UART receiver


From: Michael Jin
Subject: Re: [avr-gcc-list] interrupt-driven buffered UART receiver
Date: Tue, 11 Mar 2003 16:07:46 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20021003

Lorne Gutz wrote:
On Tuesday 11 March 2003 06:20, Olaf Zenker wrote:

address@hidden



Hi folks,

     To date I have not seen any driver written in C.

I will send some that I have used in the past.   This
code has been written to produce small code, and
should be compiled with -Os.

cheers
Lorne


[snip]

// UART Transmitter buffer
static uint8_t      tx_buff[16];
static uint8_t      tx_wr_index,tx_rd_index;
volatile uint8_t    tx_counter;

// UART Transmitter interrupt service routine
SIGNAL( SIG_UART_DATA )
{
    uint8_t     tx_buffer_size = 16;

    if( tx_counter != 0 ){
        tx_counter--;

        tx_wr_index++;
        if( tx_wr_index > tx_buffer_size )
            tx_wr_index = 0;

        outp( tx_buff[ tx_wr_index ], UDR );

    }
}


// Write a character to the UART Transmitter buffer

void    putchar( uint8_t c )
{
    uint8_t     tx_buffer_size = 16;

    while( tx_counter >= tx_buffer_size );

    if( ( tx_counter == 0 ) && ( bit_is_clear( USR, UDRE )))
        outp( c, UDR );

    else{

        tx_counter++;
        if( tx_rd_index >= tx_buffer_size )
            tx_rd_index = 0;

        tx_buff[ tx_rd_index ] = c;

        cli();
        tx_counter++;
        sei();
    }
}

I don't quite understand this piece of code, can you explain why the tx_rd_index never increased while the tx_counter did twice in the above function please?
TIA.

Michael





reply via email to

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