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

drivers: nrf: Rework UARTE shim for uart ASYNC API and add power management #13064

Merged
merged 7 commits into from
Mar 28, 2019

Conversation

Mierunski
Copy link
Collaborator

@Mierunski Mierunski commented Feb 5, 2019

Rework uart_nrfx_uarte shim to work with asynchronous API.

Fix power management issues

Fixes #12501

@zephyrbot
Copy link
Collaborator

zephyrbot commented Feb 5, 2019

All checks are passing now.

Review history of this comment for details about previous failed status.
Note that some checks might have not completed yet.

@Mierunski Mierunski force-pushed the nrfx_uarte_async_api branch from 8f07709 to 33f8947 Compare February 5, 2019 15:06
@codecov-io
Copy link

codecov-io commented Feb 5, 2019

Codecov Report

Merging #13064 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 082cf7a...b1d41ba. Read the comment docs.

@Mierunski Mierunski force-pushed the nrfx_uarte_async_api branch 2 times, most recently from eb8d65c to 29b7988 Compare February 6, 2019 10:22
@Mierunski Mierunski requested a review from ioannisg as a code owner February 7, 2019 10:17
@Mierunski Mierunski force-pushed the nrfx_uarte_async_api branch from d15a823 to fbcf9a9 Compare February 7, 2019 10:26
@Mierunski
Copy link
Collaborator Author

@jarz-nordic @nordic-krch @anangl ping

Copy link
Contributor

@nordic-krch nordic-krch left a 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"
Copy link
Contributor

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.

Copy link
Collaborator Author

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

Copy link
Contributor

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

Copy link
Member

@ioannisg ioannisg Mar 21, 2019

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)

Copy link
Collaborator Author

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

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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

Copy link
Collaborator

@ulfalizer ulfalizer Mar 26, 2019

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.)

Copy link
Collaborator

@ulfalizer ulfalizer Mar 26, 2019

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 Show resolved Hide resolved
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);
Copy link
Contributor

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 :)

Copy link
Collaborator Author

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

LOG_ERR("Failed to allocate PPI Channel, "
"switching to software byte counting.");
data->async->hw_async = false;
data->async->rx_cnt.cnt = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

return error

Copy link
Collaborator Author

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.

Copy link
Member

@anangl anangl left a 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...).

dts/bindings/arm/nordic,nrf-dppi.yaml Outdated Show resolved Hide resolved
dts/bindings/arm/nordic,nrf-dppi.yaml Outdated Show resolved Hide resolved
dts/bindings/arm/nordic,nrf-dppi.yaml Outdated Show resolved Hide resolved
soc/arm/nordic_nrf/Kconfig.peripherals Outdated Show resolved Hide resolved
soc/arm/nordic_nrf/nrf52/Kconfig.soc Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
Copy link
Member

@anangl anangl left a 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.

drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
@Mierunski Mierunski force-pushed the nrfx_uarte_async_api branch 3 times, most recently from 22af70a to 72d4b40 Compare February 20, 2019 09:36
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
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;
Copy link
Member

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?

Copy link
Collaborator Author

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

drivers/serial/uart_nrfx_uarte.c Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
drivers/serial/uart_nrfx_uarte.c Outdated Show resolved Hide resolved
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);
Copy link
Member

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.

Copy link
Collaborator Author

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 Show resolved Hide resolved
@@ -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,
Copy link
Member

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.

Copy link
Collaborator Author

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

@Mierunski Mierunski force-pushed the nrfx_uarte_async_api branch 2 times, most recently from 50d6b24 to be5f6d8 Compare February 26, 2019 13:47
@Mierunski
Copy link
Collaborator Author

Fixes #12501

Copy link
Member

@ioannisg ioannisg left a 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

drivers/serial/Kconfig.nrfx Outdated Show resolved Hide resolved
Hardware RX byte counting requires timer instance and one PPI channel

config UART_0_NRF_HW_ASYNC_TIMER
int "Timer instance"
Copy link
Member

@ioannisg ioannisg Mar 21, 2019

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)

dts/arm/nordic/nrf9160_common.dtsi Outdated Show resolved Hide resolved
@Mierunski Mierunski force-pushed the nrfx_uarte_async_api branch from a978297 to e37d672 Compare March 25, 2019 10:11
@Mierunski Mierunski added the bug The issue is a bug, or the PR is fixing a bug label Mar 25, 2019
ext/hal/nordic/Kconfig Outdated Show resolved Hide resolved
@Mierunski Mierunski force-pushed the nrfx_uarte_async_api branch from e37d672 to 224136e Compare March 25, 2019 14:40
@carlescufi carlescufi added this to the v1.14.0 milestone Mar 26, 2019
@carlescufi carlescufi requested a review from ulfalizer March 26, 2019 10:59
@carlescufi carlescufi changed the title drivers: nrf: Rework UARTE shim for uart ASYNC API. drivers: nrf: Rework UARTE shim for uart ASYNC API and add power management Mar 26, 2019
drivers/serial/Kconfig.nrfx Show resolved Hide resolved
drivers/serial/Kconfig.nrfx Show resolved Hide resolved
drivers/serial/Kconfig.nrfx Show resolved Hide resolved
@carlescufi carlescufi added the TSC Topics that need TSC discussion label Mar 26, 2019
@Mierunski Mierunski force-pushed the nrfx_uarte_async_api branch 2 times, most recently from 5cc55c7 to b545a6f Compare March 27, 2019 10:28
Mieszko Mierunski added 7 commits March 27, 2019 11:38
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]>
@Mierunski Mierunski force-pushed the nrfx_uarte_async_api branch from b545a6f to b1d41ba Compare March 27, 2019 10:38
@Mierunski Mierunski requested a review from ulfalizer March 27, 2019 11:45
Copy link
Collaborator

@ulfalizer ulfalizer left a comment

Choose a reason for hiding this comment

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

Kconfig nits fixed

@nashif nashif removed the TSC Topics that need TSC discussion label Mar 27, 2019
@nashif nashif merged commit 0b2946f into zephyrproject-rtos:master Mar 28, 2019
@Mierunski Mierunski deleted the nrfx_uarte_async_api branch March 28, 2019 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Drivers bug The issue is a bug, or the PR is fixing a bug platform: nRF Nordic nRFx
Projects
None yet
Development

Successfully merging this pull request may close these issues.