Created
October 4, 2013 18:34
-
-
Save dagon666/6830527 to your computer and use it in GitHub Desktop.
interrupt driven transmission
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ISR(USART_UDRE_vect, ISR_BLOCK) { | |
| // proceed if there still is data to be send | |
| if (g_tx_buff.head != g_tx_buff.tail) { | |
| UDR0 = g_tx_buff.ring[g_tx_buff.tail]; | |
| g_tx_buff.tail = (g_tx_buff.tail + 1) % SERIAL_TX_RING_SIZE; | |
| } | |
| else { | |
| // mask the interrupt everything has been send | |
| UCSR0B &= ~_BV(UDRIE0); | |
| } | |
| } | |
| unsigned char serial_sendc(unsigned char a_data) { | |
| uint8_t n = 0x00; | |
| uint8_t next = | |
| ((g_tx_buff.head + 1) % SERIAL_TX_RING_SIZE); | |
| /// do not overflow the buffer | |
| if (next != g_tx_buff.tail) { | |
| g_tx_buff.ring[g_tx_buff.head] = a_data; | |
| g_tx_buff.head = next; | |
| n = 1; | |
| // enable data register empty interrupt | |
| UCSR0B |= _BV(UDRIE0); | |
| } | |
| return n; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment