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
// 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();
}
}