Where is uart_read_bytes_available()

murray_lang
Posts: 24
Joined: Fri Oct 07, 2016 4:43 pm

Where is uart_read_bytes_available()

Postby murray_lang » Tue Feb 28, 2017 6:29 am

Hi,

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;
}
Although highly dubious, I have copied this into uart.c in order to have access to static objects defined therein. It would make life much nicer if such a function could be provided by the SDK.
Regards,
Murray

LozzaGMK
Posts: 1
Joined: Fri Apr 09, 2021 5:00 pm

Re: Where is uart_read_bytes_available()

Postby LozzaGMK » Fri Apr 09, 2021 5:47 pm

Tried to post a reply but it didn't work...

How about

Code: Select all

uart_get_buffered_data_len()
?

Thought I'd reply, even though this is an old comment, as I had the same issue.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 114 guests