Question to the uart_async_rxtxtasks_main.c example

NRollo
Posts: 21
Joined: Fri Jan 22, 2021 1:04 pm

Question to the uart_async_rxtxtasks_main.c example

Postby NRollo » Fri Mar 04, 2022 11:09 am

In the "uart_async_rxtxtasks_main.c" UART example I came across these two lines of code:

Code: Select all

 uart_driver_install(UART_NUM_1, RX_BUF_SIZE * 2, 0, 0, NULL, 0);

Code: Select all

xTaskCreate(rx_task, "uart_rx_task", 1024*2, NULL, configMAX_PRIORITIES, NULL);
Why use the
*2
in these cases, is to "inform" about eg. a 16 bit data configuration?

Thanks!

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: Question to the uart_async_rxtxtasks_main.c example

Postby ESP_Sprite » Sat Mar 05, 2022 1:30 am

I don't know why RX_BUF_SIZE * 2 is there, could be that the UART driver is storing metadata next to each received byte. The 1024*2 probably is because it's a more readable/adjustable way to say '2K of memory' than 2048.

NRollo
Posts: 21
Joined: Fri Jan 22, 2021 1:04 pm

Re: Question to the uart_async_rxtxtasks_main.c example

Postby NRollo » Sat Mar 05, 2022 10:38 am

@ESP_Sprite, thanks for the reply.

It just seemed wired to me - because later on in the code the RX buffer is allocated as:

Code: Select all

uint8_t* data = (uint8_t*) malloc(RX_BUF_SIZE+1);
not taking into account that the driver was installed with an RX buffer of size 2048?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Question to the uart_async_rxtxtasks_main.c example

Postby WiFive » Sat Mar 05, 2022 4:45 pm

Seems like it is saying we're going to process at most RX_BUF_SIZE data at once and we'll keep a ring buffer of twice that size for overhead.

NRollo
Posts: 21
Joined: Fri Jan 22, 2021 1:04 pm

Re: Question to the uart_async_rxtxtasks_main.c example

Postby NRollo » Tue Mar 08, 2022 1:46 pm

@WiFive - You are right, that could be it - make sense at least.

Thanks for chipping in.

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 102 guests