Skip to content

Instantly share code, notes, and snippets.

@dagon666
Created October 4, 2013 18:34
Show Gist options
  • Save dagon666/6830527 to your computer and use it in GitHub Desktop.
Save dagon666/6830527 to your computer and use it in GitHub Desktop.
interrupt driven transmission
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