Page 1 of 1

Should I use xQueueReceive for UART?

Posted: Mon Dec 26, 2016 12:27 pm
by Espagnole
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) {
		...
	}
}

Re: Should I use xQueueReceive for UART?

Posted: Mon Dec 26, 2016 5:21 pm
by kolban
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.