[an error occurred while processing this directive]
[an error occurred while processing this directive]
|
/* -----------------12.12.99 21:39---------------------------------------------------------------------*/
volatile U8 tx_buffer[TX_BUFFER_SIZE];
volatile U8 *tx_tail, *tx_head;
volatile U8 rx_buffer[RX_BUFFER_SIZE];
volatile U8 *rx_tail, *rx_head;
/* -----------------12.12.99 21:37-------------------
UART receive into circle buffer
--------------------------------------------------*/
interrupt [UART_RX_vect] void UART_RX_interrupt(void)
{
//_SEI();
*rx_head = UDR;
rx_head++;
//_SEI();
if(rx_head >= (rx_buffer + RX_BUFFER_SIZE))
rx_head = rx_buffer;
}
/* -----------------12.12.99 21:37-------------------
UART transmit from circular buffer
--------------------------------------------------*/
interrupt [UART_UDRE_vect] void UART_UDRE_interrupt(void)
{
//_SEI();
if(tx_tail != tx_head)
{
UDR = *tx_tail;
tx_tail++;
//_SEI();
if (tx_tail >= (tx_buffer + TX_BUFFER_SIZE))
tx_tail = tx_buffer;
}
else
clr_bit(UCR, UDRIE);
}
// -------------------------------------------------------
// UART initialisation
//
void init_uart (U32 baud)
{
UBRR = (F_CLK/16)/baud - 1; /* the baud rate */tx_tail = tx_head = tx_buffer;
rx_tail = rx_head = rx_buffer;UCR = (1<
}
/*-------------------------------------------------------
This functions use char instead of int
-------------------------------------------------------*/
char _low_level_get(void)
{
return 0;
}
/*-------------------------------------------------------*/
void put_char(char c)
{
char *ptemp;
do
{
ptemp = tx_head + 1;
if(ptemp >= (tx_buffer + TX_BUFFER_SIZE))
ptemp = tx_buffer;
}
while(ptemp == tx_tail); /* wait for free space in buffer */clr_bit(UCR, UDRIE);
*tx_head = c;
tx_head = ptemp;
set_bit(UCR, UDRIE);
}
/*-------------------------------------------------------*/
char get_char (void)
{
char c;
while (rx_head == rx_tail)
_WDR();clr_bit(UCR, RXCIE);
c = *rx_tail++;
if(rx_tail >= (rx_buffer + RX_BUFFER_SIZE))
rx_tail = rx_buffer;set_bit(UCR, RXCIE);
return c;
/*-------------------------------------------------------*/
E-mail: info@telesys.ru