Skip to content

Conversation

@shlomow
Copy link
Contributor

@shlomow shlomow commented Dec 17, 2020

This pr fixes multiple bugs in the uart async test.

The waiting for RX_RDY takes makes timeout in rx
since it was enabled with timeout of 50 ms, and
the semaphore waits for 100 ms.

Signed-off-by: Shlomi Vaknin <[email protected]>
Currently, this test expects the rx_rdy flag to not
occur after transmitting 5 bytes, which is not the case
in loopback uart test.

Signed-off-by: Shlomi Vaknin <[email protected]>
First, increase the timeout in rx_enable, as it takes
much more than 10 ms to send 1500 bytes in 115200
baudrate.

Second, after sending the 1000 bytes, we expect to
receive first rx_rdy and after that tx_done. Currently,
this order makes the rx_rdy to be received twice
before taking the rx_rdy the semaphore. Since this
semaphore has max count of 1 we have a bug.

Signed-off-by: Shlomi Vaknin <[email protected]>
@shlomow shlomow requested a review from Mierunski as a code owner December 17, 2020 17:53
@github-actions github-actions bot added the area: Tests Issues related to a particular existing or missing test label Dec 17, 2020

uart_rx_enable(uart_dev, rx_buf, 10, 50);
zassert_equal(k_sem_take(&rx_rdy, K_MSEC(100)), -EAGAIN,
zassert_equal(k_sem_take(&rx_rdy, K_MSEC(10)), -EAGAIN,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least on nrf drivers RX timeout was implemented as break between bytes. It allows to report user when some data was received. It seems like more reasonable than timeouting even without any bytes received. In that case 100ms is an arbitrary value.

However, i see that api is not clear about it.

zassert_equal(k_sem_take(&tx_done, K_MSEC(100)), 0, "TX_DONE timeout");
zassert_equal(k_sem_take(&rx_rdy, K_MSEC(100)), 0, "RX_RDY timeout");
zassert_equal(k_sem_take(&rx_rdy, K_MSEC(100)), -EAGAIN,
zassert_equal(k_sem_take(&rx_rdy, K_MSEC(10)), -EAGAIN,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100ms was an arbitrary value.

zassert_equal(k_sem_take(&tx_done, K_MSEC(100)), 0, "TX_DONE timeout");
zassert_not_equal(k_sem_take(&rx_rdy, K_MSEC(1000)), 0,
"RX_RDY timeout");
zassert_equal(k_sem_take(&rx_rdy, K_MSEC(100)), 0, "RX_RDY timeout");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when rx is started with SYS_FOREVER_MS timeout, it shall report RX_RDY event only if full buffer is recieved (100 bytes) so there should be no event after 5 bytes.

memset(long_tx_buf, 1, sizeof(long_tx_buf));

uart_rx_enable(uart_dev, long_rx_buf, sizeof(long_rx_buf), 10);
uart_rx_enable(uart_dev, long_rx_buf, sizeof(long_rx_buf), 150);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RX timeout is a inactive time on RX which leads to RX_RDY event.

@nordic-krch
Copy link
Contributor

@shlomow i think that test failures you are seeing are caused by different interpretation of rx timeout. I will make a PR to clarify what rx timeout means.

@nordic-krch
Copy link
Contributor

See

* is counted from last byte received i.e. if no data was received, there
where it is clarified.

@shlomow
Copy link
Contributor Author

shlomow commented Dec 18, 2020

@nordic-krch Thanks a lot for the clarifications! I think that I expected the driver to notify the user for available data as soon as it detects it. Since I am using stm32 the hardware has a feature that it sends interrupt when it finds no activity for one uart frame (typically 10 bit times). This api force some latency on users who want to respond fast to uart reception. I guess this is what I missed. Thanks again!

@nordic-krch
Copy link
Contributor

@shlomow some time ago i was also mentioning that milliseconds timeout is too much in some cases when API was initially discussed: #10820 (comment)
As there are only few implementations present maybe it's worth to pursue change to microseconds.

@nordic-krch
Copy link
Contributor

@shlomow I've created #30861. Can you leave your comment there?

@shlomow
Copy link
Contributor Author

shlomow commented Dec 18, 2020

I commented there. Thanks again! I am closing this PR.

@shlomow shlomow closed this Dec 18, 2020
@shlomow shlomow deleted the fix-uart-async-test branch December 19, 2020 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants