libs/avr_lib/uart.c
bool UART_TransmitByte(uint8_t c, bool blocking)
{
#ifdef UART_TX_INTERUPT

    if (!tx_busy)
    {
        // send the first byte to start the ISR
        tx_busy = true;
        loop_until_bit_is_set(UCSRnA, UDREn);
        UDRn = c; /* send data */
        return true;
    }
    else
    {
        // ISR will handle sending subsequent bytes
        // in case the buffer is full we need to wait
        while (BUFFER_full(&txbuff) && blocking)
        {
            ;
        }
        return BUFFER_enqueue(&txbuff, c);
    }
#else // not interupt driven
    if (blocking)
    {
        /* Wait for empty transmit buffer */
        loop_until_bit_is_set(UCSRnA, UDREn);
        UDRn = c; /* send data */
        return true;
    }
    else if (bit_is_clear(UCSRnA, UDREn))
    { // buffer full and not waiting
        return false;
    }
    else
    {
        // buffer empty
        UDRn = c;
        return true;
    }
#endif
}
/**
 * @brief Low level routine for sending a byte of data through the UART
 * Method utilized is dependant on if interupt driven transfers are used.
 *
 * @param c byte of data to send
 */
@brief Low level routine for sending a byte of data through the UART
Method utilized is dependant on if interupt driven transfers are used.

@param c byte of data to send
@brief Low level routine for sending a byte of data through the UART Method utilized is dependant on if interupt driven transfers are used . @param c byte of data to send
bool UART_TransmitByte(uint8_t c, bool blocking)
{
#ifdef UART_TX_INTERUPT
    if (!tx_busy)
    {
        tx_busy = true;
        loop_until_bit_is_set(UCSRnA, UDREn);
        UDRn = c; 
        return true;
    }
    else
    {
        while (BUFFER_full(&txbuff) && blocking)
        {
            ;
        }
        return BUFFER_enqueue(&txbuff, c);
    }
#else 
    if (blocking)
    {
        loop_until_bit_is_set(UCSRnA, UDREn);
        UDRn = c; 
        return true;
    }
    else if (bit_is_clear(UCSRnA, UDREn))
    { 
        return false;
    }
    else
    {
        UDRn = c;
        return true;
    }
#endif
}
bool UART_TransmitByte ( uint8_t c , bool blocking ) { #ifdef UART_TX_INTERUPT if ( ! tx_busy ) { tx_busy = true ; loop_until_bit_is_set ( UCSRnA , UDREn ) ; UDRn = c ; return true ; } else { while ( BUFFER_full ( & txbuff ) && blocking ) { ; } return BUFFER_enqueue ( & txbuff , c ) ; } #else if ( blocking ) { loop_until_bit_is_set ( UCSRnA , UDREn ) ; UDRn = c ; return true ; } else if ( bit_is_clear ( UCSRnA , UDREn ) ) { return false ; } else { UDRn = c ; return true ; } #endif }
@brief Low level routine for sending a byte of data through the UART
 Method utilized is dependant on if interupt driven transfers are used.
@brief Low level routine for sending a byte of data through the UART Method utilized is dependant on if interupt driven transfers are used .
// send the first byte to start the ISR /* send data */ // ISR will handle sending subsequent bytes // in case the buffer is full we need to wait // not interupt driven /* Wait for empty transmit buffer */ /* send data */ // buffer full and not waiting // buffer empty