Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing timeouts with MCUXpresso SDK and LPUART FreeRTOS Driver #73

Open
abusca opened this issue Nov 21, 2024 · 1 comment
Open

Comments

@abusca
Copy link

abusca commented Nov 21, 2024

Hi!
I'm using this library with MCUXpresso SDK's LPUART FreeRTOS Driver (API reference here).
I implemented the read and write functions with LPUART_RTOS_Receive and LPUART_RTOS_Send functions. This driver also allows me to add timeouts with LPUART_RTOS_SetRxTimeout and LPUART_RTOS_SetTxTimeout functions (described here).
These functions accept a constant timeout in ms (rx_timeout_constant_ms) and a per-byte timeout (rx_timeout_multiplier_ms).

Then, LPUART_RTOS_Receive and LPUART_RTOS_Send functions calculate the timeout like this:
const TickType_t rxTickTimeout = (length * handle->rx_timeout_multiplier_ms + handle->rx_timeout_constant_ms) / portTICK_PERIOD_MS;
...
Nonblocking send/receive and wait for events
...
ev = xEventGroupWaitBits(handle->rxEvent, RTOS_LPUART_RX_COMPLETE | RTOS_LPUART_RING_BUFFER_OVERRUN | RTOS_LPUART_HARDWARE_BUFFER_OVERRUN, pdTRUE, pdFALSE, (rxTickTimeout > 0u) ? rxTickTimeout : portMAX_DELAY);

So, as you can see, when timeout is less or equal to 0 it waits forever.

My questions are:

  • In order to adapt byte_timeout_ms to this driver's timeout functions, should I assign byte_timeout_ms to rx_timeout_multiplier_ms and keep rx_timeout_constant_ms to 0?
  • When byte_timeout_ms is 0 it should expire, but how can I do this? Can I just add a timeout of 1ms to rx_timeout_constant_ms in this case?

Thank you!

@debevv
Copy link
Owner

debevv commented Nov 25, 2024

Hi,

  • I guess? byte_timeout_ms was conceived with a primitive byte-by-byte read loop in mind, where you reset a timeout every time before receiving a byte. What you are doing here looks like the closest thing to a byte timeout so i guest that's the way
  • 0 means that you try to read once and then immediately return whatever you read. So yes, if that API does not support this behavior, put the smallest timeout you can to simulate it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants