[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] interrupt-driven buffered UART receiver
From: |
Lorne Gutz |
Subject: |
Re: [avr-gcc-list] interrupt-driven buffered UART receiver |
Date: |
Wed, 12 Mar 2003 07:26:47 -0500 |
Michael sorry about that, and thanks for pointing it out
In the code that works things are a little different.
See below.
Lorne
On Tuesday 11 March 2003 16:07, Michael Jin wrote:
> 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++;
The above line should be
tx_rd_index++;
I'm impressed that you found an error like that.
> > 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
- Re: [avr-gcc-list] interrupt-driven buffered UART receiver, (continued)