/* This Function Wait until Data RX Ready, and return Data Read from UART.  */
uint8_t uart_read_timeout(uart_num_t uart_num, uint32_t rx_timeout_nb_cycles, uart_error_t *error)
/* This Function Wait until Data RX Ready, and return Data Read from UART.  */
uint8_t uart_read_timeout(uart_num_t uart_num, uint32_t rx_timeout_nb_cycles, uart_error_t *error)
{
	uint32_t uart_port;
	uint8_t uart_val;
	uint32_t counter;
	uart_port = uart_num;
	counter = 0;
	while ((UART_LSR(uart_port) & UART_LSR_RDR) == 0) {
		if (rx_timeout_nb_cycles > 0) {
			counter++;
			if (counter >= rx_timeout_nb_cycles) {
				*error = UART_TIMEOUT_ERROR;
				return 0;
			}
		}
	}
	uart_val = (UART_RBR(uart_port) & UART_RBR_MASKBIT);
	*error = UART_NO_ERROR;
	return uart_val;
}