-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
uart: update meaning of uart_irq_tx_ready
return code
#70939
uart: update meaning of uart_irq_tx_ready
return code
#70939
Conversation
Looking for initial feedback on approach before going through stable API change process |
Part of me thinks that the term "ready" is a boolean entity: whether it is ready or not (and in this case if there are any errors). So I think a new API can be introduced in this case to return number of bytes that can be transmitted. |
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.
Looks fine to me, my only concern is about the potential race conditions. What guarantees that there is no concurrent call from other context to uart_fifo_fill()
in between uart_irq_tx_ready()
and the uart_fifo_fill()
using output from uart_irq_tx_ready()
?
All of these functions are only valid to call inside the interrupt context (triggered by |
What about SMP? |
Great question, I have no idea. This is not really any different from the current situation though. My suspicion is that the API is not really designed to handle SMP, as the requirement for all operations to be run from an interrupt context sounds like a band-aid to avoid multi-threading issues. Does the situation of multiple cores trying to access/modify/control a single hardware peripheral even make sense though? That sounds like a recipe for disaster no matter what we do at an API level, short of wrapping everything in mutexes or spinlocks. |
Yes, it is not different from the current situation and this is why I did approve this PR despite this concern.
The only case in my mind would be that the interrupt itself is handled by multiple cores. My concern is about the SMP where the interrupt handling can end up in any core, not the heterogeneous multicore systems where there it seems to be out of scope. On SMP, I believe this can be handled by using spinlocks instead of irq locking, but I don't currently work on any SMP-capable Zephyr target. |
I suggest at least mentioning it in the migration guide. |
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.
USB LGTM
e8ecd43
to
9e685a7
Compare
drivers/serial/uart_nrfx_uart.c
Outdated
NRF_UART_INT_MASK_TXDRDY) && | ||
!disable_tx_irq && | ||
event_txdrdy_check(); | ||
return ready ? INT_MAX : 0; |
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.
shouldn't 1
be returned instead of INT_MAX
?
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.
uart_nrfx_fifo_fill
will accept any length buffer without truncating it
drivers/serial/uart_async_to_irq.c
Outdated
|
||
return (data->flags & A2I_TX_IRQ_ENABLED) && !(data->flags & A2I_TX_BUSY); | ||
/* async API handles arbitrary sizes */ | ||
return ready ? INT_MAX : 0; |
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.
data->tx.len
contains TX buffer size so it should be returned instead of INT_MAX
.
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.
Ah, I thought it was the length of the currently sending buffer, will fix
9e685a7
to
3694617
Compare
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
Update the documented value range that `uart_irq_tx_ready` returns in order to provide more information to the callers about the number of bytes that could be writted with `uart_fifo_fill` without fragmentation. Signed-off-by: Jordan Yates <jordan@embeint.com>
Update the interrupt driver UART drivers that use `struct ring_buf` internally to report the number of bytes that can be pushed in `uart_fifo_fill` without fragmentation. Signed-off-by: Jordan Yates <jordan@embeint.com>
The async IRQ shim supports writes of any size up to the TX buffer size. Signed-off-by: Jordan Yates <jordan@embeint.com>
9c8c211
to
3273d86
Compare
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.
LGTM. Thanks for the clear migration guide addition!
3273d86
to
9e1be14
Compare
Update nrfx drivers with the minimum number of bytes that can be sent in a single call to `uart_fifo_fill`. Signed-off-by: Jordan Yates <jordan@embeint.com>
4efcd7a
9e1be14
to
4efcd7a
Compare
Update the documented value range that
uart_irq_tx_ready
returns inorder to provide more information to the callers about the number of
bytes that could be written with
uart_fifo_fill
without fragmentation.Does not break any current users of the API, unless they are explicitly checking for
uart_irq_tx_ready() == 1
.Other UART drivers can be updated in the future without violating the API documentation.
Implements #70937.