#ifndef _FILE_UART_DRIVER_H_
#define _FILE_UART_DRIVER_H_

// ****************************************************************************
// CONDITIONAL COMPILATION DIRECTIVES: Conditional compilation control
// ****************************************************************************
// Uncomment following define in case diagnostic data needs to be gathered
// from UART driver (e.g. receiver error counts). Just for debugging
//#define UD_DIAG_ENABLED


// ****************************************************************************
// INCLUDE FILES: Header files of modules referenced by this module
// ****************************************************************************


// ****************************************************************************
// MODULE DOCUMENTATION: Detailed description of the module
// ****************************************************************************


// ****************************************************************************
// PUBLIC TYPES: Public types shared with other modules
// ****************************************************************************


// ****************************************************************************
// PUBLIC MACROS: Public #define directives shared with other modules
// ****************************************************************************
#define UD_RX_BUFF_SIZE_BYTES (700)


// ****************************************************************************
// PUBLIC VARIABLES: Public variables shared with other modules
// ****************************************************************************


// ****************************************************************************
// PUBLIC FUNCTIONS: Public functions shared with other modules
// ****************************************************************************
//---------------------------------------------------------------------
//! @brief Initialization of UART0 periphery 
//!
//! Initializes UART0 periphery for 1 start / stop bit, no parity, 
//! and baud rate specified as input parameter. Receiver and
//! transmitter are enabled as well as receiver interrupt.
//!
//! @param[in] baudRateBpS - requested baud rate in bits per second
//! @param[out] N/A
//! @return N/A
//---------------------------------------------------------------------
void UDinitialize( uint32_t baudRateBpS );

//---------------------------------------------------------------------
//! @brief Read data received on UART0 periphery
//!
//! Reads the data received on UART0 periphery since the last call
//! of UDread function. Received data are already present in the 
//! internal buffer of uart driver module, pointer to such buffer
//! is provided as return value and number of received bytes is
//! provided as output parameter. Data are valid until the next
//! call of the UDread function. Uart driver module internally 
//! switches the receive buffer (in critical section) with each
//! call of UDread, so that one buffer is always available for
//! receiver and one is available for user application. This
//! way continuous reception is achieved, however user application
//! must read the data enough fast, so that the uarts internal
//! buffer does not overflow.
//!
//! @param[in] N/A
//! @param[out] lengthBytes - number of bytes received since the
//!                           last call of the UDread function
//! @param[out] overflow - indication if the uarts internal
//!                        rx buffer overflowed since the last
//!                        call of UDread function  
//! @return data - pointer to the uarts internal rx buffer,
//!                contains bytes received since the last call
//!                of the UDread function, starting at address
//!                0 of the provided buffer.
//---------------------------------------------------------------------
uint8_t * UDread( uint16_t * lengthBytes, uint8_t * overflow );

//---------------------------------------------------------------------
//! @brief Flush data in the active receive buffer
//!
//! Throws out data in the active receive buffer. Overflow
//! flag is also cleared.
//!
//! @param[in] N/A
//! @param[out] N/A
//! @return N/A
//---------------------------------------------------------------------
void UDflushRxBuffer( void );

#endif /* _FILE_UART_DRIVER_H_ */