1 | ISR (UART0_RECEIVE_INTERRUPT)
|
2 | /*************************************************************************
|
3 | Function: UART Receive Complete interrupt
|
4 | Purpose: called when the UART has received a character
|
5 | **************************************************************************/
|
6 | {
|
7 | unsigned char tmphead;
|
8 | unsigned char data;
|
9 | unsigned char usr;
|
10 | unsigned char lastRxError;
|
11 |
|
12 |
|
13 | /* read UART status register and UART data register */
|
14 | usr = UART0_STATUS;
|
15 | data = UART0_DATA;
|
16 |
|
17 | /* */
|
18 | #if defined( AT90_UART )
|
19 | lastRxError = (usr & (_BV(FE)|_BV(DOR)) );
|
20 | #elif defined( ATMEGA_USART )
|
21 | lastRxError = (usr & (_BV(FE)|_BV(DOR)) );
|
22 | #elif defined( ATMEGA_USART0 )
|
23 | lastRxError = (usr & (_BV(FE0)|_BV(DOR0)) );
|
24 | #elif defined ( ATMEGA_UART )
|
25 | lastRxError = (usr & (_BV(FE)|_BV(DOR)) );
|
26 | #endif
|
27 |
|
28 | /* calculate buffer index */
|
29 | tmphead = ( UART_RxHead + 1) & UART_RX_BUFFER_MASK;
|
30 |
|
31 | if ( tmphead == UART_RxTail ) {
|
32 | /* error: receive buffer overflow */
|
33 | lastRxError = UART_BUFFER_OVERFLOW >> 8;
|
34 | }else{
|
35 | /* store new index */
|
36 | UART_RxHead = tmphead;
|
37 | /* store received data in buffer */
|
38 | UART_RxBuf[tmphead] = data;
|
39 | }
|
40 | UART_LastRxError |= lastRxError;
|
41 | }
|
42 |
|
43 |
|
44 | ISR (UART0_TRANSMIT_INTERRUPT)
|
45 | /*************************************************************************
|
46 | Function: UART Data Register Empty interrupt
|
47 | Purpose: called when the UART is ready to transmit the next byte
|
48 | **************************************************************************/
|
49 | {
|
50 | unsigned char tmptail;
|
51 |
|
52 |
|
53 | if ( UART_TxHead != UART_TxTail) {
|
54 | /* calculate and store new buffer index */
|
55 | tmptail = (UART_TxTail + 1) & UART_TX_BUFFER_MASK;
|
56 | UART_TxTail = tmptail;
|
57 | /* get one byte from buffer and write it to UART */
|
58 | UART0_DATA = UART_TxBuf[tmptail]; /* start transmission */
|
59 | }else{
|
60 | /* tx buffer empty, disable UDRE interrupt */
|
61 | UART0_CONTROL &= ~_BV(UART0_UDRIE);
|
62 | }
|
63 | }
|