Should I use xQueueReceive for UART?

Espagnole
Posts: 10
Joined: Mon Dec 19, 2016 10:18 am

Should I use xQueueReceive for UART?

Postby Espagnole » Mon Dec 26, 2016 12:27 pm

What is more optimal way to use UART: using xQueueReceive or not and read one by one byte?
I wont use any other event.type.

Code: Select all

while (1) {
	if (xQueueReceive(m_uart_queue, (void *)&event, 10 / portTICK_PERIOD_MS)) {
		if (event.type == UART_DATA) {
			uint32_t len = bufferEnd - ptr;
			if (len > event.size) len = event.size;
			int ret = uart_read_bytes(MODULE_UART_NUM, (uint8_t *) ptr, len, 10);
			if (ret > 0) {
				...
			}
		}
	}
}

Code: Select all

while (1) {
	uint32_t len = 1;
	int ret = uart_read_bytes(MODULE_UART_NUM, (uint8_t *) ptr, len, 10 / portTICK_PERIOD_MS);
	if (ret > 0) {
		...
	}
}

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Should I use xQueueReceive for UART?

Postby kolban » Mon Dec 26, 2016 5:21 pm

Optimal usually has a target that you are optimizing for. In computing sometimes it is memory, sometimes it is compilation size, sometimes it is performance of CPU instructions and sometimes it is latency to when a result is processed. In many occasions, one trades-off one dimension of optimization for another. With that in mind, which of the flavors of optimization are you searching for?

For me, I tend to optimize for "simplicity and readability". If I could i.e. 3 hours to get something working that I can come back to and understand rather that 3 days knowing that I have achieved what might be the fastest possible execution.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: No registered users and 71 guests