-
Notifications
You must be signed in to change notification settings - Fork 3k
UnbufferedSerial: add is_tx_active() #14420
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the one hand the PR in itself looks Ok to me.
On the other hand I am not sure this is good to bring it that or at least this way in the API.
This method has a high potential of creating TOCTOU issues that would be hard to debug.
Since it's at the C++ level, it might be interesting to have a method that takes a lambda to prevent further TX to be started in a thread/interrupt safe manner.
@pan- Is there a c++ pattern that would help us dealing with this?
@ithinuel thanks for reviewing this. Just to better clarify the use case of is_tx_active() method; this is meant to be used not only to prevent further tx to be started but also to prevent other actions such as GPIO state changes. For the particular case of #14227 this can be also changed in someting that waits the end of serial transmission and not just reporting the state, but maybe it becomes too specific. If there is any suggestion on how to make this more safe i'm happy to implement and test it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I think the PR is OK with the current API however we should seriously consider fixing write
to return when the last byte in the buffer has been transmitted. Some signal indicating that the internal UART buffer is empty could be nice too.
* | ||
* @return Non-zero if the TX transaction is ongoing, 0 otherwise | ||
*/ | ||
int is_tx_active(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to reimplement the method. Just import it from the parent class:
using SerialBase::is_tx_active;
That's a bit extreme, and would have real-world performance impact. Normal users want their bytes going out back-to-back to maintain line rate, and you want at least one byte of data register/FIFO to do that, and have the next byte ready. "Unbuffered" means "no software buffer", not "sync the hardware FIFO after every write". It would make sense to wire up
Both could be modified to spin waiting for |
Thanks @kjbracey-arm That would definitely make sense to wait for |
@kjbracey-arm @pan- Thanks a lot for your suggestions. I will prepare another pr adding HAL synchronization with |
Cool. Note that even if you put
|
This pull request has automatically been marked as stale because it has had no recent activity. @pennam, please carry out any necessary work to get the changes merged. Thank you for your contributions. |
i'm closing this pr because i think further improvements should rely on #14600 |
Summary of changes
in certain situations, like #14227, using UnbufferedSerial we need to know if serial transmission ended before going on. This pr adds is_tx_active() method to UnbufferedSerial class.
/cc @facchinm
Impact of changes
Migration actions required
Documentation
Pull request type
Test results
Reviewers
@0xc0170