Why is there no function such as "uart_read_bytes_available()" i the UART API?
I have implemented my own by copying uart_read_bytes() and taking out the stuff that consumes the data:
Code: Select all
size_t uart_read_bytes_available(uart_port_t uart_num)
{
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", (-1));
uint8_t* data = NULL;
size_t avail = 0;
size_t size;
if(xSemaphoreTake(p_uart_obj[uart_num]->rx_mux, 100/portTICK_RATE_MS) != pdTRUE) {
return 0;
}
if(p_uart_obj[uart_num]->rx_cur_remain == 0) {
data = (uint8_t*) xRingbufferReceive(p_uart_obj[uart_num]->rx_ring_buf, &size, 100/portTICK_RATE_MS);
if(data) {
p_uart_obj[uart_num]->rx_head_ptr = data;
p_uart_obj[uart_num]->rx_ptr = data;
p_uart_obj[uart_num]->rx_cur_remain = size;
}
}
avail = p_uart_obj[uart_num]->rx_cur_remain;
xSemaphoreGive(p_uart_obj[uart_num]->rx_mux);
return avail;
}
Regards,
Murray