-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
drivers: nrf: Rework UARTE shim for uart ASYNC API and add power management #13064
drivers: nrf: Rework UARTE shim for uart ASYNC API and add power management #13064
Conversation
All checks are passing now. Review history of this comment for details about previous failed status. |
8f07709
to
33f8947
Compare
Codecov Report
@@ Coverage Diff @@
## master #13064 +/- ##
=======================================
Coverage 52.93% 52.93%
=======================================
Files 309 309
Lines 45251 45251
Branches 10447 10447
=======================================
Hits 23953 23953
Misses 16533 16533
Partials 4765 4765 Continue to review full report at Codecov.
|
eb8d65c
to
29b7988
Compare
d15a823
to
fbcf9a9
Compare
@jarz-nordic @nordic-krch @anangl ping |
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.
im leaving some initial comments but i'm not finished with this! will come back soon.
Hardware RX byte counting requires timer instance and one PPI channel | ||
|
||
config UART_0_NRF_HW_ASYNC_TIMER | ||
int "Timer instance" |
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.
what will be the default value? if 0 then it will enable TIMER0 instance and it may conflict with bluetooth as im afraid that it's using timer0 directly.
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.
There is no default value, user has to set it explicitly
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.
So as for now default value is n
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.
If I understand kconfig properly (@ulfalizer can help) this will be a bit undefined, i.e. it's not really a "not-set", cause the value is not boolean. So, it appears to me that the macro is still generated (Without a value though)
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.
If value is not set then cmake will report an error and won't generate the project
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.
We should give the developer the option to build this without menuconfig, and as far as I can understand Kconfig, this requires a default value for int- Kconfig symbols.
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.
This value is taken into account only when developer selects hardware byte counting. When build with default configuration there are no issues with it. I don't want to select a default value here, as it should be explicitly set by developer if he decides to use hardware byte counting.
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.
Understood, now, thanks. So, I suggest you do as @ulfalizer has done in several similar cases, i.e. remove the "depends on" and add the whole Kconfig definition in if UART_0_NRF_HW_ASYNC ... endif #UART_0_NRF_HW_ASYNC
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.
There's some notes on int
defaults on the best practices page.
Usually, it's a good idea to give int
symbols defaults, because they don't default to zero (for semi-messy reasons). If no default is given, then the prj.conf
(or board defconfig
files, etc.) must set the symbol. Otherwise, you'll get a .config
that generates warnings when read back in, and that probably breaks the menuconfig
, because warnings are turned into errors in scripts/kconfig/kconfig.py
(there's an issue for it).
(Super nit: Trying to standardize making it # UART_0_NRF_HW_ASYNC
instead of #UART_0_NRF_HW_ASYNC
too btw. It's more common.)
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.
Re. if
vs depends on
, depends on
is cleaner if there's just a single symbol with the dependency.
If there's many symbols with the same dependencies in a row, if
is cleaner.
It's a bit subjective when you have just two symbols or the like. It's good to be aware that if FOO
is just a shorthand for adding depends on FOO
to all the stuff within at least.
People tend to read a bunch of things into Kconfig that aren't there (probably because the official docs aren't great). :)
drivers/serial/uart_nrfx_uarte.c
Outdated
u32_t ret; | ||
|
||
if (IS_ENABLED(CONFIG_UARTE_NRF_HW_ASYNC) && data->async->hw_async) { | ||
ret = nrfx_ppi_channel_alloc(&data->async->rx_cnt.ppi); |
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.
what about dppi? maybe it would be worth extracting dppi/ppi stuff to another file with simple call like ppi_configure
or gppi_configure
where g stands for generic :)
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.
There are some differences in how PPI and DPPI handle signals, I believe it can be done but it won't be a part of this PR
drivers/serial/uart_nrfx_uarte.c
Outdated
LOG_ERR("Failed to allocate PPI Channel, " | ||
"switching to software byte counting."); | ||
data->async->hw_async = false; | ||
data->async->rx_cnt.cnt = 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.
return error
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.
If we return error here, device won't be initialized and if this UARTE instance is set as shell output, user won't see any information what has gone wrong.
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.
A couple of minor comments for the beginning. I just started digging in the code (well, some comments there could help a lot...).
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.
Some more comments. Not finished reviewing.
22af70a
to
72d4b40
Compare
user_callback(dev, &evt); | ||
data->async->rx_buf = NULL; | ||
if (data->async->rx_next_buf) { | ||
evt.data.rx_buf.buf = data->async->rx_next_buf; |
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.
evt.type = UART_RX_BUF_RELEASED;
missing (the evt
structure might be modified in evt_handler
called from user_callback
).
BTW do you know why API does not define evt
in uart_callback_t
as a pointer to a constant structure?
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.
Good point, I will patch it later
data->async->rx_total_byte_cnt += evt.data.rx.len; | ||
evt.type = UART_RX_BUF_RELEASED; | ||
evt.data.rx_buf.buf = data->async->rx_buf; | ||
user_callback(dev, &evt); |
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.
What if the user decides to reuse the released buffer and provides it in a call to uart_rx_buf_rsp
from the event handler? API does not seem to forbid such scenario.
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_rx_buf_rsp
can be called only in response to UART_RX_BUF_REQUEST
drivers/serial/uart_nrfx_uarte.c
Outdated
@@ -286,8 +820,24 @@ static int uarte_nrfx_poll_in(struct device *dev, unsigned char *c) | |||
static void uarte_nrfx_poll_out(struct device *dev, |
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.
What about uarte_nrfx_poll_in
? Currently it will always return -1
when CONFIG_UART_ASYNC_API
is enabled.
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.
There is no possibility to handle poll_in while using asynchronous API, I will change it to return -EBUSY
50d6b24
to
be5f6d8
Compare
Fixes #12501 |
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.
Some comments/suggestions from my side
Hardware RX byte counting requires timer instance and one PPI channel | ||
|
||
config UART_0_NRF_HW_ASYNC_TIMER | ||
int "Timer instance" |
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.
If I understand kconfig properly (@ulfalizer can help) this will be a bit undefined, i.e. it's not really a "not-set", cause the value is not boolean. So, it appears to me that the macro is still generated (Without a value though)
a978297
to
e37d672
Compare
e37d672
to
224136e
Compare
5cc55c7
to
b545a6f
Compare
Rework uart_nrfx_uarte shim to work with asynchronous API. Signed-off-by: Mieszko Mierunski <[email protected]>
Add DPPIC to dts. Add HAS_HW_NRF_DPPIC to nrf91 soc. Signed-off-by: Mieszko Mierunski <[email protected]>
Enable TIMER1 by default in nrf9160_pca10090 so it can be selected by user for hardware byte counting in UARTE or other purpose. Signed-off-by: Mieszko Mierunski <[email protected]>
Modify driver to use PPI or DPPI depending on soc. Signed-off-by: Mieszko Mierunski <[email protected]>
Add new test case Signed-off-by: Mieszko Mierunski <[email protected]>
Add nrf9160_pca10090 to UART async test. Add myself as codeowner to uart_async_api tests. Signed-off-by: Mieszko Mierunski <[email protected]>
Adds power management to uarte shim. Fixes 12501 Signed-off-by: Mieszko Mierunski <[email protected]>
b545a6f
to
b1d41ba
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.
Kconfig nits fixed
Rework uart_nrfx_uarte shim to work with asynchronous API.
Fix power management issues
Fixes #12501