#ifndef AL_UART_H
#define AL_UART_H

#include <inttypes.h>
#include <al_config.h>

#ifndef CLOCK_FREQ
#error CLOCK_FREQ must be defined!
#endif 

#if !defined(UART_BAUDRATE) && !defined(UART_BR_DIVIDER)
#error UART_BAUDRATE or UART_DIVIDER must be defined!
#endif

#ifndef UART_RX_FIFO_DEPTH
#define UART_RX_FIFO_DEPTH		16
#endif

#ifndef UART_TX_FIFO_DEPTH
#define UART_TX_FIFO_DEPTH		UART_RX_FIFO_DEPTH
#endif

#ifndef UART_RX_TIMEOUT
#define UART_RX_TIMEOUT			500
#endif

#ifndef UART_BR_DIVIDER
#define UART_BR_DIVIDER			(uint8_t)((CLOCK_FREQ/UART_BAUDRATE/16)-1)
#endif

#define UART_RX_TO_LOOPS		(UART_RX_TIMEOUT/(1000/(CLOCK_FREQ/1024/256)))


void		uart_init(void);
void		uart_suspend(void);
uint8_t		uart_getc(void);
int16_t		uart_timeout_getc(void);
void		uart_putc(uint8_t c_);
void		uart_puts(char* s_);
uint8_t		uart_rx_fifo_empty(void);
uint8_t		uart_tx_fifo_full(void);
uint8_t		uart_tx_fifo_capacity(void);
uint8_t		uart_tx_complete(void);

#endif
