file SIG_UART_RECV :
SIGNAL(SIG_UART_RECV)
/* signal handler for receive complete interrupt */
{
*uart_rxd_in_ptr0 = inp(UDR); // read byte from receive register
uart_rxd_buf_cnt0++;
if (++uart_rxd_in_ptr0 >= uart_rxd_buffer0 + UART_BUF0_SIZE_IN) // Pointer wrapping
uart_rxd_in_ptr0 = uart_rxd_buffer0;
}
file uart_getchar (depends on SIG_UART_RECV):
s16 uart_getchar(void)
{
u08 c;
if (uart_rxd_buf_cnt0>0) {
cli();
uart_rxd_buf_cnt0--;
c = *uart_rxd_out_ptr0; /* get character from buffer */
if (++uart_rxd_out_ptr0 >= uart_rxd_buffer0 + UART_BUF0_SIZE_IN) /* pointer wrapping */
uart_rxd_out_ptr0 = uart_rxd_buffer0;
sei();
return c;
}
else
return -1; /* buffer is empty */
}
file uart_init:
void uart_init(void)
{
uart_txd_in_ptr0 = uart_txd_out_ptr0 = uart_txd_buffer0;
uart_rxd_in_ptr0 = uart_rxd_out_ptr0 = uart_rxd_buffer0;
uart_txd_buf_cnt0 = 0;
uart_rxd_buf_cnt0 = 0;
// enable RxD/TxD, receive complete int
outp((1<<RXCIE)|(1<<RXEN)|(1<<TXEN),UCSRB); // <-- INTERRUPT enabled
// set baud rate
outp(25, UBRRL);
//outp((u08)UART_BAUD_SELECT, UBRRL);
}
this line :
outp((1<<RXCIE)|(1<<RXEN)|(1<<TXEN),UCSRB); // <-- INTERRUPT enabled receive, transfer enabled
enables the receive interrupt. if i don't have SIG_UART_RECV linked
the mashine will crash. so if i never use uart_getchar this line should
read:
outp((1<<TXEN),UCSRB); // <-- INTERRUPT disabled, receive disabled
with conditional compiling this won't be hard to do. but i don't want
the library recompile for each project, that is not the purpose of a library.
most of my projects do not use uart_getchar, but some do.
|